Jump to content
  • Advertisement
Sign in to follow this  
McCoder

2D Cursor Interacting with 3D Objects

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

Let's say I have a spinning cube on screen. I would want to build a simple move routine with the mouse, so whenever I click the cube, I would select it. But how would my mouse cursor know it touched a cube?

Share this post


Link to post
Share on other sites
Advertisement
There are multiple ways to do this, for example:
Mathematical: use glUnProject to project the mouse cursor from window coordinates into worldspace - since we're mapping 2D to 3D you will get a line (ray), then define each object as known geometrical shape (typically done with bouding boxes or bounding spheres), and it then becomes simple function of ray-box or ray-sphere intersection.

Color-based: when mouse button is clicked, render offscreen all the selectable objects in different colors, then use glReadPixels to read the color at the specific cordinates.

Share this post


Link to post
Share on other sites
I really can't "think" of that issue what you said. I'll search some code to cover the dryness. Any idea if I could use framebuffers? I was thinking when I create an object, store it's data into a hash of vertex - screen coord. And if the mouse hits that coordinate, it would select the cube or sphere or whatever.

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!