Game Development Reference
In-Depth Information
So, back to the question posed at the start of this section: Which matrix
should we use? Our answer is, “It shouldn't matter.” By that we mean
there is a way to design your matrix code in such a way that it can be used
without knowing what choice was made. As far as the C++ code goes,
this is purely a cosmetic change. For example, perhaps we just replace
the function name multiply() with objectToUpright() , and likewise we
replace multiplyByTranspose() with uprightToObject() . The version
of the code with descriptive, named coordinate spaces is easier to read and
write.
8.2.2 Direction Cosines Matrix
You might come across the (very old school) term direction cosines in the
context of using a matrix to describe orientation. A direction cosines matrix
is the same thing as a rotation matrix; the term just refers to a special way
to interpret (or construct) the matrix, and this interpretation is interesting
and educational, so let's pause for a moment to take a closer look. Each
element in a rotation matrix is equal to the dot product of a cardinal axis in
one space with a cardinal axis in the other space. For example, the center
element m 22 in a 3 × 3 matrix gives the dot product that the y-axis in one
space makes with the y-axis in the other space.
More generally, let's say that the basis vectors of a coordinate space are
the mutually orthogonal unit vectors p , q , and r , while a second coordinate
space with the same origin has as its basis a different (but also orthonormal)
basis p
. (Please allow us to break from convention by dropping
all the hats from the unit vectors in this section, to avoid distracting clutter
in the equations.) The rotation matrix that rotates row vectors from the
first space to the second can be constructed from the cosines of the angles
between each pair of basis vectors. Of course, the dot product of two unit
vectors is exactly equal to the cosine of the angle between them, so the
matrix product is
, q
, and r
2
3
p p
q p
r p
4
5
v
p q
q q
r q
= v
.
(8.1)
p r
q r
r r
These axes can be interpreted as geometric rather than numeric entities,
so it really does not matter what coordinates are used to describe the axes
(provided we use the same coordinate space to describe all of them), the
rotation matrix will be the same.
For example, let's say that our axes are described using coordinates
relative to the first basis. Then p , q , and r have the trivial forms [1,0,0],
[0,1,0] and [0,0,1], respectively. The basis vectors of the second space,
p
, q
, and r
have arbitrary coordinates. When we substitute the trivial
Search WWH ::




Custom Search