Using the mouse in OpenGL scene

Is there an easy way to take the mouse 2D pixel coordinates to rotate around and pan in the OpenGL scene? I am using the basic OpenGL with no extentions for my project and I need to be able to manipulate the scene area. Any example code would be helpful.

Thanks,

James

Hello,
what is your environment ? Do you use GLUT or do you use opengl within an mfc application ?
Usually with glut you can set a callback function to fetch the mouse position and button states. Within an mfc application you can add message handlers for
mouse events. Take a look at some glut tutorials. Actually capturing mouse positions is decoupled from what you want to do in your scene.
Here are the two functions that capture mouse positions and buttons within the GLUT library.
https://www.opengl.org/resources/libraries/glut/spec3/node51.html

regards,
lobbel

I do not use GLUT or mfc. I am using only the OPENGL standard extensions on Windows operating system. I have no problem capturing the mouse position in screen coordinates (Pixels). What I need is to convert those pixels into the actual scene coordinates so that I can have the ability to move the camera around within the scene. I have created something basic, but it does not work so well. I was hoping that there was some standard function that handles this since it is a common thing to do in the graphics environment. Why re-invent the wheel??? We are suppose to strengthen ourselves on code reuse, so I am looking for said functions to remove that portions of my task.

Regards,

James

In modern OpenGL there is no concept of a ‘scene’ since you have to send your custom matrices. From mouse position or mouse speed on both axis, it is easy to influence polar coordinates, then convert them to cartesian coordinates and build your view matrix from there.

Hello James,
of course there is some source how to handle that. But there are also differnet ways to do.
Here is a link to a great series of videos that handle moste of modern opengl topics. If you follow the link
you should move to a video that implements a first person style camera class. There is also a link to the complete source
code.

You can use the mouse delta between new x and y position and old x and y position to
determine how fast rotate you camera left and up.

regards,
lobbel