Original Post
I am writing a simple scene graph for my 3 1/2 D game. I am wondering if I am on the right track with my scene graph transversal code. I know it can be done recursively but I have had problems with stack space before and am trying to avoid the obvious recursive transversal.
Thanks,
Pest
int CGEng::Draw()
{
int ret;
static CGNode *CurrentNode,
*TmpNode;
/*
* Lets traverse
*/
CurrentNode = MasterNode;
while(CurrentNode)
{
/*
* Every node has a pre-calculated bounding sphere
* which includes all its children and a x,y,z
* posistion from which to check against
* the view frustrum.
*/
if(InViewExtent(CurrentNode)) // Master node is always in view extent
{
/*
* Draw the parent node if it has not already been
* drawn.
*/
if(!(CurrentNode->flags & GNODE_DRAWN))
CurrentNode->Draw();
/*
* If we have more children of this node then
* make this child the CurrentNode and
* increment currentChild to the next in the list
*/
if(CurrentNode->currentChild)
{
TmpNode = CurrentNode->currentChild;
CurrentNode->currentChild = CurrentNode->currentChild->next;
CurrentNode = TmpNode;
}
else
{
/*
* Already drawn and no more children.
* Resets draw states and the child list.
*/
CurrentNode->ResetDrawn();
CurrentNode = CurrentNode->Parent;
}
}
else
{
CurrentNode = CurrentNode->parent;
}
}
return ret;
}
|