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);
addedRotation = Vector3.Transform(addedRotation, rotation);
rotationVelocity += addedRotation;
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!