# Why are there different ways of building projection matrices?

Matrix.PerspectiveFovLH documentation page says that this method uses the following formula to build a perspective projection matrix.

``````[w, 0, 0, 0]
[0, h, 0, 0]
[0, 0, zFar/(zFar - zNear), 1]
[0, 0, -zNear * zFar / (zFar - zNear), 0]
``````

where

``````h = cot(fovY / 2)
w = h * aspectRatio
``````

DirectXMath's DirectX::XMMatrixPerspectiveFovLH uses the same formula but with a difference. It calculates w as w = h / aspectRatio therefore creates a different matrix.

There is a difference between orthogonal projection matrix building too.

Why are there such differences or am i missing something?

-
What makes you think that XMMatrixPerspectiveFovLH uses w = h / aspectRatio? That would be exactly opposite of the way aspect ratio is universally defined as w/h, which implies w = h * aspectRatio. And in the docs it explicitly says the aspect ratio is "X:Y" i.e. w/h. – Nathan Reed Mar 2 '14 at 20:44
I stepped in the function call when debugging. The line is `float Width = Height / AspectHByW;`. The code is in file DirectXMathMatrix.inl and can be found under C:\Program Files (x86)\Windows Kits\8.1\Include\um directory at Win8 machines. – frkn Mar 2 '14 at 20:54
Hmm, you're right. The parameter is even called `AspectHByW`, which is in contravention of both what the docs say and the way everyone else in the world defines aspect ratio. WTF. – Nathan Reed Mar 2 '14 at 20:57
To give a conclusion to anybody reading this: `AspectHByW` is incorrectly named, you should pass `W/H` and not `H/W`. Confirmed by the devs here: github.com/Microsoft/DirectXTK/issues/25 – Nicolas Louis Guillemot Apr 5 at 7:58