瀏覽代碼

Adding more bounds overlap tests.

Бранимир Караџић 6 年之前
父節點
當前提交
c0aff1f466
共有 1 個文件被更改,包括 11 次插入3 次删除
  1. 11 3
      examples/common/bounds.cpp

+ 11 - 3
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)