接着上次关于Dbvt得分析,不过漏掉了一个比较重要的函数
function btDbvt:: collideTTpersistentStack, btDbvt::collideTT
* btDbvt:: collideTTpersistentStack. 负责进行两个dbvt子树的比较,找出两个子树中重叠的节点对,基于一个全局栈(一个成员变量实例)
* btDbvt::collideTT. 负责进行两个dbvt子树的比较,找出两个子树中重叠的节点对,但是基于的是一个局部栈(函数调用结束则释放)。
* btDbvt::collideTV. 负责在一个树中搜索和对应包围体重叠的节点。
btDbvt:: collideTTpersistentStack 的算法主要是遍历两个目标子树所有可能重合的节点对(基于栈的遍历)只要两个节点中有一个不是叶子节点则压入栈中直到两个节点都为叶子节点且相互重叠,都调用预先制定好的碰撞逻辑来处理。
view plaincopy to clipboardprint?
/* Stack element Node pair*/
struct sStkNN
{
const btDbvtNode* a;
const btDbvtNode* b;
}
/* Stack element Node pair*/
struct sStkNN
{
const btDbvtNode* a;
const btDbvtNode* b;
}
view plaincopy to clipboardprint?
m_stkStack.resize(DOUBLE_STACKSIZE);
m_stkStack[0]=sStkNN(root0,root1); // push both sub tree root nodes into stack
do {
sStkNN p=m_stkStack[--depth]; //pop out the top of stack
if(depth>treshold)//dynamic expand stack size
{
m_stkStack.resize(m_stkStack.size()*2);
treshold=m_stkStack.size()-4;
}
if(p.a==p.b) // If compare the same sub-tree
{
if(p.a->isinternal())//and if node is internal node
{
//push 3 possible branch into stack
//1 compare the same left sub tree
m_stkStack[depth++]=sStkNN(p.a->childs[0],p.a->childs[0]);
//2 compare the same right sub tree
m_stkStack[depth++]=sStkNN(p.a->childs[1],p.a->childs[1]);
//3 compare the left subtree and right subtree
m_stkStack[depth++]=sStkNN(p.a->childs[0],p.a->childs[1]);
}
}
//if compare different sub-tree then test if the
// the volume is intersect
else if(Intersect(p.a->volume,p.b->volume))
{
if(p.a->isinternal()) // if a is internal node
{
if(p.b->isinternal())
{
//if both node are internal node
//push 4 possible branch into stack
//1 compare the a left and b left subtree
m_stkStack[depth++]=sStkNN(p.a->childs[0],p.b->childs[0]);
//2 compare the a right and b left subtree
m_stkStack[depth++]=sStkNN(p.a->childs[1],p.b->childs[0]);
//3 compare the a left and b right subtree
m_stkStack[depth++]=sStkNN(p.a->childs[0],p.b->childs[1]);
//4 compare the a right and b right subtree
m_stkStack[depth++]=sStkNN(p.a->childs[1],p.b->childs[1]);
}
else //if b is leaf node
{
//1 compare the a left and b node
m_stkStack[depth++]=sStkNN(p.a->childs[0],p.b);
//1 compare the a right and b node
m_stkStack[depth++]=sStkNN(p.a->childs[1],p.b);
}
}
else // if a is leaf node
{
if(p.b->isinternal()) // if b is internal node
{
//1 compare a and b left sub tree
m_stkStack[depth++]=sStkNN(p.a,p.b->childs[0]);
//2 compare a and b right sub tree
m_stkStack[depth++]=sStkNN(p.a,p.b->childs[1]);
}
else
{ //if both a and b is leaf node
policy.Process(p.a,p.b);
}
}
}
} while(depth);
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/superwiles/archive/2010/03/02/5337359.aspx