Using Quaternions for OpenGL Rotations [duplicate]

All you have done is effectively implement Euler angles with quaternions. That’s not helping.

The problem with Euler angles is that, when you compute the matrices, each angle is relative to the rotation of the matrix that came before it. What you want is to take an object’s current orientation, and apply a rotation along some axis, producing a new orientation.

You can’t do that with Euler angles. You can with matrices, and you can with quaternions (as they’re just the rotation part of a matrix). But you can’t do it by pretending they are Euler angles.

This is done by not storing angles at all. Instead, you just have a quaternion which represents the current orientation of the object. When you decide to apply a rotation to it (of some angle by some axis), you construct a quaternion that represents that rotation by an angle around that axis. Then you right-multiply that quaternion with the current orientation quaternion, producing a new current orientation.

When you render the object, you use the current orientation as… the orientation.

Leave a Comment