Skip to main content
gamedev.net
🔒 Locked

Scene Graph Transversal

Started by Pest Aug 31, 2000 at 4:07 PM 0 replies 600+ views
Original Post
Pest
Pest
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
MatrixCubed
MatrixCubed
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

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.