BEPUphysics.CollisionTests.CollisionAlgorithms.GJK.GJKToolbox.CCDSphereCast C# (CSharp) Method

CCDSphereCast() public static method

Casts a fat (sphere expanded) ray against the shape. If the raycast appears to be stuck in the shape, the cast will be attempted with a smaller ray (scaled by the MotionSettings.CoreShapeScaling each time).
public static CCDSphereCast ( BEPUutilities.Ray ray, float radius, ConvexShape target, RigidTransform &shapeTransform, float maximumLength, RayHit &hit ) : bool
ray BEPUutilities.Ray Ray to test against the shape.
radius float Radius of the ray.
target BEPUphysics.CollisionShapes.ConvexShapes.ConvexShape Shape to test against.
shapeTransform BEPUutilities.RigidTransform 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 BEPUutilities.RayHit 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;
                        
                }
            }
        }
    }