# How do I know if a perspective matrix is right or left handed coordinate system?

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?

-

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

-
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). – 21st Century Moose Mar 6 '12 at 19:46
@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. – David Gouveia Mar 6 '12 at 19:59
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. – 21st Century Moose Mar 6 '12 at 22:34