mirror of
https://github.com/recp/cglm.git
synced 2025-10-03 16:51:35 +00:00
extract fovy and aspect for perpective matrix
This commit is contained in:
@@ -426,6 +426,31 @@ glm_persp_decomp_near(mat4 proj, float * __restrict nearVal) {
|
|||||||
*nearVal = proj[3][2] / (proj[2][2] - 1);
|
*nearVal = proj[3][2] / (proj[2][2] - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief returns field of view angle along the Y-axis (in radians)
|
||||||
|
*
|
||||||
|
* if you need to degrees, use glm_deg to convert it or use this:
|
||||||
|
* fovy_deg = glm_deg(glm_persp_fovy(projMatrix))
|
||||||
|
*
|
||||||
|
* @param[in] proj perspective projection matrix
|
||||||
|
*/
|
||||||
|
CGLM_INLINE
|
||||||
|
float
|
||||||
|
glm_persp_fovy(mat4 proj) {
|
||||||
|
return 2.0 * atan(1.0 / proj[1][1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief returns aspect ratio of perspective projection
|
||||||
|
*
|
||||||
|
* @param[in] proj perspective projection matrix
|
||||||
|
*/
|
||||||
|
CGLM_INLINE
|
||||||
|
float
|
||||||
|
glm_persp_aspect(mat4 proj) {
|
||||||
|
return proj[1][1] / proj[0][0];
|
||||||
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* @brief extracts view frustum planes
|
* @brief extracts view frustum planes
|
||||||
*
|
*
|
||||||
|
@@ -93,7 +93,8 @@ libcglm_la_SOURCES=\
|
|||||||
test_tests_SOURCES=\
|
test_tests_SOURCES=\
|
||||||
test/src/test_common.c \
|
test/src/test_common.c \
|
||||||
test/src/test_main.c \
|
test/src/test_main.c \
|
||||||
test/src/test_mat4.c
|
test/src/test_mat4.c \
|
||||||
|
test/src/test_cam.c
|
||||||
|
|
||||||
all-local:
|
all-local:
|
||||||
sh ./post-build.sh
|
sh ./post-build.sh
|
||||||
|
25
test/src/test_cam.c
Normal file
25
test/src/test_cam.c
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c), Recep Aslantas.
|
||||||
|
*
|
||||||
|
* MIT License (MIT), http://opensource.org/licenses/MIT
|
||||||
|
* Full license can be found in the LICENSE file
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "test_common.h"
|
||||||
|
|
||||||
|
void
|
||||||
|
test_camera_decomp(void **state) {
|
||||||
|
mat4 proj;
|
||||||
|
float aspect, fovy, nearVal, farVal;
|
||||||
|
|
||||||
|
aspect = 0.782f;
|
||||||
|
fovy = glm_rad(49.984f);
|
||||||
|
nearVal = 0.1f;
|
||||||
|
farVal = 100.0f;
|
||||||
|
|
||||||
|
glm_perspective(fovy, aspect, nearVal, farVal, proj);
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
@@ -11,6 +11,9 @@ main(int argc, const char * argv[]) {
|
|||||||
const struct CMUnitTest tests[] = {
|
const struct CMUnitTest tests[] = {
|
||||||
/* mat4 */
|
/* mat4 */
|
||||||
cmocka_unit_test(test_mat4),
|
cmocka_unit_test(test_mat4),
|
||||||
|
|
||||||
|
/* camera */
|
||||||
|
cmocka_unit_test(test_camera_decomp)
|
||||||
};
|
};
|
||||||
|
|
||||||
return cmocka_run_group_tests(tests,
|
return cmocka_run_group_tests(tests,
|
||||||
|
@@ -9,4 +9,8 @@
|
|||||||
/* mat4 */
|
/* mat4 */
|
||||||
void test_mat4(void **state);
|
void test_mat4(void **state);
|
||||||
|
|
||||||
|
/* camera */
|
||||||
|
void
|
||||||
|
test_camera_decomp(void **state);
|
||||||
|
|
||||||
#endif /* test_tests_h */
|
#endif /* test_tests_h */
|
||||||
|
Reference in New Issue
Block a user