Game Development Reference
In-Depth Information
resentation of orientation isn't simple. Unlike for the two-dimensional case, we have
more than just the bounds to worry about: it isn't clear how to combine rotations
easily because the axis as well as the angle need to change.
Until a few years ago the most common way to represent orientations went to the
opposite extreme. Rather than use three values, a 3
×
3 matrix was used.
9.2.3
R OTATION M ATRICES
If we were interested in the mathematics of combining rotations, then we could bor-
row from 3D geometry and represent orientations with a rotation matrix. In games
we regularly use matrices to represent rotations. In fact the chances are that whatever
representation we use, we'll have to turn it into a rotation matrix and send it to the
rendering engine in order to draw the object. Why not save the effort and use the
rotation matrix from the start?
Using rotation matrices is a good solution; and we can represent any rotation with
a rotation matrix. The elements of the matrix are
tx 2
+
ctxy
+
sz txz
sy
Θ
=
txy
sz ty 2
+
ctyz
+
sx
[9.3]
sx tz 2
txz
+
sy tyz
+
x
where
x
y
z
is the axis; c
cos θ ;and θ is the angle.
Because the elements are related to the sine and cosine of the angle rather than
to the angles themselves, we don't have to do any bounds-checking. Combining two
rotations is simply a matter of multiplying the two matrices together.
The downside with using rotation matrices is their excess degrees of freedom.
We are representing a three-degree-of-freedom system with nine numbers. Floating-
point arithmetic in the computer isn't totally accurate. So to make sure the matrix
represents a rotation (as opposed to some other kind of transformation such as a
skew or even a mirror image) after it has been manipulated in some way, we need
to adjust its values periodically. With so many degrees of freedom this adjustment
processneedstotakeplacemoreoftenthanwe'dlike,anditisn'tatrivialprocessas
normalizing a vector is.
Ideally we'd like a representation that has the advantages of matrices: a straightfor-
ward combination of rotations, no bounds-checking, and fewer degrees of freedom.
The solution, now almost ubiquitous, is to use a mathematical structure called a
“quaternion.”
=
cos θ , s
=
sin θ ,and t
=
1
Search Nedrilad ::




Custom Search