Microsoft DirectX 8.1 (Visual Basic)

Step 3: Defining the Projection Transformation Matrix

The projection transformation matrix defines how geometry will be transformed from 3-D view space to 2-D viewport space.

The following code fragment creates the projection transformation matrix and then applies the transformation to the Microsoft® Direct3D® device.

Dim matProj As D3DMATRIX
D3DXMatrixPerspectiveFovLH matProj, g_pi / 4, 1, 1, 1000
g_D3DDevice.SetTransform D3DTS_PROJECTION, matProj

The first step is to call D3DXMatrixPerspectiveFovLH to set up the projection matrix. The first parameter is a D3DMATRIX type that contains the returned matrix. The second parameter defines the field of view, which tells how objects in the distance get smaller. A typical field of view is 1/4 pi, which is what the sample uses. The third parameter defines the aspect ratio. The sample uses the typical aspect ratio of 1. The fourth and fifth parameter define the near and far clipping plane. This determines the distance at which geometry should no longer be rendered. The Matrices sample project has its near clipping plane set at 1 and its far clipping plane set at 100.

The next step is to call Direct3DDevice8.SetTransform to set the current projection transformation for the Direct3D device. The first parameter accepted by SetTransform tells which transformation to set. This sample uses the D3DTS_PROJECTION flag to specify that the projection transformation should be set. The second parameter is a pointer to a matrix that is set as the current transformation.

For more information on projection transformations, see Projection Transformation.

This tutorial has shown you how to use matrices. Tutorial 4: Creating and Using Lights shows how to add lights to your scene for more realism.