public static CCDSphereCast ( BEPUutilities.Ray ray, float radius, |
||
ray | BEPUutilities.Ray | Ray to test against the shape. |
radius | float | Radius of the ray. |
target | Shape to test against. | |
shapeTransform | Transform to apply to the shape for the test. | |
maximumLength | float | Maximum length of the ray in units of the ray direction's length. |
hit | Hit data of the sphere cast, if any. | |
return | bool |
public static bool CCDSphereCast(Ray ray, float radius, ConvexShape target, ref RigidTransform shapeTransform, float maximumLength,
out RayHit hit)
{
int iterations = 0;
while (true)
{
if (GJKToolbox.SphereCast(ray, radius, target, ref shapeTransform, maximumLength, out hit) &&
hit.T > 0)
{
//The ray cast isn't embedded in the shape, and it's less than maximum length away!
return true;
}
if (hit.T > maximumLength || hit.T < 0)
return false; //Failure showed it was too far, or behind.
radius *= MotionSettings.CoreShapeScaling;
iterations++;
if (iterations > 3) //Limit could be configurable.
{
//It's iterated too much, let's just do a last ditch attempt using a raycast and hope that can help.
return GJKToolbox.RayCast(ray, target, ref shapeTransform, maximumLength, out hit) && hit.T > 0;
}
}
}
}