public override void UpdateCollision(float dt)
{
WasContaining = Containing;
WasTouching = Touching;
//Gather current pairs.
UpdateContainedPairs();
//Eliminate old pairs.
foreach (var other in subPairs.Keys)
{
if (!containedPairs.Contains(other))
pairsToRemove.Add(other);
}
for (int i = 0; i < pairsToRemove.Count; i++)
{
var toReturn = subPairs[pairsToRemove.Elements[i]];
subPairs.Remove(pairsToRemove.Elements[i]);
toReturn.CleanUp();
toReturn.Factory.GiveBack(toReturn);
}
containedPairs.Clear();
pairsToRemove.Clear();
//Scan the pairs in sequence, updating the state as we go.
//Touching can be set to true by a single touching subpair.
Touching = false;
//Containing can be set to false by a single noncontaining or nontouching subpair.
Containing = subPairs.Count > 0;
foreach (var pair in subPairs.Values)
{
//For child convex pairs, we don't need to always perform containment checks.
//Only check if the containment state has not yet been invalidated or a touching state has not been identified.
var convexPair = pair as DetectorVolumeConvexPairHandler;
if (convexPair != null)
convexPair.CheckContainment = Containing || !Touching;
pair.UpdateCollision(dt);
if (pair.Touching)
Touching = true; //If one child is touching, then we are touching too.
else
Containing = false; //If one child isn't touching, then we aren't containing.
if (!pair.Containing) //If one child isn't containing, then we aren't containing.
Containing = false;
if (!Containing && Touching)
{
//If it's touching but not containing, no further pairs will change the state.
//Containment has been invalidated by something that either didn't touch or wasn't contained.
//Touching has been ensured by at least one object touching.
break;
}
}
NotifyDetectorVolumeOfChanges();
}