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

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.

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.

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.

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

sZ = ( (float)(cos(DEGTORAD(camrx))) )

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

Thanks anyway.

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