IntrHalfspace3Capsule3.h 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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/Capsule.h>
  10. #include <Mathematics/Halfspace.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>, Capsule3<Real>>
  17. {
  18. public:
  19. struct Result
  20. {
  21. bool intersect;
  22. };
  23. Result operator()(Halfspace3<Real> const& halfspace, Capsule3<Real> const& capsule)
  24. {
  25. Result result;
  26. // Project the capsule onto the normal line. The plane of the
  27. // halfspace occurs at the origin (zero) of the normal line.
  28. Real e0 = Dot(halfspace.normal, capsule.segment.p[0]) - halfspace.constant;
  29. Real e1 = Dot(halfspace.normal, capsule.segment.p[1]) - halfspace.constant;
  30. // The capsule and halfspace intersect when the projection
  31. // interval maximum is nonnegative.
  32. result.intersect = (std::max(e0, e1) + capsule.radius >= (Real)0);
  33. return result;
  34. }
  35. };
  36. }