Game Development Reference
In-Depth Information
matrix. The scaling in the x -axis is Sx , scaling in the y -axis is Sy and
scaling in the z -axis is Sz . This results in the matrix
Sx 00
S =0 Sy
0
00 Sz
Scaling should be applied before any other operations. We can
concatenate our rotation matrix to ensure that scaling occurs first. If R is
our rotation matrix from either Euler angles or from the angle/axis method,
then the matrix becomes:
abc
Sx 00
aSx bSy cSz
R =
def
S =0 Sy
0
RS =
dSx eSy fSz
ghi
00 Sz
gSx nSy iSz
The full operation to translate a vertex in the object to a location in world
space including pivot point consideration becomes
RS ( v - p ) + t + p , where R is the rotation matrix, S the scaling matrix,
v is the vertex, p is the pivot point and t is the translation vector.
For every vertex in a solid object, t + p and RS will be the same. Pre-
calculating these will therefore speed up the transformation operations. It is
highly likely that the pivot point of an object will remain constant throughout
an animation, so the object could be stored already transformed to its pivot
point. If this is the case then the equation becomes
RSv + t
So now we can move and rotate our box. We are now ready to transfer
this to the screen.
Perspective transforms
Converting 3D world space geometry to a 2D screen is surprisingly easy.
Essentially we divide the x and y terms by z to get screen locations ( sx ,
sy ). The technique uses similar triangles to derive the new value for ( sx ,
sy ) from the world coordinates. Referring to Figure 1.8, here we indicate
the position of the camera, the screen and the object. Following the vertex
P to the image of this on the screen at P
, we get two similar triangles,
CPP z and CP
d , where d is the distance from the camera to the screen.
We want to know the position of P
: