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?
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.
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.
Indeed you are right. I’ll take a look at this method since it seems to be every fast and easy. Thanks!