mgoetschius

09-01-2015, 09:32 AM

I'm not sure exactly where to ask this, so I'll try here.

I've put together a collada loader to load up an animated skeletal mesh. All of my keyframes load and display correctly. The collada keyframes use matrices. I'm trying to convert these matrices to quaternions to use slerp then convert them back to matrices to send them to the gpu. The problem is that I can't even seem to convert a single matrix to a quaternion and back. Here's an example:

// set up example matrix

glm::mat4 m(0.0);

m[0][0] = 0.6143; m[0][1] = 0.0000000001; m[0][2] = 4.309; m[0][3] = 0;

m[1][0] = -3.731; m[1][1] = 2.176; m[1][2] = .532; m[1][3] = 0;

m[2][0] = -2.154; m[2][1] = -3.769; m[2][2] = .3071; m[2][3] = 0;

m[3][0] = 4.61; m[3][1] = 12.22; m[3][2] = 8.013; m[3][3] = 1;

PrintM(m); // just prints a glm matrix

// convert matrix to quat

glm::quat rotation = glm::quat_cast(m);

std::cout << rotation.x << ", " << rotation.y << ", " << rotation.z << ", " << rotation.w << std::endl;

// convert quat to matrix

m = glm::mat4_cast(rotation);

PrintM(m); // just prints a glm matrix

//convert new matrix back to quat

glm::quat q = glm::quat_cast(m);

std::cout << q.x << ", " << q.y << ", " << q.z << ", " << q.w << std::endl;

Here's the output

0.6143 -3.731 -2.154 4.61

1e-010 2.176 -3.769 12.22

4.309 0.532 0.3071 8.013

0 0 0 1

1.06239, -1.59643, 0.921597, 1.0121

-5.796 -5.258 -1.273 0

-1.527 -2.956 -5.093 0

5.19 -0.792 -6.355 0

0 0 0 1

-1.06239, 1.59643, -0.921597, -1.0121

Notice the the two quaternions are the same except the signs are opposite. I am not a math expert so that's my first problem. So, my question is, shouldn't this process give me back the same matrix I used as input? I'm not worried about the translation portion of the matrix currently; I have that working. Any thoughts would be appreciated.

Thanks

I've put together a collada loader to load up an animated skeletal mesh. All of my keyframes load and display correctly. The collada keyframes use matrices. I'm trying to convert these matrices to quaternions to use slerp then convert them back to matrices to send them to the gpu. The problem is that I can't even seem to convert a single matrix to a quaternion and back. Here's an example:

// set up example matrix

glm::mat4 m(0.0);

m[0][0] = 0.6143; m[0][1] = 0.0000000001; m[0][2] = 4.309; m[0][3] = 0;

m[1][0] = -3.731; m[1][1] = 2.176; m[1][2] = .532; m[1][3] = 0;

m[2][0] = -2.154; m[2][1] = -3.769; m[2][2] = .3071; m[2][3] = 0;

m[3][0] = 4.61; m[3][1] = 12.22; m[3][2] = 8.013; m[3][3] = 1;

PrintM(m); // just prints a glm matrix

// convert matrix to quat

glm::quat rotation = glm::quat_cast(m);

std::cout << rotation.x << ", " << rotation.y << ", " << rotation.z << ", " << rotation.w << std::endl;

// convert quat to matrix

m = glm::mat4_cast(rotation);

PrintM(m); // just prints a glm matrix

//convert new matrix back to quat

glm::quat q = glm::quat_cast(m);

std::cout << q.x << ", " << q.y << ", " << q.z << ", " << q.w << std::endl;

Here's the output

0.6143 -3.731 -2.154 4.61

1e-010 2.176 -3.769 12.22

4.309 0.532 0.3071 8.013

0 0 0 1

1.06239, -1.59643, 0.921597, 1.0121

-5.796 -5.258 -1.273 0

-1.527 -2.956 -5.093 0

5.19 -0.792 -6.355 0

0 0 0 1

-1.06239, 1.59643, -0.921597, -1.0121

Notice the the two quaternions are the same except the signs are opposite. I am not a math expert so that's my first problem. So, my question is, shouldn't this process give me back the same matrix I used as input? I'm not worried about the translation portion of the matrix currently; I have that working. Any thoughts would be appreciated.

Thanks