Plane.hpp 1.9 KB

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