Jump to content
  • Advertisement
Sign in to follow this  
Yofar

Selecting Objects?

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

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.

Share this post


Link to post
Share on other sites
Advertisement
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.

Share this post


Link to post
Share on other sites
its called picking...

google for it

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

Share this post


Link to post
Share on other sites
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.

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!