geom/frustum: add symbolic constants for plane indices
This commit is contained in:
parent
c33a679e81
commit
92ba5469c4
@ -24,40 +24,40 @@ template <typename T>
|
|||||||
frustum<T>::frustum (const matrix4<T> &transform)
|
frustum<T>::frustum (const matrix4<T> &transform)
|
||||||
{
|
{
|
||||||
// left
|
// left
|
||||||
planes[0].coefficients[0] = transform[3][0] + transform[0][0];
|
planes[X_NEG].coefficients[0] = transform[3][0] + transform[0][0];
|
||||||
planes[0].coefficients[1] = transform[3][1] + transform[0][1];
|
planes[X_NEG].coefficients[1] = transform[3][1] + transform[0][1];
|
||||||
planes[0].coefficients[2] = transform[3][2] + transform[0][2];
|
planes[X_NEG].coefficients[2] = transform[3][2] + transform[0][2];
|
||||||
planes[0].coefficients[3] = transform[3][3] + transform[0][3];
|
planes[X_NEG].coefficients[3] = transform[3][3] + transform[0][3];
|
||||||
|
|
||||||
// Right clipping plane
|
// Right clipping plane
|
||||||
planes[1].coefficients[0] = transform[3][0] - transform[0][0];
|
planes[X_POS].coefficients[0] = transform[3][0] - transform[0][0];
|
||||||
planes[1].coefficients[1] = transform[3][1] - transform[0][1];
|
planes[X_POS].coefficients[1] = transform[3][1] - transform[0][1];
|
||||||
planes[1].coefficients[2] = transform[3][2] - transform[0][2];
|
planes[X_POS].coefficients[2] = transform[3][2] - transform[0][2];
|
||||||
planes[1].coefficients[3] = transform[3][3] - transform[0][3];
|
planes[X_POS].coefficients[3] = transform[3][3] - transform[0][3];
|
||||||
|
|
||||||
// Top clipping plane
|
// Top clipping plane
|
||||||
planes[2].coefficients[0] = transform[3][0] - transform[1][0];
|
planes[Y_POS].coefficients[0] = transform[3][0] - transform[1][0];
|
||||||
planes[2].coefficients[1] = transform[3][1] - transform[1][1];
|
planes[Y_POS].coefficients[1] = transform[3][1] - transform[1][1];
|
||||||
planes[2].coefficients[2] = transform[3][2] - transform[1][2];
|
planes[Y_POS].coefficients[2] = transform[3][2] - transform[1][2];
|
||||||
planes[2].coefficients[3] = transform[3][3] - transform[1][3];
|
planes[Y_POS].coefficients[3] = transform[3][3] - transform[1][3];
|
||||||
|
|
||||||
// Bottom clipping plane
|
// Bottom clipping plane
|
||||||
planes[3].coefficients[0] = transform[3][0] + transform[1][0];
|
planes[Y_NEG].coefficients[0] = transform[3][0] + transform[1][0];
|
||||||
planes[3].coefficients[1] = transform[3][1] + transform[1][1];
|
planes[Y_NEG].coefficients[1] = transform[3][1] + transform[1][1];
|
||||||
planes[3].coefficients[2] = transform[3][2] + transform[1][2];
|
planes[Y_NEG].coefficients[2] = transform[3][2] + transform[1][2];
|
||||||
planes[3].coefficients[3] = transform[3][3] + transform[1][3];
|
planes[Y_NEG].coefficients[3] = transform[3][3] + transform[1][3];
|
||||||
|
|
||||||
// Near clipping plane
|
// Near clipping plane
|
||||||
planes[4].coefficients[0] = transform[3][0] + transform[2][0];
|
planes[Z_POS].coefficients[0] = transform[3][0] + transform[2][0];
|
||||||
planes[4].coefficients[1] = transform[3][1] + transform[2][1];
|
planes[Z_POS].coefficients[1] = transform[3][1] + transform[2][1];
|
||||||
planes[4].coefficients[2] = transform[3][2] + transform[2][2];
|
planes[Z_POS].coefficients[2] = transform[3][2] + transform[2][2];
|
||||||
planes[4].coefficients[3] = transform[3][3] + transform[2][3];
|
planes[Z_POS].coefficients[3] = transform[3][3] + transform[2][3];
|
||||||
|
|
||||||
// Far clipping plane
|
// Far clipping plane
|
||||||
planes[5].coefficients[0] = transform[3][0] - transform[2][0];
|
planes[Z_NEG].coefficients[0] = transform[3][0] - transform[2][0];
|
||||||
planes[5].coefficients[1] = transform[3][1] - transform[2][1];
|
planes[Z_NEG].coefficients[1] = transform[3][1] - transform[2][1];
|
||||||
planes[5].coefficients[2] = transform[3][2] - transform[2][2];
|
planes[Z_NEG].coefficients[2] = transform[3][2] - transform[2][2];
|
||||||
planes[5].coefficients[3] = transform[3][3] - transform[2][3];
|
planes[Z_NEG].coefficients[3] = transform[3][3] - transform[2][3];
|
||||||
|
|
||||||
for (auto &p: planes)
|
for (auto &p: planes)
|
||||||
p = normalised (p);
|
p = normalised (p);
|
||||||
|
@ -34,6 +34,19 @@ namespace util::geom {
|
|||||||
explicit frustum (const matrix<4,4,ValueT>&);
|
explicit frustum (const matrix<4,4,ValueT>&);
|
||||||
|
|
||||||
std::array<plane<3,ValueT>, 6> planes;
|
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>;
|
using frustum3f = frustum<float>;
|
||||||
|
Loading…
Reference in New Issue
Block a user