For frustum-culling purposes, I need to modify the left/right/top/bottom planes to encapsulate a smaller volume.
Existing structs are simply:
struct Frustum{
vec4 planes[6];
void ConstructFromMatrix(const mat4& ViewProjection);
};
The required function/method is:
void Frustum::ShrinkToRect(int x=77,int y=93, int width=128,int height=64, int ScreenWidth=1280,int ScreenHeight=720);
Sanity check: if the func is called with the following args, there is no change in the frustum data:
ShrinkToRect(0,0,1280,720, 1280,720);
My model/view/projection spaces are all with +Z pointing forward (not back). (left hand coords) +Y points up, +X points to the right. The screenspace coords are +X to right, +Y to up.
I attempted approaching the problem in several ways, but failed - possibly some of my maths was buggy. One of the approaches was:
- project a quad on the near-plane, vertices at the specified x/y/x+width/y+height positions when projected by the ViewProjection matrix.
- another quad on the far-plane, same calcs.
- construct the 6 planes out of the 8 resulting vertices
All the matrices and their creation args are available (I’m not dealing with external code), and optimizations aren’t necessary.
Any help is appreciated.