BsBounds.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #pragma once
  4. #include "Prerequisites/BsPrerequisitesUtil.h"
  5. #include "Math/BsVector3.h"
  6. #include "Math/BsAABox.h"
  7. #include "Math/BsSphere.h"
  8. #include "Math/BsMatrix4.h"
  9. namespace bs
  10. {
  11. /** @addtogroup Math
  12. * @{
  13. */
  14. /** Bounds represented by an axis aligned box and a sphere. */
  15. class BS_UTILITY_EXPORT Bounds
  16. {
  17. public:
  18. Bounds();
  19. Bounds(const AABox& box, const Sphere& sphere);
  20. ~Bounds() { }
  21. /** Returns the axis aligned box representing the bounds. */
  22. const AABox& getBox() const { return mBox; }
  23. /** Returns the sphere representing the bounds. */
  24. const Sphere& getSphere() const { return mSphere; }
  25. /** Updates the bounds by setting the new bounding box and sphere. */
  26. void setBounds(const AABox& box, const Sphere& sphere);
  27. /** Merges the two bounds, creating a new bounds that encapsulates them both. */
  28. void merge(const Bounds& rhs);
  29. /** Expands the bounds so it includes the provided point. */
  30. void merge(const Vector3& point);
  31. /**
  32. * Transforms the bounds by the given matrix.
  33. *
  34. * @note
  35. * As the resulting box will no longer be axis aligned, an axis align box
  36. * is instead created by encompassing the transformed oriented bounding box.
  37. * Retrieving the value as an actual OBB would provide a tighter fit.
  38. */
  39. void transform(const Matrix4& matrix);
  40. /**
  41. * Transforms the bounds by the given matrix.
  42. *
  43. * @note
  44. * As the resulting box will no longer be axis aligned, an axis align box
  45. * is instead created by encompassing the transformed oriented bounding box.
  46. * Retrieving the value as an actual OBB would provide a tighter fit.
  47. *
  48. * @note
  49. * Provided matrix must be affine.
  50. */
  51. void transformAffine(const Matrix4& matrix);
  52. protected:
  53. AABox mBox;
  54. Sphere mSphere;
  55. };
  56. /** @} */
  57. }