# glTranslatef independent of camera rotation. How to do it?

This topic is 2954 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I have a cam, which i move by VK_LEFT, VK_UP, VKDOWN and VK_RIGHT keys.
Im rotating cam using glRotatef(ax, 0, 0) and glRotatef(0, 0, ay.

I just subtract / add value of 1 from cam X,Y coord.

But the arrow keys only work fine until i rotate cam. If i run my app and do not rotate the cam, the arrow keys do what they should ( they move cam to right coordinates.)
If i rotate scene for ex: by 90 degrees, then the VK_LEFT acts like VK_UP is pressed.

VK_UP acts like VK_RIGHT is pressed and so on. So it should be independent of cam rotation. So that VK_LEFT always moves scene to left, no matter what rotation the cam has currently and so on.

Sin / Cos and current cam angle is probably needed but i need help with that.

I can't figure out the formula, so it will work as i want.
Can somebody please tell me how this should be done?

Thanks.

##### Share on other sites
because you are restricting yourself to move only on the worlds x,y. Imagine standing on a giant painted plus + sign on the ground. Rotate 45 degrees, your forward vector is not aligned with either edge of the + sign anymore but it is some random direction. Its like:

//walk forward
x += sin();
z -= cos();

something like that.

##### Share on other sites
Hey friend,

i am not quite sure if i understood your problem right but it sounds like u have a problem which i had too :-)
I solved it with this tutorial:

A little bit down below u can find some math which adjusts your camera and rotates the world around the player to simulate moving and looking up/down.

Bye
Markus

##### Share on other sites

because you are restricting yourself to move only on the worlds x,y.

Well, almost. Z is handled by mouse wheel.
But yes, Z doesn't count in this case. It has it's own handler.

##### Share on other sites
Either you want to move before you rotate or after. Translations are always along LOCAL axes, so you will have to translate before rotation. If you setup your camera purely with rotate and translate calls you must be using the inverse order of inverted transformations, but you still just have to change the order or translations and rotations.

It's all about understanding transformation matrices and the concept of local coordinate systems. As long as you treat those as magical black box, it will just be fiddling around until the result seems to be right (or worse, stubbornly thinking in global space and insisting that OpenGL is doing everything "backwards" as someone tried to tell us at University).

• ### Game Developer Survey

We are looking for qualified game developers to participate in a 10-minute online survey. Qualified participants will be offered a \$15 incentive for your time and insights. Click here to start!

• 9
• 11
• 15
• 21
• 26