Jump to content
  • Advertisement
Sign in to follow this  
BytePtr

glTranslatef independent of camera rotation. How to do it?

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
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:

http://nehe.gamedev.net/tutorial/loading_and_moving_through_a_3d_world/22003/

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 this post


Link to post
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 this post


Link to post
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).

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!