mat4 to quaternion

This commit is contained in:
Recep Aslantas
2018-04-07 19:46:46 +03:00
parent f5140ea005
commit 257c57d41f
10 changed files with 132 additions and 5 deletions

View File

@@ -27,6 +27,33 @@ test_rand_mat4(mat4 dest) {
/* glm_scale(dest, (vec3){drand48(), drand48(), drand48()}); */
}
void
test_rand_vec3(vec3 dest) {
srand((unsigned int)time(NULL));
dest[0] = drand48();
dest[1] = drand48();
dest[2] = drand48();
}
float
test_rand_angle(void) {
srand((unsigned int)time(NULL));
return drand48();
}
void
test_rand_quat(versor q) {
srand((unsigned int)time(NULL));
q[0] = drand48();
q[1] = drand48();
q[2] = drand48();
q[3] = drand48();
glm_quat_normalize(q);
}
void
test_assert_mat4_eq(mat4 m1, mat4 m2) {
int i, j, k;
@@ -53,7 +80,16 @@ test_assert_mat4_eq2(mat4 m1, mat4 m2, float eps) {
void
test_assert_vec3_eq(vec3 v1, vec3 v2) {
assert_true(fabsf(v1[0] - v2[0]) <= 0.0000009);
assert_true(fabsf(v1[0] - v2[0]) <= 0.0000009); /* rounding errors */
assert_true(fabsf(v1[1] - v2[1]) <= 0.0000009);
assert_true(fabsf(v1[2] - v2[2]) <= 0.0000009);
}
void
test_assert_quat_eq(versor v1, versor v2) {
assert_true(fabsf(v1[0] - v2[0]) <= 0.0009); /* rounding errors */
assert_true(fabsf(v1[1] - v2[1]) <= 0.0009);
assert_true(fabsf(v1[2] - v2[2]) <= 0.0009);
assert_true(fabsf(v1[3] - v2[3]) <= 0.0009);
}

View File

@@ -34,4 +34,16 @@ test_assert_mat4_eq2(mat4 m1, mat4 m2, float eps);
void
test_assert_vec3_eq(vec3 v1, vec3 v2);
void
test_assert_quat_eq(versor v1, versor v2);
void
test_rand_vec3(vec3 dest);
float
test_rand_angle(void);
void
test_rand_quat(versor q);
#endif /* test_common_h */

View File

@@ -23,7 +23,10 @@ main(int argc, const char * argv[]) {
cmocka_unit_test(test_clamp),
/* euler */
cmocka_unit_test(test_euler)
cmocka_unit_test(test_euler),
/* quaternion */
cmocka_unit_test(test_quat)
};
return cmocka_run_group_tests(tests, NULL, NULL);

22
test/src/test_quat.c Normal file
View File

@@ -0,0 +1,22 @@
/*
* 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_quat(void **state) {
mat4 rot;
versor inQuat, outQuat;
int i;
for (i = 0; i < 10000; i++) {
test_rand_quat(inQuat);
glmc_quat_mat4(inQuat, rot);
glm_mat4_quat(rot, outQuat);
test_assert_quat_eq(inQuat, outQuat);
}
}

View File

@@ -25,4 +25,7 @@ test_clamp(void **state);
void
test_euler(void **state);
void
test_quat(void **state);
#endif /* test_tests_h */