/// <summary>
/// Tests a ray against the space, possibly returning multiple hits.
/// </summary>
/// <param name="ray">Ray to test.</param>
/// <param name="maximumLength">Maximum length of the ray in units of the ray direction's length.</param>
/// <param name="filter">Delegate to prune out hit candidates before performing a cast against them. Return true from the filter to process an entry or false to ignore the entry.</param>
/// <param name="outputRayCastResults">Hit data of the ray, if any.</param>
/// <returns>Whether or not the ray hit anything.</returns>
public bool RayCast(Ray ray, float maximumLength, Func <BroadPhaseEntry, bool> filter, IList <RayCastResult> outputRayCastResults)
{
var outputIntersections = PhysicsResources.GetBroadPhaseEntryList();
if (BroadPhase.QueryAccelerator.RayCast(ray, maximumLength, outputIntersections))
{
for (int i = 0; i < outputIntersections.Count; i++)
{
RayHit rayHit;
BroadPhaseEntry candidate = outputIntersections.Elements[i];
if (candidate.RayCast(ray, maximumLength, filter, out rayHit))
{
outputRayCastResults.Add(new RayCastResult(rayHit, candidate));
}
}
}
PhysicsResources.GiveBack(outputIntersections);
return(outputRayCastResults.Count > 0);
}