public void MoveUnderConsiderationToOverlaps() { for (int i = 0; i < Count; i++) { if (this[i].underConsideration.Count == 0) { continue; } Body g1 = this[i].body; BoundingRectangle aabb1 = g1.Rectangle; // First transfer those under consideration to overlaps, // for, they have been considered... int startIndex = this[i].overlaps.Count; this[i].overlaps.AddRange(this[i].underConsideration); this[i].underConsideration.Clear(); for (int j = startIndex; j < this[i].overlaps.Count; j++) { Body g2 = this[i].overlaps[j]; // It is possible that we may test the same pair of geometries // for both extents (x and y), however, I'm banking on that // one of the extents has probably already been cached and // therefore, won't be checked. if (FrameCoherentSAPDetector.TestForCollisions(g1, g2) == false) { continue; } owner.collisionPairs.AddPair(g1, g2); } } }
/// <summary> /// This function can be used for times when frame-coherence is temporarily lost /// or when it is simply more convenient to completely rebuild all the cached /// data instead of incrementally updating it. Currently it is used after /// removing disposed/removed geometries. If your application had an object /// that teleported across the universe or some other situation where /// frame-coherence was lost, you might consider this function. /// </summary> public void ForceNonIncrementalUpdate() { UpdateExtentValues(); // First, wipe out the collision records collisionPairs.Clear(); // And clear out all the overlap records System.Diagnostics.Debug.Assert(xInfoList.Count == yInfoList.Count); for (int i = 0; i < xInfoList.Count; i++) { xInfoList[i].overlaps.Clear(); xInfoList[i].underConsideration.Clear(); yInfoList[i].overlaps.Clear(); yInfoList[i].underConsideration.Clear(); } // Force sort xExtentList.Sort(delegate(Extent l, Extent r) { return(l.value.CompareTo(r.value)); }); yExtentList.Sort(delegate(Extent l, Extent r) { return(l.value.CompareTo(r.value)); }); // Rebuild overlap information List <Body> overlaps = new List <Body>(); for (int i = 0; i < 2; i++) { overlaps.Clear(); ExtentList extentList = null; if (i == 0) { extentList = xExtentList; } else { extentList = yExtentList; } foreach (Extent extent in extentList) { if (extent.isMin) { // Add whatever is currently in overlaps to this extent.info.overlaps.AddRange(overlaps); // Now add, this geom to overlaps overlaps.Add(extent.info.body); } else { // remove this geom from overlaps overlaps.Remove(extent.info.body); // Test this geom against its overlaps for collisionpairs Body thisGeom = extent.info.body; foreach (Body g in extent.info.overlaps) { if (FrameCoherentSAPDetector.TestForCollisions(thisGeom, g) == false) { continue; } collisionPairs.AddPair(thisGeom, g); } } } } HandleCollisions(); }
public ExtentInfoList(FrameCoherentSAPDetector sap) { owner = sap; }