IntrLine3OrientedBox3.h 3.3 KB

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