IntrOrientedBox3Cylinder3.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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/IntrAlignedBox3Cylinder3.h>
  9. #include <Mathematics/OrientedBox.h>
  10. // The query considers the cylinder and box to be solids.
  11. namespace WwiseGTE
  12. {
  13. template <typename Real>
  14. class TIQuery<Real, OrientedBox3<Real>, Cylinder3<Real>>
  15. {
  16. public:
  17. struct Result
  18. {
  19. bool intersect;
  20. };
  21. Result operator()(OrientedBox3<Real> const& box, Cylinder3<Real> const& cylinder)
  22. {
  23. // Transform the box and cylinder so that the box is axis-aligned.
  24. AlignedBox3<Real> aabb(-box.extent, box.extent);
  25. Vector3<Real> diff = cylinder.axis.origin - box.center;
  26. Cylinder3<Real> transformedCylinder;
  27. transformedCylinder.radius = cylinder.radius;
  28. transformedCylinder.height = cylinder.height;
  29. for (int i = 0; i < 3; ++i)
  30. {
  31. transformedCylinder.axis.origin[i] = Dot(box.axis[i], diff);
  32. transformedCylinder.axis.direction[i] = Dot(box.axis[i], cylinder.axis.direction);
  33. }
  34. TIQuery<Real, AlignedBox3<Real>, Cylinder3<Real>> aabbCylinderQuery;
  35. auto aabbCylinderResult = aabbCylinderQuery(aabb, transformedCylinder);
  36. Result result;
  37. result.intersect = aabbCylinderResult.intersect;
  38. return result;
  39. }
  40. };
  41. }