Jump to content
  • Advertisement
Sign in to follow this  
phling

OpenGL mapping mouse cursor position to 3D world geometry

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

hi gamedev forums, i'm not actually working on a game, yet looking for a solution to a problem most likely encountered in 3D game programming so i came here to ask for help. using OpenGL via Processing, there is a camera of which i know the location and the lookAt point. Also the up-vector is always 0,1,0. (y is probably reversed compared to standard OpenGL? doesn't really matter). This camera behaves mostly like a standard 3D shooter, it can move around, rotate horizontally and tilt up/down up to 90 degrees. no roll. now on the plane that is your screen panel, you have a mouse (or in this case, tablet) cursor. i need to be able to get the game world 3D coordinates of this mouse cursor in order to use it to draw things into the 3D space with the tablet pen. i'm having troubles to get the rotations right. so i've read a bit about Quaternions… and have concluded that i don't get them. is why i'm asking here now.

Share this post


Link to post
Share on other sites
Advertisement
You can calculate the reverse transformation and multiple it by the mouse position, or just use gluUnProject to calculate it for you.

Share this post


Link to post
Share on other sites
You don't need quaternions. What you're wanting to do is called 'picking', and is discussed fairly frequently here on the forums. A typical solution is to 'unproject' the mouse coordinates into world space, and use the resulting coordinate(s) to build a picking ray or segment. You can unproject the mouse coordinates at the near plane and use the camera position as the origin for the ray (which will work for perspective projections), or unproject at the near and far planes and construct a 'picking segment' (while will work for both orthographic and perspective projections).

For more info on the subject, try searching the forum archives for 'opengl picking'.

Share this post


Link to post
Share on other sites
ah yes, i guess what i'm doing is only the first part of picking, as i don't even need to reach into space and calculate intersections. So if this 'unprojecting' takes window coordinates and unprojects them into 3d coordinates, it is exactly what i need.

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!