# How to convert pitch and yaw to x, y, z rotations?

I tried asking this on the game development forum but didn't get a response and since it's pretty much math I figured I ask here.

I'm trying to make a ship fly around in 3-D space.

Update: I'm having a slightly hard time describing this so I made a little animation to show what I'm talking about: http://www.youtube.com/watch?v=4TyGQX_iRI4&feature=youtu.be

What is the function taking pitch and yaw and produces the x, y and z rotations to achieve the same orientation?

Here's a snippet of code I have to show where I got stuck - this produces a wobble effect instead of the smooth rotation in the plane that object is currently in.

// Thrust +Y / Forward
if (currentKeyboardState.IsKeyDown(Keys.I))
{
this.ship.AccelerationY += (float)Math.Cos(this.ship.RotationZ) * accel;
this.ship.AccelerationX += (float)Math.Sin(this.ship.RotationZ) * -accel;
this.ship.AccelerationZ += (float)Math.Sin(this.ship.RotationX) * accel;
}

// Rotation +Z / Yaw
if (currentKeyboardState.IsKeyDown(Keys.J))
{
this.ship.RotationAccelerationZ += (float)Math.Cos(this.ship.RotationX) * accel;
this.ship.RotationAccelerationY += (float)Math.Sin(this.ship.RotationX) * accel;
this.ship.RotationAccelerationX += (float)Math.Sin(this.ship.RotationY) * accel;
}

// Rotation -Z / Yaw
if (currentKeyboardState.IsKeyDown(Keys.K))
{
this.ship.RotationAccelerationZ += (float)Math.Cos(this.ship.RotationX) * -accel;
this.ship.RotationAccelerationY += (float)Math.Sin(this.ship.RotationX) * -accel;
this.ship.RotationAccelerationX += (float)Math.Sin(this.ship.RotationY) * -accel;
}

// Rotation +X / Pitch
if (currentKeyboardState.IsKeyDown(Keys.F))
{
this.ship.RotationAccelerationX += accel;
}

// Rotation -X / Pitch
if (currentKeyboardState.IsKeyDown(Keys.D))
{
this.ship.RotationAccelerationX -= accel;
}

-
What is your reference coordinate system? The fact that you associate pitch with the x axis implies a coordinate system relative to the vehicle, while your handling of thrust suggests a frame fixed in space. –  MvG Nov 2 '12 at 8:49
I'm kind of learning as I go - my goal is to get the effect of a motor boat in 3D space, except when pitch is applied, the ocean surface tilts with it... does that makes sense? I appreciate any pointers.. from readon more on my own I think I might need to learn more about quaternions –  Aaron Anodide Nov 2 '12 at 9:12
Your comment doesn't answer mine: do you want to describe the rotation of the scene relative to a reference frame fixed with the craft, or do you want to describe the rotation of the craft with a reference frame fixed to the scene? Or in other words, are you looking down on the craft from a fixed location, or are you looking out the windshield from a seat fixed within the craft? Quaternions sure would be useful. Are your x/y/z rotations simultaneous or one after the other? –  MvG Nov 2 '12 at 10:43