g/frustum: simplify aabb intersection test
This commit is contained in:
parent
48e007c545
commit
a4634a771b
@ -47,20 +47,17 @@ namespace util::geom {
|
|||||||
intersects (const frustum<T> &f, const aabb<S,T> &b)
|
intersects (const frustum<T> &f, const aabb<S,T> &b)
|
||||||
{
|
{
|
||||||
for (const auto &p: f.planes) {
|
for (const auto &p: f.planes) {
|
||||||
const auto n = normal (p);
|
// find the distance to the point, if it's positive it's inside
|
||||||
const auto positive = n > 0;
|
// the frustum.
|
||||||
|
const auto d = max (
|
||||||
|
p.coefficients * b.lo.template redim<S+1> (1),
|
||||||
|
p.coefficients * b.hi.template redim<S+1> (1)
|
||||||
|
);
|
||||||
|
|
||||||
const auto lo = select (positive, b.lo, b.hi);
|
if (sum (d) < 0)
|
||||||
const auto hi = select (positive, b.hi, b.lo);
|
return false;
|
||||||
|
|
||||||
if (dot (n, lo) + p.coefficients[S] > 0)
|
|
||||||
return false; // OUTSIDE
|
|
||||||
|
|
||||||
if (dot (n, hi) + p.coefficients[S] >= 0)
|
|
||||||
return true; //INTERSECT
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// INSIDE
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -25,6 +25,7 @@ main ()
|
|||||||
{ { { -1, -1, -1 }, { 1, 1, 1 } }, true, "covers origin with unit radius" },
|
{ { { -1, -1, -1 }, { 1, 1, 1 } }, true, "covers origin with unit radius" },
|
||||||
{ { { -9, -9, -9 }, { -8, -8, -8 } }, false, "out of view negative" },
|
{ { { -9, -9, -9 }, { -8, -8, -8 } }, false, "out of view negative" },
|
||||||
{ { { -1, -1, 2 }, { 1, 1, 3 } }, false, "past far plane" },
|
{ { { -1, -1, 2 }, { 1, 1, 3 } }, false, "past far plane" },
|
||||||
|
{ { { 0, 0, 0 }, { 0, 0, 0 } }, false, "before near plane" },
|
||||||
};
|
};
|
||||||
|
|
||||||
for (const auto &t: TESTS) {
|
for (const auto &t: TESTS) {
|
||||||
|
Loading…
Reference in New Issue
Block a user