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

How do I generate a quaternion from euler angles? #306

Open
badasahog opened this issue May 30, 2023 · 14 comments
Open

How do I generate a quaternion from euler angles? #306

badasahog opened this issue May 30, 2023 · 14 comments

Comments

@badasahog
Copy link

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

@recp
Copy link
Owner

recp commented Jun 2, 2023

Hi @badasahog,

Sorry for the delay,

It could be nice to have this feature in cglm too. I had tried to update Euler with #128 but couldn't finished that PR yet,

We can have this before that,

Any PR would be awesome otherwise I added to TODOs. 🙂

@Nonesence999
Copy link

Yes It would be amazing I also need a quat structure for my project.

@telephone001
Copy link
Contributor

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);

@recp
Copy link
Owner

recp commented Nov 28, 2023

@telephone001 many thanks, hope we add this asap 🚀

@telephone001
Copy link
Contributor

telephone001 commented Dec 5, 2023

do you think glm_quate_xyz or glm_quat_euler_xyz would be a better name for this new function?

@recp
Copy link
Owner

recp commented Dec 6, 2023

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()

@telephone001
Copy link
Contributor

Alright thanks for the response. I'll try and get this done soon

@recp
Copy link
Owner

recp commented Dec 6, 2023

@telephone001 thanks 🤗

@telephone001
Copy link
Contributor

telephone001 commented Dec 8, 2023

@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?

@recp
Copy link
Owner

recp commented Dec 8, 2023

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 #360 (comment) but fixed later.

@telephone001
Copy link
Contributor

I created a pr and most tests failed. The error is just that all tests fail on certain builds.

@gottfriedleibniz
Copy link

gottfriedleibniz commented Dec 9, 2023

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).

@telephone001
Copy link
Contributor

telephone001 commented Dec 9, 2023

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?

@recp
Copy link
Owner

recp commented Dec 9, 2023

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 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants