Game Development Reference
In-Depth Information
Scale
Suppose we have a player character model that was created to be a certain size. In
game, there is a power-up that can double the size of the character. This means we
need to be able to increase the size of the model in world space. This could be ac-
complished by multiplying every vertex in the model by an appropriate
scale mat-
rix
, which can scale a vector or position along any of the three coordinate axes. It
looks a lot like the identity matrix, except the diagonal comprises the scale factors.
If
s
x
=
s
y
=
s
z
, this is a
uniform scale
, which means the vector is transformed
equally along all axes. So if all the scale values are 2, the model will double in
size.
To invert a scale matrix, simply take the reciprocal of each scale factor.
Translation
A
translation matrix
moves a point by a set amount. It does not work on vectors,
because the value of a vector does not depend on where we draw the vector. The
translation matrix fills in the final row of the identity matrix with the x, y, and z
translation values.
For example, suppose the center of a model is to be placed at the position 5, 10,
-15 in the world. The matrix for this translation would be as follows: