mirror of
https://github.com/recp/cglm.git
synced 2025-10-03 16:51:35 +00:00
finally done with tests and all euler to quaternion functions
This commit is contained in:
@@ -215,12 +215,10 @@ glm_euler_yxz_quat(versor q, vec3 angles) {
|
|||||||
float zc = cosf(angles[2] / 2.0f);
|
float zc = cosf(angles[2] / 2.0f);
|
||||||
|
|
||||||
glm_quat_init(q,
|
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 * ys + zs * xc * yc,
|
||||||
zc * xs * yc + zs * xc * ys,
|
|
||||||
zc * xc * yc - zs * xs * ys);
|
zc * xc * yc - zs * xs * ys);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@@ -271,9 +269,9 @@ glm_euler_zxy_quat(versor q, vec3 angles) {
|
|||||||
|
|
||||||
glm_quat_init(q,
|
glm_quat_init(q,
|
||||||
yc * xs * zc + ys * xc * zs,
|
yc * xs * zc + ys * xc * zs,
|
||||||
|
-yc * xs * zs + ys * xc * zc,
|
||||||
yc * xc * zs - ys * xs * 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,
|
glm_quat_init(q,
|
||||||
xc * ys * zs + xs * yc * zc,
|
xc * ys * zs + xs * yc * zc,
|
||||||
|
xc * ys * zc - xs * yc * zs,
|
||||||
xc * yc * zs + xs * ys * zc,
|
xc * yc * zs + xs * ys * zc,
|
||||||
-xc * ys * zc + xs * yc * zs,
|
|
||||||
xc * yc * zc - xs * ys * zs);
|
xc * yc * zc - xs * ys * zs);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -272,7 +272,7 @@ TEST_IMPL(GLM_PREFIX, euler_xzy_quat) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST_IMPL(GLM_PREFIX, euler_yxz_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*/
|
/*random angles for testing*/
|
||||||
vec3 angles;
|
vec3 angles;
|
||||||
|
|
||||||
@@ -336,11 +336,8 @@ TEST_IMPL(GLM_PREFIX, euler_yxz_quat) {
|
|||||||
glm_quat_mul(rot_z, expected, expected);
|
glm_quat_mul(rot_z, expected, expected);
|
||||||
|
|
||||||
/*use my function to get the quaternion*/
|
/*use my function to get the quaternion*/
|
||||||
glm_euler_zxy_quat(result, angles);
|
glm_euler_yxz_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))
|
ASSERTIFY(test_assert_quat_eq(result, expected))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -350,7 +347,7 @@ fprintf(stderr, "\n");
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST_IMPL(GLM_PREFIX, euler_yzx_quat) {
|
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*/
|
/*random angles for testing*/
|
||||||
vec3 angles;
|
vec3 angles;
|
||||||
|
|
||||||
@@ -379,7 +376,7 @@ TEST_IMPL(GLM_PREFIX, euler_yzx_quat) {
|
|||||||
glm_quat_mul(rot_x, expected, expected);
|
glm_quat_mul(rot_x, expected, expected);
|
||||||
|
|
||||||
/*use my function to get the quaternion*/
|
/*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))
|
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);
|
glm_quat_mul(rot_x, expected, expected);
|
||||||
|
|
||||||
/*use my function to get the quaternion*/
|
/*use my function to get the quaternion*/
|
||||||
glm_euler_zxy_quat(result, angles);
|
glm_euler_yzx_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))
|
ASSERTIFY(test_assert_quat_eq(result, expected))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -428,7 +422,7 @@ fprintf(stderr, "\n");
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST_IMPL(GLM_PREFIX, euler_zxy_quat) {
|
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*/
|
/*random angles for testing*/
|
||||||
vec3 angles;
|
vec3 angles;
|
||||||
|
|
||||||
@@ -493,10 +487,7 @@ TEST_IMPL(GLM_PREFIX, euler_zxy_quat) {
|
|||||||
|
|
||||||
/*use my function to get the quaternion*/
|
/*use my function to get the quaternion*/
|
||||||
glm_euler_zxy_quat(result, angles);
|
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))
|
ASSERTIFY(test_assert_quat_eq(result, expected))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -506,7 +497,7 @@ fprintf(stderr, "\n");
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST_IMPL(GLM_PREFIX, euler_zyx_quat) {
|
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*/
|
/*random angles for testing*/
|
||||||
vec3 angles;
|
vec3 angles;
|
||||||
|
|
||||||
@@ -535,7 +526,7 @@ TEST_IMPL(GLM_PREFIX, euler_zyx_quat) {
|
|||||||
glm_quat_mul(rot_x, expected, expected);
|
glm_quat_mul(rot_x, expected, expected);
|
||||||
|
|
||||||
/*use my function to get the quaternion*/
|
/*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))
|
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_y, angles[1], axis_y);
|
||||||
glm_quatv(rot_z, angles[2], axis_z);
|
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_z, expected, expected);
|
||||||
glm_quat_mul(rot_y, expected, expected);
|
glm_quat_mul(rot_y, expected, expected);
|
||||||
glm_quat_mul(rot_x, expected, expected);
|
glm_quat_mul(rot_x, expected, expected);
|
||||||
|
|
||||||
/*use my function to get the quaternion*/
|
/*use my function to get the quaternion*/
|
||||||
glm_euler_zxy_quat(result, angles);
|
glm_euler_zyx_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))
|
ASSERTIFY(test_assert_quat_eq(result, expected))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user