Rect3.hpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. #ifndef RECT3_H
  2. #define RECT3_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 "Plane.hpp"
  14. #include <cstdlib>
  15. namespace godot {
  16. class GD_CPP_CORE_API Rect3 {
  17. public:
  18. Vector3 pos;
  19. Vector3 size;
  20. real_t get_area() const; /// get area
  21. inline bool has_no_area() const {
  22. return (size.x<=CMP_EPSILON || size.y<=CMP_EPSILON || size.z<=CMP_EPSILON);
  23. }
  24. inline bool has_no_surface() const {
  25. return (size.x<=CMP_EPSILON && size.y<=CMP_EPSILON && size.z<=CMP_EPSILON);
  26. }
  27. inline const Vector3& get_pos() const { return pos; }
  28. inline void set_pos(const Vector3& p_pos) { pos=p_pos; }
  29. inline const Vector3& get_size() const { return size; }
  30. inline void set_size(const Vector3& p_size) { size=p_size; }
  31. bool operator==(const Rect3& p_rval) const;
  32. bool operator!=(const Rect3& p_rval) const;
  33. bool intersects(const Rect3& p_aabb) const; /// Both AABBs overlap
  34. bool intersects_inclusive(const Rect3& p_aabb) const; /// Both AABBs (or their faces) overlap
  35. bool encloses(const Rect3 & p_aabb) const; /// p_aabb is completely inside this
  36. Rect3 merge(const Rect3& p_with) const;
  37. void merge_with(const Rect3& p_aabb); ///merge with another AABB
  38. Rect3 intersection(const Rect3& p_aabb) const; ///get box where two intersect, empty if no intersection occurs
  39. bool intersects_segment(const Vector3& p_from, const Vector3& p_to,Vector3* r_clip=NULL,Vector3* r_normal=NULL) const;
  40. bool intersects_ray(const Vector3& p_from, const Vector3& p_dir,Vector3* r_clip=NULL,Vector3* r_normal=NULL) const;
  41. bool smits_intersect_ray(const Vector3 &from,const Vector3& p_dir, real_t t0, real_t t1) const;
  42. bool intersects_convex_shape(const Plane *p_plane, int p_plane_count) const;
  43. bool intersects_plane(const Plane &p_plane) const;
  44. bool has_point(const Vector3& p_point) const;
  45. Vector3 get_support(const Vector3& p_normal) const;
  46. Vector3 get_longest_axis() const;
  47. int get_longest_axis_index() const;
  48. real_t get_longest_axis_size() const;
  49. Vector3 get_shortest_axis() const;
  50. int get_shortest_axis_index() const;
  51. real_t get_shortest_axis_size() const;
  52. Rect3 grow(real_t p_by) const;
  53. void grow_by(real_t p_amount);
  54. void get_edge(int p_edge,Vector3& r_from,Vector3& r_to) const;
  55. Vector3 get_endpoint(int p_point) const;
  56. Rect3 expand(const Vector3& p_vector) const;
  57. void project_range_in_plane(const Plane& p_plane,real_t &r_min,real_t& r_max) const;
  58. void expand_to(const Vector3& p_vector); /** expand to contain a point if necesary */
  59. operator String() const;
  60. inline Rect3() {}
  61. inline Rect3(const Vector3 &p_pos,const Vector3& p_size) { pos=p_pos; size=p_size; }
  62. };
  63. }
  64. #endif // RECT3_H