IntrRay3OrientedBox3.h 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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/IntrRay3AlignedBox3.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, Ray3<Real>, OrientedBox3<Real>>
  21. :
  22. public TIQuery<Real, Ray3<Real>, AlignedBox3<Real>>
  23. {
  24. public:
  25. struct Result
  26. :
  27. public TIQuery<Real, Ray3<Real>, AlignedBox3<Real>>::Result
  28. {
  29. // No additional information to compute.
  30. };
  31. Result operator()(Ray3<Real> const& ray, OrientedBox3<Real> const& box)
  32. {
  33. // Transform the ray to the oriented-box coordinate system.
  34. Vector3<Real> diff = ray.origin - box.center;
  35. Vector3<Real> rayOrigin
  36. {
  37. Dot(diff, box.axis[0]),
  38. Dot(diff, box.axis[1]),
  39. Dot(diff, box.axis[2])
  40. };
  41. Vector3<Real> rayDirection = Vector3<Real>
  42. {
  43. Dot(ray.direction, box.axis[0]),
  44. Dot(ray.direction, box.axis[1]),
  45. Dot(ray.direction, box.axis[2])
  46. };
  47. Result result;
  48. this->DoQuery(rayOrigin, rayDirection, box.extent, result);
  49. return result;
  50. }
  51. };
  52. template <typename Real>
  53. class FIQuery<Real, Ray3<Real>, OrientedBox3<Real>>
  54. :
  55. public FIQuery<Real, Ray3<Real>, AlignedBox3<Real>>
  56. {
  57. public:
  58. struct Result
  59. :
  60. public FIQuery<Real, Ray3<Real>, AlignedBox3<Real>>::Result
  61. {
  62. // No additional information to compute.
  63. };
  64. Result operator()(Ray3<Real> const& ray, OrientedBox3<Real> const& box)
  65. {
  66. // Transform the ray to the oriented-box coordinate system.
  67. Vector3<Real> diff = ray.origin - box.center;
  68. Vector3<Real> rayOrigin
  69. {
  70. Dot(diff, box.axis[0]),
  71. Dot(diff, box.axis[1]),
  72. Dot(diff, box.axis[2])
  73. };
  74. Vector3<Real> rayDirection = Vector3<Real>
  75. {
  76. Dot(ray.direction, box.axis[0]),
  77. Dot(ray.direction, box.axis[1]),
  78. Dot(ray.direction, box.axis[2])
  79. };
  80. Result result;
  81. this->DoQuery(rayOrigin, rayDirection, box.extent, result);
  82. for (int i = 0; i < result.numPoints; ++i)
  83. {
  84. result.point[i] = ray.origin + result.lineParameter[i] * ray.direction;
  85. }
  86. return result;
  87. }
  88. };
  89. }