Sparky icon indicating copy to clipboard operation
Sparky copied to clipboard

Perspective matrix seems incorrect

Open nyanzebra opened this issue 9 years ago • 2 comments

There seems to be a missing assignment for the last element in the matrix.

mat4 mat4::perspective(float fov, float aspectRatio, float near, float far)
    {
        mat4 result(1.0f);

        float q = 1.0f / tan(toRadians(0.5f * fov));
        float a = q / aspectRatio;

        float b = (near + far) / (near - far);
        float c = (2.0f * near * far) / (near - far);

        result.elements[0 + 0 * 4] = a;
        result.elements[1 + 1 * 4] = q;
        result.elements[2 + 2 * 4] = b;
        result.elements[3 + 2 * 4] = -1.0f;
        result.elements[2 + 3 * 4] = c;

        return result;
    }

I believe the 15th element should be 0. source = http://www.songho.ca/opengl/gl_projectionmatrix.html

So, fix would be adding

result.elements[3+3*4]=0;

nyanzebra avatar Jul 15 '15 23:07 nyanzebra

This should be fixed. I had a problem trying to setup a true first person camera but it kept on looking like a third person camera. By adding that line, the problem was fixed.

Jacob-Mango avatar Dec 23 '16 07:12 Jacob-Mango

Make a pull request

Crisspl avatar Dec 23 '16 11:12 Crisspl