Microsoft DirectX 8.1 (Visual Basic)

Setting Up a Projection Matrix

Applications written in Microsoft® Visual Basic® can create a projection matrix as described in the What Is the Projection Transformation? topic. However, the Direct3DX utility library provides the following functions to help you set up your projections matrix.

The following Visual Basic code example shows how D3DXMatrixPerspectiveLH is commonly used.

    ' This example assumes that g_D3DDevice is a valid reference 
    ' to a Direct3DDevice8 object. 

    ' For the projection matrix, set up a perspective transform, which 
    ' transforms geometry from 3-D view space to 2-D viewport space, 
    ' with a perspective divide that makes objects smaller in the 
    ' distance. To build a perspective transform, you need the field
    ' of view (1/4 pi is common), the aspect ratio, and the near and 
    ' far clipping planes, which define the distances at which 
    ' geometry should be no longer be rendered.

    Dim matProj As D3DMATRIX

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

After you create the matrix, you must set it in a call to the Direct3DDevice8.SetTransform method, specifying D3DTRANSFORMSTATE_PROJECTION in the first parameter. For details, see Setting Transformations.