View Full Version : Clicking point in 3d space

10-17-2010, 05:23 AM
Dear forum,

If I want to select a 3d object (a 3d mesh) with my mouse (which is a (x,y)-pair), what is the best way to achieve this task?

Do I have to calculate a direction and cast a ray and test for intersection with the faces of the objects, or is it possible to use the matrices of OpenGL to check which object is projected on the (x,y) point which is clicked?


10-17-2010, 09:01 PM
You could search for "color picking."

Here's a link to one discussion of it:

http://www.opengl.org/discussion_boards/ubbthreads.php?ubb=showflat&Number=283313#Post2833 13

10-19-2010, 08:38 AM
Color picking will not work, since chess pieces generally have the same color (chess pieces of one kind).

I used gluUnProject and after some tweaking, I now have a ray with the camera-position as origin and a unit-vector as direction.

What is the best way to test the intersection of a ray with a 3d model? I have seen some algorithms where for every face of every 3d model a plane is calculated and tested for intersection and after that there is a check whether the intersection is within the the face. Are there other algorithms that deal with the intersection of a ray and a set of faces? Every face has n points (n >= 3) and a normal.


10-19-2010, 09:30 AM
The idea of color picking is to do a separate rendering without lighting/texture etc, with each selectable object having a different bright color. Then readpixels, then glClear, and do normal rendering.

10-19-2010, 02:06 PM
Indeed you are right. I'll take a look at this method since it seems to be every fast and easy. Thanks!