Reputation: 77
The problem that I am having is as follows. When I rotate my spaceship up (pitch) and rotate it at a full 90 degrees in the pitch, it stands up straight, and then try to rotate it again on the y-axis the model now rotates in the same fashion as a roll in the starting position.
Now my question, how can I fix this? How can I make sure my model always rolls when I want it to roll, always pitch when I want it to pitch, etc. Instead of what it does now.
I'm using c++ and opengl.
Upvotes: 1
Views: 112
Reputation: 6145
As has been pointed out already, you're seeing Gimbal Lock as a result of the way you're using Euler angles to perform rotations.
Quaternions are not the only solution, however. You can instead construct a 4x4 matrix to represent an object's current orientation, and apply relative rotations to it each time you change facing. It isn't perfect, as you need to keep track of 16 values per object instead of 4 for a quaternion, and in order to deal with floating point rounding errors you'll need to periodically normalise things so your orientation matrix doesn't become a skew transform. On the other hand, it is conceptually simple and pretty quick to put together.
Upvotes: 1