i
i
i
i
i
i
i
i
Chapter 4
Transforms
“What if angry vectors veer
Round your sleeping head, and form.
There’s never need to fear
Violence of the poor world’s abstract storm.”
—Robert Penn Warren
A transform is an operation that takes entities such as points, vectors, or
colors and converts them in some way. For the computer graphics prac-
titioner, it is extremely important to master transforms. With them, you
can position, reshape, and animate objects, lights, and cameras. You can
also ensure that all computations are carried out in the same coordinate
system, and project objects onto a plane in different ways. These are only a
few of the operations that can be performed with transforms, but they are
sufficient to demonstrate the importance of the transform’s role in real-time
graphics, or, for that matter, in any kind of computer graphics.
A linear transform is one that preserves vector addition and scalar mul-
tiplication. Specifically,
f(x)+f(y)=f(x + y),
kf(x)=f(kx).
(4.1)
As an example, f(x)=5x is a transform that takes a vector and multiplies
each element by five. This type of transform is linear, as any two vectors
multiplied by five and then added will be the same as adding the vectors and
then multiplying. The scalar multiplication condition is clearly fulfilled.
This function is called a scaling transform, as it changes the scale (size) of
an object. The rotation transform is another linear transform that rotates
a vector about the origin. Scaling and rotation transforms, in fact all linear
transforms for 3-element vectors, can be represented using a 3 ×3matrix.
53
i
i
i
i
i
i
i
i
54 4. Transforms
However, this size of matrix is usually not large enough. A function for a
three element vector x such as f(x)=x+(7, 3, 2) is not linear. Performing
this function on two separate vectors will add each value of (7, 3, 2) twice
to form the result. Adding a fixed vector to another vector performs a
translation, e.g., it moves all locations by the same amount. This is a
useful type of transform, and we would like to combine various transforms,
e.g., scale an object to be half as large, then move it to a different location.
Keeping functions in the simple forms used so far makes it difficult to easily
combine them.
Combining linear transforms and translations can be done using an
affine transform, typically stored as a 4 ×4 matrix. An affine transform is
one that performs a linear transform and then a translation. To represent
4-element vectors we use homogeneous notation, denoting points and direc-
tions in the same way (using bold lowercase letters). A direction vector is
represented as v =(v
x
v
y
v
z
0)
T
and a point as v =(v
x
v
y
v
z
1)
T
.
Throughout the chapter, we will make extensive use of the terminology
explained in Appendix A. You may wish to review this appendix now,
especially Section A.4, page 905, on homogeneous notation.
All translation, rotation, scaling, reflection, and shearing matrices are
affine. The main characteristic of an affine matrix is that it preserves
the parallelism of lines, but not necessarily lengths and angles. An affine
transform may also be any sequence of concatenations of individual affine
transforms.
This chapter will begin with the most essential, basic affine trans-
forms. These are indeed very basic, and this section could be seen as a
“reference manual” for simple transforms. More specialized matrices are
then described, followed by a discussion and description of quaternions,
a powerful transform tool. Then follows vertex blending and morphing,
which are two simple but more powerful ways of expressing animations
of meshes. Finally, projection matrices are described. Most of these
transforms, their notations, functions, and properties are summarized in
Table 4.1.
Transforms are a basic tool for manipulating geometry. Most graphics
application programming interfaces (APIs) include matrix operations that
implement many of the transforms discussed in this chapter. However, it
is still worthwhile to understand the real matrices and their interaction
behind the function calls. Knowing what the matrix does after such a
function call is a start, but understanding the properties of the matrix
itself will take you further. For example, such an understanding enables
you to discern when you are dealing with an orthogonal matrix, whose
inverse is its transpose (see page 904), making for faster matrix inversions.
Knowledge like this can lead to accelerated code.

Get Real-Time Rendering, Third Edition, 3rd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.