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;
}