From 4a7cd2eb268c68b91f826b5044388ef8f4954299 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Thu, 18 Jan 2018 16:23:34 +0300 Subject: [PATCH] cam: convenient util for crating orthographic proj with AABB --- include/cglm/cam.h | 56 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/include/cglm/cam.h b/include/cglm/cam.h index 0d13a3d..9290ffa 100644 --- a/include/cglm/cam.h +++ b/include/cglm/cam.h @@ -52,6 +52,9 @@ CGLM_INLINE void glm_persp_decomp_near(mat4 proj, float *__restrict nearVal); CGLM_INLINE void glm_frustum_planes(mat4 m, vec4 dest[6]); CGLM_INLINE void glm_frustum_corners(mat4 invMat, vec4 dest[8]); + CGLM_INLINE glm_ortho_box(vec3 box[2], mat4 dest); + CGLM_INLINE void glm_ortho_boxp(vec3 box[2], float padding, mat4 dest); + CGLM_INLINE void glm_ortho_boxp(vec3 box[2], float padding, mat4 dest); */ #ifndef cglm_vcam_h @@ -135,6 +138,59 @@ glm_ortho(float left, dest[3][3] = 1.0f; } +/*! + * @brief set up orthographic projection matrix using bounding box + * + * bounding box (AABB) must be in view space + * + * @param[in] box AABB + * @param[out] dest result matrix + */ +CGLM_INLINE +void +glm_ortho_aabb(vec3 box[2], mat4 dest) { + glm_ortho(box[0][0], box[1][0], + box[0][1], box[1][1], + -box[1][2], -box[0][2], + dest); +} + +/*! + * @brief set up orthographic projection matrix using bounding box + * + * bounding box (AABB) must be in view space + * + * @param[in] box AABB + * @param[in] padding padding + * @param[out] dest result matrix + */ +CGLM_INLINE +void +glm_ortho_aabb_p(vec3 box[2], float padding, mat4 dest) { + glm_ortho(box[0][0] - padding, box[1][0] + padding, + box[0][1] - padding, box[1][1] + padding, + -(box[1][2] + padding), -(box[0][2] - padding), + dest); +} + +/*! + * @brief set up orthographic projection matrix using bounding box + * + * bounding box (AABB) must be in view space + * + * @param[in] box AABB + * @param[in] padding padding for near and far + * @param[out] dest result matrix + */ +CGLM_INLINE +void +glm_ortho_aabb_pz(vec3 box[2], float padding, mat4 dest) { + glm_ortho(box[0][0], box[1][0], + box[0][1], box[1][1], + -(box[1][2] + padding), -(box[0][2] - padding), + dest); +} + /*! * @brief set up unit orthographic projection matrix *