3
\$\begingroup\$

I have an application which uses openGL and i have to port it to DirectX. To sum up my issue : How can I port rotation matrix based on a right-handed coordinate system to a left-handed coordinate system ? I hardly found some documentation on the internet.

This is what i found on MSDN:

  • Flip the order of triangle vertices so that the system traverses them clockwise from the front. In other words, if the vertices are v0, v1, v2, pass them to Direct3D as v0, v2, v1.

  • Use the view matrix to scale world space by -1 in the z-direction. To do this, flip the sign of the _31, _32, _33, and _34 member of the D3DMATRIX structure that you use for your view matrix.

This is work fine except i can not flip easily my vertices because i got an 3D model from CATIA which is not a primitive, so i can't use it.

(I'm aware of row-major and column-major difference, it does not matter)

Do you know how i can port my rotation matrix from openGL to DirectX ?

Thanks a lot

\$\endgroup\$
5
  • \$\begingroup\$ If you are using DirectX 10 or higher you can choose to use right-handed \$\endgroup\$
    – Roy T.
    Commented Mar 19, 2013 at 11:45
  • \$\begingroup\$ Thanks but actually i'm using the sotware 3DVIA Studio which use directX, so i can't choose the coordinates-systemes. \$\endgroup\$
    – Pep
    Commented Mar 19, 2013 at 12:22
  • 1
    \$\begingroup\$ "If you are using DirectX 10 or higher you can choose to use right-handed" - the option of using RH has actually been present since at least D3D8. See, e.g. D3DXMatrixPerspectiveFovRH in the D3D8 documentation. \$\endgroup\$ Commented Mar 20, 2013 at 13:00
  • 1
    \$\begingroup\$ Better than simply porting it would be to write a platform independent layer that abstracts your game code from the actual platform specific libraries. This way you never have to change stuff like this, you simply choose which math and rendering back end to use based on something like a pre-processor directive or something. \$\endgroup\$
    – Evan
    Commented Apr 19, 2013 at 14:23
  • \$\begingroup\$ @Evan: there's no need to have different math backends, you really only need to abstract the projection matrix to deal with depth range differences, and a few coordinate differences easily dealt with. Both GL and D3D (when using the programmable pipeline) are neutral to how you do the rest of your math. \$\endgroup\$ Commented Jun 18, 2013 at 17:26

1 Answer 1

1
\$\begingroup\$

I believe, the only difference (besides row/column majorness) is that DirectX uses lefthanded coordinate system and openGL uses righthanded system. You simply need to flip one base vector. Rotation matrix (r) is just a definition of those vectors. So making

r._31 = -r._31;
r._32 = -r._32;
r._33 = -r._33;
r._34 = -r._34;

will just flip the z-coordinates.

The other problem is the triangle ordering (and Front/Back face culling). If you can turn backface-culling off (or switch to frontface-culling), you are OK.

\$\endgroup\$
4
  • \$\begingroup\$ "the only difference (besides row/column majorness) is that DirectX uses lefthanded coordinate system and openGL uses righthanded system" - sorry but that's totally wrong. Neither API is fixed to either LR/RH or RM/CM - you can use either convention with both. See 9.005 here: opengl.org/archives/resources/faq/technical/transformations.htm - "Column-major versus row-major is purely a notational convention...You can use any notation, as long as it's clearly stated". \$\endgroup\$ Commented Mar 20, 2013 at 13:03
  • \$\begingroup\$ oh, OK. That's just about column/row-major - is't it? Of course, it's just a notation problem and all the internal operations of either DX or OGL will perform correctly. You just be aware of that when you need to fill/read this matrices by yourself. Of course right/left handedness can be switched in DX (I suppose OGL can do that as well). But the problem is the default behaviour. I still believe that it's different in DX/OGL. And since Pep is not able to directly interact with DX and change this behaviour, I assumed defaults... Is it still wrong? \$\endgroup\$
    – GPUquant
    Commented Mar 20, 2013 at 13:21
  • \$\begingroup\$ D3D can also do RH matrices and has been able to do so since D3D8 if not earlier; really, it's not an API difference but more a software matrix library difference. There is no longer any "default behaviour" in either API since the GL matrix stack is deprecated and D3D has never had an equivalent. \$\endgroup\$ Commented Mar 20, 2013 at 13:25
  • \$\begingroup\$ Thanks everyone for yours answers. Actually, i just found a way to manage it easily on this website Transformation matrices between OpenGL and Direct3D \$\endgroup\$
    – Pep
    Commented Mar 21, 2013 at 13:44

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .