Fix perspective calc

v1
Brett 2023-02-08 23:21:25 -05:00
parent ba35e4645b
commit 20ce0e2e9b
1 changed files with 5 additions and 4 deletions

View File

@ -509,12 +509,13 @@ namespace blt {
} }
// https://www.scratchapixel.com/lessons/3d-basic-rendering/perspective-and-orthographic-projection-matrix/building-basic-perspective-projection-matrix.html // https://www.scratchapixel.com/lessons/3d-basic-rendering/perspective-and-orthographic-projection-matrix/building-basic-perspective-projection-matrix.html
static inline mat4x4 perspective(float fov, float near, float far){ // https://ogldev.org/www/tutorial12/tutorial12.html
static inline mat4x4 perspective(float fov, float aspect_ratio, float near, float far){
mat4x4 perspectiveMat4x4; mat4x4 perspectiveMat4x4;
float scale = 1.0f / (float)tan(fov * 0.5f * M_PI / 180.0f); float halfTan = tanf(fov * 0.5f * (float)M_PI / 180.0f);
perspectiveMat4x4.m00(scale); perspectiveMat4x4.m00(1.0f/(aspect_ratio*halfTan));
perspectiveMat4x4.m11(scale); perspectiveMat4x4.m11(1.0f/halfTan);
perspectiveMat4x4.m22(-far / (far - near)); perspectiveMat4x4.m22(-far / (far - near));
perspectiveMat4x4.m32(-far * near / (far - near)); perspectiveMat4x4.m32(-far * near / (far - near));
perspectiveMat4x4.m23(-1); perspectiveMat4x4.m23(-1);