Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 4 of 4

Thread: Rotations

  1. #1
    Junior Member Newbie
    Join Date
    Aug 2000
    Posts
    2

    Rotations

    I am writing a flight simulator which has the ship viewed in 3rd person 10 units form the camera.Both are looking down the Z axis.

    When the camera is rotated around the Y axis I caculate the ships XYZ coords with the folowing equation.

    sY = (float)(-sin(DEGTORAD(camry)))*10;
    sX = (float)(-sin(DEGTORAD(camrx)))*10;
    sZ = (float)(-cos(DEGTORAD(camrx)))*10;
    shipz = sZ - camz;
    shipx = sX - camx;
    shipy = sY - camy;

    When the camera is rotated around the X axis I caculate the ships XYZ coords with the folowing equation.

    sY = (float)(-sin(DEGTORAD(camry)))*10;
    sX = (float)(-sin(DEGTORAD(camrx)))*10;
    sZ = (float)(cos(DEGTORAD(camry)))*10;
    shipz = sZ - camz;
    shipx = sX - camx;
    shipy = sY - camy;

    The problem I having is how do I get the two equations to work together, as they both calculate different sZ values for the plane.

    Thanks for any help.

  2. #2
    Senior Member OpenGL Guru
    Join Date
    Feb 2000
    Location
    Sweden
    Posts
    2,982

    Re: Rotations

    Erm, are you sure these functions are correct?

    Rotation about the y-axis does not affect the y-coordinates. But I can't see why you would want to touch it at all...

    Anyways, just multiply them. Well, make sure you multiply that 10 only once. If you would multiply the two sZ you got now, you would end up with a multiplication of 100.

  3. #3
    Junior Member Newbie
    Join Date
    Aug 2000
    Posts
    2

    Re: Rotations

    Yeh got my angles messed up when I posted
    the message.
    Tryed multiplying the two but still dosnt
    work properly.

    sX = (float)(-sin(DEGTORAD(camry)))*10;
    sY = (float)(-sin(DEGTORAD(camrx)))*10;
    sZ = ( (float)(cos(DEGTORAD(camrx))) )*
    ( (float)(-cos(DEGTORAD(camry))))*10;

    shipz = sZ - camz;
    shipx = sX - camx;
    shipy = sY - camy;

    Thanks anyway.

  4. #4
    Junior Member Newbie
    Join Date
    Jul 2000
    Location
    Reno NV USA
    Posts
    16

    Re: Rotations

    The easiest way to solve this problem to use roll pitch and yaw. Heres what I mean:

    First define roll as rotation around the z axis. Define pitch as the rotation around the x axis and yaw as rotation around the y axis. Then do something like this:

    float pitch;
    float yaw;
    float roll;

    // Get joystick data
    GetJoystickData (&pitch, &yaw, &roll);

    glMatrixMode (GL_MODELVIEW);
    glPushMatrix();
    glRotatef (pitch, 1.0f, 0.0f, 0.0f);
    glRotatef (yaw, 0.0f, 1.0f, 0.0f);
    glRotatef (roll, 0.0f, 0.0f, 1.0f);

    // Render plane
    renderPlane();

    glPopMatrix();

    // Set up the camera
    glPushMatrix ();
    glRotatef (-pitch, 1.0f, 0.0f, 0.0f);
    glRotatef (-yaw, 0.0f, 1.0f, 0.0f);
    glRotatef (-roll, 0.0f, 0.0f, 1.0f);

    // Render the rest of the scene
    renderScene ();

    // balance the matrix stack
    glPopMatrix();

    Notice that the camera is the inverse of rotations that are applied to the plane.

    [This message has been edited by Greg (edited 08-22-2000).]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •