convert transformation matrix to quaternion

I am working with .X file format export from blender.

In .X format export from blender,the keyframe information are stored in transformation matrix
format (it doesn’t have any option to export to seperate euler angle/translation keyframe).

The problem is,When my animation invole some rotation of root bone around an axis(Rigid body transformation ?),the linear interpolation give a very bad result(the model become flat/turn inside out)

I search on google and found this quaternion-thing.

question:

  1. Since I dont have an euler angle to convert to quartenion,can I directly convert Transformation matrix into quartenion ?

  2. will quatenion interpolation fix my rotation problem ?

thank in advance

  1. Since I dont have an euler angle to convert to quartenion,can I directly convert Transformation matrix into quartenion ?
    Yes. See here:
    http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/index.htm

Of course this works only if the matrix is a pure rotation matrix. Otherwise you have to decompose the matrix first.

  1. will quatenion interpolation fix my rotation problem ?
    You can’t simply linearly interpolate quaternions, you have to use spherical interpolation:
    http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/slerp/index.htm

Of course this works only if the matrix is a pure rotation matrix. Otherwise you have to decompose the matrix first

Does this mean just using rotation part of the matrix for the Conversion right?

So what I have to do is

1.For every keyframe convert transformation matrix in to quaternion(using rotation part of matrix) and translation

2.For quartenion using slerp to interpolate

3.For translation just use linear interpolation

4.Rebuild transformation matrix from quaternion/translation

Please correct me if i am wrong.

Thank for your Answer.

Somboon.

Correct.

Thank :slight_smile:

Just to post a usefull link for matrix, quaternion and euler angles.

http://www.j3d.org/matrix_faq/matrfaq_latest.html

:wink:

You should check out geometric algebra, I recently started playing around with it and it makes many matrix and quaternion ideas much more intuitive. A good starting point is:

http://www.lomont.org/Math/GeometricAlgebra/Geometric%20Algebra%20Primer%20-%20Suter%20-%202003.pdf

Everyone,Thank for yours answer/link.

I managed to fixed the rotation problem now.

:slight_smile: