Game Development Reference
In-Depth Information
Figure 4.18 A 90° rotation about the z-axis causes gimbal lock.
Finally, there is a problem of smoothly interpolating between two orientations.
Suppose a game has an arrow that points to the next objective. Once that objective
isreached,thearrowshouldchangetopointtothesubsequentone.Butitshouldn't
just instantly snap to the new objective, because an instant change won't look
great. It should instead smoothly change its orientation, over the course of a
second or two, so that it points at the new objective. Although this can be done
with Euler angles, it can be difficult to make the interpolation look good.
Because of these limitations, using Euler angle rotations is typically not the pre-
ferred way to represent the rotation of objects in the world. Instead, a different
math construct is used for this.
Quaternions
As described by mathematicians, quaternions are, quite frankly, extremely confus-
ing. But for game programming, you really can just think of a quaternion as a
waytorepresentarotationaboutanarbitraryaxis.Sowithaquaternion,youaren't
limited to rotations about x, y, and z. You can pick any axis you want and rotate
around that axis.
Another advantage of quaternions is that two quaternions can easily be interpol-
ated between. There are two types of interpolations: the standard lerp and the
slerp , or spherical linear interpolation. Slerp is more accurate than lerp but may
Search WWH ::




Custom Search