# How to use glTranslate to do "pan"?

I post this on Math and Algorithms yesterday. However, no one gave any suggestion. Perhaps I post it on a wrong place. I post it here and hope someone can help me. Thank you very much and sorry for the cross post.

I draw some object and would like to do “pan”. I have some trouble to reach what I want. Here is what I want: when I move my mouse, I hope the object I draw can follow my mouse point.

I tried 2 ways:
Way 1

1. LoadIdentity; 2) Rotate; 3) Translate; 4) Draw Object
The object move along the rotated coordinate system instead of the original coordinate system;

Way 2)

1. LoadIdentity; 2) Translate; 3) Rotate; 4) Draw Object
The object moves fine. However, when I try to rotate the object, I want to rotate it around the original coordinate system, not the local one, or the translated one.

How can I solve my problem? Thank you very much.

What do you mean by the “original” system? A picture would clear this out very much. I guess a glRotated(angle1); glTranslated(pos); glRotated(-angle1); glRotated(angle2); is what you are looking for. Here angle2 means the one you already have, angle1 is the other rotation.

But I’m still very confused, I’d say the original coordinate system is the local one (that’s what you get with glLoadIdentity()).

When I said “original” system, I mean the one that I get with glLoadIdentity(), or the fixed screen coordinate system. When I do “pan” operation with my mouse, I want the object to move in the screen coordinate system. After that, if I would like to rotate the object, I want it rotate around the screen coordinate system, or the center of the screen, instead of the translated one. Did I make it clear? Thank you very much for your reply. Any suggestion?

Might be my English which isn’t too good but I still don’t get the idea

So, what would you like to rotate the object around. The origin, the objects center or some other point; should the object move because of the rotation or stay put but just turn?

gardener,

gluUnProject() may be helpful to you:

http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/glu/unproject.html

In the simplest case, you can pass the resulting objX, objY, objZ values into a glTransform() call. Note, though, that the Z value you get back will depend on the value of winZ that you pass in. You can pass in 1.0 for winZ and then ignore the outputting objZ, replacing it with your own Z position, if you like.

• Sean

Thank you for your reply. When I send a “rotate” command, I want the object to rotate around the axes of the coordinate system after glLoadIdentity(), not the coordinate system attached to the object. When I do glTranslate, I also want the object to move along the the axes of the coordinate system after glLoadIdentity(), not the coordinate system attached to the object. In this case, no matter what is the state of the local coordinate system(object coordiate system), when I do “pan” operation, my object will follow my mouse to move left/right or up/down, instead of moving along the coordinate system attached to the object. Hope you understand my problem.