示例#1
0
 public virtual bool ProcessOverlap(BroadphasePair pair)
 {
     if (pair != null && ((pair.m_pProxy0 == m_cleanProxy) ||
                          (pair.m_pProxy1 == m_cleanProxy)))
     {
         m_pairCache.CleanOverlappingPair(pair, m_dispatcher);
     }
     return(false);
 }
示例#2
0
        public virtual void CalculateOverlappingPairs(IDispatcher dispatcher)
        {
            if (m_pairCache.HasDeferredRemoval())
            {
                ObjectArray <BroadphasePair> overlappingPairArray = m_pairCache.GetOverlappingPairArray();

                //perform a sort, to find duplicates and to sort 'invalid' pairs to the end
                overlappingPairArray.QuickSort(new BroadphasePairQuickSort());
                //overlappingPairArray.resize(overlappingPairArray.size() - m_invalidPair);
                m_invalidPair = 0;

                BroadphasePair previousPair = new BroadphasePair();

                for (int i = 0; i < overlappingPairArray.Count; i++)
                {
                    BroadphasePair pair = overlappingPairArray[i];

                    bool isDuplicate = pair.Equals(previousPair);

                    // MAN - not sure if this should be a deep copy or not...
                    previousPair = pair;

                    bool needsRemoval = false;

                    if (!isDuplicate)
                    {
                        ///important to use an AABB test that is consistent with the broadphase
                        bool hasOverlap = TestAabbOverlap(pair.m_pProxy0, pair.m_pProxy1);

                        if (hasOverlap)
                        {
                            needsRemoval = false;//callback.processOverlap(pair);
                        }
                        else
                        {
                            needsRemoval = true;
                        }
                    }
                    else
                    {
                        //remove duplicate
                        needsRemoval = true;
                        //should have no algorithm
                        Debug.Assert(pair.m_algorithm == null);
                    }

                    if (needsRemoval)
                    {
                        m_pairCache.CleanOverlappingPair(pair, dispatcher);

                        //		m_overlappingPairArray.swap(i,m_overlappingPairArray.size()-1);
                        //		m_overlappingPairArray.pop_back();
                        pair.m_pProxy0 = null;
                        pair.m_pProxy1 = null;
                        m_invalidPair++;
                        OverlappingPairCacheGlobals.gOverlappingPairs--;
                    }
                }

                ///if you don't like to skip the invalid pairs in the array, execute following code:
#if CLEAN_INVALID_PAIRS
                overlappingPairArray.QuickSort(new BroadphasePairQuickSort());

                overlappingPairArray.Resize(overlappingPairArray.Count - m_invalidPair);
                m_invalidPair = 0;
#endif//CLEAN_INVALID_PAIRS

                //printf("overlappingPairArray.size()=%d\n",overlappingPairArray.size());
            }
        }