Accord.Math.Matrix4x4.CreatePerspective C# (CSharp) Method

CreatePerspective() public static method

Creates a perspective projection matrix.
Both near and far view planes' distances must be greater than zero. Near plane must be closer than the far plane.
public static CreatePerspective ( float width, float height, float nearPlaneDistance, float farPlaneDistance ) : Matrix4x4
width float Width of the view volume at the near view plane.
height float Height of the view volume at the near view plane.
nearPlaneDistance float Distance to the near view plane.
farPlaneDistance float Distance to the far view plane.
return Matrix4x4
        public static Matrix4x4 CreatePerspective(float width, float height, float nearPlaneDistance, float farPlaneDistance)
        {
            if (nearPlaneDistance <= 0)
                throw new ArgumentOutOfRangeException("nearPlaneDistance ", "Near plane distance must be greater than zero.");

            if (farPlaneDistance <= 0)
                throw new ArgumentOutOfRangeException("farPlaneDistance", "Far view plane distance must be greater than zero.");

            if (nearPlaneDistance >= farPlaneDistance)
                throw new ArgumentException("Near plane must be closer than the far plane.", "farPlaneDistance");

            Matrix4x4 m = new Matrix4x4();

            m.V00 = 2.0f * nearPlaneDistance / width;
            m.V11 = 2.0f * nearPlaneDistance / height;
            m.V22 = farPlaneDistance / (nearPlaneDistance - farPlaneDistance);

            m.V32 = -1;
            m.V23 = (nearPlaneDistance * farPlaneDistance) / (nearPlaneDistance - farPlaneDistance);

            return m;
        }