I've been having trouble understanding why the transformation of the Z coordinate in orthographic projection is the way it is in a right-handed coordinate system.
The "function" for Z using the matrix everyone uses is:
f(z) = -2*z/(far-near) - (far+near)/(far-near)
As far as I know the way orthographic projection works is that it should map the left/right, top/bottom, near/far coordinates to 1/-1.
But if we substitute the near and far coordinates in we get:
f(far) = -2*far/(far-near) - (far+near)/(far-near) = (-3*far - near)/(far - near)
f(near) = -2*near/(far-near) - (far+near)/(far-near) = (-far - 3*near)/(far-near)
Which in most cases won't give back -1 and +1.
Basically my assumption would be that the entire function should be negated (compared to how the X and Y coordinates are computed), but instead the "translation" part stays the same.
The near
and far
values are actually the distances to the corresponding depth clipping planes and are thus positive values. The coordinate frame to consider is (e_x, e_y, e_z)
with e_x
pointing to the right, e_y
pointing upwards and e_z
pointing towards the camera / eye. In this coordinate frame, the z coordinates of the depth clipping planes end up being -near
and -far
which make the math check out as you noticed.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.