AABB.hpp 2.5 KB

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