From c5628b028bfdd7189d65a37f6af0ba1e8f27834b Mon Sep 17 00:00:00 2001 From: josh Date: Thu, 15 Feb 2024 01:51:51 -0500 Subject: [PATCH] Implement Matrix4x4::OpenGLOrthoProjLH --- include/J3ML/LinearAlgebra/Matrix4x4.h | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/include/J3ML/LinearAlgebra/Matrix4x4.h b/include/J3ML/LinearAlgebra/Matrix4x4.h index 578aa4c..4607676 100644 --- a/include/J3ML/LinearAlgebra/Matrix4x4.h +++ b/include/J3ML/LinearAlgebra/Matrix4x4.h @@ -209,7 +209,18 @@ namespace J3ML::LinearAlgebra { static Matrix4x4 D3DPerspProjLH(float nearPlane, float farPlane, float hViewportSize, float vViewportSize); static Matrix4x4 D3DPerspProjRH(float nearPlane, float farPlane, float hViewportSize, float vViewportSize); - static Matrix4x4 OpenGLOrthoProjLH(float nearPlane, float farPlane, float hViewportSize, float vViewportSize); + static Matrix4x4 OpenGLOrthoProjLH(float n, float f, float h, float v) + { + /// Same as OpenGLOrthoProjRH, except that the camera looks towards +Z in view space, instead of -Z. + using f32 = float; + f32 p00 = 2.f / h; f32 p01 = 0; f32 p02 = 0; float p03 = 0.f; + f32 p10 = 0; f32 p11 = 2.f / v; f32 p12 = 0; float p13 = 0.f; + f32 p20 = 0; f32 p21 = 0; f32 p22 = 2.f / (f-n); float p23 = (f+n) / (n-f); + f32 p30 = 0; f32 p31 = 0; f32 p32 = 0; float p33 = 1.f; + + return {p00, p01, p02, p03, p10, p11, p12, p13, p20, p21, p22, p23, p30, p31, p32, p33}; + + } static Matrix4x4 OpenGLOrthoProjRH(float nearPlane, float farPlane, float hViewportSize, float vViewportSize); static Matrix4x4 OpenGLPerspProjLH(float nearPlane, float farPlane, float hViewportSize, float vViewportSize); static Matrix4x4 OpenGLPerspProjRH(float nearPlane, float farPlane, float hViewportSize, float vViewportSize);