math3d
MitIoanAdrian opened this issue · 1 comments
The implementation for InitPersProjTransform currently includes:
m[0][0] = 1/tanHalfFOV and m[1][1] = 1.0f/(tanHalfFOV*ar);
Shouldn't m[0][0] be (1/tanHalfFOV) * ar and m[1][1] be 1.0f/tanHalfFOV?
Let's understand this using a simple example: if the horizontal field of view is 90 degrees the focal length is 1 (tangent of 45). So 1/tanHalfFOV is 1. This means that we just need to divide X by its Z in order to project it: (1,y,1) is projected to (1,y,1), (2,y,2) is projected to (1,y,1) and etc. What happens with Y? Let's say that the width of the window is 2000 and the height is 1000. We say that the aspect ratio here is 0.5 and this is important that we calculate it this way and not the other way around because the calculation depend on it. What we want in this case is for (1,0.5,1) to be projected to (1,1,1) because we have half the range on the Y compared to X but they are both projected to a NDC range of [-1,1]. So we divide 0.5 by the aspect ratio which means that we multiply by 2. This will take the Y range of [-0.5,0.5] and expand it to [-1,1] in NDC. So the image is distorted in NDC but viewport transformation back to 2000x1000 will fix it. If Y=0.51 it will be projected to 1.02 which is outside the range and this is what we need. Do you agree?