Sign in to follow this  
ajm113

Win32/OpenGL mouse detection question

Recommended Posts

How can I detect when the user is holding the right button down on a object in 3d space then lets say drag it a bit and release then that object selected would do action. Move pretty much where the mouse moved when the right button was hold down. I know I could do something like this for starters. int oldMouseX, oldMouseY; int newMouseX, newMouseY; so when the user clicks AND holds down the mouse button the position will get recorded in old x and y then drags a quick bit left (lets say) then it would get recorded too the new mouse position variable then think if the user's mouse was moving more to the left then up or down so OpenGL knows if it should rotate a object at 90 digress left when the cursor is over the object or group of objects. The scene will rotate around when the user wants too look at the object more closely to solve the puzzle. So this is kinda a headscratcher for me with 3D and 2d mouse pointer. Project Info VS2005 STD OpenGL Win32/C++

Share this post


Link to post
Share on other sites
My response assumes you already know how to work with the mouse in 2D. This also assumes that you know how to track and apply a transformation (such as the rotation you mentioned) to a 3D object in OpenGL.

The hard part is determining which object you click on. As you mentioned, the mouse works in 2D but you're clicking on a 3D scene. The process of finding out what you have clicked on in the 3D world is known as "picking." There are 2 ways to do this:

1. Construct a ray from the camera, through the viewport, into the 3D world and test it for intersections on the polygons of the object. If you find an intersection, then you know you've clicked on a particular object.

2. Use OpenGL's built-in selection mode. A great tutorial can be found here.

Once you have "picked" an object, you can modify your rotation, etc., as the mouse moves in 2D.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this