Adding more bounds overlap tests.

This commit is contained in:
Бранимир Караџић 2019-02-04 22:01:56 -08:00
parent a91b4bb4c8
commit c0aff1f466
1 changed files with 11 additions and 3 deletions

View File

@ -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)