public static bool AabbOverlap(SimpleBroadphaseProxy proxy0, SimpleBroadphaseProxy proxy1) { Vector3 p0Min = proxy0.GetMinAABB(); Vector3 p0Max = proxy0.GetMaxAABB(); Vector3 p1Min = proxy1.GetMinAABB(); Vector3 p1Max = proxy1.GetMaxAABB(); return p0Min.X <= p1Max.X && p1Min.X <= p0Max.X && p0Min.Y <= p1Max.Y && p1Min.Y <= p0Max.Y && p0Min.Z <= p1Max.Z && p1Min.Z <= p0Max.Z; }
public SimpleBroadphase(int maxProxies,IOverlappingPairCache overlappingPairCache) { if (overlappingPairCache == null) { overlappingPairCache = new HashedOverlappingPairCache(); m_ownsPairCache = true; } m_pHandles = new SimpleBroadphaseProxy[maxProxies]; m_pairCache = overlappingPairCache; m_maxHandles = maxProxies; m_numHandles = 0; m_firstFreeHandle = 0; m_LastHandleIndex = -1; for (int i = m_firstFreeHandle; i < maxProxies; i++) { m_pHandles[i] = new SimpleBroadphaseProxy(i); m_pHandles[i].SetNextFree(i + 1); m_pHandles[i].m_uniqueId = ++m_proxyCounter;;//any UID will do, we just avoid too trivial values (0,1) for debugging purposes } m_pHandles[maxProxies - 1].SetNextFree(0); }
public virtual BroadphaseProxy CreateProxy(ref Vector3 aabbMin, ref Vector3 aabbMax, BroadphaseNativeTypes shapeType, Object userPtr, CollisionFilterGroups collisionFilterGroup, CollisionFilterGroups collisionFilterMask, IDispatcher dispatcher, Object multiSapProxy) { if (m_numHandles >= m_maxHandles) { Debug.Assert(false); return null; //should never happen, but don't let the game crash ;-) } int position = AllocHandle(); m_pHandles[position] = new SimpleBroadphaseProxy(position,ref aabbMin,ref aabbMax,shapeType,userPtr,collisionFilterGroup,collisionFilterMask,multiSapProxy);; m_pHandles[position].m_uniqueId = ++m_proxyCounter; return m_pHandles[position]; }
private void FreeHandle(SimpleBroadphaseProxy proxy) { int handle = proxy.GetPosition(); Debug.Assert(handle >= 0 && handle < m_maxHandles); if(handle == m_LastHandleIndex) { m_LastHandleIndex--; } proxy.SetNextFree(m_firstFreeHandle); m_firstFreeHandle = handle; proxy.m_clientObject = null; m_numHandles--; }