Trouble with camera translation using mouse

Started by
0 comments, last by mrbastard 15 years, 9 months ago
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?
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.
[size="1"]

This topic is closed to new replies.

Advertisement