7
\$\begingroup\$

For example, if I define my perspective matrix as the following:

m[0]  = 1.f / ( aspect * focalLength );
m[5]  = 1.f / focalLength;
m[10] = -zFar / (zFar - zNear);
m[11] = -1;
m[14] = -(zFar*zNear)/(zFar - zNear);

How can I tell if my perspective matrix is right or left handed coordinate system?

\$\endgroup\$
0

1 Answer 1

7
\$\begingroup\$

I think you can tell the difference from whether you have 1 or -1 in the Z line (or column depending on the matrix orientation). In particular:

  • Left handed: 1
  • Right handed: -1

For a comparison, see both of these links - D3DXMatrixPerspectiveLH and D3DXMatrixPerspectiveRH. Since DirectX is left handed, you'd normally use the left handed version which has a 1 in the third row fourth column.

On the other hand, OpenGL and XNA are both right handed and I can confirm that the perspective matrices they generate use -1 instead, although OpenGL has it in the fourth row third column, whereas XNA has it in the third row fourth column like DirectX (column major matrices versus row major matrices).

\$\endgroup\$
3
  • 4
    \$\begingroup\$ It's not actually correct to describe either API as having a specific handedness; the handedness commonly attributed to each is more of a historical convention than anything else these days, and each is perfectly capable of supporting the other handedness if required/desired. Some OpenGL notes: opengl.org/resources/faq/technical/transformations.htm (9.150). \$\endgroup\$ Mar 6, 2012 at 19:46
  • \$\begingroup\$ @mh01 Sure, converting between right handed and left handed coordinate systems can be as easy as applying a (1,1,-1) scale transformation before everything else. But it's wiser to play along with the conventions of each API than having to do the conversion yourself. \$\endgroup\$ Mar 6, 2012 at 19:59
  • 2
    \$\begingroup\$ As for D3D, it explicitly doesn't specify any convention at all and has had both -RH and -LH versions of all of it's projection matrix functions since at least D3D8. Regarding RM vs CM - D3D actually uses CM internally and the matrix must be transposed when sending it to the shader. D3D9 will do that automatically for you; in 10 and 11 you must do it yourself. Agreed though on the count that if you're following sample code it's more likely to use established conventions so it will be clearer if you follow them yourself. \$\endgroup\$ Mar 6, 2012 at 22:34

You must log in to answer this question.

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