Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

euler to quat functions #369

Merged
merged 19 commits into from
Dec 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
05ea35f
made euler to quat xyz. Now I'm trying to test if it works or not
telephone001 Dec 7, 2023
d67ac97
got the euler to quat xyz working and got the tests to pass
telephone001 Dec 7, 2023
c5694c5
made all the functions. I have miscalculated some stuff and am curren…
telephone001 Dec 8, 2023
2f7dbad
finally done with tests and all euler to quaternion functions
telephone001 Dec 8, 2023
4ee6aea
made quat struct and also exported it
telephone001 Dec 8, 2023
45f2fff
Merge branch 'recp:master' into master
telephone001 Dec 8, 2023
ec37969
finished but trying to figure out why its not running in wasm
telephone001 Dec 8, 2023
666d692
fixed the bug with the tester. Its weird that the broken tester worke…
telephone001 Dec 9, 2023
036fd48
moved all my stuff to euler because it fits there better. Also, had t…
telephone001 Dec 9, 2023
fee2b7d
Merge branch 'recp:master' into master
telephone001 Dec 10, 2023
2eb9a67
fixed up the code to fit with the style, Also found out that I was ca…
telephone001 Dec 10, 2023
d613955
Merge remote-tracking branch 'refs/remotes/origin/master'
telephone001 Dec 10, 2023
e24675c
Merge branch 'recp:master' into master
telephone001 Dec 10, 2023
7e4383c
found out I was using glm_euler_xyz_quat in some testers that tests o…
telephone001 Dec 10, 2023
732a403
changed last parameter to be destination and also removed the euler->…
telephone001 Dec 13, 2023
42b5e83
re-added the euler->mat4->quat tests
telephone001 Dec 14, 2023
46aaf25
Merge branch 'master' into master
telephone001 Dec 14, 2023
39c0c1e
added handed folder and also made rh tests for the euler->quat functi…
telephone001 Dec 25, 2023
d820410
Merge remote-tracking branch 'refs/remotes/origin/master'
telephone001 Dec 25, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions include/cglm/call/euler.h
Original file line number Diff line number Diff line change
Expand Up @@ -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(vec3 angles, versor dest);

CGLM_EXPORT
void
glmc_euler_xzy_quat(vec3 angles, versor dest);

CGLM_EXPORT
void
glmc_euler_yxz_quat(vec3 angles, versor dest);

CGLM_EXPORT
void
glmc_euler_yzx_quat(vec3 angles, versor dest);

CGLM_EXPORT
void
glmc_euler_zxy_quat(vec3 angles, versor dest);

CGLM_EXPORT
void
glmc_euler_zyx_quat(vec3 angles, versor dest);


#ifdef __cplusplus
}
#endif
Expand Down
113 changes: 112 additions & 1 deletion include/cglm/euler.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,21 @@
CGLM_INLINE void glm_euler_by_order(vec3 angles,
glm_euler_seq ord,
mat4 dest);
CGLM_INLINE void glm_euler_xyz_quat(vec3 angles, versor dest);
CGLM_INLINE void glm_euler_xzy_quat(vec3 angles, versor dest);
CGLM_INLINE void glm_euler_yxz_quat(vec3 angles, versor dest);
CGLM_INLINE void glm_euler_yzx_quat(vec3 angles, versor dest);
CGLM_INLINE void glm_euler_zxy_quat(vec3 angles, versor dest);
CGLM_INLINE void glm_euler_zyx_quat(vec3 angles, versor dest);
*/

#ifndef cglm_euler_h
#define cglm_euler_h

#include "common.h"

#include "handed/euler_to_quat_rh.h"

/*!
* if you have axis order like vec3 orderVec = [0, 1, 2] or [0, 2, 1]...
* vector then you can convert it to this enum by doing this:
Expand Down Expand Up @@ -188,7 +196,6 @@ glm_euler_xzy(vec3 angles, mat4 dest) {
dest[3][3] = 1.0f;
}


/*!
* @brief build rotation matrix from euler angles
*
Expand Down Expand Up @@ -448,4 +455,108 @@ glm_euler_by_order(vec3 angles, glm_euler_seq ord, mat4 dest) {
dest[3][3] = 1.0f;
}


/*!
* @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(vec3 angles, versor dest) {
#ifdef CGLM_FORCE_LEFT_HANDED
glm_euler_xyz_quat_lh(angles, dest);
#else
glm_euler_xyz_quat_rh(angles, dest);
#endif
}

/*!
* @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(vec3 angles, versor dest) {
#ifdef CGLM_FORCE_LEFT_HANDED
glm_euler_xzy_quat_lh(angles, dest);
#else
glm_euler_xzy_quat_rh(angles, dest);
#endif
}

/*!
* @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(vec3 angles, versor dest) {
#ifdef CGLM_FORCE_LEFT_HANDED
glm_euler_yxz_quat_lh(angles, dest);
#else
glm_euler_yxz_quat_rh(angles, dest);
#endif
}

/*!
* @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(vec3 angles, versor dest) {
#ifdef CGLM_FORCE_LEFT_HANDED
glm_euler_yzx_quat_lh(angles, dest);
#else
glm_euler_yzx_quat_rh(angles, dest);
#endif
}

/*!
* @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(vec3 angles, versor dest) {
#ifdef CGLM_FORCE_LEFT_HANDED
glm_euler_zxy_quat_lh(angles, dest);
#else
glm_euler_zxy_quat_rh(angles, dest);
#endif
}

/*!
* @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(vec3 angles, versor dest) {
#ifdef CGLM_FORCE_LEFT_HANDED
glm_euler_zyx_quat_lh(angles, dest);
#else
glm_euler_zyx_quat_rh(angles, dest);
#endif
}


#endif /* cglm_euler_h */
165 changes: 165 additions & 0 deletions include/cglm/handed/euler_to_quat_rh.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
/*
* 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_rh(vec3 angles, versor dest);
CGLM_INLINE void glm_euler_xzy_quat_rh(vec3 angles, versor dest);
CGLM_INLINE void glm_euler_yxz_quat_rh(vec3 angles, versor dest);
CGLM_INLINE void glm_euler_yzx_quat_rh(vec3 angles, versor dest);
CGLM_INLINE void glm_euler_zxy_quat_rh(vec3 angles, versor dest);
CGLM_INLINE void glm_euler_zyx_quat_rh(vec3 angles, versor dest);
*/

#ifndef cglm_euler_to_quat_rh_h
#define cglm_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[out] q quaternion
* @param[in] angle angles x y z (radians)
*/
CGLM_INLINE
void
glm_euler_xyz_quat_rh(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 right hand (roll yaw pitch)
*
* @param[out] q quaternion
* @param[in] angle angles x y z (radians)
*/
CGLM_INLINE
void
glm_euler_xzy_quat_rh(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 right hand (pitch roll yaw)
*
* @param[out] q quaternion
* @param[in] angle angles x y z (radians)
*/
CGLM_INLINE
void
glm_euler_yxz_quat_rh(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 right hand (pitch yaw roll)
*
* @param[out] q quaternion
* @param[in] angle angles x y z (radians)
*/
CGLM_INLINE
void
glm_euler_yzx_quat_rh(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 right hand (yaw roll pitch)
*
* @param[out] q quaternion
* @param[in] angle angles x y z (radians)
*/
CGLM_INLINE
void
glm_euler_zxy_quat_rh(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 right hand (yaw pitch roll)
*
* @param[out] q quaternion
* @param[in] angle angles x y z (radians)
*/
CGLM_INLINE
void
glm_euler_zyx_quat_rh(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_rh_h*/
Loading
Loading