From 75565ecf2d0d5cf3c257b8376c45ef3e5675000f Mon Sep 17 00:00:00 2001 From: Orange Date: Wed, 27 Aug 2025 23:17:56 +0300 Subject: [PATCH] Adds left- and right-handed ortho matrices. Adds functions to generate left- and right-handed orthographic projection matrices. This provides more flexibility when defining a projection for rendering. --- include/omath/mat.hpp | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/include/omath/mat.hpp b/include/omath/mat.hpp index 0ad81f1..1f1f086 100644 --- a/include/omath/mat.hpp +++ b/include/omath/mat.hpp @@ -479,6 +479,35 @@ namespace omath {0.f, 0.f, -(far + near) / (far - near), -(2.f * near * far) / (far - near)}, {0.f, 0.f, -1.f, 0.f}}; } + template + [[nodiscard]] + Mat<4, 4, Type, St> mat_ortho_left_handed(const Type left, const Type right, + const Type bottom, const Type top, + const Type near, const Type far) noexcept + { + return + { + { static_cast(2) / (right - left), 0.f, 0.f, -(right + left) / (right - left)}, + { 0.f, static_cast(2) / (top - bottom), 0.f, -(top + bottom) / (top - bottom)}, + { 0.f, 0.f, static_cast(2) / (far - near), -(far + near) / (far - near) }, + { 0.f, 0.f, 0.f, 1.f } + }; + } + template + [[nodiscard]] + Mat<4, 4, Type, St> mat_ortho_right_handed(const Type left, const Type right, + const Type bottom, const Type top, + const Type near, const Type far) noexcept + { + return + { + { static_cast(2) / (right - left), 0.f, 0.f, -(right + left) / (right - left)}, + { 0.f, static_cast(2) / (top - bottom), 0.f, -(top + bottom) / (top - bottom)}, + { 0.f, 0.f, -static_cast(2) / (far - near), -(far + near) / (far - near) }, + { 0.f, 0.f, 0.f, 1.f } + }; + } + } // namespace omath template