Jump to content
  • Advertisement

Archived

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

Pest

Scene Graph Transversal

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
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

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!