DistPointOrientedBox.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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/DistPointAlignedBox.h>
  9. #include <Mathematics/OrientedBox.h>
  10. namespace WwiseGTE
  11. {
  12. template <int N, typename Real>
  13. class DCPQuery<Real, Vector<N, Real>, OrientedBox<N, Real>>
  14. :
  15. public DCPQuery<Real, Vector<N, Real>, AlignedBox<N, Real>>
  16. {
  17. public:
  18. struct Result
  19. :
  20. public DCPQuery<Real, Vector<N, Real>, AlignedBox<N, Real>>::Result
  21. {
  22. // No additional information to compute.
  23. };
  24. Result operator()(Vector<N, Real> const& point, OrientedBox<N, Real> const& box)
  25. {
  26. // Translate the point to the coordinate system of the box. In
  27. // this system, the box is axis-aligned with center at the origin.
  28. Vector<N, Real> diff = point - box.center;
  29. Vector<N, Real> closest;
  30. for (int i = 0; i < N; ++i)
  31. {
  32. closest[i] = Dot(diff, box.axis[i]);
  33. }
  34. Result result;
  35. this->DoQuery(closest, box.extent, result);
  36. // Compute the closest point on the box.
  37. result.boxClosest = box.center;
  38. for (int i = 0; i < N; ++i)
  39. {
  40. result.boxClosest += closest[i] * box.axis[i];
  41. }
  42. return result;
  43. }
  44. };
  45. // Template aliases for convenience.
  46. template <int N, typename Real>
  47. using DCPPointOrientedBox = DCPQuery<Real, Vector<N, Real>, AlignedBox<N, Real>>;
  48. template <typename Real>
  49. using DCPPoint2OrientedBox2 = DCPPointOrientedBox<2, Real>;
  50. template <typename Real>
  51. using DCPPoint3OrientedBox3 = DCPPointOrientedBox<3, Real>;
  52. }