IntrHalfspace3OrientedBox3.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. // David Eberly, Geometric Tools, Redmond WA 98052
  2. // Copyright (c) 1998-2020
  3. // Distributed under the Boost Software License, Version 1.0.
  4. // https://www.boost.org/LICENSE_1_0.txt
  5. // https://www.geometrictools.com/License/Boost/LICENSE_1_0.txt
  6. // Version: 4.0.2019.08.13
  7. #pragma once
  8. #include <Mathematics/TIQuery.h>
  9. #include <Mathematics/Halfspace.h>
  10. #include <Mathematics/OrientedBox.h>
  11. // Queries for intersection of objects with halfspaces. These are useful for
  12. // containment testing, object culling, and clipping.
  13. namespace WwiseGTE
  14. {
  15. template <typename Real>
  16. class TIQuery<Real, Halfspace3<Real>, OrientedBox3<Real>>
  17. {
  18. public:
  19. struct Result
  20. {
  21. bool intersect;
  22. };
  23. Result operator()(Halfspace3<Real> const& halfspace, OrientedBox3<Real> const& box)
  24. {
  25. Result result;
  26. // Project the box center onto the normal line. The plane of the
  27. // halfspace occurs at the origin (zero) of the normal line.
  28. Real center = Dot(halfspace.normal, box.center) - halfspace.constant;
  29. // Compute the radius of the interval of projection.
  30. Real radius =
  31. std::fabs(box.extent[0] * Dot(halfspace.normal, box.axis[0])) +
  32. std::fabs(box.extent[1] * Dot(halfspace.normal, box.axis[1])) +
  33. std::fabs(box.extent[2] * Dot(halfspace.normal, box.axis[2]));
  34. // The box and halfspace intersect when the projection interval
  35. // maximum is nonnegative.
  36. result.intersect = (center + radius >= (Real)0);
  37. return result;
  38. }
  39. };
  40. }