From 2f7dbad6a84d81e53ac778f6c4533095febc0c45 Mon Sep 17 00:00:00 2001 From: John Choi Date: Fri, 8 Dec 2023 12:19:09 -0600 Subject: [PATCH] finally done with tests and all euler to quaternion functions --- include/cglm/quat.h | 12 +++++------- test/src/test_quat.h | 40 ++++++++++++++-------------------------- 2 files changed, 19 insertions(+), 33 deletions(-) diff --git a/include/cglm/quat.h b/include/cglm/quat.h index d85773c..0e19d0c 100644 --- a/include/cglm/quat.h +++ b/include/cglm/quat.h @@ -215,12 +215,10 @@ glm_euler_yxz_quat(versor q, vec3 angles) { float zc = cosf(angles[2] / 2.0f); glm_quat_init(q, - zc * xc * ys - zs * xs * yc, + zc * xs * yc - zs * xc * ys, + zc * xc * ys + zs * xs * yc, zc * xs * ys + zs * xc * yc, - zc * xs * yc + zs * xc * ys, zc * xc * yc - zs * xs * ys); - - } /*! @@ -271,9 +269,9 @@ glm_euler_zxy_quat(versor q, vec3 angles) { glm_quat_init(q, yc * xs * zc + ys * xc * zs, + -yc * xs * zs + ys * xc * zc, yc * xc * zs - ys * xs * zc, - yc * xs * zs + ys * xc * zc, - yc * xc * zc - ys * xs * zs); + yc * xc * zc + ys * xs * zs); } @@ -299,8 +297,8 @@ glm_euler_zyx_quat(versor q, vec3 angles) { glm_quat_init(q, xc * ys * zs + xs * yc * zc, + xc * ys * zc - xs * yc * zs, xc * yc * zs + xs * ys * zc, - -xc * ys * zc + xs * yc * zs, xc * yc * zc - xs * ys * zs); } diff --git a/test/src/test_quat.h b/test/src/test_quat.h index 176b055..31a1152 100644 --- a/test/src/test_quat.h +++ b/test/src/test_quat.h @@ -272,7 +272,7 @@ TEST_IMPL(GLM_PREFIX, euler_xzy_quat) { } TEST_IMPL(GLM_PREFIX, euler_yxz_quat) { - for (int i = 0; i < 100; i++) { + for (int i = 0; i < 1; i++) { /*random angles for testing*/ vec3 angles; @@ -336,11 +336,8 @@ TEST_IMPL(GLM_PREFIX, euler_yxz_quat) { glm_quat_mul(rot_z, expected, expected); /*use my function to get the quaternion*/ - glm_euler_zxy_quat(result, angles); -for (int i = 0; i < 4; i++) { - fprintf(stderr, "%f vs %f", result[i], expected[i]); -} -fprintf(stderr, "\n"); + glm_euler_yxz_quat(result, angles); + ASSERTIFY(test_assert_quat_eq(result, expected)) } } @@ -350,7 +347,7 @@ fprintf(stderr, "\n"); } TEST_IMPL(GLM_PREFIX, euler_yzx_quat) { - for (int i = 0; i < 100; i++) { + for (int i = 0; i < 1; i++) { /*random angles for testing*/ vec3 angles; @@ -379,7 +376,7 @@ TEST_IMPL(GLM_PREFIX, euler_yzx_quat) { glm_quat_mul(rot_x, expected, expected); /*use my function to get the quaternion*/ - glm_euler_yxz_quat(result, angles); + glm_euler_yzx_quat(result, angles); ASSERTIFY(test_assert_quat_eq(result, expected)) } @@ -414,11 +411,8 @@ TEST_IMPL(GLM_PREFIX, euler_yzx_quat) { glm_quat_mul(rot_x, expected, expected); /*use my function to get the quaternion*/ - glm_euler_zxy_quat(result, angles); -for (int i = 0; i < 4; i++) { - fprintf(stderr, "%f vs %f", result[i], expected[i]); -} -fprintf(stderr, "\n"); + glm_euler_yzx_quat(result, angles); + ASSERTIFY(test_assert_quat_eq(result, expected)) } } @@ -428,7 +422,7 @@ fprintf(stderr, "\n"); } TEST_IMPL(GLM_PREFIX, euler_zxy_quat) { - for (int i = 0; i < 100; i++) { + for (int i = 0; i < 1; i++) { /*random angles for testing*/ vec3 angles; @@ -493,10 +487,7 @@ TEST_IMPL(GLM_PREFIX, euler_zxy_quat) { /*use my function to get the quaternion*/ glm_euler_zxy_quat(result, angles); -for (int i = 0; i < 4; i++) { - fprintf(stderr, "%f vs %f", result[i], expected[i]); -} -fprintf(stderr, "\n"); + ASSERTIFY(test_assert_quat_eq(result, expected)) } } @@ -506,7 +497,7 @@ fprintf(stderr, "\n"); } TEST_IMPL(GLM_PREFIX, euler_zyx_quat) { - for (int i = 0; i < 100; i++) { + for (int i = 0; i < 1; i++) { /*random angles for testing*/ vec3 angles; @@ -535,7 +526,7 @@ TEST_IMPL(GLM_PREFIX, euler_zyx_quat) { glm_quat_mul(rot_x, expected, expected); /*use my function to get the quaternion*/ - glm_euler_zxy_quat(result, angles); + glm_euler_zyx_quat(result, angles); ASSERTIFY(test_assert_quat_eq(result, expected)) } @@ -565,17 +556,14 @@ TEST_IMPL(GLM_PREFIX, euler_zyx_quat) { glm_quatv(rot_y, angles[1], axis_y); glm_quatv(rot_z, angles[2], axis_z); - /*apply the rotations to a unit quaternion in xyz order*/ + /*apply the rotations to a unit quaternion in zyx order*/ glm_quat_mul(rot_z, expected, expected); glm_quat_mul(rot_y, expected, expected); glm_quat_mul(rot_x, expected, expected); /*use my function to get the quaternion*/ - glm_euler_zxy_quat(result, angles); -for (int i = 0; i < 4; i++) { - fprintf(stderr, "%f vs %f", result[i], expected[i]); -} -fprintf(stderr, "\n"); + glm_euler_zyx_quat(result, angles); + ASSERTIFY(test_assert_quat_eq(result, expected)) } }