Microsoft DirectX 9.0 SDK Update (October 2004)

Matrix.PerspectiveFovLH Method

Language:

Note: This documentation is preliminary and is subject to change.
How Do I...?

Builds a left-handed perspective projection matrix based on a field of view.

Definition

Visual Basic .NET Public Shared Function PerspectiveFovLH( _
    ByVal fieldOfViewY As Single, _
    ByVal aspectRatio As Single, _
    ByVal znearPlane As Single, _
    ByVal zfarPlane As Single _
) As Matrix
C# public static Matrix PerspectiveFovLH(
    float fieldOfViewY,
    float aspectRatio,
    float znearPlane,
    float zfarPlane
);
Managed C++ public: static Matrix PerspectiveFovLH(
    float fieldOfViewY,
    float aspectRatio,
    float znearPlane,
    float zfarPlane
);
JScript .NET public static function PerspectiveFovLH(
    fieldOfViewY : float,
    aspectRatio : float,
    znearPlane : float,
    zfarPlane : float
) : Matrix;

Parameters

fieldOfViewY System.Single. Field of view in the y direction, in radians.
aspectRatio System.Single. Aspect ratio, defined as the view space width divided by height.
znearPlane System.Single. Z-value of the near view plane.
zfarPlane System.Single. Z-value of the far view plane.

Return Value

Microsoft.DirectX.Matrix . A Matrix structure that is a left-handed perspective projection matrix.

Remarks

This method uses the following formula to compute the returned matrix. The view space height is represented by h, which is calculated from h = cot(fieldOfViewY/2). The view space width is represented by w, which is calculated from h = w / aspectRatio.

w       0       0                                             0
0       h       0                                             0
0       0       zfarPlane/(zfarPlane-znearPlane)              1
0       0       -znearPlane*zfarPlane/(zfarPlane-znearPlane)  0

How Do I...?

Set Up a Projection Matrix

This example demonstrates how to set up the projection transformation matrix, which transforms 3-D camera or view space coordinates into 2-D screen coordinates.

See the following C# code example, the Projection transformation matrix is set to be equal to the left-handed (LH) PerspectiveFovLH matrix. Input arguments to PerspectiveFovLH are as follows.

  1. Field of view in radians: pi/4.
  2. Aspect ratio, or view-space height divided by width: 1, for a square window.
  3. Near clipping plane distance: 1 unit.
  4. Far clipping plane distance: 100 units.

              [C#]
              
using Microsoft.DirectX; Direct3D.Device device = null; // Create rendering device. // For the projection matrix, you set up a perspective transform (which // transforms geometry from 3-D view space to 2-D viewport space, with // a perspective divide making 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 no longer be rendered). device.Transform.Projection = Matrix.PerspectiveFovLH( (float)Math.PI / 4, 1.0f, 1.0f, 100.0f );

See Also


© 2004 Microsoft Corporation. All rights reserved. Terms of use.

Feedback? Please provide us with your comments on this topic.
For more help, visit the DirectX Developer Center