DistRay3AlignedBox3.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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/DistLine3AlignedBox3.h>
  9. #include <Mathematics/Ray.h>
  10. namespace WwiseGTE
  11. {
  12. template <typename Real>
  13. class DCPQuery<Real, Ray3<Real>, AlignedBox3<Real>>
  14. {
  15. public:
  16. struct Result
  17. {
  18. Real distance, sqrDistance;
  19. Real rayParameter;
  20. Vector3<Real> closestPoint[2];
  21. };
  22. Result operator()(Ray3<Real> const& ray, AlignedBox3<Real> const& box)
  23. {
  24. Result result;
  25. Line3<Real> line(ray.origin, ray.direction);
  26. DCPQuery<Real, Line3<Real>, AlignedBox3<Real>> lbQuery;
  27. auto lbResult = lbQuery(line, box);
  28. if (lbResult.lineParameter >= (Real)0)
  29. {
  30. result.sqrDistance = lbResult.sqrDistance;
  31. result.distance = lbResult.distance;
  32. result.rayParameter = lbResult.lineParameter;
  33. result.closestPoint[0] = lbResult.closestPoint[0];
  34. result.closestPoint[1] = lbResult.closestPoint[1];
  35. }
  36. else
  37. {
  38. DCPQuery<Real, Vector3<Real>, AlignedBox3<Real>> pbQuery;
  39. auto pbResult = pbQuery(ray.origin, box);
  40. result.sqrDistance = pbResult.sqrDistance;
  41. result.distance = pbResult.distance;
  42. result.rayParameter = (Real)0;
  43. result.closestPoint[0] = ray.origin;
  44. result.closestPoint[1] = pbResult.boxClosest;
  45. }
  46. return result;
  47. }
  48. };
  49. }