Jump to content
• Advertisement

# animated transform

This topic is 3867 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

## Recommended Posts

I have a bit of a problem exporting animation data from 3d max. The problem is i can only obtain matrix transforms for each keyframe (or each frame if needed). I need to convert this to quaternions for my engine, how ever the quaternion i calculate, if converted back to a matrix, is not the same. If there a way i can fudge the quaternion if i know it results in an incorrect matrix, maybe invert or negate it or something? or can I use multiple matrices to help generate the correct quaternions?

#### Share this post

##### Share on other sites
Advertisement
Why don't you post the code you are using to convert from matrix to quaternion and back?

#### Share this post

##### Share on other sites
If you are using the 3dsmax sdk you can use the decomp_affine(...) function of the sdk to decompose the matrix into separated components like position, rotation and scale. The rotation is represented by a quaternion.

If you do not use the Max SDK and only have the Matrix because the file format you use only provides this, then if you want to go the safe way you can decompose the matrix using polar decomposition, just like the Max SDK does.
There is some free code on the net that you can use, from the graphic gems books if i remember correctly. It has basically exactly the same decomp_affine function as the Max SDK.

Decompose.c
Decompose.h

If you know you only use rotation and no non-uniform scale, then you could also decompose the matrix yourself without polar decomposition, but on a much simpler way. But there are already some threads about that.

#### Share this post

##### Share on other sites
this is the code i use to convert a matrix to a quat:
void Quaternion::CreateFromMatrix(const Matrix4& mat){	float t = 1 + mat[0] + mat[5] + mat[10];	if (t > Math::Epsilon) // should this be less than epsilon also?	{		float s = sqrtf(t) * 2;		x = (mat[9] - mat[6]) / s;		y = (mat[2] - mat[8]) / s;		z = (mat[4] - mat[1]) / s;		w = 0.25f * s;	}	else // if t == 0	{		if (mat[0] > mat[5] && mat[0] > mat[10]) // col1		{			float s = sqrtf(1.0f + mat[0] - mat[5] - mat[10]) * 2;			x = 0.25f * s;			y = (mat[4] + mat[1]) / s;			z = (mat[2] + mat[8]) / s;			w = (mat[9] - mat[6]) / s;		}		else if (mat[5] > mat[10]) // col2		{			float s = sqrtf(1.0f + mat[5] - mat[0] - mat[10]) * 2;			x = (mat[4] + mat[1]) / s;			y = 0.25f * s;			z = (mat[9] + mat[6]) / s;			w = (mat[2] - mat[8]) / s;		}		else //col3		{			float s = sqrtf(1.0f + mat[10] - mat[0] - mat[5]) * 2;			x = (mat[2] - mat[8]) / s;			y = (mat[9] - mat[6]) / s;			z = 0.25f * s;			w = (mat[4] - mat[1]) / s;		}	}}

as for the decompose code, it seems to have matrix[row][column] and in right hand cord system, while my system is matrix[column][row] in left hand system

im just wondering how that means that codes matrices are layed out, like this?:
m|0|1|2|3--------------------0|x-axis|t.x--------------------1|y-axis|t.y--------------------2|z-axis|t.z--------------------3|0 0 0 |1where t represents translation

#### Share this post

##### Share on other sites

• Advertisement

### Announcements

• Advertisement

• ### Popular Contributors

1. 1
2. 2
3. 3
Rutin
15
4. 4
khawk
14
5. 5
frob
12
• Advertisement

• 9
• 11
• 11
• 23
• 12
• ### Forum Statistics

• Total Topics
633660
• Total Posts
3013221
×

## Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!