Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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]


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?

share|improve this question
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: – Nicolas Louis Guillemot Apr 5 at 7:58
up vote 3 down vote accepted

Simply because there are many ways to compute the projection of objects in a 3D scene onto a 2D plane. That's why you have perspective versus orthographic projections (and various flavors thereof, such as off-center projections), and that's why you can use slightly different formulae to compute the projection transformation.

Sometimes the differences are semantic in nature (such as in the case of perspective versus orthographic). Sometimes they are purely conventional in nature. Sometimes they are due to known quantities or characteristics of the inputs the system.

It's sort of similar to how you can represent your vectors as 4x1 or 1x4 matrices, and that consequently has a impact on whether you multiply your vectors on the right or the left of your transformation matrices.

share|improve this answer
Hmm, i see. So both are correct and used for creating different projections. But i don't understand why would anyone want to use w = h * aspectRatio one. Because when i render a square it gets stretched horizontally and looks like a rectangle therefore unrealistic. – frkn Mar 2 '14 at 20:04
Perhaps that method expects a different computation for aspect ratio. – Josh Petrie Mar 2 '14 at 20:11
yes, you are right! i tried 1:1 aspect ratio and it looked as expected. thank you. – frkn Mar 2 '14 at 20:29

Your Answer


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.