Sign in to follow this  
Deliverance

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

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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 :).

Share this post


Link to post
Share on other sites
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 :)

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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 :)





Share this post


Link to post
Share on other sites
The code that extracts the bone matrices is as follows:


Matrix3 mTransform = pMatrixInverses[b] * m_vBones[b]->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 quaternion
q.Normalize();

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this