Exemplo n.º 1
0
        public CollisionSystem(int gridSize = 10, int groupCount = 10, int poolSize = 1000, int bucketSize = 1000)
        {
            this.bucketSize = bucketSize;
            this.groupCount = groupCount;

            narrowPhase    = new NarrowPhase();
            broadPhase     = new BroadPhase(gridSize);
            groups         = new Dictionary <Type, CollisionGroup>(groupCount);
            hashSetPool    = new Pool <HashSet <AbstractCollider> >(() => new HashSet <AbstractCollider>(), poolSize);
            listPool       = new Pool <List <AbstractCollider> >(() => new List <AbstractCollider>(bucketSize), poolSize);
            dictionaryPool = new Pool <Dictionary <AbstractCollider, float2> >(() => new Dictionary <AbstractCollider, float2>(bucketSize), poolSize);
        }
Exemplo n.º 2
0
        public void Initialize(AbstractCollider collider, BroadPhase broadPhase, NarrowPhase narrowPhase, int index)
        {
            buckets[index].Add(collider);
            UpdateIndices(index, broadPhase.columns);

            for (int i = 0; groups.Count > i; i++)
            {
                AdjacentAABBIntersections(collider, broadPhase, groups[i], indices, containedBy[i] ? broadPhase.containedByCandidates[collider] : null, intersect[i] ? broadPhase.intersectionCandidates[collider] : null, depenetrate[i] ? broadPhase.depenetrationCandidates[collider] : null);
            }

            narrowPhase.FindContainedBy(collider, broadPhase.containedByCandidates[collider], narrowPhase.containedBy[collider]);
            narrowPhase.FindIntersections(collider, broadPhase.intersectionCandidates[collider], narrowPhase.intersections[collider]);
            narrowPhase.FindDepenetrations(collider, broadPhase.depenetrationCandidates[collider], narrowPhase.depenetrationsByCollider[collider]);
        }