i
i
i
i
i
i
i
i
4.1. Basic Transforms 63
Another way to compute the inverse of X is to consider R (making R
appear as 3 × 3 matrix) and X in the following notation:
¯
R =
r
,0
r
,1
r
,2
=
r
T
0,
r
T
1,
r
T
2,
,
=
X =
¯
Rt
0
T
1
.
(4.15)
Here, 0 is a 3 ×1 column vector filled with zeros. Some simple calcula-
tions yield the inverse in the expression shown in Equation 4.16:
X
1
=
r
0,
r
1,
r
2,
¯
R
T
t
000 1
. (4.16)
4.1.7 Normal Transform
A single matrix can be used to consistently transform points, lines, poly-
gons, and other geometry. The same matrix can also transform tangent
vectors following along these lines or on the surfaces of polygons. However,
this matrix cannot always be used to transform one important geometric
property, the surface normal (and also the vertex lighting normal). Fig-
ure 4.5 shows what can happen if this same matrix is used.
Instead of multiplying by the matrix itself, the proper method is to use
the transpose of the matrix’s adjoint [156]. Computation of the adjoint is
Figure 4.5. On the left is the original geometry, a polygon and its normal shown from
the side. The middle illustration shows what happens if the model is scaled along the
x-axisby0.5 and the normal uses the same matrix. The right figure shows the proper
transform of the normal.
i
i
i
i
i
i
i
i
64 4. Transforms
described in Section A.3.1. The adjoint is always guaranteed to exist. The
normal is not guaranteed to be of unit length after being transformed, so
typically needs to be normalized.
The traditional answer for transforming the normal is that the transpose
of the inverse is computed [1277]. This method normally works. The full
inverse is not necessary, however, and occasionally cannot be created. The
inverse is the adjoint divided by the original matrix’s determinant. If this
determinant is zero, the matrix is singular, and the inverse does not exist.
Even computing just the adjoint for a full 4×4 matrix can be expensive,
and is usually not necessary. Since the normal is a vector, translation will
not affect it. Furthermore, most modeling transforms are affine. They do
not change the w component of the homogeneous coordinate passed in, i.e.,
they do not perform projection. Under these (common) circumstances, all
that is needed for normal transformation is to compute the adjoint of the
upper-left 3 × 3components.
Often even this adjoint computation is not needed. Say we know the
transform matrix is composed entirely of a concatenation of translations,
rotations, and uniform scaling operations (no stretching or squashing).
Translations do not affect the normal. The uniform scaling factors sim-
ply change the length of the normal. What is left is a series of rotations,
which always yields a net rotation of some sort, nothing more. A rotation
matrix is defined by the fact that its transpose is its inverse. The transpose
of the inverse can be used to transform normals, and two transposes (or two
inverses) cancel each other out. Put together, the result is that the original
transform itself can also be used directly to transform normals under these
circumstances.
Finally, fully renormalizing the normal produced is not always neces-
sary. If only translations and rotations are concatenated together, the
normal will not change length when transformed by the matrix, so no
renormalizing is needed. If uniform scalings are also concatenated, the
overall scale factor (if known, or extracted—Section 4.2.3) can be used to
directly normalize the normals produced. For example, if we know that a
series of scalings were applied that makes the object 5.2 times larger, then
normals transformed directly by this matrix are renormalized by dividing
them by 5.2. Alternately, to create a normal transform matrix that would
produce normalized results, the original matrix’s 3 × 3 upper-left could be
divided by this scale factor once.
Note that normal transforms are not an issue in systems where, after
transformation, the surface normal is derived from the triangle (e.g., using
the cross product of the triangle’s edges). Tangent vectors are different
than normals in nature, and are always directly transformed by the original
matrix.
i
i
i
i
i
i
i
i
4.2. Special Matrix Transforms and Operations 65
4.1.8 Computation of Inverses
Inverses are needed in many cases, for example, when changing back and
forth between coordinate systems. Depending on the available information
about a transform, one of the following three methods of computing the
inverse of a matrix can be used.
If the matrix is a single transform or a sequence of simple transforms
with given parameters, then the matrix can be computed easily by
“inverting the parameters” and the matrix order. For example, if
M = T(t)R(φ), then M
1
= R(φ)T(t).
If the matrix is known to be orthogonal, then M
1
= M
T
, i.e., the
transpose is the inverse. Any sequence of rotations is a rotation, and
so is orthogonal.
If nothing in particular is known, then the adjoint method
(Equation A.38 on page 902), Cramer’s rule, LU decomposition, or
Gaussian elimination could be used to compute the inverse (see Sec-
tion A.3.1). Cramer’s rule and the adjoint method are generally
preferable, as they have fewer branch operations; “if tests are good
to avoid on modern architectures. See Section 4.1.7 on how to use
the adjoint to inverse transform normals.
The purpose of the inverse computation can also be taken into account
when optimizing. For example, if the inverse is to be used for transforming
vectors, then only the 3 × 3 upper left part of the matrix normally needs
to be inverted (see the previous section).
4.2 Special Matrix Transforms and Operations
In this section, a number of matrix transforms and operations that are
essential to real-time graphics will be introduced and derived. First, we
present the Euler transform (along with its extraction of parameters), which
is an intuitive way to describe orientations. Then we touch upon retrieving
a set of basic transforms from a single matrix. Finally, a method is derived
that rotates an entity around an arbitrary axis.
4.2.1 The Euler Transform
This transform is an intuitive way to construct a matrix to orient yourself
(i.e., the camera) or any other entity in a certain direction. Its name comes
from the great Swiss mathematician Leonhard Euler (1707–1783).
i
i
i
i
i
i
i
i
66 4. Transforms
Figure 4.6. Depicting the way, in terms of the Euler transform, you turn your head,
pitch,androl l. The default view direction is shown, looking along the negative z-axis
with the head oriented along the y-axis.
First, some kind of default view direction must be established. Most
often it lies along the negative z-axis with the head oriented along the y-
axis, as depicted in Figure 4.6. The Euler transform is the multiplication
of three matrices, namely the rotations shown in the figure. More formally,
the transform, denoted E, is given by Equation 4.17:
5
E(h, p, r)=R
z
(r)R
x
(p)R
y
(h). (4.17)
Since E is a concatenation of rotations, it is also clearly orthogonal. There-
fore its inverse can be expressed as E
1
= E
T
=(R
z
R
x
R
y
)
T
= R
T
y
R
T
x
R
T
z
,
although it is, of course, easier to use the transpose of E directly.
The Euler angles h, p,andr represent in which order and how much
the head, pitch, and roll should rotate around their respective axes.
6
This
5
Actually, the order of the matrices can be chosen in 24 different ways [1179], but we
choose this one because it is commonly used.
6
Sometimes the angles are all called “rolls,” e.g., our “head” is the “y-roll” and our
“pitch” is the “x-roll.” Also, “head is sometimes known as “yaw,” for example, in flight
simulation.
i
i
i
i
i
i
i
i
4.2. Special Matrix Transforms and Operations 67
transform is intuitive and therefore easy to discuss in layperson’s language.
For example, changing the head angle makes the viewer shake his head
“no,” changing the pitch makes him nod, and rolling makes him tilt his
head sideways. Rather than talking about rotations around the x-, y-, and
z-axes, we talk about altering the head, pitch, and roll. Note that this
transform can orient not only the camera, but also any object or entity
as well. These transforms can be performed using the global axes of the
world’s space or relative to a local frame of reference.
When you use Euler transforms, something called gimbal lock may oc-
cur [1176, 1330]. This happens when rotations are made so that one degree
of freedom is lost. For example, say the order of transforms is x/y/z.
Consider a rotation of π/2 around just the y-axis, the second rotation per-
formed. Doing so rotates the local z-axis to be aligned with the original
x-axis, so that the final rotation around z is redundant.
Another way to see that one degree of freedom is lost is to set p = π/2
and examine what happens to the Euler matrix E(h, p, r):
E(h, π/2,r)=
cos r cos hsin r sin h 0cosr sin h+sinr cos h
sin r cos h+cos r sin h 0sinr sin hcos r cos h
010
=
cos(r + h)0 sin(r + h)
sin(r + h)0 cos(r + h)
01 0
. (4.18)
Since the matrix is dependent on only one angle (r + h), we conclude that
one degree of freedom has been lost.
While Euler angles are commonly presented as being in x/y/z order
in modeling systems, a rotation around each local axis, other orderings
are feasible. For example, z/x/y is used in animation and z/x/z in both
animation and physics. All are valid ways of specifying three separate
rotations. This last ordering, z/x/z, can be superior for some applications,
as only when rotating π radians around x (a half-rotation) does gimbal lock
occur. That said, by the “hairy ball theorem” gimbal lock is unavoidable,
there is no perfect sequence that avoids it.
While useful for small angle changes or viewer orientation, Euler an-
gles have some other serious limitations. It is difficult to work with two
sets of Euler angles in combination. For example, interpolation between
one set and another is not a simple matter of interpolating each angle. In
fact, two different sets of Euler angles can give the same orientation, so any
interpolation should not rotate the object at all. These are some of the rea-
sons that using alternate orientation representations such as quaternions,
discussed later in this chapter, are worth pursuing.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset