Rotations and angular velocity

I'm new to 3D-game programming and I'm having some trouble making objects rotate the way I want them to. I just read Glenn Fiedler's tutorials on game physics, awesome stuff by the way! (http://gafferongames.com/game-physics/physics-in-3d/)

Now, I'm trying to make a simple space sim. If you imagine a spaceship that is not yet rotated in any way (up = Vector3.Up etc..). If I apply some yaw-input (which would increase the angular velocity) I'd then expect the ship to rotate around the up-vector of the ship (which is also the world y-axis at the moment). That works fine. If I would then roll the ship a little bit, I'd expect the ship to roll around its forward axis, but it should also continue to spin around the world y-axis.

At the moment with my implementation instead of keeping it's momentum around the y-axis, it continues to spin around its local up-vector - which is obviously wrong.

I think I understand why this happens with my current implementation, I'm just not sure how to fix it.

This is what I have at the moment, with some minor simplifications (runs every update):

Vector3 addedRotation = new Vector3(pitchInput, yawInput, rollInput);

rotation.Normalize();

Quaternion w = new Quaternion(rotationVelocity, 0);
rotation += Quaternion.Multiply(w * rotation, 0.5f);


I'd be very happy if someone could point me in the right direction here. If anything needs clarification, please tell me and I'll try explain it better.

Thanks for taking the time!

• Will have to take a closer look at this, but one thing I can say is that 'rotationVelocity += addedRotation' almost certainly isn't what you want; you can't simply add Y/P/R values to add rotations, but instead need to properly compose them (via something like quaternion or matrix multiplication). Commented Sep 11, 2013 at 23:48
• Hm, yes. I don't even think what I want is possible with a rotation around a single axis. After yawing and rolling a little bit, I think I basically want one rotation around the up vector (up vector at the time of adding yaw rotation that is - so world y-axis in my example above) and one around the forward axis simultaneously and independently from each other. Commented Sep 12, 2013 at 0:21
• Note that every rotation can be expressed as a rotation around a single axis (this is actually a fairly deep theorem, and related to quaternion representations) - but that's only true for static rotations, and when you're animating you can certainly expect some 'tumble'. Commented Sep 12, 2013 at 0:27

rotationVelocity += addedRotation is actually fine. Angular velocity is a vector and adds in the usual way.
Also note that the quaternion renormalization, rotation.Normalize(), should probably be done after you add 0.5 * w * rotation, not before. (Also, you seem to be missing the delta time, which should be multiplied in there as well - your angular velocities are in radians per frame instead of radians per second.)