animated transform

Started by
2 comments, last by supagu 15 years, 11 months ago
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?
Advertisement
Why don't you post the code you are using to convert from matrix to quaternion and back?
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.
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

This topic is closed to new replies.

Advertisement