GLM lib differences in matrix to quaternion ?

Hello,
I guess a lot of you people know about the awesome GLM math library. I’ve a question about the matrix to quaternion conversion. I tried out several “tutorials” and code snippets from the net for matrix to quaternion conversion. There’s is a different between the signs of the quaterion created by GLM and by the tutorials / code snippets. The numbers it self are equal. But when I transpose the matrix and did the conversion again, the quaternion created by the code from the net delivered exactly the same results like the GLM (correct signs and numbers).

Although GLM is mostely used for GLM it uses a row major alignment for the matrices and not the column major used by opengl. Of course you can change that with GLM but the default setting is row major.

When I had a look at the GLM conversion code I saw some differences in the calculation

internet code snippet


  qw = 0.25 * S;
  qx = (m21 - m12) / S;
  qy = (m02 - m20) / S; 
  qz = (m10 - m01) / S; 

…and in GLM it looks like


  qw = 0.25 * S;
  qx = (m12 - m21) / S;
  qy = (m20 - m02) / S; 
  qz = (m01 - m10) / S; 

What is the correct way for OpenGL that uses the right handed coordinate system ?

regards,
lobbel

Although GLM is mostely used for GLM it uses a row major alignment for the matrices and not the column major used by opengl.

No, it uses column-major.

Hello,
let’s see this short snippet


glm::mat4 mat(1.0f, 2.0f, 3.0f, 4.0f,
              5.0f, 6.0f, 7.0f, 8.0f,
              9.0f, 10.0f, 11.0f, 12.0f,
              13.0f, 14.0f, 15.0f, 16.0f
             );
float* pfData = glm::value_ptr(mat);

When I step through the code I can not see any rearrangement of the matrix elements. The data fpData points to is contigous piece of memory with the elements order 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f … 16.0f.
So to me this looks row major. Column-major shoud look like
1.0f, 5.0f, 9.0f, 13.0f, 2.0f, 6.0f, 10.0f, 14.0f …etc.

Or did I totally misunderstood some important thing ?

regards,
lobbel

Edit: Just realized, that he internally uses some kind of col_type thing… So the matrix is created in column major from the beginning, right ?

So the matrix is created in column major from the beginning, right ?

Exactly. The first four values, just as for GLSL, are the first column. That’s what it means to be column-major.