Jump to content
  • Advertisement
Sign in to follow this  
Odiee

OpenGL Trouble with camera translation using mouse

This topic is 3735 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. I'm using openGL to render the scene and GLUT to display window. Currently I have a mouse routine that pass callback values of mouse_x and mouse_y coordinates to another function when button is pressed. I want to make the camera move for (x,y) units to left/right or up/down based on the offset from the mouse starting point. (when button is pressed, start is (0,0). In other words, I want to "grab" the scene and when I pull mouse down the y axis, the camera goes up the y axis and vice versa on x axis. Anyone know how to do this or some article about it?

Share this post


Link to post
Share on other sites
Advertisement
OK, so you know the translation you want to perform in screenspace, and need to know the transform to apply in worldspace to reproduce it.

This is simplified quite a bit if your viewing angle is restricted - e.g. top down.

The first thing to do is to unproject your screenspace points to get get worldspace line segments. Google 'gluunproject' and you should find lots of forum posts about it.

Then you'll have to decide what points on the line segments to use. A common choice would be where the lines intersect your ground plane.

Now that you have 2 points in worldspace, you can easily find the needed translation from one to the other.

Hope that makes sense.

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!