Ejemplo n.º 1
0
 public FrameCoherentSAPDetector()
 {
     this.xExtentList    = new ExtentList(this);
     this.yExtentList    = new ExtentList(this);
     this.xInfoList      = new ExtentInfoList(this);
     this.yInfoList      = new ExtentInfoList(this);
     this.collisionPairs = new CollisionPairDictionary();
 }
 public SweepAndPruneCollider(PhysicsSimulator physicsSimulator)
 {
     _physicsSimulator = physicsSimulator;
     _xExtentList      = new ExtentList(this);
     _yExtentList      = new ExtentList(this);
     _xInfoList        = new ExtentInfoList(this);
     _yInfoList        = new ExtentInfoList(this);
     collisionPairs    = new CollisionPairDictionary();
 }
Ejemplo n.º 3
0
 public JoinSymbol(string name, TypeUsage type, List <Symbol> extents)
     : base(name, type)
 {
     extentList   = new List <Symbol>(extents.Count);
     nameToExtent = new Dictionary <string, Symbol>(extents.Count, StringComparer.OrdinalIgnoreCase);
     foreach (var symbol in extents)
     {
         nameToExtent[symbol.Name] = symbol;
         ExtentList.Add(symbol);
     }
 }
Ejemplo n.º 4
0
        private int ExtentListRemoveAllDisposed(ExtentList l)
        {
            int removed = 0;

            for (int i = 0; i < l.Count; i++)
            {
                if (l[i].Info.Geometry.IsDisposed)
                {
                    removed++;
                    l.RemoveAt(i);
                    i--;
                }
            }
            return(removed);
        }
Ejemplo n.º 5
0
        private int ExtentListRemoveAllRemoved(ExtentList l)
        {
            int removed = 0;

            for (int i = 0; i < l.Count; i++)
            {
                if (!l[i].Info.Geometry.InSimulation)
                {
                    removed++;
                    l.RemoveAt(i);
                    i--;
                }
            }
            return(removed);
        }
        /// <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
            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((l, r) => l.value.CompareTo(r.value));
            _yExtentList.Sort((l, r) => l.value.CompareTo(r.value));

            // Rebuild overlap information
            List <Geom> overlaps = new List <Geom>();

            for (int i = 0; i < 2; i++)
            {
                overlaps.Clear();

                ExtentList extentList = i == 0 ? _xExtentList : _yExtentList;

                foreach (Extent extent in extentList)
                {
                    if (extent.isMin)
                    {
                        // Add whatever is currently in overlaps to this
                        extent.info.overlaps.InsertRange(0, overlaps);

                        // Now add, this geom to overlaps
                        overlaps.Add(extent.info.geometry);
                    }
                    else
                    {
                        // remove this geom from overlaps
                        overlaps.Remove(extent.info.geometry);

                        // Test this geom against its overlaps for collisionpairs
                        Geom thisGeom = extent.info.geometry;
                        foreach (Geom g in extent.info.overlaps)
                        {
                            if (DoCollision(thisGeom, g) == false)
                            {
                                continue;
                            }

                            collisionPairs.AddPair(thisGeom, g);
                        }
                    }
                }
            }
            HandleCollisions();
        }
Ejemplo n.º 7
0
        /// <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();
        }