BsConvexVolume.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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/BsPlane.h"
  6. namespace bs
  7. {
  8. /** @addtogroup Math
  9. * @{
  10. */
  11. /** Clip planes that form the camera frustum (visible area). */
  12. enum FrustumPlane
  13. {
  14. FRUSTUM_PLANE_NEAR = 0,
  15. FRUSTUM_PLANE_FAR = 1,
  16. FRUSTUM_PLANE_LEFT = 2,
  17. FRUSTUM_PLANE_RIGHT = 3,
  18. FRUSTUM_PLANE_TOP = 4,
  19. FRUSTUM_PLANE_BOTTOM = 5
  20. };
  21. /** Represents a convex volume defined by planes representing the volume border. */
  22. class BS_UTILITY_EXPORT ConvexVolume
  23. {
  24. public:
  25. ConvexVolume() {}
  26. ConvexVolume(const Vector<Plane>& planes);
  27. /** Creates frustum planes from the provided projection matrix. */
  28. ConvexVolume(const Matrix4& projectionMatrix, bool useNearPlane = true);
  29. /**
  30. * Checks does the volume intersects the provided axis aligned box.
  31. * This will return true if the box is fully inside the volume.
  32. */
  33. bool intersects(const AABox& box) const;
  34. /**
  35. * Checks does the volume intersects the provided sphere.
  36. * This will return true if the sphere is fully inside the volume.
  37. */
  38. bool intersects(const Sphere& sphere) const;
  39. /**
  40. * Checks if the convex volume contains the provided point.
  41. *
  42. * @param[in] p Point to check.
  43. * @param[in] expand Optional value to expand the size of the convex volume by the specified value during the
  44. * check. Negative values shrink the volume.
  45. */
  46. bool contains(const Vector3& p, float expand = 0.0f) const;
  47. /** Returns the internal set of planes that represent the volume. */
  48. Vector<Plane> getPlanes() const { return mPlanes; }
  49. private:
  50. Vector<Plane> mPlanes;
  51. };
  52. /** @} */
  53. }