private void UpdateAxisLists()
{
HashSet<CollisionPair> overlaps = new HashSet<CollisionPair>();
int i, j;
// Sort the vertical axis
for (i = 1; i < verticalAxis.Count; i++)
{
Bound bound = verticalAxis[i];
j = i - 1;
// if our bound needs to be moved left... lower in the list
while ((j >= 0) && verticalAxis[j].CompareTo(bound) > 0)
{
// What are we passing, and what are we passing it with?
if (verticalAxis[j].Type == BoundType.Min && bound.Type == BoundType.Max)
{
// when a Max bound passes a min, we remove it from
// the collision set
collisions.Remove(new CollisionPair(verticalAxis[j].Box.GameObjectID, bound.Box.GameObjectID));
verticalOverlaps.Remove(new CollisionPair(verticalAxis[j].Box.GameObjectID, bound.Box.GameObjectID));
}
else if (verticalAxis[j].Type == BoundType.Max && bound.Type == BoundType.Min)
{
// when a Min bound passes a Max, we add it to the
// potential collision set
verticalOverlaps.Add(new CollisionPair(verticalAxis[j].Box.GameObjectID, bound.Box.GameObjectID));
}
// Shift the elment at j up the list by one index
verticalAxis[j + 1] = verticalAxis[j];
j--;
}
verticalAxis[j + 1] = bound;
}
// Check the potential overlaps for intersection
foreach (CollisionPair pair in verticalOverlaps)
{
GameObject A = GetObject(pair.A);
GameObject B = GetObject(pair.B);
if (A.Bounds.Intersects(B.Bounds))
{
collisions.Add(pair);
}
}
}