Plane.hpp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #ifndef PLANE_H
  2. #define PLANE_H
  3. #include "Vector3.hpp"
  4. #include <cmath>
  5. namespace godot {
  6. enum ClockDirection {
  7. CLOCKWISE,
  8. COUNTERCLOCKWISE
  9. };
  10. class Plane {
  11. public:
  12. Vector3 normal;
  13. real_t d;
  14. void set_normal(const Vector3& p_normal);
  15. inline Vector3 get_normal() const { return normal; } ///Point is coplanar, CMP_EPSILON for precision
  16. void normalize();
  17. Plane normalized() const;
  18. /* Plane-Point operations */
  19. inline Vector3 center() const { return normal*d; }
  20. Vector3 get_any_point() const;
  21. Vector3 get_any_perpendicular_normal() const;
  22. bool is_point_over(const Vector3 &p_point) const; ///< Point is over plane
  23. real_t distance_to(const Vector3 &p_point) const;
  24. bool has_point(const Vector3 &p_point,real_t _epsilon=CMP_EPSILON) const;
  25. /* intersections */
  26. bool intersect_3(const Plane &p_plane1, const Plane &p_plane2, Vector3 *r_result=0) const;
  27. bool intersects_ray(Vector3 p_from, Vector3 p_dir, Vector3* p_intersection) const;
  28. bool intersects_segment(Vector3 p_begin, Vector3 p_end, Vector3* p_intersection) const;
  29. Vector3 project(const Vector3& p_point) const;
  30. /* misc */
  31. inline Plane operator-() const { return Plane(-normal,-d); }
  32. bool is_almost_like(const Plane& p_plane) const;
  33. bool operator==(const Plane& p_plane) const;
  34. bool operator!=(const Plane& p_plane) const;
  35. operator String() const;
  36. inline Plane() { d=0; }
  37. inline Plane(real_t p_a, real_t p_b, real_t p_c, real_t p_d) : normal(p_a,p_b,p_c), d(p_d) { }
  38. Plane(const Vector3 &p_normal, real_t p_d);
  39. Plane(const Vector3 &p_point, const Vector3& p_normal);
  40. Plane(const Vector3 &p_point1, const Vector3 &p_point2,const Vector3 &p_point3,ClockDirection p_dir = CLOCKWISE);
  41. };
  42. }
  43. #endif // PLANE_H