From 626ca46aa0ea080efda11ca6d325b953c8ee7e75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=91=D1=80=D0=B0=D0=BD=D0=B8=D0=BC=D0=B8=D1=80=20=D0=9A?= =?UTF-8?q?=D0=B0=D1=80=D0=B0=D1=9F=D0=B8=D1=9B?= Date: Sat, 17 Oct 2020 22:16:18 -0700 Subject: [PATCH] Bounds: Overlap cone/plane. --- examples/common/bounds.cpp | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/examples/common/bounds.cpp b/examples/common/bounds.cpp index fe5e42ce8..967d4647c 100644 --- a/examples/common/bounds.cpp +++ b/examples/common/bounds.cpp @@ -1478,8 +1478,7 @@ bool overlap(const Cone& _cone, const Aabb& _aabb) bool overlap(const Cone& _cone, const Plane& _plane) { - BX_UNUSED(_cone, _plane); - return false; + return overlap(_plane, _cone); } bool overlap(const Cone& _cone, const Triangle& _triangle) @@ -1769,6 +1768,11 @@ bool overlap(const Obb& _obbA, const Obb& _obbB) return false; } +bool overlap(const Plane& _plane, const LineSegment& _line) +{ + return isNearZero(distance(_plane, _line) ); +} + bool overlap(const Plane& _plane, const Vec3& _pos) { return isNearZero(distance(_plane, _pos) ); @@ -1809,8 +1813,23 @@ bool overlap(const Plane& _plane, const Capsule& _capsule) bool overlap(const Plane& _plane, const Cone& _cone) { - BX_UNUSED(_plane, _cone); - return false; + const Vec3 axis = sub(_cone.pos, _cone.end); + const float len = length(axis); + const Vec3 dir = normalize(axis); + + const Vec3 v1 = cross(_plane.normal, dir); + const Vec3 v2 = cross(v1, dir); + + const float bb = len; + const float aa = _cone.radius; + const float cc = sqrt(square(aa) + square(bb) ); + + const Vec3 pos = add(add(_cone.end + , mul(dir, len * bb/cc) ) + , mul(v2, len * aa/cc) + ); + + return overlap(_plane, LineSegment{pos, _cone.end}); } bool overlap(const Plane& _plane, const Disk& _disk)