mirror of
https://github.com/recp/cglm.git
synced 2025-12-25 12:55:04 +00:00
fix unproject, add tests to project/unproject
This commit is contained in:
@@ -15,6 +15,9 @@ main(int argc, const char * argv[]) {
|
||||
/* camera */
|
||||
cmocka_unit_test(test_camera_lookat),
|
||||
cmocka_unit_test(test_camera_decomp)
|
||||
|
||||
/* project */
|
||||
cmocka_unit_test(test_project)
|
||||
};
|
||||
|
||||
return cmocka_run_group_tests(tests, NULL, NULL);
|
||||
|
||||
31
test/src/test_project.c
Normal file
31
test/src/test_project.c
Normal file
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* 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_project(void **state) {
|
||||
mat4 model, view, proj, mvp;
|
||||
vec4 viewport = {0.0f, 0.0f, 800.0f, 600.0f};
|
||||
vec3 pos = {13.0f, 45.0f, 0.74f};
|
||||
vec3 projected, unprojected;
|
||||
|
||||
glm_translate_make(model, (vec3){0.0f, 0.0f, -10.0f});
|
||||
glm_lookat((vec3){0.0f, 0.0f, 0.0f}, pos, GLM_YUP, view);
|
||||
|
||||
glm_perspective_default(0.5f, proj);
|
||||
glm_mat4_mulN((mat4 *[]){&proj, &view, &model}, 3, mvp);
|
||||
|
||||
glmc_project(pos, mvp, viewport, projected);
|
||||
glmc_unproject(projected, mvp, viewport, unprojected);
|
||||
|
||||
/* unprojected of projected vector must be same as original one */
|
||||
/* we used 0.01 because of projection floating point errors */
|
||||
assert_true(fabsf(pos[0] - unprojected[0]) < 0.01);
|
||||
assert_true(fabsf(pos[1] - unprojected[1]) < 0.01);
|
||||
assert_true(fabsf(pos[2] - unprojected[2]) < 0.01);
|
||||
}
|
||||
@@ -16,4 +16,7 @@ test_camera_lookat(void **state);
|
||||
void
|
||||
test_camera_decomp(void **state);
|
||||
|
||||
void
|
||||
test_project(void **state);
|
||||
|
||||
#endif /* test_tests_h */
|
||||
|
||||
Reference in New Issue
Block a user