Jump to content
  • Advertisement
Sign in to follow this  
BytePtr

OpenGL Ray picking fails with glTranslatef? Why

This topic is 2494 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Let's take simple ray picking with OpenGL.

http://www.alsprogra...n_tutorial.html

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?

Share this post


Link to post
Share on other sites
Advertisement
Hi,

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.

Cheers!

Share this post


Link to post
Share on other sites
Instead of pissing and moaning about nobody knowing about picking, why don't you try posting some code so we can see what you are screwing up.

Share this post


Link to post
Share on other sites
[color=#1C2837][size=2]Nobody ever used ray picking and nobody knows anything about it.


Amazing.[/quote]
[color=#1C2837][size=2]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.
[color=#1C2837][size=2]

[color=#1C2837][size=2]There are other ways to do raycast collision as well.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!