Game Development Reference
In-Depth Information
object. The three transforms are called the world transform, the view transform, and
the projection transform.
World Transform
When objects are created by a programmer plotting out 3D points on graph paper or
an artist models something in 3ds Max, they exist in object space. As the object
moves around the 3D world, it is much easier to modify a single Mat4 × 4 object
than to change each individual point that describes the shape of the object. That
Mat4 x 4 matrix describes the world transform, and it can be used to move and
reorient any object, just as you saw with the teapotahedron on the previous pages.
View Transform
If you are going to render the scene, you need to have a camera. That camera must
have an orientation and a position just like any other object in the world. Similar to
any other object, the camera needs a transform matrix that converts world space ver-
tices to camera space.
Calculating the transform matrix for a camera can be tricky. In many cases, you want
the camera to look at something, like a teapot. If you have a desired camera position
and a target to look at, you don
t quite have enough information to place the camera.
The missing data is a definition of the up direction for your world. This last bit of
data gives the camera a hint about how to orient itself. The BuildRotationLookAt
method of the Mat4 x 4 class wraps D3DXMatrixLookAtLH , which takes these
inputs and constructs the view transform:
'
Mat4x4 matView;
Vec3 vFromPt = Vec3( 6.0f, 6.0f, 6.0f );
Vec3 vLookatPt = Vec3( 0.0f, 0.0f, 0.0f );
Vec3 vUpVec = Vec3( 0.0f, 1.0f, 0.0f );
matView.BuildRotationLookAt( &vFromPt, &vLookatPt, &vUpVec );
By the way, the LH at the end of the DirectX function
s name is a hint that this func-
tion assumes a left-handed coordinate system. There is a right-handed version of this
and most other matrix functions, as well.
The vFromPt is out along the positive values of X, Y, and Z, and the vLookatPt
point is right back at the origin. The last parameter defines the up direction. If you
think about a camera as having an orientation constraint similar to a camera boom
like you see on ESPN, it can move anywhere, pan around to see its surroundings, and
pitch up or down. It doesn
'
t tilt, at least not normally. This is important, because if
tilting were allowed in constructing a valid view transform, there could be many dif-
ferent orientations that would satisfy your input data.
'
Search WWH ::




Custom Search