Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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?

share|improve this question
add comment

2 Answers

up vote 3 down vote accepted

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.

share|improve this answer
    
I freakin' love you for this! That is such a big chunk of work gone! –  Asher Einhorn Nov 21 '11 at 21:07
add comment

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 :)

share|improve this answer
1  
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. –  Jimmy Shelter Nov 20 '11 at 12:51
    
@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 –  Ray Dey Nov 20 '11 at 15:45
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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