Skip to main content
GameDev.net gamedev.net
🔒 Locked

Selecting Objects?

Started by Yofar Sep 9, 2005 at 4:41 PM 3 replies 550+ views
Original Post
Yofar
Yofar
I am working on an interactive chess board and am hung up on how to select the different pieces. Does anyone know how I should go about doing this. I haven't been able to find anything even telling me where to start. Any help would be much appreciated.
SiCrane
SiCrane
You might want to start with gluUnproject().
hplus0603
hplus0603
Typically, you have a representation of your scene that's not just graphical, but physical. You then project a ray through space in the direction the user clicked, and see what object the ray intersects.

If you want to do it with OpenGL, you can use GL picking (ick!) or render the scene with each object being a different color (turn off lighting and texturing), and read back the color that the clicked pixel has.
enum Bool { True, False, FileNotFound };
rip-off
rip-off
its called picking...

google for it

see http://www.lighthouse3d.com/opengl/picking/ (random example from google)

Zakwayda
Zakwayda
Just to be a little more specific, there are a couple of ways to do picking in OpenGL. The above link discusses picking in OpenGL selection mode. With this method you render your scene twice, once for display and once for picking. Before rendering for picking, you set up a special pick matrix which restricts your view frustum to a small volume that more or less corresponds to a ray through the mouse position. OpenGL can then be set up to inform you whenever a rendered object intersects this frustum; such objects can be considered picked.

Another method is geometrical, and as suggested earlier can be implemented using gluUnProject(). The standard method is to unproject two points. Each is constructed from the mouse x and y (adjusted to be in window coordinates); the z values are chosen to correspond with the depth range (usually [0,1]). These two points form a line segment in world space that can be used to pick objects. As OpenGL provides no collision detection support, determining which objects the segment (ray) intersects is up to you.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.