Merge pull request #377 from telephone001/euler_to_quat_lh

This commit is contained in:
Recep Aslantas
2023-12-30 21:31:28 +03:00
committed by GitHub
9 changed files with 1020 additions and 38 deletions

View File

@@ -43,7 +43,46 @@
#include "common.h"
#include "handed/euler_to_quat_rh.h"
#ifdef CGLM_FORCE_LEFT_HANDED
# include "handed/euler_to_quat_lh.h"
#else
# include "handed/euler_to_quat_rh.h"
#endif
#ifndef CGLM_CLIPSPACE_INCLUDE_ALL
# if CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_ZO
# include "clipspace/ortho_lh_zo.h"
# include "clipspace/persp_lh_zo.h"
# include "clipspace/view_lh_zo.h"
# elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_NO
# include "clipspace/ortho_lh_no.h"
# include "clipspace/persp_lh_no.h"
# include "clipspace/view_lh_no.h"
# elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_ZO
# include "clipspace/ortho_rh_zo.h"
# include "clipspace/persp_rh_zo.h"
# include "clipspace/view_rh_zo.h"
# elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_NO
# include "clipspace/ortho_rh_no.h"
# include "clipspace/persp_rh_no.h"
# include "clipspace/view_rh_no.h"
# endif
#else
# include "clipspace/ortho_lh_zo.h"
# include "clipspace/persp_lh_zo.h"
# include "clipspace/ortho_lh_no.h"
# include "clipspace/persp_lh_no.h"
# include "clipspace/ortho_rh_zo.h"
# include "clipspace/persp_rh_zo.h"
# include "clipspace/ortho_rh_no.h"
# include "clipspace/persp_rh_no.h"
# include "clipspace/view_lh_zo.h"
# include "clipspace/view_lh_no.h"
# include "clipspace/view_rh_zo.h"
# include "clipspace/view_rh_no.h"
#endif
/*!
* if you have axis order like vec3 orderVec = [0, 1, 2] or [0, 2, 1]...
@@ -460,8 +499,8 @@ 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)
* @param[in] angles angles x y z (radians)
* @param[out] dest quaternion
*/
CGLM_INLINE
void
@@ -477,8 +516,8 @@ glm_euler_xyz_quat(vec3 angles, versor 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)
* @param[in] angles angles x y z (radians)
* @param[out] dest quaternion
*/
CGLM_INLINE
void
@@ -494,8 +533,8 @@ glm_euler_xzy_quat(vec3 angles, versor 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)
* @param[in] angles angles x y z (radians)
* @param[out] dest quaternion
*/
CGLM_INLINE
void
@@ -511,8 +550,8 @@ glm_euler_yxz_quat(vec3 angles, versor 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)
* @param[in] angles angles x y z (radians)
* @param[out] dest quaternion
*/
CGLM_INLINE
void
@@ -528,8 +567,8 @@ glm_euler_yzx_quat(vec3 angles, versor 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)
* @param[in] angles angles x y z (radians)
* @param[out] dest quaternion
*/
CGLM_INLINE
void
@@ -545,8 +584,8 @@ glm_euler_zxy_quat(vec3 angles, versor 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)
* @param[in] angles angles x y z (radians)
* @param[out] dest quaternion
*/
CGLM_INLINE
void

View File

@@ -0,0 +1,167 @@
/*
* Copyright (c), Recep Aslantas.
*
* MIT License (MIT), http://opensource.org/licenses/MIT
* Full license can be found in the LICENSE file
*/
/*
Functions:
CGLM_INLINE void glm_euler_xyz_quat_lh(vec3 angles, versor dest);
CGLM_INLINE void glm_euler_xzy_quat_lh(vec3 angles, versor dest);
CGLM_INLINE void glm_euler_yxz_quat_lh(vec3 angles, versor dest);
CGLM_INLINE void glm_euler_yzx_quat_lh(vec3 angles, versor dest);
CGLM_INLINE void glm_euler_zxy_quat_lh(vec3 angles, versor dest);
CGLM_INLINE void glm_euler_zyx_quat_lh(vec3 angles, versor dest);
*/
/*
Things to note:
The only difference between euler to quat rh vs lh is that the zsin part is negative
*/
#ifndef cglm_euler_to_quat_lh_h
#define cglm_euler_to_quat_lh_h
#include "../common.h"
/*!
* @brief creates NEW quaternion using rotation angles and does
* rotations in x y z order in left hand (roll pitch yaw)
*
* @param[in] angles angles x y z (radians)
* @param[out] dest quaternion
*/
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;
}
/*!
* @brief creates NEW quaternion using rotation angles and does
* rotations in x z y order in left hand (roll yaw pitch)
*
* @param[in] angles angles x y z (radians)
* @param[out] dest quaternion
*/
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;
}
/*!
* @brief creates NEW quaternion using rotation angles and does
* rotations in y x z order in left hand (pitch roll yaw)
*
* @param[in] angles angles x y z (radians)
* @param[out] dest quaternion
*/
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;
}
/*!
* @brief creates NEW quaternion using rotation angles and does
* rotations in y z x order in left hand (pitch yaw roll)
*
* @param[in] angles angles x y z (radians)
* @param[out] dest quaternion
*/
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;
}
/*!
* @brief creates NEW quaternion using rotation angles and does
* rotations in z x y order in left hand (yaw roll pitch)
*
* @param[in] angles angles x y z (radians)
* @param[out] dest quaternion
*/
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;
}
/*!
* @brief creates NEW quaternion using rotation angles and does
* rotations in z y x order in left hand (yaw pitch roll)
*
* @param[in] angles angles x y z (radians)
* @param[out] dest quaternion
*/
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*/

View File

@@ -15,6 +15,11 @@
CGLM_INLINE void glm_euler_zyx_quat_rh(vec3 angles, versor dest);
*/
/*
Things to note:
The only difference between euler to quat rh vs lh is that the zsin part is negative
*/
#ifndef cglm_euler_to_quat_rh_h
#define cglm_euler_to_quat_rh_h
@@ -24,8 +29,8 @@
* @brief creates NEW quaternion using rotation angles and does
* rotations in x y z order in right hand (roll pitch yaw)
*
* @param[out] q quaternion
* @param[in] angle angles x y z (radians)
* @param[in] angles angles x y z (radians)
* @param[out] dest quaternion
*/
CGLM_INLINE
void
@@ -48,8 +53,8 @@ glm_euler_xyz_quat_rh(vec3 angles, versor dest) {
* @brief creates NEW quaternion using rotation angles and does
* rotations in x z y order in right hand (roll yaw pitch)
*
* @param[out] q quaternion
* @param[in] angle angles x y z (radians)
* @param[in] angles angles x y z (radians)
* @param[out] dest quaternion
*/
CGLM_INLINE
void
@@ -72,8 +77,8 @@ glm_euler_xzy_quat_rh(vec3 angles, versor dest) {
* @brief creates NEW quaternion using rotation angles and does
* rotations in y x z order in right hand (pitch roll yaw)
*
* @param[out] q quaternion
* @param[in] angle angles x y z (radians)
* @param[in] angles angles x y z (radians)
* @param[out] dest quaternion
*/
CGLM_INLINE
void
@@ -95,8 +100,8 @@ glm_euler_yxz_quat_rh(vec3 angles, versor dest) {
* @brief creates NEW quaternion using rotation angles and does
* rotations in y z x order in right hand (pitch yaw roll)
*
* @param[out] q quaternion
* @param[in] angle angles x y z (radians)
* @param[in] angles angles x y z (radians)
* @param[out] dest quaternion
*/
CGLM_INLINE
void
@@ -119,8 +124,8 @@ glm_euler_yzx_quat_rh(vec3 angles, versor dest) {
* @brief creates NEW quaternion using rotation angles and does
* rotations in z x y order in right hand (yaw roll pitch)
*
* @param[out] q quaternion
* @param[in] angle angles x y z (radians)
* @param[in] angles angles x y z (radians)
* @param[out] dest quaternion
*/
CGLM_INLINE
void
@@ -142,8 +147,8 @@ glm_euler_zxy_quat_rh(vec3 angles, versor dest) {
* @brief creates NEW quaternion using rotation angles and does
* rotations in z y x order in right hand (yaw pitch roll)
*
* @param[out] q quaternion
* @param[in] angle angles x y z (radians)
* @param[in] angles angles x y z (radians)
* @param[out] dest quaternion
*/
CGLM_INLINE
void

View File

@@ -159,8 +159,8 @@ glms_euler_by_order(vec3s angles, glm_euler_seq ord) {
* @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)
* @param[in] angles angles x y z (radians)
* @param[out] dest quaternion
*/
CGLM_INLINE
versors
@@ -174,8 +174,8 @@ glms_euler_xyz_quat(vec3s angles) {
* @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)
* @param[in] angles angles x y z (radians)
* @param[out] dest quaternion
*/
CGLM_INLINE
versors
@@ -189,8 +189,8 @@ glms_euler_xzy_quat(vec3s angles) {
* @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)
* @param[in] angles angles x y z (radians)
* @param[out] dest quaternion
*/
CGLM_INLINE
versors
@@ -204,8 +204,8 @@ glms_euler_yxz_quat(vec3s angles) {
* @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)
* @param[in] angles angles x y z (radians)
* @param[out] dest quaternion
*/
CGLM_INLINE
versors
@@ -219,8 +219,8 @@ glms_euler_yzx_quat(vec3s angles) {
* @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)
* @param[in] angles angles x y z (radians)
* @param[out] dest quaternion
*/
CGLM_INLINE
versors
@@ -234,8 +234,8 @@ glms_euler_zxy_quat(vec3s angles) {
* @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)
* @param[in] angles angles x y z (radians)
* @param[out] dest quaternion
*/
CGLM_INLINE
versors

View File

@@ -0,0 +1,115 @@
/*
* Copyright (c), Recep Aslantas.
*
* MIT License (MIT), http://opensource.org/licenses/MIT
* Full license can be found in the LICENSE file
*/
/*
Functions:
CGLM_INLINE void glms_euler_xyz_quat_lh(vec3 angles, versor dest);
CGLM_INLINE void glms_euler_xzy_quat_lh(vec3 angles, versor dest);
CGLM_INLINE void glms_euler_yxz_quat_lh(vec3 angles, versor dest);
CGLM_INLINE void glms_euler_yzx_quat_lh(vec3 angles, versor dest);
CGLM_INLINE void glms_euler_zxy_quat_lh(vec3 angles, versor dest);
CGLM_INLINE void glms_euler_zyx_quat_lh(vec3 angles, versor dest);
*/
#ifndef cglms_euler_to_quat_lh_h
#define cglms_euler_to_quat_lh_h
#include "../common.h"
/*!
* @brief creates NEW quaternion using rotation angles and does
* rotations in x y z order in left hand (roll pitch yaw)
*
* @param[in] angles angles x y z (radians)
* @param[out] dest quaternion
*/
CGLM_INLINE
versors
glms_euler_xyz_quat_lh(vec3s angles) {
versors dest;
glm_euler_xyz_quat_lh(angles.raw, dest.raw);
return dest;
}
/*!
* @brief creates NEW quaternion using rotation angles and does
* rotations in x z y order in left hand (roll yaw pitch)
*
* @param[in] angles angles x y z (radians)
* @param[out] dest quaternion
*/
CGLM_INLINE
versors
glms_euler_xzy_quat_lh(vec3s angles) {
versors dest;
glm_euler_xzy_quat_lh(angles.raw, dest.raw);
return dest;
}
/*!
* @brief creates NEW quaternion using rotation angles and does
* rotations in y x z order in left hand (pitch roll yaw)
*
* @param[in] angles angles x y z (radians)
* @param[out] dest quaternion
*/
CGLM_INLINE
versors
glms_euler_yxz_quat_lh(vec3s angles) {
versors dest;
glm_euler_yxz_quat_lh(angles.raw, dest.raw);
return dest;
}
/*!
* @brief creates NEW quaternion using rotation angles and does
* rotations in y z x order in left hand (pitch yaw roll)
*
* @param[in] angles angles x y z (radians)
* @param[out] dest quaternion
*/
CGLM_INLINE
versors
glms_euler_yzx_quat_lh(vec3s angles) {
versors dest;
glm_euler_yzx_quat_lh(angles.raw, dest.raw);
return dest;
}
/*!
* @brief creates NEW quaternion using rotation angles and does
* rotations in z x y order in left hand (yaw roll pitch)
*
* @param[in] angles angles x y z (radians)
* @param[out] dest quaternion
*/
CGLM_INLINE
versors
glms_euler_zxy_quat_lh(vec3s angles) {
versors dest;
glm_euler_zxy_quat_lh(angles.raw, dest.raw);
return dest;
}
/*!
* @brief creates NEW quaternion using rotation angles and does
* rotations in z y x order in left hand (yaw pitch roll)
*
* @param[in] angles angles x y z (radians)
* @param[out] dest quaternion
*/
CGLM_INLINE
versors
glms_euler_zyx_quat_lh(vec3s angles) {
versors dest;
glm_euler_zyx_quat_lh(angles.raw, dest.raw);
return dest;
}
#endif /* cglms_euler_to_quat_lh_h */

View File

@@ -0,0 +1,115 @@
/*
* Copyright (c), Recep Aslantas.
*
* MIT License (MIT), http://opensource.org/licenses/MIT
* Full license can be found in the LICENSE file
*/
/*
Functions:
CGLM_INLINE void glms_euler_xyz_quat_rh(vec3 angles, versor dest);
CGLM_INLINE void glms_euler_xzy_quat_rh(vec3 angles, versor dest);
CGLM_INLINE void glms_euler_yxz_quat_rh(vec3 angles, versor dest);
CGLM_INLINE void glms_euler_yzx_quat_rh(vec3 angles, versor dest);
CGLM_INLINE void glms_euler_zxy_quat_rh(vec3 angles, versor dest);
CGLM_INLINE void glms_euler_zyx_quat_rh(vec3 angles, versor dest);
*/
#ifndef cglms_euler_to_quat_rh_h
#define cglms_euler_to_quat_rh_h
#include "../common.h"
/*!
* @brief creates NEW quaternion using rotation angles and does
* rotations in x y z order in right hand (roll pitch yaw)
*
* @param[in] angles angles x y z (radians)
* @param[out] dest quaternion
*/
CGLM_INLINE
versors
glms_euler_xyz_quat_rh(vec3s angles) {
versors dest;
glm_euler_xyz_quat_rh(angles.raw, dest.raw);
return dest;
}
/*!
* @brief creates NEW quaternion using rotation angles and does
* rotations in x z y order in right hand (roll yaw pitch)
*
* @param[in] angles angles x y z (radians)
* @param[out] dest quaternion
*/
CGLM_INLINE
versors
glms_euler_xzy_quat_rh(vec3s angles) {
versors dest;
glm_euler_xzy_quat_rh(angles.raw, dest.raw);
return dest;
}
/*!
* @brief creates NEW quaternion using rotation angles and does
* rotations in y x z order in right hand (pitch roll yaw)
*
* @param[in] angles angles x y z (radians)
* @param[out] dest quaternion
*/
CGLM_INLINE
versors
glms_euler_yxz_quat_rh(vec3s angles) {
versors dest;
glm_euler_yxz_quat_rh(angles.raw, dest.raw);
return dest;
}
/*!
* @brief creates NEW quaternion using rotation angles and does
* rotations in y z x order in right hand (pitch yaw roll)
*
* @param[in] angles angles x y z (radians)
* @param[out] dest quaternion
*/
CGLM_INLINE
versors
glms_euler_yzx_quat_rh(vec3s angles) {
versors dest;
glm_euler_yzx_quat_rh(angles.raw, dest.raw);
return dest;
}
/*!
* @brief creates NEW quaternion using rotation angles and does
* rotations in z x y order in right hand (yaw roll pitch)
*
* @param[in] angles angles x y z (radians)
* @param[out] dest quaternion
*/
CGLM_INLINE
versors
glms_euler_zxy_quat_rh(vec3s angles) {
versors dest;
glm_euler_zxy_quat_rh(angles.raw, dest.raw);
return dest;
}
/*!
* @brief creates NEW quaternion using rotation angles and does
* rotations in z y x order in right hand (yaw pitch roll)
*
* @param[in] angles angles x y z (radians)
* @param[out] dest quaternion
*/
CGLM_INLINE
versors
glms_euler_zyx_quat_rh(vec3s angles) {
versors dest;
glm_euler_zyx_quat_rh(angles.raw, dest.raw);
return dest;
}
#endif /* cglms_euler_to_quat_rh_h */