cglm
cglm copied to clipboard
How do I generate a quaternion from euler angles?
I want to get a quaternion based on roll, pitch, and yaw, but as far as I can tell there is no function for this.
The only functions I could find were based on a unit vector and an angle (glm_quatv, glm_quat)
glm provides this functionality in the form of the glm::quat(glm::vec3) constructor
Hi @badasahog,
Sorry for the delay,
It could be nice to have this feature in cglm too. I had tried to update Euler with https://github.com/recp/cglm/pull/128 but couldn't finished that PR yet,
We can have this before that,
Any PR would be awesome otherwise I added to TODOs. 🙂
Yes It would be amazing I also need a quat structure for my project.
Sorry for answering very late, but for anyone else who needs help in the future, you could try making a function that rotates the quaternion by each axis. I guess you could also try and push it to the repository even though it might not be optimal
// example for rotating the quaternion by the y axis by an angle:
// y axis vec3s axis = {0, 1, 0};
// creates a quaternion with the angle and axis versors rotation = glms_quatv(angle, axis);
// when multiplying this rotation with an angular position quaternion, it will apply the rotation to the angular position angular_position = glms_quat_mul(rotation, angular_position);
@telephone001 many thanks, hope we add this asap 🚀
do you think glm_quate_xyz or glm_quat_euler_xyz would be a better name for this new function?
To convert Euler to Quat, I would use glm_euler_[x|y|z]_quat
which is similar pattern used in cglm e.g. glm_mat4_quat() convert mat4 to quat.
glm_SRC_DST()
Alright thanks for the response. I'll try and get this done soon
@telephone001 thanks 🤗
@recp Finished making it and all my tests pass on my computer, but it fails using meson webassembly for some reason. I think I did everything I needed though (exported it in call/quat, made struct versions of it, declared and entered tests) Do I need to add anything in the wasmfiles?
Thanks for the implementation a PR would be nice to see,
it fails using meson webassembly for some reason.
https://github.com/recp/cglm/actions seems fine, may I ask what are the errors? Also can you pull latest commits and try again? there was an issue about https://github.com/recp/cglm/pull/360#issuecomment-1838122934 but fixed later.
I created a pr and most tests failed. The error is just that all tests fail on certain builds.
The 'expected' quaternion is overwriting itself during multiplication.
Another thing to check is whether glm_euler_*_quat
matches, or roughly matches, glm_euler_by_order + glm_mat4_quat
. GLM_EULER_XYZ
looks like X*Y*Z
(local/intrinsic) instead of Z*Y*X
(global/extrinsic).
Oh I see now. Thank you for the reply. I'll try and get this fixed up. I'll also add glm_euler_by_order + glm_mat4_quat in tests Would it be preferred to use the glm_euler_seq ord or the xyz combo in the name? Because euler.h has both Also, I'm thinking of moving these functions to euler.h would that be better than quat.h? If we do settle on the xyz combo in the name, would it be allowed for me to make a macro function to create the xyz combination tests for me?
The 'expected' quaternion is overwriting itself during multiplication.
@gottfriedleibniz many thanks for the catch!
I'll also check all places e.g. dest[0]
to fix similar situations
Also, I'm thinking of moving these functions to euler.h would that be better than quat.h?
Yes since SRC->DST is Euler -> Quat I think they must be in euler.h, In the future we can add reverse quat_to_euler in quat.h.
If we do settle on the xyz combo in the name, would it be allowed for me to make a macro function to create the xyz combination tests for me?
To simplify creating tests, any macro, utility functions can be used 👍