示例#1
0
        public virtual void Cleanup()
        {
            if (m_raycastAccelerator != null)
            {
                m_nullPairCache.Cleanup();
                m_nullPairCache = null;
                m_raycastAccelerator.Cleanup();
                m_raycastAccelerator = null;
            }

            for (int i = 0; i < m_pHandles.Length; ++i)
            {
                m_pHandles[i].Cleanup();
            }
            m_pHandles = null;
            if (m_ownsPairCache)
            {
                m_pairCache = null;
            }
        }
 public void Initialize(DbvtBroadphase p)
 {
     pbp   = p;
     proxy = null;
 }
示例#3
0
        //public AxisSweep3Internal(ref IndexedVector3 worldAabbMin,ref IndexedVector3 worldAabbMax, int handleMask, int handleSentinel, int maxHandles = 16384, OverlappingPairCache* pairCache=0,bool disableRaycastAccelerator = false);
        public AxisSweep3Internal(ref IndexedVector3 worldAabbMin, ref IndexedVector3 worldAabbMax, int handleMask, ushort handleSentinel, ushort userMaxHandles, IOverlappingPairCache pairCache, bool disableRaycastAccelerator)
        {
            m_bpHandleMask       = (handleMask);
            m_handleSentinel     = (handleSentinel);
            m_pairCache          = (pairCache);
            m_userPairCallback   = null;
            m_ownsPairCache      = (false);
            m_invalidPair        = 0;
            m_raycastAccelerator = null;
            ushort maxHandles = (ushort)(userMaxHandles + 1);//need to add one sentinel handle

            if (m_pairCache == null)
            {
                m_pairCache     = new HashedOverlappingPairCache();
                m_ownsPairCache = true;
            }

            if (!disableRaycastAccelerator)
            {
                m_nullPairCache      = new NullPairCache();
                m_raycastAccelerator = new DbvtBroadphase(m_nullPairCache); //m_pairCache);
                m_raycastAccelerator.m_deferedcollide = true;               //don't add/remove pairs
            }

            //btAssert(bounds.HasVolume());

            // init bounds
            m_worldAabbMin = worldAabbMin;
            m_worldAabbMax = worldAabbMax;

            IndexedVector3 aabbSize = m_worldAabbMax - m_worldAabbMin;

            int maxInt = m_handleSentinel;

            m_quantize = new IndexedVector3((float)maxInt) / aabbSize;

            // allocate handles buffer, using btAlignedAlloc, and put all handles on free list
            m_pHandles = new Handle[maxHandles];
            for (int i = 0; i < m_pHandles.Length; ++i)
            {
                m_pHandles[i] = new Handle();
            }

            m_maxHandles = maxHandles;
            m_numHandles = 0;

            // handle 0 is reserved as the null index, and is also used as the sentinel
            m_firstFreeHandle = 1;
            {
                for (ushort i = m_firstFreeHandle; i < maxHandles; i++)
                {
                    ushort nextFree = (ushort)(i + (ushort)1);
                    m_pHandles[i].SetNextFree(nextFree);
                }
                m_pHandles[maxHandles - 1].SetNextFree(0);
            }

            {
                m_pEdges = new Edge[3, (maxHandles * 2)];
                // allocate edge buffers
                for (int i = 0; i < 3; i++)
                {
                    for (int j = 0; j < maxHandles * 2; ++j)
                    {
                        m_pEdges[i, j] = new Edge();
                    }
                }
            }
            //removed overlap management

            // make boundary sentinels

            m_pHandles[0].SetClientObject(null);

            for (int axis = 0; axis < 3; axis++)
            {
                m_pHandles[0].m_minEdges[axis] = 0;
                m_pHandles[0].m_maxEdges[axis] = 1;

                m_pEdges[axis, 0].m_pos    = 0;
                m_pEdges[axis, 0].m_handle = 0;
                m_pEdges[axis, 1].m_pos    = m_handleSentinel;
                m_pEdges[axis, 1].m_handle = 0;


#if DEBUG_BROADPHASE
                debugPrintAxis(axis);
#endif //DEBUG_BROADPHASE
            }
        }
        }                             // for pool;

        public DbvtTreeCollider(DbvtBroadphase p)
        {
            pbp   = p;
            proxy = null;
        }