1
$\begingroup$

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; } 
  • 0
    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](http://tinyurl.com/yuaee9) sure would be useful. Are your *x/y/z* rotations [simultaneous](http://tinyurl.com/cryg8sh) or one after the other?2012-11-02

0 Answers 0