BsPlane.h 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. #pragma once
  2. #include "BsPrerequisitesUtil.h"
  3. #include "BsVector3.h"
  4. namespace BansheeEngine
  5. {
  6. /**
  7. * @brief A plane represented by a normal and a distance.
  8. */
  9. class BS_UTILITY_EXPORT Plane
  10. {
  11. public:
  12. /**
  13. * @brief The "positive side" of the plane is the half space to which the
  14. * plane normal points. The "negative side" is the other half
  15. * space. The flag "no side" indicates the plane itself.
  16. */
  17. enum Side
  18. {
  19. NO_SIDE,
  20. POSITIVE_SIDE,
  21. NEGATIVE_SIDE,
  22. BOTH_SIDE
  23. };
  24. public:
  25. Plane();
  26. Plane(const Plane& copy);
  27. Plane(const Vector3& normal, float d);
  28. Plane(float a, float b, float c, float d);
  29. Plane(const Vector3& normal, const Vector3& point);
  30. Plane(const Vector3& point0, const Vector3& point1, const Vector3& point2);
  31. /**
  32. * @brief Returns the side of the plane where the point is located on.
  33. *
  34. * @note NO_SIDE signifies the point is on the plane.
  35. */
  36. Side getSide(const Vector3& point) const;
  37. /**
  38. * @brief Returns the side where the alignedBox is. The flag BOTH_SIDE indicates an intersecting box.
  39. * One corner ON the plane is sufficient to consider the box and the plane intersecting.
  40. */
  41. Side getSide(const AABox& box) const;
  42. /**
  43. * @brief Returns a distance from point to plane.
  44. *
  45. * @note The sign of the return value is positive if the point is on the
  46. * positive side of the plane, negative if the point is on the negative
  47. * side, and zero if the point is on the plane.
  48. */
  49. float getDistance(const Vector3& point) const;
  50. /**
  51. * @brief Project a vector onto the plane.
  52. */
  53. Vector3 projectVector(const Vector3& v) const;
  54. /**
  55. * @brief Normalizes the plane's normal and the length scale of d
  56. * is as well.
  57. */
  58. float normalize();
  59. /**
  60. * @brief Box/plane intersection.
  61. */
  62. bool intersects(const AABox& box) const;
  63. /**
  64. * @brief Sphere/plane intersection.
  65. */
  66. bool intersects(const Sphere& sphere) const;
  67. /**
  68. * @brief Ray/plane intersection, returns boolean result and distance to intersection point.
  69. */
  70. std::pair<bool, float> intersects(const Ray& ray) const;
  71. bool operator==(const Plane& rhs) const
  72. {
  73. return (rhs.d == d && rhs.normal == normal);
  74. }
  75. bool operator!=(const Plane& rhs) const
  76. {
  77. return (rhs.d != d || rhs.normal != normal);
  78. }
  79. public:
  80. Vector3 normal;
  81. float d;
  82. };
  83. typedef Vector<Plane> PlaneList;
  84. }