Jump to content
  • Advertisement
Sign in to follow this  
billconan

how to pick up object using mouse?

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

Advertisement
What you want is a technique called 'Picking.' It involves projecting a ray from the eyepoint, through the point on the near plane that you clicked on, and out into your scene (you then collide it with objects to find out what it hits). If you're using DirectX there are D3DX functions that can help you with it; if you're using OpenGL I think there might be some GLU functions for it.

Share this post


Link to post
Share on other sites
I've you're using OpenGL, take a look here; http://www.mevis.de/~uwe/opengl/glSelectBuffer.html

:)

Share this post


Link to post
Share on other sites
An alternative approach is to have a second frame buffer which holds a second render of your scene, but this time you don't bother lighting the objects at all but set the colour of each one to a unique ID colour, then when the user clicks on the screen the x and y coordinates can be used to get the appropriate location in the offscreen buffer, using the colour at that location to retrieve the object ID.

Advantages : No ray/object intersection tests are needed.
Disadvantages : You have to render twice.

hope this helps

Share this post


Link to post
Share on other sites
Sorry just read ur post again, tutorial available :

http://www.codeguru.com/Cpp/G-M/opengl/article.php/c5579/

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!