Browse Source

Adding more bounds overlap tests.

Бранимир Караџић 6 years ago
parent
commit
f19491c274
2 changed files with 49 additions and 4 deletions
  1. 44 0
      examples/29-debugdraw/debugdraw.cpp
  2. 5 4
      examples/common/bounds.cpp

+ 44 - 0
examples/29-debugdraw/debugdraw.cpp

@@ -1165,6 +1165,50 @@ public:
 						dde.draw(diskB);
 						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 ---
 					{
 					{
 						Triangle triangleA =
 						Triangle triangleA =

+ 5 - 4
examples/common/bounds.cpp

@@ -1259,14 +1259,15 @@ bool overlap(const Aabb& _aabb, const Cylinder& _cylinder)
 
 
 bool overlap(const Aabb& _aabb, const Capsule& _capsule)
 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)
 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)
 bool overlap(const Aabb& _aabb, const Disk& _disk)