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:
John Choi
2023-12-09 00:38:38 -06:00
parent 666d692dfb
commit 036fd4848b
11 changed files with 883 additions and 876 deletions

View File

@@ -49,6 +49,31 @@ CGLM_EXPORT
void
glmc_euler_by_order(vec3 angles, glm_euler_seq axis, mat4 dest);
CGLM_EXPORT
void
glmc_euler_xyz_quat(versor q, vec3 angles);
CGLM_EXPORT
void
glmc_euler_xzy_quat(versor q, vec3 angles);
CGLM_EXPORT
void
glmc_euler_yxz_quat(versor q, vec3 angles);
CGLM_EXPORT
void
glmc_euler_yzx_quat(versor q, vec3 angles);
CGLM_EXPORT
void
glmc_euler_zxy_quat(versor q, vec3 angles);
CGLM_EXPORT
void
glmc_euler_zyx_quat(versor q, vec3 angles);
#ifdef __cplusplus
}
#endif

View File

@@ -25,30 +25,6 @@ CGLM_EXPORT
void
glmc_quat_init(versor q, float x, float y, float z, float w);
CGLM_EXPORT
void
glmc_euler_xyz_quat(versor q, vec3 angles);
CGLM_EXPORT
void
glmc_euler_xzy_quat(versor q, vec3 angles);
CGLM_EXPORT
void
glmc_euler_yxz_quat(versor q, vec3 angles);
CGLM_EXPORT
void
glmc_euler_yzx_quat(versor q, vec3 angles);
CGLM_EXPORT
void
glmc_euler_zxy_quat(versor q, vec3 angles);
CGLM_EXPORT
void
glmc_euler_zyx_quat(versor q, vec3 angles);
CGLM_EXPORT
void
glmc_quat(versor q, float angle, float x, float y, float z);

View File

@@ -30,6 +30,12 @@
CGLM_INLINE void glm_euler_by_order(vec3 angles,
glm_euler_seq ord,
mat4 dest);
CGLM_INLINE void glm_euler_xyz_quat(versor q, vec3 angles);
CGLM_INLINE void glm_euler_xzy_quat(versor q, vec3 angles);
CGLM_INLINE void glm_euler_yxz_quat(versor q, vec3 angles);
CGLM_INLINE void glm_euler_yzx_quat(versor q, vec3 angles);
CGLM_INLINE void glm_euler_zxy_quat(versor q, vec3 angles);
CGLM_INLINE void glm_euler_zyx_quat(versor q, vec3 angles);
*/
#ifndef cglm_euler_h
@@ -449,5 +455,167 @@ glm_euler_by_order(vec3 angles, glm_euler_seq ord, mat4 dest) {
}
/*!
* @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)
*/
CGLM_INLINE
void
glm_euler_xyz_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 * 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 * xs * yc - zs * xc * ys,
zc * xc * ys + zs * xs * yc,
zc * xs * ys + zs * xc * yc,
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 * xs * zs + ys * xc * zc,
yc * xc * zs - ys * xs * 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 * ys * zc - xs * yc * zs,
xc * yc * zs + xs * ys * zc,
xc * yc * zc - xs * ys * zs);
}
#endif /* cglm_euler_h */

View File

@@ -13,12 +13,6 @@
Functions:
CGLM_INLINE void glm_quat_identity(versor q);
CGLM_INLINE void glm_quat_init(versor q, float x, float y, float z, float w);
CGLM_INLINE void glm_euler_xyz_quat(versor q, vec3 angles);
CGLM_INLINE void glm_euler_xzy_quat(versor q, vec3 angles);
CGLM_INLINE void glm_euler_yxz_quat(versor q, vec3 angles);
CGLM_INLINE void glm_euler_yzx_quat(versor q, vec3 angles);
CGLM_INLINE void glm_euler_zxy_quat(versor q, vec3 angles);
CGLM_INLINE void glm_euler_zyx_quat(versor q, vec3 angles);
CGLM_INLINE void glm_quat(versor q, float angle, float x, float y, float z);
CGLM_INLINE void glm_quatv(versor q, float angle, vec3 axis);
CGLM_INLINE void glm_quat_copy(versor q, versor dest);
@@ -145,168 +139,6 @@ glm_quat_init(versor q, float x, float y, float z, float w) {
q[3] = w;
}
/*!
* @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)
*/
CGLM_INLINE
void
glm_euler_xyz_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 * 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 * xs * yc - zs * xc * ys,
zc * xc * ys + zs * xs * yc,
zc * xs * ys + zs * xc * yc,
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 * xs * zs + ys * xc * zc,
yc * xc * zs - ys * xs * 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 * ys * zc - xs * yc * zs,
xc * yc * zs + xs * ys * zc,
xc * yc * zc - xs * ys * zs);
}
/*!
* @brief creates NEW quaternion with axis vector
*

View File

@@ -26,6 +26,12 @@
CGLM_INLINE mat4s glms_euler_zxy(vec3s angles)
CGLM_INLINE mat4s glms_euler_zyx(vec3s angles)
CGLM_INLINE mat4s glms_euler_by_order(vec3s angles, glm_euler_seq ord)
CGLM_INLINE versors glms_euler_xyz_quat(versors q, vec3s angles)
CGLM_INLINE versors glms_euler_xzy_quat(versors q, vec3s angles)
CGLM_INLINE versors glms_euler_yxz_quat(versors q, vec3s angles)
CGLM_INLINE versors glms_euler_yzx_quat(versors q, vec3s angles)
CGLM_INLINE versors glms_euler_zxy_quat(versors q, vec3s angles)
CGLM_INLINE versors glms_euler_zyx_quat(versors q, vec3s angles)
*/
#ifndef cglms_euler_h
@@ -149,4 +155,95 @@ glms_euler_by_order(vec3s angles, glm_euler_seq ord) {
return dest;
}
/*!
* @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)
*/
CGLM_INLINE
versors
glms_euler_xyz_quat(versors q, vec3s angles) {
versors dest;
glm_euler_xyz_quat(dest.raw, angles.raw);
return dest;
}
/*!
* @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
versors
glms_euler_xzy_quat(versors q, vec3s angles) {
versors dest;
glm_euler_xzy_quat(dest.raw, angles.raw);
return dest;
}
/*!
* @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
versors
glms_euler_yxz_quat(versors q, vec3s angles) {
versors dest;
glm_euler_yxz_quat(dest.raw, angles.raw);
return dest;
}
/*!
* @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
versors
glms_euler_yzx_quat(versors q, vec3s angles) {
versors dest;
glm_euler_yzx_quat(dest.raw, angles.raw);
return dest;
}
/*!
* @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
versors
glms_euler_zxy_quat(versors q, vec3s angles) {
versors dest;
glm_euler_zxy_quat(dest.raw, angles.raw);
return dest;
}
/*!
* @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
versors
glms_euler_zyx_quat(versors q, vec3s angles) {
versors dest;
glm_euler_zyx_quat(dest.raw, angles.raw);
return dest;
}
#endif /* cglms_euler_h */

View File

@@ -14,12 +14,6 @@
CGLM_INLINE versors glms_quat_identity(void)
CGLM_INLINE void glms_quat_identity_array(versor *q, size_t count)
CGLM_INLINE versors glms_quat_init(float x, float y, float z, float w)
CGLM_INLINE versors glms_euler_xyz_quat(versors q, vec3s angles)
CGLM_INLINE versors glms_euler_xzy_quat(versors q, vec3s angles)
CGLM_INLINE versors glms_euler_yxz_quat(versors q, vec3s angles)
CGLM_INLINE versors glms_euler_yzx_quat(versors q, vec3s angles)
CGLM_INLINE versors glms_euler_zxy_quat(versors q, vec3s angles)
CGLM_INLINE versors glms_euler_zyx_quat(versors q, vec3s angles)
CGLM_INLINE versors glms_quatv(float angle, vec3s axis)
CGLM_INLINE versors glms_quat(float angle, float x, float y, float z)
CGLM_INLINE versors glms_quat_from_vecs(vec3s a, vec3s b)
@@ -126,97 +120,6 @@ glms_quat_(init)(float x, float y, float z, float w) {
return dest;
}
/*!
* @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)
*/
CGLM_INLINE
versors
glms_euler_xyz_quat(versors q, vec3s angles) {
versors dest;
glm_euler_xyz_quat(dest.raw, angles.raw);
return dest;
}
/*!
* @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
versors
glms_euler_xzy_quat(versors q, vec3s angles) {
versors dest;
glm_euler_xzy_quat(dest.raw, angles.raw);
return dest;
}
/*!
* @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
versors
glms_euler_yxz_quat(versors q, vec3s angles) {
versors dest;
glm_euler_yxz_quat(dest.raw, angles.raw);
return dest;
}
/*!
* @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
versors
glms_euler_yzx_quat(versors q, vec3s angles) {
versors dest;
glm_euler_yzx_quat(dest.raw, angles.raw);
return dest;
}
/*!
* @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
versors
glms_euler_zxy_quat(versors q, vec3s angles) {
versors dest;
glm_euler_zxy_quat(dest.raw, angles.raw);
return dest;
}
/*!
* @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
versors
glms_euler_zyx_quat(versors q, vec3s angles) {
versors dest;
glm_euler_zyx_quat(dest.raw, angles.raw);
return dest;
}
/*!
* @brief creates NEW quaternion with axis vector
*