diff options
author | RĂ©mi Verschelde <rverschelde@gmail.com> | 2018-06-13 18:49:35 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-06-13 18:49:35 +0200 |
commit | 8efbe9ed3dc51e89d032cc2464cfe96fa9e4ea78 (patch) | |
tree | eefcc77509fe5e5167207b5ea7e95d9045147b62 /core/math/aabb.h | |
parent | 1651dbb54df30dd189658b9cf9cd84f650be6bdc (diff) | |
parent | 9cd1c20f6aae87e34b45471271062127d385871e (diff) |
Merge pull request #19487 from JFonS/better_3d_select
Improve 3D selection
Diffstat (limited to 'core/math/aabb.h')
-rw-r--r-- | core/math/aabb.h | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/core/math/aabb.h b/core/math/aabb.h index 39b8f403e7..cdb8eb48a3 100644 --- a/core/math/aabb.h +++ b/core/math/aabb.h @@ -76,6 +76,7 @@ public: _FORCE_INLINE_ bool smits_intersect_ray(const Vector3 &p_from, const Vector3 &p_dir, real_t t0, real_t t1) const; _FORCE_INLINE_ bool intersects_convex_shape(const Plane *p_planes, int p_plane_count) const; + _FORCE_INLINE_ bool inside_convex_shape(const Plane *p_planes, int p_plane_count) const; bool intersects_plane(const Plane &p_plane) const; _FORCE_INLINE_ bool has_point(const Vector3 &p_point) const; @@ -207,6 +208,25 @@ bool AABB::intersects_convex_shape(const Plane *p_planes, int p_plane_count) con return true; } +bool AABB::inside_convex_shape(const Plane *p_planes, int p_plane_count) const { + + Vector3 half_extents = size * 0.5; + Vector3 ofs = position + half_extents; + + for (int i = 0; i < p_plane_count; i++) { + const Plane &p = p_planes[i]; + Vector3 point( + (p.normal.x < 0) ? -half_extents.x : half_extents.x, + (p.normal.y < 0) ? -half_extents.y : half_extents.y, + (p.normal.z < 0) ? -half_extents.z : half_extents.z); + point += ofs; + if (p.is_point_over(point)) + return false; + } + + return true; +} + bool AABB::has_point(const Vector3 &p_point) const { if (p_point.x < position.x) |