Ray picking fails with glTranslatef? Why
Members - Reputation: 106
Posted 16 September 2011 - 01:23 PM
Draw some stuff with glTanslatef and glVertex3f and try to detect click.
For first object the picking works for the rest of the objects ("made by glTranslatef") the picking fails.
I tried so many functions (lineTriangleIntersect, RayTriangleIntersect etc etc) and all of them have same problem.
If glTranslatef comes into scene the picking fails on all objects, except first..
Why the hell it fails?
What's the point of ray picking then if i can only detect click on "ONE item at the time"?
I am so disappointed.Is it even possible to do ray picking if i draw stuff with glTranslatef?
Crossbones+ - Reputation: 2918
Posted 17 September 2011 - 08:37 AM
The symptoms you describe give me an idea that when you use translation / rotation, the ray and the object aren't any more in the same space which results the polygon hit test not working as intended.
On the other hand, object drawn with identity matrix makes the objects local space same as the world space which is why the code works.
In order to pick translated / rotated objects, you'll need to transform the polygons to the world space (transform all vertices by the objects transform matrix) or transform the view ray from world space to the objects local space (transform view ray by inverted objects model matrix).
I use the "transform view ray method" since it has smaller memory foot print.
Members - Reputation: 1625
Posted 19 September 2011 - 10:23 AM
Nobody ever used ray picking and nobody knows anything about it.
Nobody here gets paid to help you. Considering this is doing per triangle collision with objects in the world, its pretty obvious it you call glTranslatef() the graphics card draws it to translated, but you still just have the original data.
There are other ways to do raycast collision as well.