From c0aff1f466d7ad0def0119d2ad5e87c456d61328 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: Mon, 4 Feb 2019 22:01:56 -0800 Subject: [PATCH] Adding more bounds overlap tests. --- examples/common/bounds.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/examples/common/bounds.cpp b/examples/common/bounds.cpp index 1d25de871..470916b2d 100644 --- a/examples/common/bounds.cpp +++ b/examples/common/bounds.cpp @@ -1024,14 +1024,21 @@ struct LineSegment Vec3 end; }; -Vec3 closestPoint(const LineSegment& _line, const Vec3& _point) +Vec3 closestPoint(const LineSegment& _line, const Vec3& _point, float& _outT) { const Vec3 axis = sub(_line.end, _line.pos); const float lengthSq = dot(axis, axis); const float tt = clamp(projectToAxis(axis, sub(_point, _line.pos) ) / lengthSq, 0.0f, 1.0f); + _outT = tt; return mad(axis, tt, _line.pos); } +Vec3 closestPoint(const LineSegment& _line, const Vec3& _point) +{ + float ignore; + return closestPoint(_line, _point, ignore); +} + Vec3 closestPoint(const Plane& _plane, const Vec3& _point) { const float dist = distance(_plane, _point); @@ -1127,8 +1134,9 @@ bool overlap(const Sphere& _sphere, const Capsule& _capsule) bool overlap(const Sphere& _sphere, const Cone& _cone) { - BX_UNUSED(_sphere, _cone); - return false; + float tt; + const Vec3 pos = closestPoint(LineSegment{_cone.pos, _cone.end}, _sphere.center, tt); + return overlap(_sphere, Sphere{pos, lerp(_cone.radius, 0.0f, tt)}); } bool overlap(const Sphere& _sphere, const Disk& _disk)