CSharpGL.glm.perspectiveFov C# (CSharp) Method

perspectiveFov() public static method

Builds a perspective projection matrix based on a field of view.
public static perspectiveFov ( float fov, float width, float height, float zNear, float zFar ) : CSharpGL.mat4
fov float The fov (in radians).
width float The width.
height float The height.
zNear float The z near.
zFar float The z far.
return CSharpGL.mat4
        public static mat4 perspectiveFov(float fov, float width, float height, float zNear, float zFar)
        {
            if (width <= 0 || height <= 0 || fov <= 0)
                throw new ArgumentOutOfRangeException();

            var rad = fov;

            var h = glm.cos((0.5f) * rad) / glm.sin((0.5f) * rad);
            var w = h * height / width;

            var result = new mat4(0);
            result[0, 0] = w;
            result[1, 1] = h;
            result[2, 2] = -(zFar + zNear) / (zFar - zNear);
            result[2, 3] = -(1f);
            result[3, 2] = -((2f) * zFar * zNear) / (zFar - zNear);
            return result;
        }