rustgd / cgmath

A linear algebra and mathematics library for computer graphics.
https://docs.rs/cgmath
Apache License 2.0
1.12k stars 155 forks source link

Creating a Matrix4 from Quaternions #530

Open Perseus opened 3 years ago

Perseus commented 3 years ago

I've been working with cgmath, trying to use the Matrix4 and Quaternion structs for some animation related graphics stuff.

I ran into something which required me to create a 4x4 Matrix from a Quaternion. On doing this using Matrix4::from(quaternion), the value of the matrix seemed to be row-major. Is this something that is intended or am I mistaken here? I've only recently started working with quaternions, so there might be a gap in my knowledge in this area.

Since the resultant matrix seemed to be row-major, multiplication with other matrices would give the wrong result. I looked at the source for Matrix::from(<Quaternion>) and Matrix::from_translation<Vector3>, they both seemed to be returning row-major matrices

Would love some help/clarification here. Thanks!

kvark commented 3 years ago

We used quaternions quite a bit, and matrix multiplication from quaternions works fine. I don't have the bandwidth to go into details right now, but perhaps if you write down the details somebody can find it and help?

aloucks commented 3 years ago

I recall getting hung up on this (or something similar) before. There seemed to be an inconsistency with row/column major as well as the handedness. I think we've resolved most of the handedness issues, but I'm not certain about row vs column major.