Skip to content

Commit

Permalink
[NEW] Added mat4_ortho_projection2
Browse files Browse the repository at this point in the history
 - This orthographic projection matrix doesn't swap the widths and heights internally.
  • Loading branch information
ravi688 committed Jul 30, 2024
1 parent 28bba22 commit ec3a2ce
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
2 changes: 2 additions & 0 deletions include/hpml/affine_transformation.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 24 additions & 0 deletions source/affine_transformation.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ec3a2ce

Please sign in to comment.