DistRay3OrientedBox3.h 1.9 KB

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