mirror of
https://github.com/recp/cglm.git
synced 2025-12-25 12:55:04 +00:00
moved all my stuff to euler because it fits there better. Also, had to move my tests into a single euler test because it wouldn't work outside that one test. Maybe later I will create test_euler.h like how test_quat.h works
This commit is contained in:
@@ -7,6 +7,545 @@
|
||||
|
||||
#include "test_common.h"
|
||||
|
||||
|
||||
TEST_IMPL(GLM_PREFIX, euler_xyz_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 xyz order*/
|
||||
versor tmp;
|
||||
glm_quat_copy(expected, tmp);
|
||||
glm_quat_mul(rot_x, tmp, expected);
|
||||
glm_quat_copy(expected, tmp);
|
||||
glm_quat_mul(rot_y, tmp, expected);
|
||||
glm_quat_copy(expected, tmp);
|
||||
glm_quat_mul(rot_z, tmp, expected);
|
||||
|
||||
/*use my function to get the quaternion*/
|
||||
glm_euler_xyz_quat(result, angles);
|
||||
|
||||
/*verify if the magnitude of the quaternion stays 1*/
|
||||
ASSERT(test_eq(glm_quat_norm(result), 1.0f))
|
||||
|
||||
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*/
|
||||
versor tmp;
|
||||
glm_quat_copy(expected, tmp);
|
||||
glm_quat_mul(rot_x, tmp, expected);
|
||||
glm_quat_copy(expected, tmp);
|
||||
glm_quat_mul(rot_y, tmp, expected);
|
||||
glm_quat_copy(expected, tmp);
|
||||
glm_quat_mul(rot_z, tmp, expected);
|
||||
|
||||
/*use my function to get the quaternion*/
|
||||
glm_euler_xyz_quat(result, angles);
|
||||
|
||||
/*verify if the magnitude of the quaternion stays 1*/
|
||||
ASSERT(test_eq(glm_quat_norm(result), 1.0f))
|
||||
|
||||
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*/
|
||||
versor tmp;
|
||||
glm_quat_copy(expected, tmp);
|
||||
glm_quat_mul(rot_x, tmp, expected);
|
||||
glm_quat_copy(expected, tmp);
|
||||
glm_quat_mul(rot_z, tmp, expected);
|
||||
glm_quat_copy(expected, tmp);
|
||||
glm_quat_mul(rot_y, tmp, expected);
|
||||
|
||||
/*use my function to get the quaternion*/
|
||||
glm_euler_xzy_quat(result, angles);
|
||||
|
||||
/*verify if the magnitude of the quaternion stays 1*/
|
||||
ASSERT(test_eq(glm_quat_norm(result), 1.0f))
|
||||
|
||||
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*/
|
||||
versor tmp;
|
||||
glm_quat_copy(expected, tmp);
|
||||
glm_quat_mul(rot_x, tmp, expected);
|
||||
glm_quat_copy(expected, tmp);
|
||||
glm_quat_mul(rot_z, tmp, expected);
|
||||
glm_quat_copy(expected, tmp);
|
||||
glm_quat_mul(rot_y, tmp, expected);
|
||||
|
||||
/*use my function to get the quaternion*/
|
||||
glm_euler_xzy_quat(result, angles);
|
||||
|
||||
/*verify if the magnitude of the quaternion stays 1*/
|
||||
ASSERT(test_eq(glm_quat_norm(result), 1.0f))
|
||||
|
||||
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*/
|
||||
versor tmp;
|
||||
glm_quat_copy(expected, tmp);
|
||||
glm_quat_mul(rot_y, tmp, expected);
|
||||
glm_quat_copy(expected, tmp);
|
||||
glm_quat_mul(rot_x, tmp, expected);
|
||||
glm_quat_copy(expected, tmp);
|
||||
glm_quat_mul(rot_z, tmp, expected);
|
||||
|
||||
/*use my function to get the quaternion*/
|
||||
glm_euler_yxz_quat(result, angles);
|
||||
|
||||
/*verify if the magnitude of the quaternion stays 1*/
|
||||
ASSERT(test_eq(glm_quat_norm(result), 1.0f))
|
||||
|
||||
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 yxz order*/
|
||||
versor tmp;
|
||||
glm_quat_copy(expected, tmp);
|
||||
glm_quat_mul(rot_y, tmp, expected);
|
||||
glm_quat_copy(expected, tmp);
|
||||
glm_quat_mul(rot_x, tmp, expected);
|
||||
glm_quat_copy(expected, tmp);
|
||||
glm_quat_mul(rot_z, tmp, expected);
|
||||
|
||||
/*use my function to get the quaternion*/
|
||||
glm_euler_yxz_quat(result, angles);
|
||||
|
||||
/*verify if the magnitude of the quaternion stays 1*/
|
||||
ASSERT(test_eq(glm_quat_norm(result), 1.0f))
|
||||
|
||||
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*/
|
||||
versor tmp;
|
||||
glm_quat_copy(expected, tmp);
|
||||
glm_quat_mul(rot_y, tmp, expected);
|
||||
glm_quat_copy(expected, tmp);
|
||||
glm_quat_mul(rot_z, tmp, expected);
|
||||
glm_quat_copy(expected, tmp);
|
||||
glm_quat_mul(rot_x, tmp, expected);
|
||||
|
||||
/*use my function to get the quaternion*/
|
||||
glm_euler_yzx_quat(result, angles);
|
||||
|
||||
/*verify if the magnitude of the quaternion stays 1*/
|
||||
ASSERT(test_eq(glm_quat_norm(result), 1.0f))
|
||||
|
||||
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*/
|
||||
versor tmp;
|
||||
glm_quat_copy(expected, tmp);
|
||||
glm_quat_mul(rot_y, tmp, expected);
|
||||
glm_quat_copy(expected, tmp);
|
||||
glm_quat_mul(rot_z, tmp, expected);
|
||||
glm_quat_copy(expected, tmp);
|
||||
glm_quat_mul(rot_x, tmp, expected);
|
||||
|
||||
/*use my function to get the quaternion*/
|
||||
glm_euler_yzx_quat(result, angles);
|
||||
|
||||
/*verify if the magnitude of the quaternion stays 1*/
|
||||
ASSERT(test_eq(glm_quat_norm(result), 1.0f))
|
||||
|
||||
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*/
|
||||
versor tmp;
|
||||
glm_quat_copy(expected, tmp);
|
||||
glm_quat_mul(rot_z, tmp, expected);
|
||||
glm_quat_copy(expected, tmp);
|
||||
glm_quat_mul(rot_x, tmp, expected);
|
||||
glm_quat_copy(expected, tmp);
|
||||
glm_quat_mul(rot_y, tmp, expected);
|
||||
|
||||
/*use my function to get the quaternion*/
|
||||
glm_euler_zxy_quat(result, angles);
|
||||
|
||||
/*verify if the magnitude of the quaternion stays 1*/
|
||||
ASSERT(test_eq(glm_quat_norm(result), 1.0f))
|
||||
|
||||
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*/
|
||||
versor tmp;
|
||||
glm_quat_copy(expected, tmp);
|
||||
glm_quat_mul(rot_z, tmp, expected);
|
||||
glm_quat_copy(expected, tmp);
|
||||
glm_quat_mul(rot_x, tmp, expected);
|
||||
glm_quat_copy(expected, tmp);
|
||||
glm_quat_mul(rot_y, tmp, expected);
|
||||
|
||||
|
||||
/*use my function to get the quaternion*/
|
||||
glm_euler_zxy_quat(result, angles);
|
||||
|
||||
/*verify if the magnitude of the quaternion stays 1*/
|
||||
ASSERT(test_eq(glm_quat_norm(result), 1.0f))
|
||||
|
||||
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*/
|
||||
versor tmp;
|
||||
glm_quat_copy(expected, tmp);
|
||||
glm_quat_mul(rot_z, tmp, expected);
|
||||
glm_quat_copy(expected, tmp);
|
||||
glm_quat_mul(rot_y, tmp, expected);
|
||||
glm_quat_copy(expected, tmp);
|
||||
glm_quat_mul(rot_x, tmp, expected);
|
||||
|
||||
|
||||
/*use my function to get the quaternion*/
|
||||
glm_euler_zyx_quat(result, angles);
|
||||
|
||||
/*verify if the magnitude of the quaternion stays 1*/
|
||||
ASSERT(test_eq(glm_quat_norm(result), 1.0f))
|
||||
|
||||
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 zyx order*/
|
||||
versor tmp;
|
||||
glm_quat_copy(expected, tmp);
|
||||
glm_quat_mul(rot_z, tmp, expected);
|
||||
glm_quat_copy(expected, tmp);
|
||||
glm_quat_mul(rot_y, tmp, expected);
|
||||
glm_quat_copy(expected, tmp);
|
||||
glm_quat_mul(rot_x, tmp, expected);
|
||||
|
||||
|
||||
/*use my function to get the quaternion*/
|
||||
glm_euler_zyx_quat(result, angles);
|
||||
|
||||
/*verify if the magnitude of the quaternion stays 1*/
|
||||
ASSERT(test_eq(glm_quat_norm(result), 1.0f))
|
||||
|
||||
ASSERTIFY(test_assert_quat_eq(result, expected))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TEST_SUCCESS
|
||||
}
|
||||
|
||||
TEST_IMPL(euler) {
|
||||
mat4 rot1, rot2;
|
||||
vec3 inAngles, outAngles;
|
||||
@@ -41,5 +580,14 @@ TEST_IMPL(euler) {
|
||||
glmc_euler_xyz(outAngles, rot2);
|
||||
ASSERTIFY(test_assert_mat4_eq(rot1, rot2))
|
||||
|
||||
/* somehow when I try to make tests outside of this thing,
|
||||
it won't work. So they stay here for now */
|
||||
ASSERTIFY(test_GLM_PREFIXeuler_xyz_quat());
|
||||
ASSERTIFY(test_GLM_PREFIXeuler_xzy_quat());
|
||||
ASSERTIFY(test_GLM_PREFIXeuler_yxz_quat());
|
||||
ASSERTIFY(test_GLM_PREFIXeuler_yzx_quat());
|
||||
ASSERTIFY(test_GLM_PREFIXeuler_zxy_quat());
|
||||
ASSERTIFY(test_GLM_PREFIXeuler_zyx_quat());
|
||||
|
||||
TEST_SUCCESS
|
||||
}
|
||||
|
||||
@@ -102,544 +102,6 @@ TEST_IMPL(GLM_PREFIX, quat_init) {
|
||||
TEST_SUCCESS
|
||||
}
|
||||
|
||||
TEST_IMPL(GLM_PREFIX, euler_xyz_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 xyz order*/
|
||||
versor tmp;
|
||||
glm_quat_copy(expected, tmp);
|
||||
glm_quat_mul(rot_x, tmp, expected);
|
||||
glm_quat_copy(expected, tmp);
|
||||
glm_quat_mul(rot_y, tmp, expected);
|
||||
glm_quat_copy(expected, tmp);
|
||||
glm_quat_mul(rot_z, tmp, expected);
|
||||
|
||||
/*use my function to get the quaternion*/
|
||||
glm_euler_xyz_quat(result, angles);
|
||||
|
||||
/*verify if the magnitude of the quaternion stays 1*/
|
||||
ASSERT(test_eq(glm_quat_norm(result), 1.0f))
|
||||
|
||||
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*/
|
||||
versor tmp;
|
||||
glm_quat_copy(expected, tmp);
|
||||
glm_quat_mul(rot_x, tmp, expected);
|
||||
glm_quat_copy(expected, tmp);
|
||||
glm_quat_mul(rot_y, tmp, expected);
|
||||
glm_quat_copy(expected, tmp);
|
||||
glm_quat_mul(rot_z, tmp, expected);
|
||||
|
||||
/*use my function to get the quaternion*/
|
||||
glm_euler_xyz_quat(result, angles);
|
||||
|
||||
/*verify if the magnitude of the quaternion stays 1*/
|
||||
ASSERT(test_eq(glm_quat_norm(result), 1.0f))
|
||||
|
||||
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*/
|
||||
versor tmp;
|
||||
glm_quat_copy(expected, tmp);
|
||||
glm_quat_mul(rot_x, tmp, expected);
|
||||
glm_quat_copy(expected, tmp);
|
||||
glm_quat_mul(rot_z, tmp, expected);
|
||||
glm_quat_copy(expected, tmp);
|
||||
glm_quat_mul(rot_y, tmp, expected);
|
||||
|
||||
/*use my function to get the quaternion*/
|
||||
glm_euler_xzy_quat(result, angles);
|
||||
|
||||
/*verify if the magnitude of the quaternion stays 1*/
|
||||
ASSERT(test_eq(glm_quat_norm(result), 1.0f))
|
||||
|
||||
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*/
|
||||
versor tmp;
|
||||
glm_quat_copy(expected, tmp);
|
||||
glm_quat_mul(rot_x, tmp, expected);
|
||||
glm_quat_copy(expected, tmp);
|
||||
glm_quat_mul(rot_z, tmp, expected);
|
||||
glm_quat_copy(expected, tmp);
|
||||
glm_quat_mul(rot_y, tmp, expected);
|
||||
|
||||
/*use my function to get the quaternion*/
|
||||
glm_euler_xzy_quat(result, angles);
|
||||
|
||||
/*verify if the magnitude of the quaternion stays 1*/
|
||||
ASSERT(test_eq(glm_quat_norm(result), 1.0f))
|
||||
|
||||
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*/
|
||||
versor tmp;
|
||||
glm_quat_copy(expected, tmp);
|
||||
glm_quat_mul(rot_y, tmp, expected);
|
||||
glm_quat_copy(expected, tmp);
|
||||
glm_quat_mul(rot_x, tmp, expected);
|
||||
glm_quat_copy(expected, tmp);
|
||||
glm_quat_mul(rot_z, tmp, expected);
|
||||
|
||||
/*use my function to get the quaternion*/
|
||||
glm_euler_yxz_quat(result, angles);
|
||||
|
||||
/*verify if the magnitude of the quaternion stays 1*/
|
||||
ASSERT(test_eq(glm_quat_norm(result), 1.0f))
|
||||
|
||||
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 yxz order*/
|
||||
versor tmp;
|
||||
glm_quat_copy(expected, tmp);
|
||||
glm_quat_mul(rot_y, tmp, expected);
|
||||
glm_quat_copy(expected, tmp);
|
||||
glm_quat_mul(rot_x, tmp, expected);
|
||||
glm_quat_copy(expected, tmp);
|
||||
glm_quat_mul(rot_z, tmp, expected);
|
||||
|
||||
/*use my function to get the quaternion*/
|
||||
glm_euler_yxz_quat(result, angles);
|
||||
|
||||
/*verify if the magnitude of the quaternion stays 1*/
|
||||
ASSERT(test_eq(glm_quat_norm(result), 1.0f))
|
||||
|
||||
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*/
|
||||
versor tmp;
|
||||
glm_quat_copy(expected, tmp);
|
||||
glm_quat_mul(rot_y, tmp, expected);
|
||||
glm_quat_copy(expected, tmp);
|
||||
glm_quat_mul(rot_z, tmp, expected);
|
||||
glm_quat_copy(expected, tmp);
|
||||
glm_quat_mul(rot_x, tmp, expected);
|
||||
|
||||
/*use my function to get the quaternion*/
|
||||
glm_euler_yzx_quat(result, angles);
|
||||
|
||||
/*verify if the magnitude of the quaternion stays 1*/
|
||||
ASSERT(test_eq(glm_quat_norm(result), 1.0f))
|
||||
|
||||
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*/
|
||||
versor tmp;
|
||||
glm_quat_copy(expected, tmp);
|
||||
glm_quat_mul(rot_y, tmp, expected);
|
||||
glm_quat_copy(expected, tmp);
|
||||
glm_quat_mul(rot_z, tmp, expected);
|
||||
glm_quat_copy(expected, tmp);
|
||||
glm_quat_mul(rot_x, tmp, expected);
|
||||
|
||||
/*use my function to get the quaternion*/
|
||||
glm_euler_yzx_quat(result, angles);
|
||||
|
||||
/*verify if the magnitude of the quaternion stays 1*/
|
||||
ASSERT(test_eq(glm_quat_norm(result), 1.0f))
|
||||
|
||||
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*/
|
||||
versor tmp;
|
||||
glm_quat_copy(expected, tmp);
|
||||
glm_quat_mul(rot_z, tmp, expected);
|
||||
glm_quat_copy(expected, tmp);
|
||||
glm_quat_mul(rot_x, tmp, expected);
|
||||
glm_quat_copy(expected, tmp);
|
||||
glm_quat_mul(rot_y, tmp, expected);
|
||||
|
||||
/*use my function to get the quaternion*/
|
||||
glm_euler_zxy_quat(result, angles);
|
||||
|
||||
/*verify if the magnitude of the quaternion stays 1*/
|
||||
ASSERT(test_eq(glm_quat_norm(result), 1.0f))
|
||||
|
||||
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*/
|
||||
versor tmp;
|
||||
glm_quat_copy(expected, tmp);
|
||||
glm_quat_mul(rot_z, tmp, expected);
|
||||
glm_quat_copy(expected, tmp);
|
||||
glm_quat_mul(rot_x, tmp, expected);
|
||||
glm_quat_copy(expected, tmp);
|
||||
glm_quat_mul(rot_y, tmp, expected);
|
||||
|
||||
|
||||
/*use my function to get the quaternion*/
|
||||
glm_euler_zxy_quat(result, angles);
|
||||
|
||||
/*verify if the magnitude of the quaternion stays 1*/
|
||||
ASSERT(test_eq(glm_quat_norm(result), 1.0f))
|
||||
|
||||
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*/
|
||||
versor tmp;
|
||||
glm_quat_copy(expected, tmp);
|
||||
glm_quat_mul(rot_z, tmp, expected);
|
||||
glm_quat_copy(expected, tmp);
|
||||
glm_quat_mul(rot_y, tmp, expected);
|
||||
glm_quat_copy(expected, tmp);
|
||||
glm_quat_mul(rot_x, tmp, expected);
|
||||
|
||||
|
||||
/*use my function to get the quaternion*/
|
||||
glm_euler_zyx_quat(result, angles);
|
||||
|
||||
/*verify if the magnitude of the quaternion stays 1*/
|
||||
ASSERT(test_eq(glm_quat_norm(result), 1.0f))
|
||||
|
||||
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 zyx order*/
|
||||
versor tmp;
|
||||
glm_quat_copy(expected, tmp);
|
||||
glm_quat_mul(rot_z, tmp, expected);
|
||||
glm_quat_copy(expected, tmp);
|
||||
glm_quat_mul(rot_y, tmp, expected);
|
||||
glm_quat_copy(expected, tmp);
|
||||
glm_quat_mul(rot_x, tmp, expected);
|
||||
|
||||
|
||||
/*use my function to get the quaternion*/
|
||||
glm_euler_zyx_quat(result, angles);
|
||||
|
||||
/*verify if the magnitude of the quaternion stays 1*/
|
||||
ASSERT(test_eq(glm_quat_norm(result), 1.0f))
|
||||
|
||||
ASSERTIFY(test_assert_quat_eq(result, expected))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TEST_SUCCESS
|
||||
}
|
||||
|
||||
TEST_IMPL(GLM_PREFIX, quatv) {
|
||||
versor q1 = {1.0f, 2.0f, 3.0f, 4.0f};
|
||||
vec3 v1, v2;
|
||||
|
||||
21
test/tests.h
21
test/tests.h
@@ -361,6 +361,12 @@ TEST_DECLARE(clamp)
|
||||
|
||||
/* euler */
|
||||
TEST_DECLARE(euler)
|
||||
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)
|
||||
|
||||
/* ray */
|
||||
TEST_DECLARE(glm_ray_triangle)
|
||||
@@ -374,12 +380,6 @@ TEST_DECLARE(glm_quat_identity)
|
||||
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)
|
||||
@@ -1341,9 +1341,10 @@ TEST_LIST {
|
||||
|
||||
/* utils */
|
||||
TEST_ENTRY(clamp)
|
||||
|
||||
|
||||
/* euler */
|
||||
TEST_ENTRY(euler)
|
||||
|
||||
|
||||
/* ray */
|
||||
TEST_ENTRY(glm_ray_triangle)
|
||||
@@ -1357,12 +1358,6 @@ TEST_LIST {
|
||||
TEST_ENTRY(glm_quat_identity_array)
|
||||
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