`177`

4.4.5.2. To SLERP or Not to SLERP (That’s Still the Question)

The jury is still out on whether or not to use SLERP in a game engine. Jonathan

Blow wrote a great article positing that SLERP is too expensive, and LERP’s

quality is not really that bad—therefore, he suggests, we should understand

SLERP but avoid it in our game engines (see htt p://number-none.com/prod-

uct/Understanding%20Slerp,%20Then%20Not%20Using%20It/index.html).

On the other hand, some of my colleagues at Naughty Dog have found that

a good SLERP implementation performs nearly as well as LERP. (For exam-

ple, on the PS3’s SPUs, Naughty Dog’s Ice team’s implementation of SLERP

takes 20 cycles per joint, while its LERP implementation takes 16.25 cycles per

joint.) Therefore, I’d personally recommend that you profi le your SLERP and

LERP implementations before making any decisions. If the performance hit

for SLERP isn’t unacceptable, I say go for it, because it may result in slightly

bett er-looking animations. But if your SLERP is slow (and you cannot speed

it up, or you just don’t have the time to do so), then LERP is usually good

enough for most purposes.

### 4.5 Comparison of Rotational Representations

We’ve seen that rotations can be represented in quite a few diff erent ways.

This section summarizes the most common rotational representations and

outlines their pros and cons. No one representation is ideal in all situations.

Using the information in this section, you should be able to select the best

representation for a particular application.

4.5.1. Euler Angles

We briefl y explored Euler angles in Section 4.3.9.1. A rotation represented via

Euler angles consists of three scalar values: yaw, pitch, and roll. These quanti-

ties are sometimes represented by a 3D vector [ θY θP θR ].

The benefi ts of this representation are its simplicity, its small size (three

fl oating-point numbers), and its intuitive nature—yaw, pitch, and roll are easy

to visualize. You can also easily interpolate simple rotations about a single axis.

For example, it’s trivial to fi nd intermediate rotations between two distinct yaw

angles by linearly interpolating the scalar θY. However, Euler angles cannot be

interpolated easily when the rotation is about an arbitrarily-oriented axis.

In addition, Euler angles are prone to a condition known as gimbal lock.

This occurs when a 90-degree rotation causes one of the three principal axes

to “collapse” onto another principal axis. For example, if you rotate by 90

degrees about the x-axis, the y-axis collapses onto the z-axis. This prevents

4.5. Comparison of Rotational Representations