Game Development Reference
In-Depth Information
doing just this, but to understand why we need to look more closely at what the 3
×
4
matrix will be used for.
In the previous section we looked at transformation matrices. The transforma-
tions that can be represented as a 3
3 matrix all keep the origin at the same place.
To handle general combinations of movement and rotation in our game we need to
be able to move the origin around: there is no use modeling a car if it is stuck with its
origin at the origin of the game level. We could do this as a two-stage process: perform
a rotation matrix multiplication and then add an offset vector. A better alternative is
to extend our matrices and do it in one step.
Firstweextendourvectorbyoneelement,sowehavefourelements,wherethe
last element is always 1:
×
x
y
z
1
The four values in the vector are called “homogeneous” coordinates, and they are
used in some graphics packages. You can think of them as a four-dimensional coor-
dinate if you like, although thinking in four dimensions may not help you visualize
what we're doing with them (it doesn't help me).
If we now take a 3
×
4matrix,
abcd
ef gh
ijkl
and multiply it in the normal way, by our four-element vector,
x
y
z
1
abcd
ef gh
ijkl
ax
+
by
+
cz
+
d
=
[9.6]
ex
+
fy
+
gz
+
h
ix
+
jy
+
kz
+
l
we get a combination of two effects. It is as if we had first multiplied by the 3
×
3
matrix,
⎦ =
+
+
abc
ef g
ijk
x
y
z
ax
by
cz
ex
+
fy
+
gz
ix
+
jy
+
kz