
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.

Senior Member
OpenGL Guru
Re: Rotations
Erm, are you sure these functions are correct?
Rotation about the yaxis does not affect the ycoordinates. 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.

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.

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 08222000).]
Posting Permissions
 You may not post new threads
 You may not post replies
 You may not post attachments
 You may not edit your posts

Forum Rules