From ab2160bdd347f4cd827835f1687437d25fae94c6 Mon Sep 17 00:00:00 2001 From: jvech Date: Tue, 30 Aug 2022 11:30:04 -0500 Subject: feat: orthographic transformation added --- src/linear.c | 20 ++++++++++++++++++++ src/linear.h | 1 + 2 files changed, 21 insertions(+) (limited to 'src') diff --git a/src/linear.c b/src/linear.c index 8bd58e8..062c103 100644 --- a/src/linear.c +++ b/src/linear.c @@ -47,6 +47,26 @@ linearPerspective(float FoV, float ratio, float near, float far) return out; } +Mat4 +linearOrtho(float left, float right, float bottom, float top, float near, float far) +{ + Mat4 out = linearMat4Identity(1.0); + + float width = right - left; + float height = top - bottom; + float depth = far - near; + + out.matrix[0][0] = 2 / (width); + out.matrix[0][3] = - (right + left) / width; + + out.matrix[1][1] = 2 / (height); + out.matrix[1][3] = - (top + bottom) / height; + + out.matrix[2][2] = -2 / (depth); + out.matrix[2][2] = - (far + near) / depth; + return out; +} + Mat4 linearTranslate(float T_x, float T_y, float T_z) { diff --git a/src/linear.h b/src/linear.h index 4ed2298..bd373f8 100644 --- a/src/linear.h +++ b/src/linear.h @@ -20,6 +20,7 @@ Mat4 linearTranslate(float translate_x, float translate_y, float translate_z); Mat4 linearScale(float scale_x, float scale_y, float scale_z); Mat4 linearRotate(float degree, float rotate_x, float rotate_y, float rotate_z); Mat4 linearPerspective(float FoV, float ratio, float near, float far); +Mat4 linearOrtho(float left, float right, float bottom, float top, float near, float far); Mat4 linearLookAt(Vec3 position, Vec3 target, Vec3 up); Mat4 linearMat4Fill(float value); -- cgit v1.2.3-70-g09d2