Panning and Zooming

Alienizer 109 Aug 09, 2012 at 04:28

I am trying to implement panning and zomming in OpenGL, which I did ok, but problem. I want to pan while keeping the click 3d point under the mouse while I mouse the mouse, and zooming, I want the 3d click point to also stay under the mouse when using the mouse wheel to zoom.

Does anyone have some suggestions or pseudo-code for this simple (but yet complicated for me) thing? I have a raycast function that gives me the 3d point under the mouse, but I have no clue how to apply this to what I’m trying to do!


3 Replies

Please log in or register to post a reply.

Alienizer 109 Aug 09, 2012 at 13:37

ok, I found a way for the zoom. I use camOrg += camDir*Delta; but for panning while keeping the clicked point under the mouse, I just can’t figure it out! please help :wacko:

moe 101 Aug 09, 2012 at 14:07

It reads a bit as though you missunderstand the problem behind what you want to do. Or… I don’t get what you mean :)

camOrg += camDir*Delta; reads as if you move the camera foreward. This is not the same as zooming. I would say that for zooming you would typically adjust the projection matrix rather than moving the camera. This means that while zooming your camera stays in one place. Therefore if your mouse position is not exactly along the center you can not zoom and keep the mouse in relative distance to the center of your screen. When you zoom, everything will move towards the outer egdes of your screen (exept the exact center). Think of a sniper in a FPS. You don’t have to move the player while you zoom in with the scope. You could reorient the camera to the point that you click and then zoom in.

As for the panning there is also a problem with your idea. Panning is essentialy a rotation around the up vector. You could make a 360 Degree rotation. It is impossible to keep the mouse click in possition while rotating like that. Maybe you need to be more specific about what you try to achieve.

Alienizer 109 Aug 09, 2012 at 14:46

For the zoom thing, yes, I move the camera in the direction of the point I clicked on, and it works great. I mean, it looks like it zoom, so it’s good enough for me, it’ only for my OBJ viewer, not for a game.

Panning, I want to move left/right/up/down the 2D screen, not rotate. But I want to keep the 3D clicked point (or the object) under the mouse while I drag the mouse, so you can predict how much to drag the mouse to have the scene moved to where you want it.