It depends a little how you construct the matrix. I assume that you use the function perspective_matrix
from your library, which actually works pretty much like good old gluPerspective
). But what this actually does is nothing else than use the more general function frustum_matrix
, which in turn creates a common arbitrary view frustum matrix, like good old glFrustum
did (from the (simplified) linalg source code):
mat4 perspective_matrix(T fovy, T aspect, T n, T f)
{
T y = n*std::tan(fovy / 2), x = y*aspect;
return frustum_matrix(-x, x, -y, y, n, f);
}
And this general frustum matrix function is actually all you need for creating arbitrary assymmetrical frustum matrices, like the ones you want. The paramters it takes are exactly the left, right, bottom, and top boundaries of the near plane, i.e. the x and y boundaries of the frustum on the z = near
(or -near
) plane. So all you actually need to do is take these left/right/bottom/top parameters and cut those ranges into whatever sub-intervals you need.
It depends a little on what information you actually have. If you have the parameters you construct your perspective matrix from (i.e. the fovY
and the aspect
) you can just replace the above procedure with something more elaborate that computes the frustum parameters from these two and then scale-biases them into the corresponding intervals.
If all you have is an already constructed perspective matrix, you might have to retrieve the parameters from that matrix first, which shouldn't be too difficult when looking at how the matrix is constructed. If you already have a general assymmetric frustum matrix, it might get a little more elaborate. But it always really all just comes down to tweaking the $M_{11}, M_{13}, M_{22}, M_{23}$ elements of the matrix a little with some scaling and offseting that I'm sure you can figure out when looking at how these matrices are constructed. The rest can stay as they are (provided you don't need chunking in the z-direction either, which would be used for different techniques than what you are trying to do).
.lib
camera manipulator to emulate camera modes like nvidia ansel or other ingame implementations, but open source, generic and without dev support. I'd guess games don't use physical models to render scenes, so I'd think this isthe camera view in a rendering setting
, I'm modding binaries so I don't know precisely what I'm altering. $\endgroup$