Mouse Selection Of Objects

Started by
3 comments, last by Promag 18 years, 5 months ago
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!
Reject the basic asumption of civialisation especially the importance of material possessions
Advertisement
Check out gluPickMatrix or gluUnproject.
______________________________________________________________________________________The Phoenix shall arise from the ashes... ThunderHawk -- ¦þ"So. Any n00bs need some pointers? I have a std::vector<n00b*> right here..." - ZahlmanMySite | Forum FAQ | File Formats______________________________________________________________________________________
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.
Easiest way I can think of would be to use picking. gluProject and gluUnProject may also come in handy.

edit: beaten by a wide margin
"I must not fear. Fear is the mindkiller. Fear is the little death that brings total obliteration. I will face my fear. I will permit it to pass over me and through me. And when it has gone past me I will turn to see fear's path. Where the fear has gone there will be nothing. Only I will remain." ~Frank Herbert, DuneMy slice of the web
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

This topic is closed to new replies.

Advertisement