Advertisement

Matrix conversion

Started by March 14, 2003 12:34 PM
5 comments, last by wall 21 years, 9 months ago
Hi! Does anybody know how to convert a 3D Studio MAX transformation matrix so that it can be used by OpenGL. You know MAX has the Z axis up and and the Y axis into the screen. So I need to switch those and also invert the Z coordinates because they''re positive into the screen in MAX and negative in my project. Thanks!
Rotate the matrix about origin of 90 degree about the x axis
to swap y,z , then negate z, i hope it helps, unfortunately i don''t know so much about 3dsmax

Advertisement
If you rotate and flip like that, It''ll reverse the order of vertexes in the triangles, which will invert normals and screw up back face culling. So just make sure you reverse ''em again when you''re done.
I''m almost positive in 3ds max you can change the axis orientation. not 100% but 90%
An alternative would be to just use the data and matrices in Max space, and then make it up in the modelview matrix when you render your meshes.

OpenGL doesn''t really have any "up," as you can make anything you want "up" in the modelview matrix (don''t rotate in the perspective projection matrix, though).
Here are some helpful coordinate transform matrices. Apply them to the matrix M as M -> T*M*T-1

Swap the Y and Z axes:
T = [1 0 0; 0 0 1; 0 1 0]

Invert the direction of the Z axis:
T = [1 0 0; 0 1 0; 0 0 -1]

I think you only need to invert the Z-axis though.
Advertisement
The above will work.
(Since this may be useful):
My converter went like this:
LOAD_FFF //loads x,y,z into f1,f2,f3 consequetively
SAVE_F1F3F2_ //saves as x,z,-y
//this results in the same as the front view in 3dsmax
LOAD_DDD //loads facelist a,b,c
If think I switched the face order around. Something like b,c,a or maybe it was c,a,b. (I''m not at my computer right now).
For the UV coordinates of textures:
LOAD_FF //loads into f1,f2
f2=-f2;
SAVE_FF

and later I do this:

CalculateSurfaceNormals();
CalculateSmoothVertexNormals(); //if using gouraud or phong

Recalculating the normals after loading is much faster than loading the normal data(not to mention as someone noted above, the normals will be wrong). Better loadtimes! :D

//note that LOAD_FFF,SAVE_FFF,etc are all personalized #defs
(>-<)

This topic is closed to new replies.

Advertisement