Converting from a 3d studio max matrix to an opengl matrix

Started by
8 comments, last by Deliverance 15 years, 8 months ago
How do you do this conversion?
Advertisement
If this is the same issue I had with the problem being 3d Max has z as up and the model rendering on its side. Either when you render rotate the model (-90,1,0,0) or for a better solution just swap the all the z-coords with the y-coords when you load the model.

I perform collisions on my 3ds meshes too and have no issues when the coords are flipped.
Well, i'm importing the bone animation and need to convert the rotation matrix for each bone into a matrix useful to opengl.
Hi Deliverance,

I'm not entirely sure what data the bone animations contain, however a "matrix useful to opengl" is a column-major matrix.

Click here for OpenGL matrix descriptions.

Hope this helps!

Edit:

In case you get confused about the OpenGL matrices (assuming you are using OpenGL 2.1), here is the Specification. Scroll down to page 43 where it talks about how matrices are laid out in OpenGL in quite a bit of detail :).
I see, I just let the animation do its thing without changing it then rotate when rendering the model. and for collision I flip the coords (and negate the z, forgot to mention this before).

I'm sure if you multiply your existing bone rotation matrix with a rotation matrix (-90 about the x-axis) this will sort you out.

|1 0 0|
|0 cos(angle) -sin(angle)|
|0 sin(angle) cos(angle)|

which is basically

|1 0 0|
|0 0 1|
|0 -1 0|

for the rotation you need.

Edit :

on second thought, I think I misunderstood your problem apologies if this is of no use :)
Quote:Original post by BlackSeeds
I see, I just let the animation do its thing without changing it then rotate when rendering the model. and for collision I flip the coords (and negate the z, forgot to mention this before).

I'm sure if you multiply your existing bone rotation matrix with a rotation matrix (-90 about the x-axis) this will sort you out.

|1 0 0|
|0 cos(angle) -sin(angle)|
|0 sin(angle) cos(angle)|

which is basically

|1 0 0|
|0 0 1|
|0 -1 0|

for the rotation you need.

Edit :

on second thought, I think I misunderstood your problem apologies if this is of no use :)


You understood what my problem is, but multiplying the matrix with a rotation matrix -90 degrees about the x axis did not solve the problem.
Ahh, so it is an issue with the co-ordinate system differences in 3ds Max?

what does your bone rotation matrix look like at the moment? give some more information on what issues you are facing and I should be able to help better :)





The code that extracts the bone matrices is as follows:

Matrix3 mTransform = pMatrixInverses * m_vBones->GetObjTMAfterWSM(i * GetTicksPerFrame());	CVector3D translation = {mTransform.GetTrans().x, 			 mTransform.GetTrans().z,			 -mTransform.GetTrans().y};	Matrix3 swapYZ(Point3(1,0,0), Point3(0,0,1), Point3(0,-1,0), Point3(0,0,0));mTransform = mTransform * swapYZ;															Quaternion q(mTransform); // matrix to quaternionq.Normalize(); 
doesn't seem anything wrong there.

Have you transformed all the vertices of the model as well so they are in the right place?

what is the observed output and why is it incorrect?

does the model render / animate correctly but just oriented incorrectly?

In my program using skeletal animation, I don't alter the vertices or the bone rotation matrix, I simply perform the calculations to get the new vertex positions and just rotate the model when rendering it to make it look correct.

I only use the rotation matrix to change the y and z when I perform collision because I need the polygons vertices in their accurate position in my scene to do sphere/poly tests.

Quote:
Have you transformed all the vertices of the model as well so they are in the right place?


Yes i did.

Quote:
what is the observed output and why is it incorrect?


Weird animated scaling of the model based on current keyframe.

Quote:
does the model render / animate correctly but just oriented incorrectly?


No

Quote:
In my program using skeletal animation, I don't alter the vertices or the bone rotation matrix, I simply perform the calculations to get the new vertex positions and just rotate the model when rendering it to make it look correct.


Yes, i managed to do that too.

This topic is closed to new replies.

Advertisement