PDA

View Full Version : How to move forward - again

08-08-2002, 09:03 AM
glTranslatef(x,y,z);
glRotatef(ax,1,0,0);
glRotatef(ay,0,1,0);
glRotatef(az,0,0,1);

How to calculate the correct x,y,z to make me move forward,backward,right and left?

nexusone
08-08-2002, 10:41 AM
Depends on the size of your world and unit that you are using.

let's use Z as our forward axis.

if( Object.forward == TRUE )z++; // The number we give to Z is based on our world size.
You may want to play around to see what value gives you the smoothes movement.
The same goes with turning right of left, start with 1 and go from there.

What each variable does, at least in a first person shooter...

Z axis is our forward and backward movement.
X axis would be strafe right of left(side step).
Y axis is our up/down movement.

ax look to the right or left and direction of travel on the x plane.
ay is look up/down
az ... rotating your whole body... 180 would be your standing on your head. http://www.opengl.org/discussion_boards/ubb/smile.gif

Originally posted by MyNameIsJohnny:
glTranslatef(x,y,z);
glRotatef(ax,1,0,0);
glRotatef(ay,0,1,0);
glRotatef(az,0,0,1);

How to calculate the correct x,y,z to make me move forward,backward,right and left?

08-09-2002, 09:11 AM
But the question is, when I rotate the camera, Z its not my front anymore...

chowe6685
08-09-2002, 09:18 AM
use sin and cos, i'd give more info but I have too much of a headache to think

nexusone
08-09-2002, 11:29 AM
You have two planes.

One is your worlds XYZ plane.
Two is your person's XYZ.

Z is always your front, thought your not facing the worlds Z. Just like if you are walking north or south, ether direction you are still moving forward.

Remember in openGL your camara can not move, what happens is you move your world around it.

Originally posted by MyNameIsJohnny:
But the question is, when I rotate the camera, Z its not my front anymore...

08-09-2002, 12:30 PM
nexusone.

I undestand what your are saying. But please, I know that you understood my problem. Its just a liltle trigonometry formula... help me http://www.opengl.org/discussion_boards/ubb/biggrin.gif

nexusone
08-09-2002, 06:45 PM
Maybe later I will feel like finding some code to post... kind of late here.

but it has to do with sin/cos to find movement along a angle vector.

Originally posted by MyNameIsJohnny:
nexusone.

I undestand what your are saying. But please, I know that you understood my problem. Its just a liltle trigonometry formula... help me http://www.opengl.org/discussion_boards/ubb/biggrin.gif

nexusone
08-11-2002, 11:50 AM
Back to the subject of movement....

xa = cos(angle); Where angle is direction of movement.
ya = sin(angle);

player.x = player.x + xa * rate;rate is => 1, the higher the number the faster the movement.
player.y = player.x + ya * rate;

// In your drawing routine something like this.

glTranslatef(player.x, player.y, 0); move player the correct position.
glRotatef(angle, 0,0,1); rotate player to correct direction.
draw_player.

note this is sample code not everything needed is presented here.

player.x and player.y keep track of player current location.