From 1907ba10466bc556eb4773715c5aa7feac2e8d68 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Thu, 23 Nov 2017 17:16:29 +0300 Subject: [PATCH] decompose perspective near and far values --- include/cglm/cam.h | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/include/cglm/cam.h b/include/cglm/cam.h index 132cc04..aa83ac0 100644 --- a/include/cglm/cam.h +++ b/include/cglm/cam.h @@ -281,4 +281,44 @@ glm_lookat(vec3 eye, dest[3][3] = 1.0f; } +/*! + * @brief decomposes near and far values of perspective projection. + * z stands for z axis (near / far axis) + * + * @param[in] proj perspective projection matrix + * @param[out] near near + * @param[out] far far + */ +CGLM_INLINE +void +glm_persp_decomp_z(mat4 proj, + float * __restrict near, + float * __restrict far) { + *near = proj[3][2] / (proj[3][3] - 1); + *far = proj[3][2] / (proj[3][3] + 1); +} + +/*! + * @brief decomposes far value of perspective projection. + * + * @param[in] proj perspective projection matrix + * @param[out] far far + */ +CGLM_INLINE +void +glm_persp_decomp_far(mat4 proj, float * __restrict far) { + *far = proj[3][2] / (proj[3][3] + 1); +} + +/*! + * @brief decomposes near value of perspective projection. + * + * @param[in] proj perspective projection matrix + * @param[out] near near + */ +CGLM_INLINE +void +glm_persp_decomp_near(mat4 proj, float * __restrict near) { + *near = proj[3][2] / (proj[3][3] - 1); +} #endif /* cglm_vcam_h */