Matrices and coordinate systems

Started by
8 comments, last by dimebolt 18 years, 7 months ago
Hi! I have loaded loaded a transform matrix from a mesh file and wanted to multiply it with the current world view matrix. The problem is that this file was creaetd for Direct3D and not for OpenGL. Since Direct3D uses another coordinate system than OpenGL (the direction of the z axis is different), this matrix (4x4) can not be used for OpenGL. How can I convert the matrix? Thanks in advance.
Advertisement
Quote:Original post by ChristophR
Hi!

I have loaded loaded a transform matrix from a mesh file and wanted to multiply it with the current world view matrix. The problem is that this file was creaetd for Direct3D and not for OpenGL. Since Direct3D uses another coordinate system than OpenGL (the direction of the z axis is different), this matrix (4x4) can not be used for OpenGL.

How can I convert the matrix?

Thanks in advance.


I believe that the matrices in OpenGL are the transposed of the Direct3D matrices. You should note, however, that there are more differences. Direct3D uses left handed coordinate system, OpenGL uses a right handed. This will mean that your model will probably be mirrored in the z direction and that the triangle order (CW or CCW) is reversed wrt Direct3D.

Tom
I know that there are more differences. I have multiplied all z valued in the vertices with -1 and everything works well. My last problem is just that I don't know how to convert the transform matrix. I tried to multiply all elements in the 3rd column with -1 in the meantime and it works relatively well, but it seems that it is not exact.
hi. well, one thing is sure. an opengl matrix is a float [16] array, where you store a 4x4 matrix as follows

the matrix is

m11 m12 m13 m14
m21 m22 m23 m24
m31 m32 m33 m34
m41 m42 m43 m44

and the array is :
m11 m21 m31 m 41 m12 m22 m32 m42 m13 m23 m33 m43 m14 m24 m34 m44

. i think that yes, the matrix is the transpose of the d3d matrix, but i'm not sure(don't use d3d).

but the matrix i've wrote above it is a standard transformation matrix, the same it look in a any book about 3d transformations.
Quote:Original post by dimebolt
I believe that the matrices in OpenGL are the transposed of the Direct3D matrices.

Did you do this?

Quote:Did you do this?


Yes, but this destroyed my mesh completely.
try to rebuild it manually, as i've explained above.
Quote:Original post by meeshoo
try to rebuild it manually, as i've explained above.


Yes, you should read the matrix from the file. Calculate it's transpose. And store the transpose in the 16 float array as pointed out by meeshoo (which probably means that in the end the memory representation of the openGL float[16] and the D3D float[4][4] are identical).

Tom
It does not work if I write the array like you explained above. I must write the first row of the matrix first, than the second row and so on (from the left to the right). If I write the first column at the beginning of the array the model is totally destroyed.
Quote:Original post by ChristophR
It does not work if I write the array like you explained above. I must write the first row of the matrix first, than the second row and so on (from the left to the right). If I write the first column at the beginning of the array the model is totally destroyed.


I'd also not recommend debugging matrix code by looking at the effect of the matrix on the scene, as that usually only shows if it's wrong not what is wrong. Try to test your code by passing a direct3D translation:
1 0 0 0
0 1 0 0
0 0 1 0
1 2 3 1

and check if your code generates the proper corresponding OpenGL array:
1 0 0 0 0 1 0 0 0 0 1 0 1 2 3 1

Tom

This topic is closed to new replies.

Advertisement