Commit 17b9694b authored by Aaron Grabowy's avatar Aaron Grabowy
Browse files

Added intersects aabb for plane and halfspace

parent d9ffba38
......@@ -1185,6 +1185,26 @@ template <class ScalarT>
return intersects(inf_of(s), b);
}
template <int D, class ScalarT>
[[nodiscard]] constexpr bool intersects(plane<D, ScalarT> const& p, aabb<D, ScalarT> const& b)
{
auto const c = centroid_of(b);
auto const shadow = dot(b.max - c, abs(p.normal));
return shadow >= distance(c, p); // Note: no square needed, since no sqrt involved
}
template <int D, class ScalarT>
[[nodiscard]] constexpr bool intersects(halfspace<D, ScalarT> const& h, aabb<D, ScalarT> const& b)
{
auto const c = centroid_of(b);
auto const dist = signed_distance(c, h);
if (dist <= ScalarT(0))
return true;
auto const shadow = dot(b.max - c, abs(h.normal));
return shadow >= dist;
}
template <int D, class ScalarT>
[[nodiscard]] constexpr bool intersects(sphere<D, ScalarT> const& a, aabb<D, ScalarT> const& b)
{
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment