IntrLine2OrientedBox2.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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/IntrLine2AlignedBox2.h>
  9. #include <Mathematics/OrientedBox.h>
  10. // The queries consider the box to be a solid.
  11. //
  12. // The test-intersection queries use the method of separating axes.
  13. // https://www.geometrictools.com/Documentation/MethodOfSeparatingAxes.pdf
  14. // The find-intersection queries use parametric clipping against the four
  15. // edges of the box.
  16. namespace WwiseGTE
  17. {
  18. template <typename Real>
  19. class TIQuery<Real, Line2<Real>, OrientedBox2<Real>>
  20. :
  21. public TIQuery<Real, Line2<Real>, AlignedBox2<Real>>
  22. {
  23. public:
  24. struct Result
  25. :
  26. public TIQuery<Real, Line2<Real>, AlignedBox2<Real>>::Result
  27. {
  28. // No additional relevant information to compute.
  29. };
  30. Result operator()(Line2<Real> const& line, OrientedBox2<Real> const& box)
  31. {
  32. // Transform the line to the oriented-box coordinate system.
  33. Vector2<Real> diff = line.origin - box.center;
  34. Vector2<Real> lineOrigin
  35. {
  36. Dot(diff, box.axis[0]),
  37. Dot(diff, box.axis[1])
  38. };
  39. Vector2<Real> lineDirection
  40. {
  41. Dot(line.direction, box.axis[0]),
  42. Dot(line.direction, box.axis[1])
  43. };
  44. Result result;
  45. this->DoQuery(lineOrigin, lineDirection, box.extent, result);
  46. return result;
  47. }
  48. };
  49. template <typename Real>
  50. class FIQuery<Real, Line2<Real>, OrientedBox2<Real>>
  51. :
  52. public FIQuery<Real, Line2<Real>, AlignedBox2<Real>>
  53. {
  54. public:
  55. struct Result
  56. :
  57. public FIQuery<Real, Line2<Real>, AlignedBox2<Real>>::Result
  58. {
  59. // No additional relevant information to compute.
  60. };
  61. Result operator()(Line2<Real> const& line, OrientedBox2<Real> const& box)
  62. {
  63. // Transform the line to the oriented-box coordinate system.
  64. Vector2<Real> diff = line.origin - box.center;
  65. Vector2<Real> lineOrigin
  66. {
  67. Dot(diff, box.axis[0]),
  68. Dot(diff, box.axis[1])
  69. };
  70. Vector2<Real> lineDirection
  71. {
  72. Dot(line.direction, box.axis[0]),
  73. Dot(line.direction, box.axis[1])
  74. };
  75. Result result;
  76. this->DoQuery(lineOrigin, lineDirection, box.extent, result);
  77. for (int i = 0; i < result.numIntersections; ++i)
  78. {
  79. result.point[i] = line.origin + result.parameter[i] * line.direction;
  80. }
  81. return result;
  82. }
  83. };
  84. }