#### Archived

This topic is now archived and is closed to further replies.

# Scene Graph Transversal

This topic is 6679 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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.
  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; } 
Thanks, Pest

##### Share on other sites
I did something like this:

class CFrame{public:BOOL RenderChildren(void);protected:TRIANGLELIST* m_pTriList;DWORD m_dwFlags;MATRIX* m_lpMatrix;CFrame* m_pChildFrames;CFrame* m_pParentFrame;DWORD m_dwNumChildren;};

Then create one frame for the scene root, and add children as necessary. In addition, in your render loop:

BOOL GraphicsEngine::RenderScene(void){m_pScene->RenderChildren();return TRUE;}

and finally:

BOOL CFrame::RenderChildren(void){for (DWORD i = 0; i < m_dwNumChildren; i++){m_pChildFrame->RenderChildren();}RenderFrame();return(TRUE);}

The RenderFrame() function would of course, call the actual graphics rendering code.

Hope this helps

Edited by - MatrixCubed on August 31, 2000 11:46:12 PM

1. 1
2. 2
3. 3
Rutin
16
4. 4
5. 5

• 11
• 26
• 10
• 11
• 9
• ### Forum Statistics

• Total Topics
633718
• Total Posts
3013522
×