Results 1 to 8 of 8

Thread: How to move forward - again

  1. #1
    Guest

    How to move forward - again

    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?

  2. #2
    Senior Member OpenGL Guru
    Join Date
    Jun 2000
    Location
    Gastonia, NC, USA
    Posts
    2,068

    Re: How to move forward - again

    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.

    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?

  3. #3
    Guest

    Re: How to move forward - again

    But the question is, when I rotate the camera, Z its not my front anymore...

  4. #4
    Senior Member Regular Contributor
    Join Date
    Oct 2001
    Location
    Princeton, NJ
    Posts
    380

    Re: How to move forward - again

    use sin and cos, i'd give more info but I have too much of a headache to think

  5. #5
    Senior Member OpenGL Guru
    Join Date
    Jun 2000
    Location
    Gastonia, NC, USA
    Posts
    2,068

    Re: How to move forward - again

    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...

  6. #6
    Guest

    Re: How to move forward - again

    nexusone.

    I undestand what your are saying. But please, I know that you understood my problem. Its just a liltle trigonometry formula... help me

  7. #7
    Senior Member OpenGL Guru
    Join Date
    Jun 2000
    Location
    Gastonia, NC, USA
    Posts
    2,068

    Re: How to move forward - again

    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

  8. #8
    Senior Member OpenGL Guru
    Join Date
    Jun 2000
    Location
    Gastonia, NC, USA
    Posts
    2,068

    Re: How to move forward - again

    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.

Similar Threads

  1. Rotations and Transformations, Move the player or move the world?
    By neurocase in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 01-14-2014, 12:41 AM
  2. Replies: 3
    Last Post: 12-11-2013, 08:52 AM
  3. trouble finding algorithm to move camera forward
    By openglbeginner in forum OpenGL: General
    Replies: 0
    Last Post: 10-02-2010, 08:12 PM
  4. Moving forward
    By Blain in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 01-23-2009, 08:25 PM
  5. Forward references
    By aliFritzsche in forum COLLADA
    Replies: 3
    Last Post: 07-19-2007, 12:50 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean