Plane.hpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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) :
  38. normal(p_a, p_b, p_c),
  39. d(p_d) {}
  40. Plane(const Vector3 &p_normal, real_t p_d);
  41. Plane(const Vector3 &p_point, const Vector3 &p_normal);
  42. Plane(const Vector3 &p_point1, const Vector3 &p_point2, const Vector3 &p_point3, ClockDirection p_dir = CLOCKWISE);
  43. };
  44. } // namespace godot
  45. #endif // PLANE_H