From f19491c2740a381b91f93ee59dc23c8942ea9668 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: Tue, 5 Feb 2019 19:42:48 -0800 Subject: [PATCH] Adding more bounds overlap tests. --- examples/29-debugdraw/debugdraw.cpp | 44 +++++++++++++++++++++++++++++ examples/common/bounds.cpp | 9 +++--- 2 files changed, 49 insertions(+), 4 deletions(-) diff --git a/examples/29-debugdraw/debugdraw.cpp b/examples/29-debugdraw/debugdraw.cpp index dca437064..c874bd625 100644 --- a/examples/29-debugdraw/debugdraw.cpp +++ b/examples/29-debugdraw/debugdraw.cpp @@ -1165,6 +1165,50 @@ public: dde.draw(diskB); } + { + Aabb aabbA; + toAabb(aabbA, { px+kStepX*6.0f, py, pz+kStepZ*1.0f }, { 0.5f, 0.5f, 0.5f }); + + Capsule capsuleB = + { + { xx+kStepX*5.9f, yy-1.0f, zz+kStepZ*1.0f+0.1f }, + { xx+kStepX*6.0f, yy+1.0f, zz+kStepZ*1.0f }, + 0.2f, + }; + + olp = overlap(aabbA, capsuleB); + + dde.setColor(olp ? kOverlapA : 0xffffffff); + dde.setWireframe(false); + dde.draw(aabbA); + + dde.setColor(olp ? kOverlapB : 0xffffffff); + dde.setWireframe(true); + dde.draw(capsuleB); + } + + { + Aabb aabbA; + toAabb(aabbA, { px+kStepX*8.0f, py, pz+kStepZ*1.0f }, { 0.5f, 0.5f, 0.5f }); + + Cone coneB = + { + { xx+kStepX*7.9f, yy-1.0f, zz+kStepZ*1.0f+0.1f }, + { xx+kStepX*8.0f, yy+1.0f, zz+kStepZ*1.0f }, + 0.25f, + }; + + olp = overlap(aabbA, coneB); + + dde.setColor(olp ? kOverlapA : 0xffffffff); + dde.setWireframe(false); + dde.draw(aabbA); + + dde.setColor(olp ? kOverlapB : 0xffffffff); + dde.setWireframe(true); + dde.draw(coneB); + } + // Triangle --- { Triangle triangleA = diff --git a/examples/common/bounds.cpp b/examples/common/bounds.cpp index 42e791f4f..f78a8760a 100644 --- a/examples/common/bounds.cpp +++ b/examples/common/bounds.cpp @@ -1259,14 +1259,15 @@ bool overlap(const Aabb& _aabb, const Cylinder& _cylinder) bool overlap(const Aabb& _aabb, const Capsule& _capsule) { - BX_UNUSED(_aabb, _capsule); - return false; + const Vec3 pos = closestPoint(LineSegment{_capsule.pos, _capsule.end}, getCenter(_aabb) ); + return overlap(_aabb, Sphere{pos, _capsule.radius}); } bool overlap(const Aabb& _aabb, const Cone& _cone) { - BX_UNUSED(_aabb, _cone); - return false; + float tt; + const Vec3 pos = closestPoint(LineSegment{_cone.pos, _cone.end}, getCenter(_aabb), tt); + return overlap(_aabb, Sphere{pos, lerp(_cone.radius, 0.0f, tt)}); } bool overlap(const Aabb& _aabb, const Disk& _disk)