mirror of
https://github.com/recp/cglm.git
synced 2025-10-03 16:51:35 +00:00
added implementation of euler_to_quat_lh and fixed the tests. Now I gotta decide what to name the macros for controlling lefthand and also make call functions for rh and lh conditionally declared
This commit is contained in:
@@ -31,6 +31,17 @@
|
|||||||
CGLM_INLINE
|
CGLM_INLINE
|
||||||
void
|
void
|
||||||
glm_euler_xyz_quat_lh(vec3 angles, versor dest) {
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@@ -43,7 +54,17 @@ glm_euler_xyz_quat_lh(vec3 angles, versor dest) {
|
|||||||
CGLM_INLINE
|
CGLM_INLINE
|
||||||
void
|
void
|
||||||
glm_euler_xzy_quat_lh(vec3 angles, versor dest) {
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@@ -56,7 +77,17 @@ glm_euler_xzy_quat_lh(vec3 angles, versor dest) {
|
|||||||
CGLM_INLINE
|
CGLM_INLINE
|
||||||
void
|
void
|
||||||
glm_euler_yxz_quat_lh(vec3 angles, versor dest) {
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@@ -69,7 +100,17 @@ glm_euler_yxz_quat_lh(vec3 angles, versor dest) {
|
|||||||
CGLM_INLINE
|
CGLM_INLINE
|
||||||
void
|
void
|
||||||
glm_euler_yzx_quat_lh(vec3 angles, versor dest) {
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@@ -82,6 +123,17 @@ glm_euler_yzx_quat_lh(vec3 angles, versor dest) {
|
|||||||
CGLM_INLINE
|
CGLM_INLINE
|
||||||
void
|
void
|
||||||
glm_euler_zxy_quat_lh(vec3 angles, versor dest) {
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@@ -94,7 +146,17 @@ glm_euler_zxy_quat_lh(vec3 angles, versor dest) {
|
|||||||
CGLM_INLINE
|
CGLM_INLINE
|
||||||
void
|
void
|
||||||
glm_euler_zyx_quat_lh(vec3 angles, versor dest) {
|
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*/
|
#endif /*cglm_euler_to_quat_lh_h*/
|
@@ -23,8 +23,6 @@ TEST_IMPL(GLM_PREFIX, euler_xyz_quat_lh) {
|
|||||||
versor result;
|
versor result;
|
||||||
versor tmp;
|
versor tmp;
|
||||||
|
|
||||||
mat4 expected_mat4;
|
|
||||||
|
|
||||||
/* 100 randomized tests */
|
/* 100 randomized tests */
|
||||||
for (int i = 0; i < 100; i++) {
|
for (int i = 0; i < 100; i++) {
|
||||||
test_rand_vec3(angles);
|
test_rand_vec3(angles);
|
||||||
@@ -213,12 +211,6 @@ TEST_IMPL(GLM_PREFIX, euler_yxz_quat_lh) {
|
|||||||
|
|
||||||
/* verify that it acts the same as rotating by 3 axis quaternions */
|
/* verify that it acts the same as rotating by 3 axis quaternions */
|
||||||
ASSERTIFY(test_assert_quat_eq(result, expected))
|
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));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -252,12 +244,6 @@ TEST_IMPL(GLM_PREFIX, euler_yxz_quat_lh) {
|
|||||||
ASSERT(test_eq(glm_quat_norm(result), 1.0f))
|
ASSERT(test_eq(glm_quat_norm(result), 1.0f))
|
||||||
|
|
||||||
ASSERTIFY(test_assert_quat_eq(result, expected))
|
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));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -305,12 +291,6 @@ TEST_IMPL(GLM_PREFIX, euler_yzx_quat_lh) {
|
|||||||
|
|
||||||
/* verify that it acts the same as rotating by 3 axis quaternions */
|
/* verify that it acts the same as rotating by 3 axis quaternions */
|
||||||
ASSERTIFY(test_assert_quat_eq(result, expected))
|
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));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -344,12 +324,6 @@ TEST_IMPL(GLM_PREFIX, euler_yzx_quat_lh) {
|
|||||||
ASSERT(test_eq(glm_quat_norm(result), 1.0f))
|
ASSERT(test_eq(glm_quat_norm(result), 1.0f))
|
||||||
|
|
||||||
ASSERTIFY(test_assert_quat_eq(result, expected))
|
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));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -40,6 +40,7 @@
|
|||||||
#include "test_cam_rh_no.h"
|
#include "test_cam_rh_no.h"
|
||||||
#include "test_cam_rh_zo.h"
|
#include "test_cam_rh_zo.h"
|
||||||
#include "test_euler_to_quat_rh.h"
|
#include "test_euler_to_quat_rh.h"
|
||||||
|
#include "test_euler_to_quat_lh.h"
|
||||||
|
|
||||||
#undef GLM
|
#undef GLM
|
||||||
#undef GLM_PREFIX
|
#undef GLM_PREFIX
|
||||||
@@ -78,6 +79,7 @@
|
|||||||
#include "test_cam_rh_no.h"
|
#include "test_cam_rh_no.h"
|
||||||
#include "test_cam_rh_zo.h"
|
#include "test_cam_rh_zo.h"
|
||||||
#include "test_euler_to_quat_rh.h"
|
#include "test_euler_to_quat_rh.h"
|
||||||
|
#include "test_euler_to_quat_lh.h"
|
||||||
|
|
||||||
#undef GLM
|
#undef GLM
|
||||||
#undef GLM_PREFIX
|
#undef GLM_PREFIX
|
||||||
|
Reference in New Issue
Block a user