[英]Depth First Search - Scene Graph - Whats my current depth?
- 大家好,我正在嘗試為場景圖實現“深度優先搜索”。 這就是我到目前為止所做的 - 但我很難想象如何跟蹤當前元素在圖形中的深度。 假設我可以將order.size()計為第一個分支的深度 - 但是當代碼再次跳轉到下一個分支時,如何彈出元素? 任何暗示都將非常感激。 非常感謝提前。
//======================================================================
//depth first search
//======================================================================
// clean start - init visited flags in joints
for (int i = 0 ; i < m_joints.size(); i++){m_joints[i]->visited = false;}
// joint indices
vector<int> stack;
vector<int> order;
for(int i = 0; i < m_joints.size(); i++)
{
if(!m_joints[i]->visited)
{
stack.push_back(i);
while(!stack.empty())
{
int top = stack.back();
stack.pop_back();
if(m_joints[top]->visited)
{
continue;
}
m_joints[top]->visited = true;
order.push_back(top);
// need to know how deep I am inside of the scene graph here
// update transformation matrix here
// draw joint here
for(int j = 0 ; j < m_joints[top]->children.size();j++)//all neighbours of top
{
if(!m_joints[top]->children[j]->visited)
{
stack.push_back(m_joints[top]->children[j]->listPosition);
}
}
}
}
}
如果我理解你的問題,你可以在每個元素中添加一個整數變量“depth”,並在每次元素的深度變化時更新它。 此外,您始終可以詢問您的元素當前的深度
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.