View Full Version : Drawing on an object.
12-28-2011, 05:11 AM
I'm importing an object file, let's say it's a plane for example. I want to be able to draw on the plane and I just can't seem to figure out how it's done. It's fairly trivial to know the x and y coordinates of the mouse click but what about the z coordinate? I need to be able to do some sort of ray tracing that shoots out a ray and tells me as soon as it reaches the object. What I'm trying to know is the z coordinate of the click which is on the object. That there are no other objects in my space is a good assumption for now.
12-28-2011, 07:29 AM
Transform the ray to object space coordinates for each object and test all triangles of the object for a intersection with the ray.
There are many possibilities to make this more efficient, some are:
- test the ray (in world coordinates) against the world space bounding volumes of the object
- use a hierarchical data structure on top of the object's bounding volumes to discard whole groups of objects
- if each object has a large number of triangles, use a hierarchical data structure for each object
A different approach is to read the depth buffer at the mouse position and transform the value from there into whatever coordinate system you need (probably world coordinates?). If you have multiple objects you won't know which one was hit though. To get that information you can assign each object a unique color and render all objects in their assigned color (lighting off) into the back buffer (or an FBO). In addition to the depth buffer you also read back the color at the mouse position which then identifies the object as well.
Powered by vBulletin® Version 4.2.3 Copyright © 2017 vBulletin Solutions, Inc. All rights reserved.