I am currently porting a demo from XNA to DirectX which, as I understand it, both have coordinate systems with different handednesses.

What are the things I need to bare in mind when converting between the two? I understand not everything needs to be changed.

Also I notice that many of the 3D maths functions in some of the direct3D libraries have right handed and left handed alternatives. Would it be better to just use these?


Direct3D doesn't actually specify any handedness, so it's no longer correct to say things like "D3D has a left-handed coordinate system". You can in fact use either left-handed or right-handed in D3D; just select either of the -LH or -RH versions for the projection matrix setup functions and that is all that is required.

For example, look in your DirectX SDK for D3DXMatrixPerspectiveFovLH and D3DXMatrixPerspectiveFovRH.

The important thing is that you're consistent in your own code, so that you don't need to switch back and forth between each system. If you're dealing with existing code you should respect it's system and convert as required, but if you're porting from XNA (or from OpenGL for that matter) then just set D3D up to be right-handed too, and be done with it.

  • \$\begingroup\$ I freakin' love you for this! That is such a big chunk of work gone! \$\endgroup\$ Nov 21 '11 at 21:07
  • \$\begingroup\$ After 9 years it’s still so much useful, especially when you read posts where guys say you need to multiply your matrixes, change vertices etc to make your world right-handed \$\endgroup\$ Mar 31 '20 at 10:11
  • \$\begingroup\$ Well, although, I still need to change vertices order from 0,1,2 to 0,2,1 \$\endgroup\$ Mar 31 '20 at 10:29

First of all, I'll refer you to an answer of mine I posted a while back:

Why / how does XNA's right-handed coordinate system effect anything if you can specify near/far Z values?

The only real difference with the change in handedness is what happens on the Z-axis.

XNA is right handed (positive Z moves out of the screen) and DirectX can be left handed (positive Z moves into the screen) or right handed, as pointed out by mh01. Refer to his answer to make use of the right handed functionality of DX.

The easy way of converting vertices etc from one system to the other is just to negate the Z value.

Another difference you might notice is that a positive rotation along the Z axis will be different. Easiest way to figure it out: Make 2 thumbs up and point your thumbs towards you. The direction in which your fingers coil around to make a fist on your left hand is a positive rotation in the left handed coordinate system. Right hand, right-handed coordinate system.

If you've got the functions available to you form DirectX, then by all means use them. Test them out, if they work for you, great; if not, observe what's going wrong and feel free to ask another question :)

  • 1
    \$\begingroup\$ D3D isn't left-handed any more; it can use either (and has had that ability since D3D8, if not earlier). I won't -1 this because it does contain useful information, but that part is fundamentally incorrect. \$\endgroup\$ Nov 20 '11 at 12:51
  • \$\begingroup\$ @mh01 Thanks for the feedback, my apologies. My experience with DX has always been left-handed (most likely due to the number of tutorials that use the same) so I haven't really looked into the right-handed aspects. Guess you learn something every day :) I'll edit to clarify some more. Cheers \$\endgroup\$
    – Ray Dey
    Nov 20 '11 at 15:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.