1
votes

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.

1
Sounds like gimbal lock. Use quaternions to manage your rotations.genpfault
You have encountered gimble lock. I suggest looking at quaternions. I don't have much experience and will be of little help, but I know they solve the gimble lock issue. flipcode.com/documents/matrfaq.htmlCharlie
Thank you, both of you this indeed appears to be the problem. So does this mean I need to go around the normal rotations of opengl and make my own? So no more glRotatef(mRotation.x, 1.0f, 0.0f, 0.0f); But my own entire fix?Roy Heijmans
Correct. Most quaternion systems can spit out a glMultMatrix()-compatible matrix that you can substitute in where your glRotatef()s were.genpfault

1 Answers

1
votes

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.