Game Engine Architecture

(Ben Green) #1

646 12. Collision and Rigid Body Dynamics


.


xx xy xz
yx yy yz
zx zy zz

III


III


III


⎡⎤


⎢⎥


=⎢⎥


⎢⎥⎣⎦


I


The elements lying along the diagonal of this matrix are the moments of
inertia of the body about its three principal axes, Ixx , Iyy , and Izz. The off -diago-
nal elements are called products of inertia. They are zero when the body is sym-
metrical about all three principal axes (as would be the case for a rectangular
box). When they are non-zero, they tend to produce physically realistic yet
somewhat unintuitive motions that the average game player would probably
think were “wrong” anyway. Therefore, the inertia tensor is oft en simplifi ed
down to the three-element vector [ Ixx Iyy Izz ] in game physics engines.
12.4.6.2. Orientation in Three Dimensions
In two dimensions, we know that the orientation of a rigid body can be de-
scribed by a single angle θ, which measures rotation about the z-axis (assum-
ing the motion is taking place in the xy-plane). In three dimensions, a body’s
orientation could be represented using three Euler angles [ θx θy θz ], each
representing the body’s rotation about one of the three Cartesian axes. How-
ever, as we saw in Chapter 4, Euler angles suff er from gimbal lock problems
and can be diffi cult to work with mathematically. Therefore, the orientation of
a body is more oft en represented using either a 3 × 3 matrix R or a unit quater-
nion q. We’ll use the quaternion form exclusively in this chapter.
Recall that a quaternion is a four-element vector whose x-, y-, and z-com-
ponents can be interpreted as a unit vector u lying along the axis of rotation,
scaled by the sine of the half angle and whose w component is the cosine of
the half angle:

() 22 ()


q[ ][ ]

sin cos.

qqqqxyzw qw
θθ

==


=⎡⎤⎣⎦


q

u

A body’s orientation is of course a function of time, so we should write it q(t).
Again, we need to select an arbitrary direction to be our zero rotation. For
example, we might say that by default, the front of every object will lie along
the positive z-axis in world space, with y up and x to the left. Any non-identity
quaternion will serve to rotate the object away from this canonical world space
orientation. The choice of the canonical orientation is arbitrary, but of course
it’s important to be consistent across all assets in the game.
12.4.6.3. Angular Velocity and Momentum in Three Dimensions
In three dimensions, angular velocity is a vector quantity, denoted by ω(t).
The angular velocity vector can be visualized as a unit-length vector u that
Free download pdf