![]() |
![]() |
![]() |
Setting Up a Projection Matrix |
Language: |
The following ProjectionMatrix sample function sets the front and back clipping planes, as well as the horizontal and vertical field-of-view angles. This C# code parallels the approach discussed in What Is the Projection Transformation?. The fields of view should be less than pi radians.
[C#]
private Matrix ProjectionMatrix(float near_plane, float far_plane, float fov_horiz, float fov_vert) { float h,w,Q; w = 1/(float)Math.Tan(fov_horiz*0.5); // 1/tan(x) == cot(x) h = 1/(float)Math.Tan(fov_vert*0.5); // 1/tan(x) == cot(x) Q = far_plane/(far_plane - near_plane); Matrix ret = new Matrix(); ret.M11 = w; ret.M22 = h; ret.M33 = Q; ret.M43 = -Q*near_plane; ret.M34 = 1; return ret; }
After creating the matrix, set it with SetTransform, specifying TransformType.Projection, or pass the matrix to the Device.Transform.Projection property.
Microsoft® DirectX® 9.0 for Managed Code provides the following functions to help you set up a projection matrix.
Feedback? Please provide us with your comments on this topic.
For more help, visit the DirectX Developer Center