OrientedBox.h 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. // SPDX-FileCopyrightText: 2021 Jorrit Rouwe
  2. // SPDX-License-Identifier: MIT
  3. #pragma once
  4. #include <Geometry/Triangle.h>
  5. #include <Geometry/IndexedTriangle.h>
  6. #include <Geometry/AABox.h>
  7. #include <Math/Mat44.h>
  8. namespace JPH {
  9. class AABox;
  10. /// Oriented box
  11. class [[nodiscard]] OrientedBox
  12. {
  13. public:
  14. /// Constructor
  15. OrientedBox() = default;
  16. OrientedBox(Mat44Arg inOrientation, Vec3Arg inHalfExtents) : mOrientation(inOrientation), mHalfExtents(inHalfExtents) { }
  17. /// Construct from axis aligned box and transform. Only works for rotation/translation matrix (no scaling / shearing).
  18. OrientedBox(Mat44Arg inOrientation, const AABox &inBox) : OrientedBox(inOrientation * Mat44::sTranslation(inBox.GetCenter()), inBox.GetExtent()) { }
  19. /// Test if oriented boxe overlaps with axis aligned box eachother
  20. bool Overlaps(const AABox &inBox, float inEpsilon = 1.0e-6f) const;
  21. /// Test if two oriented boxes overlap eachother
  22. bool Overlaps(const OrientedBox &inBox, float inEpsilon = 1.0e-6f) const;
  23. Mat44 mOrientation; ///< Transform that positions and rotates the local space axis aligned box into world space
  24. Vec3 mHalfExtents; ///< Half extents (half the size of the edge) of the local space axis aligned box
  25. };
  26. } // JPH