Jump to content
  • Advertisement
Sign in to follow this  
Cacks

OpenGL Mouse Selection Of Objects

This topic is 4705 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

Hi guys, I want to select objects in my OpenGL renderer & select them with the mouse in order to move them. How would I go about this? Thanks for any help given!

Share this post


Link to post
Share on other sites
Advertisement
There are several ways, but the two most common are probably:

1. Use OpenGL 'feedback' mode. Set up a 'picking matrix' with gluPickMatrix() (or whatever the function is); this will restrict the frustum to a small area around the mouse position, more or less. Then do a 'fake' rendering pass, where you don't actually draw onscreen. Anything that intersects the frustum will trigger a callback and return the ID of the object (which you assign).

2. Use gluUnproject() and a little vector math to create a picking ray. Intersect geometrically with your objects or their bounding volumes to find which should be selected.

The first option might be easier if you don't have much experience with collision detection. More info here, here, and in the Red Book.

Share this post


Link to post
Share on other sites
Or you could do multiple render target or use the stencil buffer to store the object id in the buffer. Then you simply readback the id on the mouse screen position and check whats the id

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!