mirror of
https://github.com/recp/cglm.git
synced 2025-12-24 12:32:40 +00:00
made all the functions. I have miscalculated some stuff and am currently trying to test them. I have created all the testing functions as well
This commit is contained in:
@@ -142,7 +142,8 @@ glm_quat_init(versor q, float x, float y, float z, float w) {
|
||||
//TODO: telephone001's eulertoquat
|
||||
|
||||
/*!
|
||||
* @brief creates NEW quaternion using rotation angles and does does rotations in x y z order
|
||||
* @brief creates NEW quaternion using rotation angles and does
|
||||
* rotations in x y z order (roll pitch yaw)
|
||||
*
|
||||
* @param[out] q quaternion
|
||||
* @param[in] angle angles x y z (radians)
|
||||
@@ -159,14 +160,153 @@ glm_euler_xyz_quat(versor q, vec3 angles) {
|
||||
float zs = sinf(angles[2] / 2.0f);
|
||||
float zc = cosf(angles[2] / 2.0f);
|
||||
|
||||
|
||||
glm_quat_init(q,
|
||||
zc * yc * xs - zs * ys * xc,
|
||||
zc * ys * xc + zs * yc * xs,
|
||||
-zc * ys * xs + zs * yc * xc,
|
||||
zc * yc * xc + zs * ys * xs);
|
||||
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief creates NEW quaternion using rotation angles and does
|
||||
* rotations in x z y order (roll yaw pitch)
|
||||
*
|
||||
* @param[out] q quaternion
|
||||
* @param[in] angle angles x y z (radians)
|
||||
*/
|
||||
CGLM_INLINE
|
||||
void
|
||||
glm_euler_xzy_quat(versor q, vec3 angles) {
|
||||
float xs = sinf(angles[0] / 2.0f);
|
||||
float xc = cosf(angles[0] / 2.0f);
|
||||
|
||||
float ys = sinf(angles[1] / 2.0f);
|
||||
float yc = cosf(angles[1] / 2.0f);
|
||||
|
||||
float zs = sinf(angles[2] / 2.0f);
|
||||
float zc = cosf(angles[2] / 2.0f);
|
||||
|
||||
glm_quat_init(q,
|
||||
yc * zc * xs + ys * zs * xc,
|
||||
yc * zs * xs + ys * zc * xc,
|
||||
yc * zs * xc - ys * zc * xs,
|
||||
yc * zc * xc - ys * zs * xs);
|
||||
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief creates NEW quaternion using rotation angles and does
|
||||
* rotations in y x z order (pitch roll yaw)
|
||||
*
|
||||
* @param[out] q quaternion
|
||||
* @param[in] angle angles x y z (radians)
|
||||
*/
|
||||
CGLM_INLINE
|
||||
void
|
||||
glm_euler_yxz_quat(versor q, vec3 angles) {
|
||||
float xs = sinf(angles[0] / 2.0f);
|
||||
float xc = cosf(angles[0] / 2.0f);
|
||||
|
||||
float ys = sinf(angles[1] / 2.0f);
|
||||
float yc = cosf(angles[1] / 2.0f);
|
||||
|
||||
float zs = sinf(angles[2] / 2.0f);
|
||||
float zc = cosf(angles[2] / 2.0f);
|
||||
|
||||
glm_quat_init(q,
|
||||
zc * xc * ys - zs * xs * yc,
|
||||
zc * xs * ys + zs * xc * yc,
|
||||
zc * xs * yc + zs * xc * ys,
|
||||
zc * xc * yc - zs * xs * ys);
|
||||
|
||||
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief creates NEW quaternion using rotation angles and does
|
||||
* rotations in y z x order (pitch yaw roll)
|
||||
*
|
||||
* @param[out] q quaternion
|
||||
* @param[in] angle angles x y z (radians)
|
||||
*/
|
||||
CGLM_INLINE
|
||||
void
|
||||
glm_euler_yzx_quat(versor q, vec3 angles) {
|
||||
float xs = sinf(angles[0] / 2.0f);
|
||||
float xc = cosf(angles[0] / 2.0f);
|
||||
|
||||
float ys = sinf(angles[1] / 2.0f);
|
||||
float yc = cosf(angles[1] / 2.0f);
|
||||
|
||||
float zs = sinf(angles[2] / 2.0f);
|
||||
float zc = cosf(angles[2] / 2.0f);
|
||||
|
||||
glm_quat_init(q,
|
||||
-xc * zs * ys + xs * zc * yc,
|
||||
xc * zc * ys - xs * zs * yc,
|
||||
xc * zs * yc + xs * zc * ys,
|
||||
xc * zc * yc + xs * zs * ys);
|
||||
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief creates NEW quaternion using rotation angles and does
|
||||
* rotations in z x y order (yaw roll pitch)
|
||||
*
|
||||
* @param[out] q quaternion
|
||||
* @param[in] angle angles x y z (radians)
|
||||
*/
|
||||
CGLM_INLINE
|
||||
void
|
||||
glm_euler_zxy_quat(versor q, vec3 angles) {
|
||||
float xs = sinf(angles[0] / 2.0f);
|
||||
float xc = cosf(angles[0] / 2.0f);
|
||||
|
||||
float ys = sinf(angles[1] / 2.0f);
|
||||
float yc = cosf(angles[1] / 2.0f);
|
||||
|
||||
float zs = sinf(angles[2] / 2.0f);
|
||||
float zc = cosf(angles[2] / 2.0f);
|
||||
|
||||
glm_quat_init(q,
|
||||
yc * xs * zc + ys * xc * zs,
|
||||
yc * xc * zs - ys * xs * zc,
|
||||
yc * xs * zs + ys * xc * zc,
|
||||
yc * xc * zc - ys * xs * zs);
|
||||
|
||||
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief creates NEW quaternion using rotation angles and does
|
||||
* rotations in z y x order (yaw pitch roll)
|
||||
*
|
||||
* @param[out] q quaternion
|
||||
* @param[in] angle angles x y z (radians)
|
||||
*/
|
||||
CGLM_INLINE
|
||||
void
|
||||
glm_euler_zyx_quat(versor q, vec3 angles) {
|
||||
float xs = sinf(angles[0] / 2.0f);
|
||||
float xc = cosf(angles[0] / 2.0f);
|
||||
|
||||
float ys = sinf(angles[1] / 2.0f);
|
||||
float yc = cosf(angles[1] / 2.0f);
|
||||
|
||||
float zs = sinf(angles[2] / 2.0f);
|
||||
float zc = cosf(angles[2] / 2.0f);
|
||||
|
||||
glm_quat_init(q,
|
||||
xc * ys * zs + xs * yc * zc,
|
||||
xc * yc * zs + xs * ys * zc,
|
||||
-xc * ys * zc + xs * yc * zs,
|
||||
xc * yc * zc - xs * ys * zs);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*!
|
||||
* @brief creates NEW quaternion with axis vector
|
||||
*
|
||||
|
||||
@@ -123,39 +123,463 @@ TEST_IMPL(GLM_PREFIX, quatv) {
|
||||
|
||||
// telephone001 changes (remove comment when done) TODO
|
||||
TEST_IMPL(GLM_PREFIX, euler_xyz_quat) {
|
||||
/*random angles for testing*/
|
||||
vec3 angles = {glm_rad(30.0f), glm_rad(60.0f), glm_rad(90.0f)};
|
||||
for (int i = 0; i < 100; i++) {
|
||||
/*random angles for testing*/
|
||||
vec3 angles;
|
||||
|
||||
/*quaternion representations for rotations*/
|
||||
versor rot_x = {0.0f, 0.0f, 0.0f, 1.0f};
|
||||
versor rot_y = {0.0f, 0.0f, 0.0f, 1.0f};
|
||||
versor rot_z = {0.0f, 0.0f, 0.0f, 1.0f};
|
||||
/*quaternion representations for rotations*/
|
||||
versor rot_x = {0.0f, 0.0f, 0.0f, 1.0f};
|
||||
versor rot_y = {0.0f, 0.0f, 0.0f, 1.0f};
|
||||
versor rot_z = {0.0f, 0.0f, 0.0f, 1.0f};
|
||||
|
||||
vec3 axis_x = {1.0f, 0.0f, 0.0f};
|
||||
vec3 axis_y = {0.0f, 1.0f, 0.0f};
|
||||
vec3 axis_z = {0.0f, 0.0f, 1.0f};
|
||||
vec3 axis_x = {1.0f, 0.0f, 0.0f};
|
||||
vec3 axis_y = {0.0f, 1.0f, 0.0f};
|
||||
vec3 axis_z = {0.0f, 0.0f, 1.0f};
|
||||
|
||||
versor expected = {0.0f, 0.0f, 0.0f, 1.0f};
|
||||
versor result = {0.0f, 0.0f, 0.0f, 0.0f};
|
||||
versor expected = {0.0f, 0.0f, 0.0f, 1.0f};
|
||||
versor result;
|
||||
|
||||
/*create the rotation quaternions using the angles and axises*/
|
||||
glm_quatv(rot_x, angles[0], axis_x);
|
||||
glm_quatv(rot_y, angles[1], axis_y);
|
||||
glm_quatv(rot_z, angles[2], axis_z);
|
||||
test_rand_vec3(angles);
|
||||
|
||||
/*apply the rotations to a unit quaternion in xyz order*/
|
||||
glm_quat_mul(rot_x, expected, expected);
|
||||
glm_quat_mul(rot_y, expected, expected);
|
||||
glm_quat_mul(rot_z, expected, expected);
|
||||
/*create the rotation quaternions using the angles and axises*/
|
||||
glm_quatv(rot_x, angles[0], axis_x);
|
||||
glm_quatv(rot_y, angles[1], axis_y);
|
||||
glm_quatv(rot_z, angles[2], axis_z);
|
||||
|
||||
/*use my function to get the quaternion*/
|
||||
glm_euler_xyz_quat(result, angles);
|
||||
/*apply the rotations to a unit quaternion in xyz order*/
|
||||
glm_quat_mul(rot_x, expected, expected);
|
||||
glm_quat_mul(rot_y, expected, expected);
|
||||
glm_quat_mul(rot_z, expected, expected);
|
||||
|
||||
fprintf(stderr,"TEST\n");
|
||||
for (int i = 0; i < 4; i++) {
|
||||
fprintf(stderr, "%f vs %f\n", expected[i], result[i]);
|
||||
/*use my function to get the quaternion*/
|
||||
glm_euler_xyz_quat(result, angles);
|
||||
|
||||
ASSERTIFY(test_assert_quat_eq(result, expected))
|
||||
}
|
||||
|
||||
/*Start gimbal lock tests*/
|
||||
for (float x = -90.0f; x <= 90.0f; x += 90.0f) {
|
||||
for (float y = -90.0f; y <= 90.0f; y += 90.0f) {
|
||||
for (float z = -90.0f; z <= 90.0f; z += 90.0f) {
|
||||
/* angles that will cause gimbal lock*/
|
||||
vec3 angles = {x, y, z};
|
||||
|
||||
/*quaternion representations for rotations*/
|
||||
versor rot_x = {0.0f, 0.0f, 0.0f, 1.0f};
|
||||
versor rot_y = {0.0f, 0.0f, 0.0f, 1.0f};
|
||||
versor rot_z = {0.0f, 0.0f, 0.0f, 1.0f};
|
||||
|
||||
vec3 axis_x = {1.0f, 0.0f, 0.0f};
|
||||
vec3 axis_y = {0.0f, 1.0f, 0.0f};
|
||||
vec3 axis_z = {0.0f, 0.0f, 1.0f};
|
||||
|
||||
versor expected = {0.0f, 0.0f, 0.0f, 1.0f};
|
||||
versor result;
|
||||
|
||||
/*create the rotation quaternions using the angles and axises*/
|
||||
glm_quatv(rot_x, angles[0], axis_x);
|
||||
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*/
|
||||
glm_quat_mul(rot_x, expected, expected);
|
||||
glm_quat_mul(rot_y, expected, expected);
|
||||
glm_quat_mul(rot_z, expected, expected);
|
||||
|
||||
/*use my function to get the quaternion*/
|
||||
glm_euler_xyz_quat(result, angles);
|
||||
|
||||
ASSERTIFY(test_assert_quat_eq(result, expected))
|
||||
}
|
||||
}
|
||||
}
|
||||
TEST_SUCCESS
|
||||
}
|
||||
|
||||
TEST_IMPL(GLM_PREFIX, euler_xzy_quat) {
|
||||
for (int i = 0; i < 100; i++) {
|
||||
/*random angles for testing*/
|
||||
vec3 angles;
|
||||
|
||||
/*quaternion representations for rotations*/
|
||||
versor rot_x = {0.0f, 0.0f, 0.0f, 1.0f};
|
||||
versor rot_y = {0.0f, 0.0f, 0.0f, 1.0f};
|
||||
versor rot_z = {0.0f, 0.0f, 0.0f, 1.0f};
|
||||
|
||||
vec3 axis_x = {1.0f, 0.0f, 0.0f};
|
||||
vec3 axis_y = {0.0f, 1.0f, 0.0f};
|
||||
vec3 axis_z = {0.0f, 0.0f, 1.0f};
|
||||
|
||||
versor expected = {0.0f, 0.0f, 0.0f, 1.0f};
|
||||
versor result;
|
||||
|
||||
test_rand_vec3(angles);
|
||||
|
||||
/*create the rotation quaternions using the angles and axises*/
|
||||
glm_quatv(rot_x, angles[0], axis_x);
|
||||
glm_quatv(rot_y, angles[1], axis_y);
|
||||
glm_quatv(rot_z, angles[2], axis_z);
|
||||
|
||||
/*apply the rotations to a unit quaternion in xzy order*/
|
||||
glm_quat_mul(rot_x, expected, expected);
|
||||
glm_quat_mul(rot_z, expected, expected);
|
||||
glm_quat_mul(rot_y, expected, expected);
|
||||
|
||||
/*use my function to get the quaternion*/
|
||||
glm_euler_xzy_quat(result, angles);
|
||||
|
||||
ASSERTIFY(test_assert_quat_eq(result, expected))
|
||||
}
|
||||
|
||||
/*Start gimbal lock tests*/
|
||||
for (float x = -90.0f; x <= 90.0f; x += 90.0f) {
|
||||
for (float y = -90.0f; y <= 90.0f; y += 90.0f) {
|
||||
for (float z = -90.0f; z <= 90.0f; z += 90.0f) {
|
||||
/* angles that will cause gimbal lock*/
|
||||
vec3 angles = {x, y, z};
|
||||
|
||||
/*quaternion representations for rotations*/
|
||||
versor rot_x = {0.0f, 0.0f, 0.0f, 1.0f};
|
||||
versor rot_y = {0.0f, 0.0f, 0.0f, 1.0f};
|
||||
versor rot_z = {0.0f, 0.0f, 0.0f, 1.0f};
|
||||
|
||||
vec3 axis_x = {1.0f, 0.0f, 0.0f};
|
||||
vec3 axis_y = {0.0f, 1.0f, 0.0f};
|
||||
vec3 axis_z = {0.0f, 0.0f, 1.0f};
|
||||
|
||||
versor expected = {0.0f, 0.0f, 0.0f, 1.0f};
|
||||
versor result;
|
||||
|
||||
/*create the rotation quaternions using the angles and axises*/
|
||||
glm_quatv(rot_x, angles[0], axis_x);
|
||||
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*/
|
||||
glm_quat_mul(rot_x, expected, expected);
|
||||
glm_quat_mul(rot_z, expected, expected);
|
||||
glm_quat_mul(rot_y, expected, expected);
|
||||
|
||||
/*use my function to get the quaternion*/
|
||||
glm_euler_xzy_quat(result, angles);
|
||||
|
||||
ASSERTIFY(test_assert_quat_eq(result, expected))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TEST_SUCCESS
|
||||
}
|
||||
|
||||
TEST_IMPL(GLM_PREFIX, euler_yxz_quat) {
|
||||
for (int i = 0; i < 100; i++) {
|
||||
/*random angles for testing*/
|
||||
vec3 angles;
|
||||
|
||||
/*quaternion representations for rotations*/
|
||||
versor rot_x = {0.0f, 0.0f, 0.0f, 1.0f};
|
||||
versor rot_y = {0.0f, 0.0f, 0.0f, 1.0f};
|
||||
versor rot_z = {0.0f, 0.0f, 0.0f, 1.0f};
|
||||
|
||||
vec3 axis_x = {1.0f, 0.0f, 0.0f};
|
||||
vec3 axis_y = {0.0f, 1.0f, 0.0f};
|
||||
vec3 axis_z = {0.0f, 0.0f, 1.0f};
|
||||
|
||||
versor expected = {0.0f, 0.0f, 0.0f, 1.0f};
|
||||
versor result;
|
||||
|
||||
test_rand_vec3(angles);
|
||||
|
||||
/*create the rotation quaternions using the angles and axises*/
|
||||
glm_quatv(rot_x, angles[0], axis_x);
|
||||
glm_quatv(rot_y, angles[1], axis_y);
|
||||
glm_quatv(rot_z, angles[2], axis_z);
|
||||
|
||||
/*apply the rotations to a unit quaternion in yxz order*/
|
||||
glm_quat_mul(rot_y, expected, expected);
|
||||
glm_quat_mul(rot_x, expected, expected);
|
||||
glm_quat_mul(rot_z, expected, expected);
|
||||
|
||||
/*use my function to get the quaternion*/
|
||||
glm_euler_yxz_quat(result, angles);
|
||||
|
||||
ASSERTIFY(test_assert_quat_eq(result, expected))
|
||||
}
|
||||
|
||||
/*Start gimbal lock tests*/
|
||||
for (float x = -90.0f; x <= 90.0f; x += 90.0f) {
|
||||
for (float y = -90.0f; y <= 90.0f; y += 90.0f) {
|
||||
for (float z = -90.0f; z <= 90.0f; z += 90.0f) {
|
||||
/* angles that will cause gimbal lock*/
|
||||
vec3 angles = {x, y, z};
|
||||
|
||||
/*quaternion representations for rotations*/
|
||||
versor rot_x = {0.0f, 0.0f, 0.0f, 1.0f};
|
||||
versor rot_y = {0.0f, 0.0f, 0.0f, 1.0f};
|
||||
versor rot_z = {0.0f, 0.0f, 0.0f, 1.0f};
|
||||
|
||||
vec3 axis_x = {1.0f, 0.0f, 0.0f};
|
||||
vec3 axis_y = {0.0f, 1.0f, 0.0f};
|
||||
vec3 axis_z = {0.0f, 0.0f, 1.0f};
|
||||
|
||||
versor expected = {0.0f, 0.0f, 0.0f, 1.0f};
|
||||
versor result;
|
||||
|
||||
/*create the rotation quaternions using the angles and axises*/
|
||||
glm_quatv(rot_x, angles[0], axis_x);
|
||||
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*/
|
||||
glm_quat_mul(rot_y, expected, expected);
|
||||
glm_quat_mul(rot_x, expected, expected);
|
||||
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");
|
||||
ASSERTIFY(test_assert_quat_eq(result, expected))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TEST_SUCCESS
|
||||
}
|
||||
|
||||
TEST_IMPL(GLM_PREFIX, euler_yzx_quat) {
|
||||
for (int i = 0; i < 100; i++) {
|
||||
/*random angles for testing*/
|
||||
vec3 angles;
|
||||
|
||||
/*quaternion representations for rotations*/
|
||||
versor rot_x = {0.0f, 0.0f, 0.0f, 1.0f};
|
||||
versor rot_y = {0.0f, 0.0f, 0.0f, 1.0f};
|
||||
versor rot_z = {0.0f, 0.0f, 0.0f, 1.0f};
|
||||
|
||||
vec3 axis_x = {1.0f, 0.0f, 0.0f};
|
||||
vec3 axis_y = {0.0f, 1.0f, 0.0f};
|
||||
vec3 axis_z = {0.0f, 0.0f, 1.0f};
|
||||
|
||||
versor expected = {0.0f, 0.0f, 0.0f, 1.0f};
|
||||
versor result;
|
||||
|
||||
test_rand_vec3(angles);
|
||||
|
||||
/*create the rotation quaternions using the angles and axises*/
|
||||
glm_quatv(rot_x, angles[0], axis_x);
|
||||
glm_quatv(rot_y, angles[1], axis_y);
|
||||
glm_quatv(rot_z, angles[2], axis_z);
|
||||
|
||||
/*apply the rotations to a unit quaternion in yzx order*/
|
||||
glm_quat_mul(rot_y, expected, expected);
|
||||
glm_quat_mul(rot_z, expected, expected);
|
||||
glm_quat_mul(rot_x, expected, expected);
|
||||
|
||||
/*use my function to get the quaternion*/
|
||||
glm_euler_yxz_quat(result, angles);
|
||||
|
||||
ASSERTIFY(test_assert_quat_eq(result, expected))
|
||||
}
|
||||
|
||||
/*Start gimbal lock tests*/
|
||||
for (float x = -90.0f; x <= 90.0f; x += 90.0f) {
|
||||
for (float y = -90.0f; y <= 90.0f; y += 90.0f) {
|
||||
for (float z = -90.0f; z <= 90.0f; z += 90.0f) {
|
||||
/* angles that will cause gimbal lock*/
|
||||
vec3 angles = {x, y, z};
|
||||
|
||||
/*quaternion representations for rotations*/
|
||||
versor rot_x = {0.0f, 0.0f, 0.0f, 1.0f};
|
||||
versor rot_y = {0.0f, 0.0f, 0.0f, 1.0f};
|
||||
versor rot_z = {0.0f, 0.0f, 0.0f, 1.0f};
|
||||
|
||||
vec3 axis_x = {1.0f, 0.0f, 0.0f};
|
||||
vec3 axis_y = {0.0f, 1.0f, 0.0f};
|
||||
vec3 axis_z = {0.0f, 0.0f, 1.0f};
|
||||
|
||||
versor expected = {0.0f, 0.0f, 0.0f, 1.0f};
|
||||
versor result;
|
||||
|
||||
/*create the rotation quaternions using the angles and axises*/
|
||||
glm_quatv(rot_x, angles[0], axis_x);
|
||||
glm_quatv(rot_y, angles[1], axis_y);
|
||||
glm_quatv(rot_z, angles[2], axis_z);
|
||||
|
||||
/*apply the rotations to a unit quaternion in yzx order*/
|
||||
glm_quat_mul(rot_y, expected, expected);
|
||||
glm_quat_mul(rot_z, 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");
|
||||
ASSERTIFY(test_assert_quat_eq(result, expected))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TEST_SUCCESS
|
||||
}
|
||||
|
||||
TEST_IMPL(GLM_PREFIX, euler_zxy_quat) {
|
||||
for (int i = 0; i < 100; i++) {
|
||||
/*random angles for testing*/
|
||||
vec3 angles;
|
||||
|
||||
/*quaternion representations for rotations*/
|
||||
versor rot_x = {0.0f, 0.0f, 0.0f, 1.0f};
|
||||
versor rot_y = {0.0f, 0.0f, 0.0f, 1.0f};
|
||||
versor rot_z = {0.0f, 0.0f, 0.0f, 1.0f};
|
||||
|
||||
vec3 axis_x = {1.0f, 0.0f, 0.0f};
|
||||
vec3 axis_y = {0.0f, 1.0f, 0.0f};
|
||||
vec3 axis_z = {0.0f, 0.0f, 1.0f};
|
||||
|
||||
versor expected = {0.0f, 0.0f, 0.0f, 1.0f};
|
||||
versor result;
|
||||
|
||||
test_rand_vec3(angles);
|
||||
|
||||
/*create the rotation quaternions using the angles and axises*/
|
||||
glm_quatv(rot_x, angles[0], axis_x);
|
||||
glm_quatv(rot_y, angles[1], axis_y);
|
||||
glm_quatv(rot_z, angles[2], axis_z);
|
||||
|
||||
/*apply the rotations to a unit quaternion in zxy order*/
|
||||
glm_quat_mul(rot_z, expected, expected);
|
||||
glm_quat_mul(rot_x, expected, expected);
|
||||
glm_quat_mul(rot_y, expected, expected);
|
||||
|
||||
/*use my function to get the quaternion*/
|
||||
glm_euler_zxy_quat(result, angles);
|
||||
|
||||
ASSERTIFY(test_assert_quat_eq(result, expected))
|
||||
}
|
||||
|
||||
/*Start gimbal lock tests*/
|
||||
for (float x = -90.0f; x <= 90.0f; x += 90.0f) {
|
||||
for (float y = -90.0f; y <= 90.0f; y += 90.0f) {
|
||||
for (float z = -90.0f; z <= 90.0f; z += 90.0f) {
|
||||
/* angles that will cause gimbal lock*/
|
||||
vec3 angles = {x, y, z};
|
||||
|
||||
/*quaternion representations for rotations*/
|
||||
versor rot_x = {0.0f, 0.0f, 0.0f, 1.0f};
|
||||
versor rot_y = {0.0f, 0.0f, 0.0f, 1.0f};
|
||||
versor rot_z = {0.0f, 0.0f, 0.0f, 1.0f};
|
||||
|
||||
vec3 axis_x = {1.0f, 0.0f, 0.0f};
|
||||
vec3 axis_y = {0.0f, 1.0f, 0.0f};
|
||||
vec3 axis_z = {0.0f, 0.0f, 1.0f};
|
||||
|
||||
versor expected = {0.0f, 0.0f, 0.0f, 1.0f};
|
||||
versor result;
|
||||
|
||||
/*create the rotation quaternions using the angles and axises*/
|
||||
glm_quatv(rot_x, angles[0], axis_x);
|
||||
glm_quatv(rot_y, angles[1], axis_y);
|
||||
glm_quatv(rot_z, angles[2], axis_z);
|
||||
|
||||
/*apply the rotations to a unit quaternion in zxy order*/
|
||||
glm_quat_mul(rot_z, expected, expected);
|
||||
glm_quat_mul(rot_x, expected, expected);
|
||||
glm_quat_mul(rot_y, 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");
|
||||
ASSERTIFY(test_assert_quat_eq(result, expected))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TEST_SUCCESS
|
||||
}
|
||||
|
||||
TEST_IMPL(GLM_PREFIX, euler_zyx_quat) {
|
||||
for (int i = 0; i < 100; i++) {
|
||||
/*random angles for testing*/
|
||||
vec3 angles;
|
||||
|
||||
/*quaternion representations for rotations*/
|
||||
versor rot_x = {0.0f, 0.0f, 0.0f, 1.0f};
|
||||
versor rot_y = {0.0f, 0.0f, 0.0f, 1.0f};
|
||||
versor rot_z = {0.0f, 0.0f, 0.0f, 1.0f};
|
||||
|
||||
vec3 axis_x = {1.0f, 0.0f, 0.0f};
|
||||
vec3 axis_y = {0.0f, 1.0f, 0.0f};
|
||||
vec3 axis_z = {0.0f, 0.0f, 1.0f};
|
||||
|
||||
versor expected = {0.0f, 0.0f, 0.0f, 1.0f};
|
||||
versor result;
|
||||
|
||||
test_rand_vec3(angles);
|
||||
|
||||
/*create the rotation quaternions using the angles and axises*/
|
||||
glm_quatv(rot_x, angles[0], axis_x);
|
||||
glm_quatv(rot_y, angles[1], axis_y);
|
||||
glm_quatv(rot_z, angles[2], axis_z);
|
||||
|
||||
/*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);
|
||||
|
||||
ASSERTIFY(test_assert_quat_eq(result, expected))
|
||||
}
|
||||
|
||||
/*Start gimbal lock tests*/
|
||||
for (float x = -90.0f; x <= 90.0f; x += 90.0f) {
|
||||
for (float y = -90.0f; y <= 90.0f; y += 90.0f) {
|
||||
for (float z = -90.0f; z <= 90.0f; z += 90.0f) {
|
||||
|
||||
/* angles that will cause gimbal lock*/
|
||||
vec3 angles = {x, y, z};
|
||||
|
||||
/*quaternion representations for rotations*/
|
||||
versor rot_x = {0.0f, 0.0f, 0.0f, 1.0f};
|
||||
versor rot_y = {0.0f, 0.0f, 0.0f, 1.0f};
|
||||
versor rot_z = {0.0f, 0.0f, 0.0f, 1.0f};
|
||||
|
||||
vec3 axis_x = {1.0f, 0.0f, 0.0f};
|
||||
vec3 axis_y = {0.0f, 1.0f, 0.0f};
|
||||
vec3 axis_z = {0.0f, 0.0f, 1.0f};
|
||||
|
||||
versor expected = {0.0f, 0.0f, 0.0f, 1.0f};
|
||||
versor result;
|
||||
|
||||
/*create the rotation quaternions using the angles and axises*/
|
||||
glm_quatv(rot_x, angles[0], axis_x);
|
||||
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*/
|
||||
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");
|
||||
ASSERTIFY(test_assert_quat_eq(result, expected))
|
||||
}
|
||||
}
|
||||
}
|
||||
ASSERTIFY(test_assert_quat_eq(result, expected))
|
||||
|
||||
TEST_SUCCESS
|
||||
}
|
||||
|
||||
10
test/tests.h
10
test/tests.h
@@ -375,6 +375,11 @@ TEST_DECLARE(glm_quat_identity_array)
|
||||
TEST_DECLARE(glm_quat_init)
|
||||
TEST_DECLARE(glm_quatv)
|
||||
TEST_DECLARE(glm_euler_xyz_quat)
|
||||
TEST_DECLARE(glm_euler_xzy_quat)
|
||||
TEST_DECLARE(glm_euler_yxz_quat)
|
||||
TEST_DECLARE(glm_euler_yzx_quat)
|
||||
TEST_DECLARE(glm_euler_zxy_quat)
|
||||
TEST_DECLARE(glm_euler_zyx_quat)
|
||||
TEST_DECLARE(glm_quat)
|
||||
TEST_DECLARE(glm_quat_copy)
|
||||
TEST_DECLARE(glm_quat_norm)
|
||||
@@ -1353,6 +1358,11 @@ TEST_LIST {
|
||||
TEST_ENTRY(glm_quat_init)
|
||||
TEST_ENTRY(glm_quatv)
|
||||
TEST_ENTRY(glm_euler_xyz_quat)
|
||||
TEST_ENTRY(glm_euler_xzy_quat)
|
||||
TEST_ENTRY(glm_euler_yxz_quat)
|
||||
TEST_ENTRY(glm_euler_yzx_quat)
|
||||
TEST_ENTRY(glm_euler_zxy_quat)
|
||||
TEST_ENTRY(glm_euler_zyx_quat)
|
||||
TEST_ENTRY(glm_quat)
|
||||
TEST_ENTRY(glm_quat_copy)
|
||||
TEST_ENTRY(glm_quat_norm)
|
||||
|
||||
Reference in New Issue
Block a user