From ec3a2ce2233b60cf22cb376055fe526d5f5d36ab Mon Sep 17 00:00:00 2001 From: ravi688 Date: Tue, 30 Jul 2024 19:23:01 +0530 Subject: [PATCH] [NEW] Added mat4_ortho_projection2 - This orthographic projection matrix doesn't swap the widths and heights internally. --- include/hpml/affine_transformation.h | 2 ++ source/affine_transformation.c | 24 ++++++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/include/hpml/affine_transformation.h b/include/hpml/affine_transformation.h index db11b00..76d34d4 100644 --- a/include/hpml/affine_transformation.h +++ b/include/hpml/affine_transformation.h @@ -23,6 +23,8 @@ HPML_API mat4_t mat4_rotation(float x, float y, float z); */ HPML_API mat4_t mat4_ortho_projection(float nearClipPlane, float farClipPlane, float height, float aspectRatio); +HPML_API mat4_t mat4_ortho_projection2(float nearClipPlane, float farClipPlane, float height, float aspectRatio); + /* mat4_persp_projection: Creates a perspective projection matrix * nearClipPlane: position of the near clip plane relative to the camera, +ve means front and -ve means back * farClipPlane: position of the far clip plane relative to the camera, +ve means front and -ve means back diff --git a/source/affine_transformation.c b/source/affine_transformation.c index af02680..de9e390 100644 --- a/source/affine_transformation.c +++ b/source/affine_transformation.c @@ -40,6 +40,30 @@ EXCEPTION_BLOCK }; } +HPML_API mat4_t mat4_ortho_projection2(float nearClipPlane, float farClipPlane, float height, float aspectRatio) +{ + float box_x = farClipPlane - nearClipPlane; + float box_y; + float box_z; + box_y = height; + box_z = aspectRatio * height; +EXCEPTION_BLOCK +( + if((box_x == 0) || (box_y == 0) || (box_z == 0)) + throw_exception(DIVIDE_BY_ZERO); + if((box_x < 0) || (box_y < 0) || (box_z < 0)) + throw_exception(NEGATIVE_VALUE); +) + float t = 1 / box_x; + return (mat4_t) + { + 0, 0, 2 / box_z, 0, + 0, 2 / box_y, 0, 0, + t, 0, 0, - nearClipPlane * t, + 0, 0, 0, 1 + }; +} + HPML_API mat4_t mat4_persp_projection(float nearClipPlane, float farClipPlane, float fieldOfView, float aspectRatio) { EXCEPTION_BLOCK