Game Development Reference

In-Depth Information

Figure 11-3. Quaternion rotation

You can readily see that quaternions, when used to represent rotation or orientation,

require you to deal with only four parameters instead of nine, subject to the easily

satisfied constraint that the quaternion be a unit quaternion.

The use of quaternions to represent orientation is similar to how you would use rotation

matrices. First, you set up a quaternion that represents the initial orientation of the rigid

body at time 0 (this is the only time you'll calculate the quaternion explicitly). Then you

update the orientation to reflect the new orientation at a given instant in time using the

angular velocities that are calculated for that instant. As you can see here, the differential

equation relating an orientation quaternion to angular velocity is very similar to that

for rotation matrices:

d
q
/dt = (1/2)
ω q

Here, the angular velocity is written in quaternion form as [0,
ω
] and is expressed in

fixed, global coordinates. (
ω
is still angular velocity, but you have to put it in quaternion

form instead of vector form when multiplying it by a quaternion
q
.) If
ω
is expressed in

rotating, body-fixed coordinates, then you need to use this equation:

d
q
/dt = (1/2)
q ω

As with rotation matrices, you can use quaternions to rotate points or vectors. If
v
is a

vector, then
v
' is the rotated vector subject to the quaternion
q
:

v
' =
qvq
*

Here
q
*
is the conjugate of the quaternion
q
defined as:

q
* = q
0
- q
x
i
- q
y
j
- q
z
k

You can also use the preceding formula to convert vectors from one coordinate system

to another, where one is rotated relative to the other. You have to do this, for example,

in your simulations where you are converting forces defined in fixed, global coordinates