-
-
Notifications
You must be signed in to change notification settings - Fork 234
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
Quaternion-to-matrix identity rotated #10
Comments
@recp Any ideas on this? |
@winduptoy sorry I didn't see this issue until now, fell free to ping me again I think identity versor (GLM_QUAT_IDENTITY_INIT) is wrong. GLM_QUAT_IDENTITY_INIT {0.0f, 0.0f, 0.0f, 1.0f} versor rotation2;
glm_quat(rotation2, 0, 0, 0, 0); gives {1.0f, 0.0f, 0.0f, 0.0f} so it must be GLM_QUAT_IDENTITY_INIT {1.0f, 0.0f, 0.0f, 0.0f} but These functions also creates versor for you: 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 v);
versor rotation;
glm_quat(rotation, glm_deg(45.0f), 1.0f, 0.0f, 0.0f);
/* or */
glm_quatv(rotation, glm_deg(45.0f), (vec3){1.0f, 0.0f, 0.0f});
/* v postrix means it accepts vector parameter */
/* this axis vector maybe stored somewhere-else */ q is out parameter, I must change its name. AdditionYou don't have to initialize dest (or out) parameters. In your case you dont have to initialize mat4 rotMatrix;
glm_quat_mat4(rotation, rotMatrix); would be enough, but since function is inline I think compiler will ignore identity initialization (I hope) Also I would use built-in print utils to print them, it would save you to write huge printf :) Print matrix: ImportantSome resources / tools / libraries may use So you may see Quaternion.Identity = [0, 0, 0, 1] in MSDN or Unity or somewhere else, but it is [1, 0, 0, 0] in cglm and some other libraries I doesn't matter for me, if it must be x, y, z, w then we can change this. EDIT: [major change] by starting v0.4.0, quaternions are stored as [x, y, z, w], it was [w, x, y, z] in v0.3.5 and earlier versions |
Ah thank you for pointing out the print functions! I must have missed those. I'd like to help you with documentation soon. I did not realize that cglm used Thank you! Hope you had a good holiday wherever in the world you may be. |
That would be wonderful
I'm confused now, probably most people may assume that is x, y, z, w. For C++ classes probably most people accessing those values by ctor or its name like quat->x, quat->w so it doesn't matter for them I think, but since we have stored them as array order is matter. versor is stored as vec4 (aligned) because it is perfectly fits with SIMD instuctions to optimize them. Maybe documentation would prevent any confusion here
Thank you very much, I hope you too. |
Fixed GLM_QUAT_IDENTITY_INIT (wxyz) instead of (xyzw). Addresses #10.
Fixed by: #11 |
@recp Sorry to bring this up again, I hope this isn't just a silly issue with my understanding. You said in the comment above that cglm uses So, if you take a look at the current implementation of
Does this go against what you said earlier? I realize that the arguments are the same order as the components in the quaternion and the name doesn't really matter, but if I have a mental model of things being stored as |
Do not worry, you are welcome to ask anything!, it helps to improve this library. cglm was used wxyz layout/order until this pull request: #43 and version v0.4.0. Check the last comment in PR ;) Currently it must use xyzw and now quaternion api is more powerful than before. So last element is w now, it is real part yes. If there is a bug please let me know or try to fix it by a PR :) PS: I added a note about this change to my previous comment for the future. Also it is important to follow "Note for previous versions" section in README. It should help to migrate to new version[s]. |
Awesome, thanks for explanation. You're improving the library faster than I can keep up! As always, thank you for this wonderful library and your excellent work. |
I'm seeing the following behavior for quaternion to matrix conversion.
outputs
The identity quaternion is what I expect, but the matrix seems to be flipped 180 degrees on X and Y. I noticed this because everything I render is flipped upside down. Shouldn't
rotMatrix[0][0]
androtMatrix[1][1]
equal positive 1 instead of negative 1 when using an identity quaternion? Or maybe I don't understand quaternions fully.Platform:
Linux 64-bit
gcc v7.2.1
cglm v0.3.1
The text was updated successfully, but these errors were encountered: