The matrix generated by glm::perspective always has the form
Sx 0 0 0
0 Sy 0 0
0 0 C D
0 0 -1 0
where Sx=cot(fov/2)/aspect and Sy=cot(fov/2); C and D are determined from the near and far distances and don’t affect this calculation. Rather than calculating Sx and Sy, you should read them from the matrix generated by glm::perspective.
So you have:
xclip = Sx*xeye
yclip = Sy*yeye
wclip = -zeye
The edges of the view frustum are defined by the equations
xclip = -wclip (left)
xclip = wclip (right)
yclip = -wclip (bottom)
yclip = wclip (top)
In eye space, these become
Sx*xeye = zeye => xeye = zeye/Sx (left)
Sx*xeye = -zeye => xeye = -zeye/Sx (right)
Sy*yeye = zeye => yeye = zeye/Sy (bottom)
Sy*yeye = -zeye => yeye = -zeye/Sy (top)
IOW, just divide ±zeye by Sx and Sy to get the left/right/top/bottom edges in eye space. Note that zeye is negative for points in front of the viewer, i.e. -zfar < zeye < -znear.
Partager