Game Development Reference

In-Depth Information

which we can verify with the matrix multiplication

⎡

⎤

⎡

⎤

⎡

⎤

⎡

⎤

abc

def

ghi

1

0

0

a

×

1

+

b

×

0

+

c

×

0

a

d

g

⎣

⎦

⎣

⎦
=

⎣

⎦
=

⎣

⎦

d

×

1

+

e

×

0

+

f

×

0

g

×

1

+

h

×

0

+

i

×

0

and so on for the other two axes. When I introduced vectors, I mentioned that their

three components could be thought of as a position along three axes. The
x
compo-

nent is the distance along the X axis and so on. We could write the vector as

⎡

⎤

⎡

⎤

⎡

⎤

⎡

⎤

x

y

z

1

0

0

0

1

0

0

0

1

⎣

⎦
=

⎣

⎦
+

⎣

⎦
+

⎣

⎦

v

=

x

y

z

In other words, a vector is made up of some proportion of each basic axis.

If the three axes move under a transformation, then the new location of the vector

will be determined in the same way as before. The axes will have moved, but the new

vector will still combine them in the same proportions:

⎡

⎤

⎡

⎤

⎡

⎤

⎡

⎤

a

d

g

b

e

h

c

f

i

ax

+

by

+

cz

⎣

⎦
+

⎣

⎦
+

⎣

⎦
=

⎣

⎦

v
=

x

y

z

dx

+

ey

+

fz

gx

+

hy

+

iz

Thinking about matrix transformations as a change of axis is an important visualiza-

tion tool.

The set of axes is called a “basis.” We looked at orthonormal bases in chap-

ter 2, where the axes all have a length of 1 and are at right angles to one another.

A3

3 matrix will transform a vector from one basis to another. This is sometimes,

not surprisingly, called a “change of basis.”

Thinking back to the rotation matrices in section 9.1.3, we saw how the position

of a headlamp on a car could be converted into a position in the game level. This is

a change of basis. We start with the local coordinates of the headlamp relative to the

origin of the car, and end up with the world coordinates of the headlamp in the game.

In the headlamp example we had two stages: first we rotated the object (using a

matrix multiplication—a change of basis), and then we translated it (by adding an

offset vector). If we extend our matrices a little, we can perform both steps in one go.

This is the purpose of the 3

×

×

4matrix.

The
3

×

4
Matrices

If you have been thinking ahead, you may have noticed that, by the matrix multipli-

cation rules, we can't multiply a 3

×

4matrixbya3

×

1vector.Infactwewillendup