adjusting the perpsective formula

v1
Brett 2023-02-11 12:05:47 -05:00
parent 5ecb127519
commit a01d5eba90
1 changed files with 4 additions and 2 deletions

View File

@ -513,11 +513,13 @@ namespace blt {
static inline mat4x4 perspective(float fov, float aspect_ratio, float near, float far){ static inline mat4x4 perspective(float fov, float aspect_ratio, float near, float far){
mat4x4 perspectiveMat4x4; mat4x4 perspectiveMat4x4;
float oneOverFarMNear = 1.0f / (far - near);
float halfTan = tanf(fov * 0.5f * (float)M_PI / 180.0f); float halfTan = tanf(fov * 0.5f * (float)M_PI / 180.0f);
perspectiveMat4x4.m00(1.0f/(aspect_ratio*halfTan)); perspectiveMat4x4.m00(1.0f/(aspect_ratio*halfTan));
perspectiveMat4x4.m11(1.0f/halfTan); perspectiveMat4x4.m11(1.0f/halfTan);
perspectiveMat4x4.m22(-far / (far - near)); perspectiveMat4x4.m22(-(far + near) * oneOverFarMNear);
perspectiveMat4x4.m32(-far * near / (far - near)); perspectiveMat4x4.m32(-2 * far * near * oneOverFarMNear);
perspectiveMat4x4.m23(-1); perspectiveMat4x4.m23(-1);
perspectiveMat4x4.m33(0); perspectiveMat4x4.m33(0);