In this tutorial, you have learned the following:
A fixed sequence of successive rotations can prevent other rotations from contributing to the object's orientation. It also makes it difficult to correctly orient the object in an intuitive way, since previous rotations have effects on later ones.
Quaternions are 4-dimensional vectors that can encode an orientation. They can be used for successively applying small rotations to an orientation. Matrices fail at this because of the difficulty of orthonormalizing them to avoid floating-point error accumulation.
Quaternions work almost identically to matrices, in so far as they specify orientations. They can be constructed directly from an angle/axis rotation, and they can be composed with one another via quaternion multiplication.
One can transform a matrix, or a quaternion with another matrix or quaternion, such that the resulting transform is specified in a different space. This is useful for applying rotations to an object's orientation that are in camera-space,, while the object's orientation remains a model-to-world transform.
Quaternions can be interpolated, either with component-wise linear interpolation or with spherical linear interpolation. If the angle between two quaternion vectors is greater than 90°, then the interpolation between them will move indirectly between the two.
Try doing the following with the orientation tutorials.
Modify the Interpolation tutorial to allow multiple animations to be
active simultaneously. The
Orientation class is
already close to being able to allow this. Instead of storing a single
Orientation::Animation object, it should store a
std::deque of them. When the external code adds a
new one, it gets pushed onto the end of the deque. During update, the
front-most entries can end and be popped off, recording its destination
index as the new current one in the
class. To get the orientation, just call each animation's orientation
function, feeding the previous result into the next one.
Change the Interpolation tutorial to allow one to specify whether the long path or short path between two orientations should be taken. This can work for both linear and spherical interpolation.
This discussion has focused on the utility of quaternions in orienting objects, and it has deftly avoided answering the question of exactly what a quaternion is. After all, saying that a quaternion is a four-dimensional complex number does not explain why they are useful in graphics. They are a quite fascinating subject for those who like oddball math concepts.
This discussion has also glossed over a few uses of quaternions in graphics, such as how to directly rotate a position or direction by a quaternion. Such information is readily available online.