mirror of
https://github.com/recp/cglm.git
synced 2026-02-17 03:39:05 +00:00
got the euler to quat xyz working and got the tests to pass
This commit is contained in:
@@ -142,7 +142,7 @@ glm_quat_init(versor q, float x, float y, float z, float w) {
|
|||||||
//TODO: telephone001's eulertoquat
|
//TODO: telephone001's eulertoquat
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* @brief creates a quaternion using rotation angles and does does rotations in x y z order
|
* @brief creates NEW quaternion using rotation angles and does does rotations in x y z order
|
||||||
*
|
*
|
||||||
* @param[out] q quaternion
|
* @param[out] q quaternion
|
||||||
* @param[in] angle angles x y z (radians)
|
* @param[in] angle angles x y z (radians)
|
||||||
@@ -150,20 +150,21 @@ glm_quat_init(versor q, float x, float y, float z, float w) {
|
|||||||
CGLM_INLINE
|
CGLM_INLINE
|
||||||
void
|
void
|
||||||
glm_euler_xyz_quat(versor q, vec3 angles) {
|
glm_euler_xyz_quat(versor q, vec3 angles) {
|
||||||
float xs = sinf(angles[0] / 2.0);
|
float xs = sinf(angles[0] / 2.0f);
|
||||||
float xc = cosf(angles[0] / 2.0);
|
float xc = cosf(angles[0] / 2.0f);
|
||||||
|
|
||||||
float ys = sinf(angles[1] / 2.0);
|
float ys = sinf(angles[1] / 2.0f);
|
||||||
float yc = cosf(angles[1] / 2.0);
|
float yc = cosf(angles[1] / 2.0f);
|
||||||
|
|
||||||
float zs = sinf(angles[2] / 2.0);
|
float zs = sinf(angles[2] / 2.0f);
|
||||||
float zc = cosf(angles[2] / 2.0);
|
float zc = cosf(angles[2] / 2.0f);
|
||||||
|
|
||||||
glm_quat_init(q,
|
glm_quat_init(q,
|
||||||
zc * yc * xs - zs * ys * xs,
|
zc * yc * xs - zs * ys * xc,
|
||||||
zc * ys * xc - zs * yc * xs,
|
zc * ys * xc + zs * yc * xs,
|
||||||
zs * yc * xc - zs * yc * xs,
|
-zc * ys * xs + zs * yc * xc,
|
||||||
zc * yc * xc + zs * ys * xs);
|
zc * yc * xc + zs * ys * xs);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
|||||||
@@ -123,29 +123,39 @@ TEST_IMPL(GLM_PREFIX, quatv) {
|
|||||||
|
|
||||||
// telephone001 changes (remove comment when done) TODO
|
// telephone001 changes (remove comment when done) TODO
|
||||||
TEST_IMPL(GLM_PREFIX, euler_xyz_quat) {
|
TEST_IMPL(GLM_PREFIX, euler_xyz_quat) {
|
||||||
vec3 axis_x = {1.0f, 0.0f, 0.0f};
|
/*random angles for testing*/
|
||||||
vec3 axis_y = {0.0f, 1.0f, 0.0f};
|
vec3 angles = {glm_rad(30.0f), glm_rad(60.0f), glm_rad(90.0f)};
|
||||||
vec3 axis_z = {0.0f, 0.0f, 1.0f};
|
|
||||||
|
|
||||||
|
/*quaternion representations for rotations*/
|
||||||
versor rot_x = {0.0f, 0.0f, 0.0f, 1.0f};
|
versor rot_x = {0.0f, 0.0f, 0.0f, 1.0f};
|
||||||
versor rot_y = {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};
|
versor rot_z = {0.0f, 0.0f, 0.0f, 1.0f};
|
||||||
|
|
||||||
//random angles for testing
|
vec3 axis_x = {1.0f, 0.0f, 0.0f};
|
||||||
vec3 angles = {glm_rad(30.0f), glm_rad(60.0f), glm_rad(90.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};
|
||||||
|
|
||||||
|
/*create the rotation quaternions using the angles and axises*/
|
||||||
glm_quatv(rot_x, angles[0], axis_x);
|
glm_quatv(rot_x, angles[0], axis_x);
|
||||||
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);
|
||||||
|
|
||||||
versor expected = {0.0f, 0.0f, 0.0f, 1.0f};
|
/*apply the rotations to a unit quaternion in xyz order*/
|
||||||
glm_quat_mul(rot_x, expected, expected);
|
glm_quat_mul(rot_x, expected, expected);
|
||||||
glm_quat_mul(rot_y, expected, expected);
|
glm_quat_mul(rot_y, expected, expected);
|
||||||
glm_quat_mul(rot_z, expected, expected);
|
glm_quat_mul(rot_z, expected, expected);
|
||||||
|
|
||||||
versor result;
|
/*use my function to get the quaternion*/
|
||||||
glm_euler_xyz_quat(angles, result);
|
glm_euler_xyz_quat(result, angles);
|
||||||
ASSERTIFY(test_assert_vec3_eq(result, expected))
|
|
||||||
|
fprintf(stderr,"TEST\n");
|
||||||
|
for (int i = 0; i < 4; i++) {
|
||||||
|
fprintf(stderr, "%f vs %f\n", expected[i], result[i]);
|
||||||
|
}
|
||||||
|
ASSERTIFY(test_assert_quat_eq(result, expected))
|
||||||
|
|
||||||
TEST_SUCCESS
|
TEST_SUCCESS
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -374,6 +374,7 @@ TEST_DECLARE(glm_quat_identity)
|
|||||||
TEST_DECLARE(glm_quat_identity_array)
|
TEST_DECLARE(glm_quat_identity_array)
|
||||||
TEST_DECLARE(glm_quat_init)
|
TEST_DECLARE(glm_quat_init)
|
||||||
TEST_DECLARE(glm_quatv)
|
TEST_DECLARE(glm_quatv)
|
||||||
|
TEST_DECLARE(glm_euler_xyz_quat)
|
||||||
TEST_DECLARE(glm_quat)
|
TEST_DECLARE(glm_quat)
|
||||||
TEST_DECLARE(glm_quat_copy)
|
TEST_DECLARE(glm_quat_copy)
|
||||||
TEST_DECLARE(glm_quat_norm)
|
TEST_DECLARE(glm_quat_norm)
|
||||||
@@ -1351,6 +1352,7 @@ TEST_LIST {
|
|||||||
TEST_ENTRY(glm_quat_identity_array)
|
TEST_ENTRY(glm_quat_identity_array)
|
||||||
TEST_ENTRY(glm_quat_init)
|
TEST_ENTRY(glm_quat_init)
|
||||||
TEST_ENTRY(glm_quatv)
|
TEST_ENTRY(glm_quatv)
|
||||||
|
TEST_ENTRY(glm_euler_xyz_quat)
|
||||||
TEST_ENTRY(glm_quat)
|
TEST_ENTRY(glm_quat)
|
||||||
TEST_ENTRY(glm_quat_copy)
|
TEST_ENTRY(glm_quat_copy)
|
||||||
TEST_ENTRY(glm_quat_norm)
|
TEST_ENTRY(glm_quat_norm)
|
||||||
|
|||||||
Reference in New Issue
Block a user