mirror of
https://github.com/recp/cglm.git
synced 2026-02-17 03:39:05 +00:00
perspective sizes
This commit is contained in:
@@ -478,6 +478,32 @@ glm_persp_aspect(mat4 proj) {
|
||||
return proj[1][1] / proj[0][0];
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief returns aspect ratio of perspective projection
|
||||
*
|
||||
* if you don't have fovy then use glm_persp_fovy(proj) to get it
|
||||
* or pass directly: glm_persp_sizes(proj, glm_persp_fovy(proj), sizes);
|
||||
*
|
||||
* @param[in] proj perspective projection matrix
|
||||
* @param[in] fovy fovy (see brief)
|
||||
* @param[out] dest sizes order: [Wnear, Hnear, Wfar, Hfar]
|
||||
*/
|
||||
CGLM_INLINE
|
||||
void
|
||||
glm_persp_sizes(mat4 proj, float fovy, vec4 dest) {
|
||||
float t, a, nearVal, farVal;
|
||||
|
||||
t = 2.0f * tanf(fovy * 0.5f);
|
||||
a = glm_persp_aspect(proj);
|
||||
|
||||
glm_persp_decomp_z(proj, &nearVal, &farVal);
|
||||
|
||||
dest[1] = t * nearVal;
|
||||
dest[3] = t * farVal;
|
||||
dest[0] = a * dest[1];
|
||||
dest[2] = a * dest[3];
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief extracts view frustum planes
|
||||
*
|
||||
|
||||
@@ -9,7 +9,8 @@
|
||||
|
||||
void
|
||||
test_camera_decomp(void **state) {
|
||||
mat4 proj;
|
||||
mat4 proj, proj2;
|
||||
vec4 sizes;
|
||||
float aspect, fovy, nearVal, farVal;
|
||||
|
||||
aspect = 0.782f;
|
||||
@@ -21,5 +22,17 @@ test_camera_decomp(void **state) {
|
||||
assert_true(fabsf(aspect - glm_persp_aspect(proj)) < FLT_EPSILON);
|
||||
assert_true(fabsf(fovy - glm_persp_fovy(proj)) < FLT_EPSILON);
|
||||
assert_true(fabsf(49.984f - glm_deg(glm_persp_fovy(proj))) < FLT_EPSILON);
|
||||
|
||||
glm_persp_sizes(proj, fovy, sizes);
|
||||
|
||||
glm_frustum(-sizes[0] * 0.5,
|
||||
sizes[0] * 0.5,
|
||||
-sizes[1] * 0.5,
|
||||
sizes[1] * 0.5,
|
||||
nearVal,
|
||||
farVal,
|
||||
proj2);
|
||||
|
||||
test_assert_mat4_eq(proj, proj2);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user