IntrPlane3Capsule3.h 1.6 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/DistPoint3Plane3.h>
  10. #include <Mathematics/Capsule.h>
  11. namespace WwiseGTE
  12. {
  13. template <typename Real>
  14. class TIQuery<Real, Plane3<Real>, Capsule3<Real>>
  15. {
  16. public:
  17. struct Result
  18. {
  19. bool intersect;
  20. };
  21. Result operator()(Plane3<Real> const& plane, Capsule3<Real> const& capsule)
  22. {
  23. Result result;
  24. DCPQuery<Real, Vector3<Real>, Plane3<Real>> vpQuery;
  25. Real sdistance0 = vpQuery(capsule.segment.p[0], plane).signedDistance;
  26. Real sdistance1 = vpQuery(capsule.segment.p[1], plane).signedDistance;
  27. if (sdistance0 * sdistance1 <= (Real)0)
  28. {
  29. // A capsule segment endpoint is on the plane or the two
  30. // endpoints are on opposite sides of the plane.
  31. result.intersect = true;
  32. return result;
  33. }
  34. // The endpoints on same side of plane, but the endpoint spheres
  35. // might intersect the plane.
  36. result.intersect =
  37. std::fabs(sdistance0) <= capsule.radius ||
  38. std::fabs(sdistance1) <= capsule.radius;
  39. return result;
  40. }
  41. };
  42. }