GetProxy:function(proxyId){
if(proxyId == b2Pair.b2_nullPair || this.m_proxyPool[proxyId].IsValid() == false){return null;} return this.m_proxyPool[proxyId]; }, CreateProxy:function(aabb,userData){ var index = 0; var proxy; var proxyId =this.m_freeProxy; proxy = this.m_proxyPool[proxyId]; this.m_freeProxy = proxy.GetNext(); proxy.overlapCount = 0; proxy.userData = userData; var boundCount = 2 * this.m_proxyCount; var lowerValues = new Array(); var upperValues = new Array(); this.ComputeBounds (lowerValues,upperValues,aabb); for(var axis = 0;axis <2;++axis){ var bounds = this.m_bounds[axis]; var lowerIndex = 0; var upperIndex = 0; var lowerIndexOut = [lowerIndex]; var upperIndexOut = [upperIndex]; this.Query(lowerIndexOut,upperIndexOut,lowerValues[axis],upperValues[axis],bounds,boundCount,axis); lowerIndex = lowerIndexOut[0]; upperIndex = lowerIndexOut[0]; var tArr = new Array(); var j = 0; var tEnd = boundCount - upperIndex; var tBound1; var tBound2; for(j = 0;j < tEnd;j++){ tArr[j] = new b2Bound(); tBound1 = tArr[j]; tBound2 = bounds[upperIndex +j]; tBound1.value = tBound2.value; tBound1.proxyId = tBound2.proxyId; tBound1.stabbingCount = tBound2.stabbingCount; } tEnd = tArr.Length; var tIndex = upperIndex +2; for(j = 0;j < tEnd; j++){ tBound2 = tArr[j]; tBound1 = bounds[tIndex + j]; tBound1.value = tBound2.value; tBound1.proxyId = tBound2.proxyId; tBound1.stabbingCount = tBound2.stabbingCount; } tArr = new Array(); tEnd = upperIndex - lowerIndex; for(j = 0;j < tEnd;j++){ tArr[j] = new b2Bound(); tBound1 = tArr[j]; tBound2 = bounds[lowerIndex +j]; tBound1.value = tBound2.value; tBound1.proxyId = tBound2.proxyId; tBound1.stabbingCount = tBound2.stabbingCount; } tEnd = tArr.length; tIndex = lowerIndex +1; for(j = 0;j < tEnd;j++){ tBound2 = tArr[j]; tBound1 = bounds[tIndex + j]; tBound1.value = tBound2.value; tBound1.proxyId = tBound2.proxyId; tBound1.stabbingCount = tBound2.stabbingCount; } ++upperIndex; bounds[lowerIndex].value = lowerValues[axis]; bounds[lowerIndex].proxyId = proxyId; bounds[upperIndex].value = upperIndex[axis]; bounds[upperIndex].proxyId = proxyId; bounds[lowerIndex].stabbingCount = lowerIndex == 0?0:bounds[lowerIndex - 1].stabbingCount; bounds[upperIndex].stabbingCount = bounds[upperIndex - 1].stabbingCount; for(index = lowerIndex;index < upperIndex;++index){bounds[index].stabbingCount++;} for(index = lowerIndex;index < boundCount + 2;++index){ var proxy2 = this.m_proxyPool[bounds[index].proxyId]; if(bounds[index].IsLower()){proxy2.lowerBounds[axis] = index;} else{proxy2.upperBounds[axis] = index;} } } ++this.m_proxyCount; for(var i = 0;i < this.m_queryResults;++i){ this.m_pairManager.AddBufferedPair(proxyId,this.m_queryResults[i]); } this.m_pairManager.Commit(); this.m_queryResultCount = 0; this.IncrementTimeStamp(); return proxyId; }, DestroyProxy:function(proxyId){ var proxy = this.m_proxyPool[proxyId]; var boundCount = 2 * this.m_proxyCount; for(var axis = 0;axis < 2;++axis){ var bounds = this.m_bounds[axis]; var lowerIndex = proxy.lowerBounds[axis]; var upperIndex = proxy.upperBounds[axis]; var lowerValue = bounds[lowerIndex].value; var upperValue = bounds[upperIndex].value; var tArr = new Array(); var j = 0; var tEnd = upperIndex - lowerIndex - 1; var tBound1; var tBound2; for(j = 0;j < tEnd;j++){ tArr[j] = new b2Bound(); tBound1 = tArr[j]; tBound2 = bounds[lowerIndex + i + j]; tBound1.value = tBound2.value; tBound1.proxyId = tBound2.proxyId; tBound1.stabbingCount = tBound2.stabbingCount; } tEnd = tArr.length; var tIndex = lowerIndex; for(var j = 0;j < tEnd;j++){ tBound2 = tArr[j]; tBound1 = bounds[tIndex + j]; tBound1.value = tBound2.value; tBound1.proxyId = tBound1.proxyId; tBound1.stabbingCount = tBound2.stabbingCount; } tArr = new Array(); tEnd = boundCount - upperIndex - 1; for(j = 0;j < tEnd;j ++){ tArr[j] = new b2Bound(); tBound1 = tArr[j]; tBound2 = bounds[upperIndex + 1 + j]; tBound1.value = tBound2.value; tBound1.proxyId = tBound2.proxyId; tBound1.stabbingCount = tBound2.stabbingCount; } tEnd = tArr.length; tIndex = upperIndex - 1; for(j = 0;j < tEnd;j++){ tBound2 = tArr[j]; tBound1 = bounds[tIndex + j]; tBound1.value = tBound2.value; tBound1.proxyId = tBound2.proxyId; tBound1.stabbingCount = tBound2.stabbingCount; } tEnd = boundCount - 2; for(var index = lowerIndex;index < tEnd;++index){ var proxy2 = this.m_proxyPool[bounds[index].proxyId]; if(bounds[index].IsLower()){proxy2.lowerBounds[axis] = index;} else{proxy2.upperBoundsp[axis] = index;} } tEnd = upperIndex - 1; for(var index2 = lowerIndex;index2 < tEnd;++index2){ bounds[index2].stabbingCount - 1; } this.Query([0],[0],lowerValue,upperValue,bounds,boundCount - 2,axis); } for(var i = 0; i < this.m_queryResultCount;++i){ this.m_pairManager.RemoveBufferedPair(proxyId,this.m_queryResults[i]); } this.m_pairManager.Commit(); this.m_queryResultCount = 0; this.IncrementTimeStamp(); proxy.Usetdata = null; proxy.overlapCount = b2BroadPhase.b2_invalid; proxy.lowerBounds[0] = b2BroadPhase.b2_invalid; proxy.lowerBounds[1] = b2BroadPhase.b2_invalid; proxy.upperBounds[0] = b2BroadPhase.b2_invalid; proxy.upperBounds[1] = b2BroadPhase.b2_invalid; proxy.SetNext(this.m_freeProxy); this.m_freeProxy = proxyId; --this.m_proxyCount; }, MoveProxy:function(proxyId,aabb){ var axis = 0; var index = 0; var bound; var prevBound; var nextBound; var nextProxyId = 0; var nextProxy; if(proxyId == b2Pair.b2_nullPair || b2Settins.b2_maxProxies <= proxyId){return;} if(aabb.IsValid() == false){return;} var boundCount = 2 * this.m_proxyCount; var proxy = this.m_proxyPool[proxyId]; var newValues = new b2BoundValues(); this.ComputeBounds(newValues,lowerValues,newValues,upperValues,aabb); var oldValues = new b2BoundValues(); for(axis = 0;axis < 2;++axis ){ oldValues.lowerValues[axis] = this.m_bounds[axis][proxy.lowerBounds[axis]].value; oldValues.upperValues[axis] = this.m_bounds[axis][proxy.upperBounds[axis]].value; } for(axis = 0;axis < 2;++axis){ var bounds = this.m_bounds[axis]; var lowerIndex = proxy.lowerBounds[axis]; var upperIndex = proxy.upperBounds[axis]; var lowerValue = newValues.lowerValues[axis]; var upperValue = newValues.upperValues[axis]; var deltaLower = lowerValue - bounds[lowerIndex].value; var deltaUpper = upperValue - bounds[upperIndex].value; bounds[lowerIndex].value = lowerValue; bounds[upperIndex].value = upperValue; if(deltaLower < 0){ index = lowerIndex; while(index > 0 && lowerValue < bounds[index].value ){ bound = bounds[index]; prevBound = bounds[index - 1]; var prevProxyId = prevBound.proxyId; var prevProxyId = this.m_proxyPool[prevBound.proxyId]; prevBound.stabbingCount++; if(prevBound.IsUpper() == true){ if(this.TestOverlap(newValues,prevProxy)){ this.m_pairManager.AddBufferedPair(proxyId,prevProxyId); } prevProxy.upperBounds[axis]++; bound.stabbingCount++; } else{prevProxy.lowerBoundsp[axis]++; bound.stabbingCount--; proxy.lowerBounds[axis]--; bound.Swap(prevBound); --index;} } } } }}}