博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
2016/02/29 codes
阅读量:5020 次
发布时间:2019-06-12

本文共 6954 字,大约阅读时间需要 23 分钟。

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;}
}
}
}
}
}
}

 

转载于:https://www.cnblogs.com/whatcanido/p/5228162.html

你可能感兴趣的文章
概述「DAG加边至强连通」模型&&luoguP2746校园网Network of Schools
查看>>
2019春第一次课程设计实验报告
查看>>
[项目改造中的点滴]-C#中IDataReader和DataSet的区别与使用场景
查看>>
火柴棒等式
查看>>
.NET对象占内存多少
查看>>
自己做的项目总结——架构(1)
查看>>
Fiddler查看接口响应时间
查看>>
map的排序
查看>>
数据结构——二项堆
查看>>
Ubuntu命令行安装显卡驱动
查看>>
poj3247:回文素数
查看>>
我与软件
查看>>
ArrayList Vector LinkedList 区别与用法
查看>>
一图看懂host_only nat bridge拓扑结构
查看>>
ext2文件系统
查看>>
Sublime text3配置C编译环境
查看>>
Python下载进度条
查看>>
MySQL Replication之主从切换
查看>>
POJ2686 Traveling by Stagecoach(状压DP)
查看>>
sql server 使用nolock提升性能
查看>>