Game Development Reference
In-Depth Information
view of the world remains the same. This transformation is called the
view space transformation , and the geometry is said to reside in view
space after this transformation.
Figure 2.10: The transformation from world space to view space. This transfor-
mation transforms the camera to the origin of the system looking down the
positive z-axis. Notice that the objects in space are transformed along with the
camera so that the camera's view of the world remains the same.
The view space transformation matrix can be computed using the fol-
lowing D3DX function:
D3DXMATRIX *D3DXMatrixLookAtLH(
D3DXMATRIX* pOut, // pointer to receive resulting view matrix
CONST D3DXVECTOR3* pEye, // position of camera in world
CONST D3DXVECTOR3* pAt, // point camera is looking at in world
CONST D3DXVECTOR3* pUp
// the world's up vector - (0, 1, 0)
);
The pEye parameter specifies the position where you want the camera
to be in the world. The pAt parameter specifies the point in the world
where you want to aim the camera. The pUp parameter is the vector
that indicates which direction is “up” in the 3D world; this is usually
always the vector coincident with the y-axis—(0, 1, 0).
Example: Suppose we want to position the camera at the point
(5, 3, -10) and have the camera look at the center of the world (0, 0, 0).
We can then build the view transformation matrix by writing:
D3DXVECTOR3 position(5.0f, 3.0f, -10.0f);
D3DXVECTOR3 targetPoint(0.0f, 0.0f, 0.0f);
D3DXVECTOR3 worldUp(0.0f, 1.0f, 0.0f);
D3DXMATRIX V;
D3DXMatrixLookAtLH(&V, &position, &targetPoint, &worldUp);
The view space transformation is set with the IDirect3DDevice9::
SetTransform method with D3DTS_VIEW as the transform type:
Device->SetTransform(D3DTS_VIEW, &V);
Search WWH ::




Custom Search