geom/frustum: add symbolic constants for plane indices

This commit is contained in:
Danny Robson 2018-05-07 11:09:53 +10:00
parent c33a679e81
commit 92ba5469c4
2 changed files with 37 additions and 24 deletions

View File

@ -24,40 +24,40 @@ template <typename T>
frustum<T>::frustum (const matrix4<T> &transform)
{
// left
planes[0].coefficients[0] = transform[3][0] + transform[0][0];
planes[0].coefficients[1] = transform[3][1] + transform[0][1];
planes[0].coefficients[2] = transform[3][2] + transform[0][2];
planes[0].coefficients[3] = transform[3][3] + transform[0][3];
planes[X_NEG].coefficients[0] = transform[3][0] + transform[0][0];
planes[X_NEG].coefficients[1] = transform[3][1] + transform[0][1];
planes[X_NEG].coefficients[2] = transform[3][2] + transform[0][2];
planes[X_NEG].coefficients[3] = transform[3][3] + transform[0][3];
// Right clipping plane
planes[1].coefficients[0] = transform[3][0] - transform[0][0];
planes[1].coefficients[1] = transform[3][1] - transform[0][1];
planes[1].coefficients[2] = transform[3][2] - transform[0][2];
planes[1].coefficients[3] = transform[3][3] - transform[0][3];
planes[X_POS].coefficients[0] = transform[3][0] - transform[0][0];
planes[X_POS].coefficients[1] = transform[3][1] - transform[0][1];
planes[X_POS].coefficients[2] = transform[3][2] - transform[0][2];
planes[X_POS].coefficients[3] = transform[3][3] - transform[0][3];
// Top clipping plane
planes[2].coefficients[0] = transform[3][0] - transform[1][0];
planes[2].coefficients[1] = transform[3][1] - transform[1][1];
planes[2].coefficients[2] = transform[3][2] - transform[1][2];
planes[2].coefficients[3] = transform[3][3] - transform[1][3];
planes[Y_POS].coefficients[0] = transform[3][0] - transform[1][0];
planes[Y_POS].coefficients[1] = transform[3][1] - transform[1][1];
planes[Y_POS].coefficients[2] = transform[3][2] - transform[1][2];
planes[Y_POS].coefficients[3] = transform[3][3] - transform[1][3];
// Bottom clipping plane
planes[3].coefficients[0] = transform[3][0] + transform[1][0];
planes[3].coefficients[1] = transform[3][1] + transform[1][1];
planes[3].coefficients[2] = transform[3][2] + transform[1][2];
planes[3].coefficients[3] = transform[3][3] + transform[1][3];
planes[Y_NEG].coefficients[0] = transform[3][0] + transform[1][0];
planes[Y_NEG].coefficients[1] = transform[3][1] + transform[1][1];
planes[Y_NEG].coefficients[2] = transform[3][2] + transform[1][2];
planes[Y_NEG].coefficients[3] = transform[3][3] + transform[1][3];
// Near clipping plane
planes[4].coefficients[0] = transform[3][0] + transform[2][0];
planes[4].coefficients[1] = transform[3][1] + transform[2][1];
planes[4].coefficients[2] = transform[3][2] + transform[2][2];
planes[4].coefficients[3] = transform[3][3] + transform[2][3];
planes[Z_POS].coefficients[0] = transform[3][0] + transform[2][0];
planes[Z_POS].coefficients[1] = transform[3][1] + transform[2][1];
planes[Z_POS].coefficients[2] = transform[3][2] + transform[2][2];
planes[Z_POS].coefficients[3] = transform[3][3] + transform[2][3];
// Far clipping plane
planes[5].coefficients[0] = transform[3][0] - transform[2][0];
planes[5].coefficients[1] = transform[3][1] - transform[2][1];
planes[5].coefficients[2] = transform[3][2] - transform[2][2];
planes[5].coefficients[3] = transform[3][3] - transform[2][3];
planes[Z_NEG].coefficients[0] = transform[3][0] - transform[2][0];
planes[Z_NEG].coefficients[1] = transform[3][1] - transform[2][1];
planes[Z_NEG].coefficients[2] = transform[3][2] - transform[2][2];
planes[Z_NEG].coefficients[3] = transform[3][3] - transform[2][3];
for (auto &p: planes)
p = normalised (p);

View File

@ -34,6 +34,19 @@ namespace util::geom {
explicit frustum (const matrix<4,4,ValueT>&);
std::array<plane<3,ValueT>, 6> planes;
enum {
X_NEG, X_POS,
Y_NEG, Y_POS,
Z_NEG, Z_POS,
LEFT = X_NEG,
RIGHT = X_POS,
TOP = Y_POS,
BOTTOM = Y_NEG,
NEAR = Z_POS,
FAR = Z_NEG
};
};
using frustum3f = frustum<float>;