Microsoft DirectX 8.1 (Visual Basic) |
The view transformation matrix defines the position and rotation of the view. The view matrix is the camera for the scene.
The following code fragment creates the view transformation matrix and then sets the current view transformation to the Microsoft® Direct3D® device.
Dim matView As D3DMATRIX D3DXMatrixLookAtLH matView, vec3(0#, 3#, -5#), _ vec3(0#, 0#, 0#), _ vec3(0#, 1#, 0#) g_D3DDevice.SetTransform D3DTS_VIEW, matView
The first step is to define the view matrix by calling D3DXMatrixLookAtLH. The first parameter is a D3DMATRIX type that contains the returned matrix. The second, third, and fourth parameters define the eye point, look at point, and "up" direction. Here the eye is set back along the z-axis by five units and up three units, the look at point is set at the origin, and "up" is defined as the y-direction.
The next step is to call Direct3DDevice8.SetTransform to set the current view transformation for the Direct3D device. The first parameter accepted by SetTransform tells which transformation to set. This sample uses the D3DTS_VIEW flag to specify that the view transformation should be set. The second parameter is a pointer to a matrix that is set as the current transformation.
For more information on view transformations, see View Transformation.
After defining the world transformation for the scene, you can prepare the projection transformation matrix. Again, note that the order in which transformations are defined is not critical. However, Direct3D applies the matrices to the scene in the following order: (1) World ,(2) View, (3) Projection.
Defining the projection transformation matrix is described in Step 3: Defining the Projection Transformation Matrix.