Skip to content

Commit

Permalink
added implementation of euler_to_quat_lh and fixed the tests. Now I g…
Browse files Browse the repository at this point in the history
…otta decide what to name the macros for controlling lefthand and also make call functions for rh and lh conditionally declared
  • Loading branch information
telephone001 committed Dec 28, 2023
1 parent fa6244c commit aa20b8a
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 26 deletions.
62 changes: 62 additions & 0 deletions include/cglm/handed/euler_to_quat_lh.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,17 @@
CGLM_INLINE
void
glm_euler_xyz_quat_lh(vec3 angles, versor dest) {
float xc, yc, zc,
xs, ys, zs;

xs = sinf(angles[0] * 0.5f); xc = cosf(angles[0] * 0.5f);
ys = sinf(angles[1] * 0.5f); yc = cosf(angles[1] * 0.5f);
zs = -sinf(angles[2] * 0.5f); zc = cosf(angles[2] * 0.5f);

dest[0] = xc * ys * zs + xs * yc * zc;
dest[1] = xc * ys * zc - xs * yc * zs;
dest[2] = xc * yc * zs + xs * ys * zc;
dest[3] = xc * yc * zc - xs * ys * zs;
}

/*!
Expand All @@ -43,7 +54,17 @@ glm_euler_xyz_quat_lh(vec3 angles, versor dest) {
CGLM_INLINE
void
glm_euler_xzy_quat_lh(vec3 angles, versor dest) {
float xc, yc, zc,
xs, ys, zs;

xs = sinf(angles[0] * 0.5f); xc = cosf(angles[0] * 0.5f);
ys = sinf(angles[1] * 0.5f); yc = cosf(angles[1] * 0.5f);
zs = -sinf(angles[2] * 0.5f); zc = cosf(angles[2] * 0.5f);

dest[0] = -xc * zs * ys + xs * zc * yc;
dest[1] = xc * zc * ys - xs * zs * yc;
dest[2] = xc * zs * yc + xs * zc * ys;
dest[3] = xc * zc * yc + xs * zs * ys;
}

/*!
Expand All @@ -56,7 +77,17 @@ glm_euler_xzy_quat_lh(vec3 angles, versor dest) {
CGLM_INLINE
void
glm_euler_yxz_quat_lh(vec3 angles, versor dest) {
float xc, yc, zc,
xs, ys, zs;

xs = sinf(angles[0] * 0.5f); xc = cosf(angles[0] * 0.5f);
ys = sinf(angles[1] * 0.5f); yc = cosf(angles[1] * 0.5f);
zs = -sinf(angles[2] * 0.5f); zc = cosf(angles[2] * 0.5f);

dest[0] = yc * xs * zc + ys * xc * zs;
dest[1] = -yc * xs * zs + ys * xc * zc;
dest[2] = yc * xc * zs - ys * xs * zc;
dest[3] = yc * xc * zc + ys * xs * zs;
}

/*!
Expand All @@ -69,7 +100,17 @@ glm_euler_yxz_quat_lh(vec3 angles, versor dest) {
CGLM_INLINE
void
glm_euler_yzx_quat_lh(vec3 angles, versor dest) {
float xc, yc, zc,
xs, ys, zs;

xs = sinf(angles[0] * 0.5f); xc = cosf(angles[0] * 0.5f);
ys = sinf(angles[1] * 0.5f); yc = cosf(angles[1] * 0.5f);
zs = -sinf(angles[2] * 0.5f); zc = cosf(angles[2] * 0.5f);

dest[0] = yc * zc * xs + ys * zs * xc;
dest[1] = yc * zs * xs + ys * zc * xc;
dest[2] = yc * zs * xc - ys * zc * xs;
dest[3] = yc * zc * xc - ys * zs * xs;
}

/*!
Expand All @@ -82,6 +123,17 @@ glm_euler_yzx_quat_lh(vec3 angles, versor dest) {
CGLM_INLINE
void
glm_euler_zxy_quat_lh(vec3 angles, versor dest) {
float xc, yc, zc,
xs, ys, zs;

xs = sinf(angles[0] * 0.5f); xc = cosf(angles[0] * 0.5f);
ys = sinf(angles[1] * 0.5f); yc = cosf(angles[1] * 0.5f);
zs = -sinf(angles[2] * 0.5f); zc = cosf(angles[2] * 0.5f);

dest[0] = zc * xs * yc - zs * xc * ys;
dest[1] = zc * xc * ys + zs * xs * yc;
dest[2] = zc * xs * ys + zs * xc * yc;
dest[3] = zc * xc * yc - zs * xs * ys;
}

/*!
Expand All @@ -94,7 +146,17 @@ glm_euler_zxy_quat_lh(vec3 angles, versor dest) {
CGLM_INLINE
void
glm_euler_zyx_quat_lh(vec3 angles, versor dest) {
float xc, yc, zc,
xs, ys, zs;

xs = sinf(angles[0] * 0.5f); xc = cosf(angles[0] * 0.5f);
ys = sinf(angles[1] * 0.5f); yc = cosf(angles[1] * 0.5f);
zs = -sinf(angles[2] * 0.5f); zc = cosf(angles[2] * 0.5f);

dest[0] = zc * yc * xs - zs * ys * xc;
dest[1] = zc * ys * xc + zs * yc * xs;
dest[2] = -zc * ys * xs + zs * yc * xc;
dest[3] = zc * yc * xc + zs * ys * xs;
}

#endif /*cglm_euler_to_quat_lh_h*/
26 changes: 0 additions & 26 deletions test/src/test_euler_to_quat_lh.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ TEST_IMPL(GLM_PREFIX, euler_xyz_quat_lh) {
versor result;
versor tmp;

mat4 expected_mat4;

/* 100 randomized tests */
for (int i = 0; i < 100; i++) {
test_rand_vec3(angles);
Expand Down Expand Up @@ -213,12 +211,6 @@ TEST_IMPL(GLM_PREFIX, euler_yxz_quat_lh) {

/* verify that it acts the same as rotating by 3 axis quaternions */
ASSERTIFY(test_assert_quat_eq(result, expected))

/* verify that it acts the same as glm_euler_by_order */
glm_euler_by_order(angles, GLM_EULER_YXZ, expected_mat4);
glm_mat4_quat(expected_mat4, expected);

ASSERTIFY(test_assert_quat_eq_abs(result, expected));
}


Expand Down Expand Up @@ -252,12 +244,6 @@ TEST_IMPL(GLM_PREFIX, euler_yxz_quat_lh) {
ASSERT(test_eq(glm_quat_norm(result), 1.0f))

ASSERTIFY(test_assert_quat_eq(result, expected))

/* verify that it acts the same as glm_euler_by_order */
glm_euler_by_order(angles, GLM_EULER_YXZ, expected_mat4);
glm_mat4_quat(expected_mat4, expected);

ASSERTIFY(test_assert_quat_eq_abs(result, expected));
}
}
}
Expand Down Expand Up @@ -305,12 +291,6 @@ TEST_IMPL(GLM_PREFIX, euler_yzx_quat_lh) {

/* verify that it acts the same as rotating by 3 axis quaternions */
ASSERTIFY(test_assert_quat_eq(result, expected))

/* verify that it acts the same as glm_euler_by_order */
glm_euler_by_order(angles, GLM_EULER_YZX, expected_mat4);
glm_mat4_quat(expected_mat4, expected);

ASSERTIFY(test_assert_quat_eq_abs(result, expected));
}


Expand Down Expand Up @@ -344,12 +324,6 @@ TEST_IMPL(GLM_PREFIX, euler_yzx_quat_lh) {
ASSERT(test_eq(glm_quat_norm(result), 1.0f))

ASSERTIFY(test_assert_quat_eq(result, expected))

/* verify that it acts the same as glm_euler_by_order */
glm_euler_by_order(angles, GLM_EULER_YZX, expected_mat4);
glm_mat4_quat(expected_mat4, expected);

ASSERTIFY(test_assert_quat_eq_abs(result, expected));
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions test/src/tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#include "test_cam_rh_no.h"
#include "test_cam_rh_zo.h"
#include "test_euler_to_quat_rh.h"
#include "test_euler_to_quat_lh.h"

#undef GLM
#undef GLM_PREFIX
Expand Down Expand Up @@ -78,6 +79,7 @@
#include "test_cam_rh_no.h"
#include "test_cam_rh_zo.h"
#include "test_euler_to_quat_rh.h"
#include "test_euler_to_quat_lh.h"

#undef GLM
#undef GLM_PREFIX
Expand Down

0 comments on commit aa20b8a

Please sign in to comment.