12
votes

I have designed a C++ class that abstracts the user from trackball rotation, zooming and panning. I have got the rotation (using trackball) and zooming working as expected. However, panning does not behave as expected. When I pick a point and drag, I expect that on finishing drag, the picked point continues to be under the mouse. My understanding of panning in perspective projection is as follows. The target and the camera position, both will be affected by a pan operation. The camera target and the camera position (eye) should be translated proportional to the drag. The proportionality (may not be constant) should be based on z depth.

Panning is straight forward in orthographic projection but poses a problem in perspective. It will be useful if one can explain the math and the implementation detail for OpenGL.

2
Are you changing cam or the whole world to get the results?huseyin tugrul buyukisik
I have implemented both. But I prefer to transform the world as it does not involve computing the inverse of model-view matrix. However, I am fine if I have a solution in either approach.Ram
"However, panning does not behave as expected. When I pick a point and drag, I expect that on finishing drag, the picked point continues to be under the mouse". Is this like your mouse button latched and didnt let go?huseyin tugrul buyukisik
Yes. When I press lButtonDown, I have picked an imaginary point under the mouse and while I continue to keep the lButtonPressed, I can move the mouse in order to pan the scene. A similar example in 2D is a pdf document viewer where the user grabs a point on the page and moves the view area.Ram
I bet you can get real good answers and reputation from gamedev.stackexchange.comhuseyin tugrul buyukisik

2 Answers

9
votes

I don't know about the OpenGL specifics, but if I understand your question correctly I can help out with the mathematics:

I assume you have already selected the object, by clicking the object and thus "sending" a ray through your scene that hits your object in the anchorpoint p.

To understand the following:

Panning with perspective projection

Now you drag your mouse along vector t. Using the intercept theorem you can easily calculate the vector s by which p has to be translated to "keep it under the cursor":

|p| / |q| = |s| / |t|

|s| = ( |p| / |q| ) * |t|

s is parallel to t, so it is t normalized multiplicated by |s|:

s = t / |t| * |s|

s = t / |t| * ( |p| / |q| ) * |t|

s = t * ( |p| / |q| )

If you are panning, you are doing the exact same thing, just that you are not shifting p by s, but you have to translate your whole scene by -s.

0
votes

It is impossible to have the finishing point under your mouse. Panning in perspective mode can be done in two ways. One is translating camera and the other is rotating camera. Translating camera will result in object rotation for user view. Rotation camera for panning has two constraints. one is not to change camera position and the other is to stop rotation with respect to camera direction. i.e., the axis of rotation should be parallel to the plane formed by camera right and up vectors.