DistLine3OrientedBox3.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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/Line.h>
  10. #include <Mathematics/OrientedBox.h>
  11. namespace WwiseGTE
  12. {
  13. template <typename Real>
  14. class DCPQuery<Real, Line3<Real>, OrientedBox3<Real>>
  15. :
  16. public DCPQuery<Real, Line3<Real>, AlignedBox3<Real>>
  17. {
  18. public:
  19. struct Result
  20. :
  21. public DCPQuery<Real, Line3<Real>, AlignedBox3<Real>>::Result
  22. {
  23. // No additional information to compute.
  24. };
  25. Result operator()(Line3<Real> const& line, OrientedBox3<Real> const& box)
  26. {
  27. // Transform the line to the coordinate system of the oriented
  28. // box. In this system, the box is axis-aligned with center at
  29. // the origin.
  30. Vector3<Real> diff = line.origin - box.center;
  31. Vector3<Real> point, direction;
  32. for (int i = 0; i < 3; ++i)
  33. {
  34. point[i] = Dot(diff, box.axis[i]);
  35. direction[i] = Dot(line.direction, box.axis[i]);
  36. }
  37. Result result;
  38. this->DoQuery(point, direction, box.extent, result);
  39. // Compute the closest point on the line.
  40. result.closestPoint[0] = line.origin + result.lineParameter * line.direction;
  41. // Compute the closest point on the box.
  42. result.closestPoint[1] = box.center;
  43. for (int i = 0; i < 3; ++i)
  44. {
  45. result.closestPoint[1] += point[i] * box.axis[i];
  46. }
  47. return result;
  48. }
  49. };
  50. }