IntrSegment3OrientedBox3.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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/IntrSegment3AlignedBox3.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, Segment3<Real>, OrientedBox3<Real>>
  21. :
  22. public TIQuery<Real, Segment3<Real>, AlignedBox3<Real>>
  23. {
  24. public:
  25. struct Result
  26. :
  27. public TIQuery<Real, Segment3<Real>, AlignedBox3<Real>>::Result
  28. {
  29. // No additional information to compute.
  30. };
  31. Result operator()(Segment3<Real> const& segment, OrientedBox3<Real> const& box)
  32. {
  33. // Transform the segment to the oriented-box coordinate system.
  34. Vector3<Real> tmpOrigin, tmpDirection;
  35. Real segExtent;
  36. segment.GetCenteredForm(tmpOrigin, tmpDirection, segExtent);
  37. Vector3<Real> diff = tmpOrigin - box.center;
  38. Vector3<Real> segOrigin
  39. {
  40. Dot(diff, box.axis[0]),
  41. Dot(diff, box.axis[1]),
  42. Dot(diff, box.axis[2])
  43. };
  44. Vector3<Real> segDirection
  45. {
  46. Dot(tmpDirection, box.axis[0]),
  47. Dot(tmpDirection, box.axis[1]),
  48. Dot(tmpDirection, box.axis[2])
  49. };
  50. Result result;
  51. this->DoQuery(segOrigin, segDirection, segExtent, box.extent, result);
  52. return result;
  53. }
  54. };
  55. template <typename Real>
  56. class FIQuery<Real, Segment3<Real>, OrientedBox3<Real>>
  57. :
  58. public FIQuery<Real, Segment3<Real>, AlignedBox3<Real>>
  59. {
  60. public:
  61. struct Result
  62. :
  63. public FIQuery<Real, Segment3<Real>, AlignedBox3<Real>>::Result
  64. {
  65. // No additional relevant information to compute.
  66. };
  67. Result operator()(Segment3<Real> const& segment, OrientedBox3<Real> const& box)
  68. {
  69. // Transform the segment to the oriented-box coordinate system.
  70. Vector3<Real> tmpOrigin, tmpDirection;
  71. Real segExtent;
  72. segment.GetCenteredForm(tmpOrigin, tmpDirection, segExtent);
  73. Vector3<Real> diff = tmpOrigin - box.center;
  74. Vector3<Real> segOrigin
  75. {
  76. Dot(diff, box.axis[0]),
  77. Dot(diff, box.axis[1]),
  78. Dot(diff, box.axis[2])
  79. };
  80. Vector3<Real> segDirection
  81. {
  82. Dot(tmpDirection, box.axis[0]),
  83. Dot(tmpDirection, box.axis[1]),
  84. Dot(tmpDirection, box.axis[2])
  85. };
  86. Result result;
  87. this->DoQuery(segOrigin, segDirection, segExtent, box.extent, result);
  88. for (int i = 0; i < result.numPoints; ++i)
  89. {
  90. // Compute the intersection point in the oriented-box
  91. // coordinate system.
  92. Vector3<Real> y = segOrigin + result.lineParameter[i] * segDirection;
  93. // Transform the intersection point to the original coordinate
  94. // system.
  95. result.point[i] = box.center;
  96. for (int j = 0; j < 3; ++j)
  97. {
  98. result.point[i] += y[j] * box.axis[j];
  99. }
  100. }
  101. return result;
  102. }
  103. };
  104. }