Game Development Reference
In-Depth Information
Figure 2.9: Several 3D objects described
relative to one world coordinate system
The world transformation is represented with a matrix and set with
Direct3D using the IDirect3DDevice9::SetTransform method
with D3DTS_WORLD as the transform type. For example, suppose we
want to position a cube at the point (-3, 2, 6) in the world and a sphere
at the point (5, 0, -2). We would write:
// Build the cube world matrix that only consists of a translation.
D3DXMATRIX cubeWorldMatrix;
D3DXMatrixTranslation(&cubeWorldMatrix, -3.0f, 2.0f, 6.0f);
// Build the sphere world matrix that only consists of a translation.
D3DXMATRIX sphereWorldMatrix;
D3DXMatrixTranslation(&sphereWorldMatrix, 5.0f, 0.0f, -2.0f);
// Set the cube's transformation
Device->SetTransform(D3DTS_WORLD, &cubeWorldMatrix);
drawCube(); // draw the cube
// Now since the sphere uses a different world transformation, we
// must change the world transformation to the sphere's. If we
// don't change this, the sphere would be drawn using the previously
// set world matrix - the cube's.
Device->SetTransform(D3DTS_WORLD, &sphereWorldMatrix);
drawSphere(); // draw the sphere
This is a simplistic example, as the objects would most likely need to
be oriented and scaled as well, but it shows how the world transforma-
tion works.
2.3.3 View Space
In world space the world geometry and the camera are defined relative
to the world coordinate system, as Figure 2.10 shows. However, projec-
tion and other operations are difficult or less efficient when the camera
is at an arbitrary position and orientation in the world. To make things
easier, we transform the camera to the origin of the world system and
rotate it so that the camera is looking down the positive z-axis. All
geometry in the world is transformed along with the camera so that the
 
Search WWH ::




Custom Search