Esempio n. 1
0
 //-----------------------------------------------------------------------
 void PagingLandScapeOctree::_unref(const bool removeChildren)
 {
     --mNumNodes;
     if (removeChildren)
     {
         //remove null children
         PagingLandScapeOctree *child;
         for (unsigned int i = 0; i < 2; i++)
         {
             for (unsigned int j = 0; j < 2; j++)
             {
                 for (unsigned int k = 0; k < 2; k++)
                 {
                     child = mChildren[ i ][ j ][ k ];
                     if (child && !child->hasChildren())
                     {
                         mSceneMgr->deleteOctree(child);
                         mChildren[ i ][ j ][ k ] = 0;
                     }
                 }
             }
         }
     }
     if (mParent != 0)
     {
         mParent->_unref(mNumNodes == 0);
     }
 };
    //-----------------------------------------------------------------------
    void Traversal::traverseChildren(PagingLandScapeOctree& node, VisibleObjectsBoundsInfo * const visibleBounds)
    {                  
        // hasLocalChildren
        if (!node.mNodes.empty())
        {
            //Add stuff to be rendered;
			PagingLandScapeOctreeNodeList::iterator it = node.mNodes.begin();
			PagingLandScapeOctreeNodeList::iterator itEnd = node.mNodes.end();
            while (it != itEnd)
            {
                (*it)->traversal (*this, visibleBounds);
                ++it;
            }
        }
      
        PagingLandScapeOctree *n = 
            node.mChildren[ 0 ][ 0 ][ 0 ];
        if (n && n->hasChildren())  
            n->traversal (*this, visibleBounds);

        n = node.mChildren[ 1 ][ 0 ][ 0 ];
        if (n && n->hasChildren())  
            n->traversal (*this, visibleBounds);

        n = node.mChildren[ 0 ][ 1 ][ 0 ];
        if (n && n->hasChildren())  
            n->traversal (*this, visibleBounds);

        n = node.mChildren[ 1 ][ 1 ][ 0 ];
        if (n && n->hasChildren())  
            n->traversal (*this, visibleBounds);

        n = node.mChildren[ 0 ][ 0 ][ 1 ];
        if (n && n->hasChildren())  
            n->traversal (*this, visibleBounds);

        n = node.mChildren[ 1 ][ 0 ][ 1 ];
        if (n && n->hasChildren())  
            n->traversal (*this, visibleBounds);

        n = node.mChildren[ 0 ][ 1 ][ 1 ];
        if (n && n->hasChildren())  
            n->traversal (*this, visibleBounds);

        n = node.mChildren[ 1 ][ 1 ][ 1 ];
        if (n && n->hasChildren())  
            n->traversal (*this, visibleBounds);

	}
    //-----------------------------------------------------------------------
    void SWTraversal::traverseChildren(PagingLandScapeOctree & node, VisibleObjectsBoundsInfo * const visibleBounds)
    {
	    FrontToBackNodeSorterPriorityQueue myStack = FrontToBackNodeSorterPriorityQueue(FrontToBackNodeSorterOperator (camPos));
       
        //assert (node.getNodeData (occlusion.mCurrentCam)->viewFrustumVisible);
        if (!node.mNodes.empty())
        {
            PagingLandScapeOctreeNodeList::const_iterator it =  node.mNodes.begin();
            while (it != node.mNodes.end())
            {
                 myStack.push(*it);
                ++it;
            }
        }

        PagingLandScapeOctree *n = 
            node.mChildren[ 0 ][ 0 ][ 0 ];
        if (n && n->hasChildren())  
            myStack.push (n);
        n = node.mChildren[ 1 ][ 0 ][ 0 ];
        if (n && n->hasChildren())  
            myStack.push (n);
        n = node.mChildren[ 0 ][ 1 ][ 0 ];
        if (n && n->hasChildren())  
            myStack.push (n);
        n = node.mChildren[ 1 ][ 1 ][ 0 ];
        if (n && n->hasChildren())  
            myStack.push (n);
        n = node.mChildren[ 0 ][ 0 ][ 1 ];
        if (n && n->hasChildren())  
            myStack.push (n);
        n = node.mChildren[ 1 ][ 0 ][ 1 ];
        if (n && n->hasChildren())  
            myStack.push (n);
        n = node.mChildren[ 0 ][ 1 ][ 1 ];
        if (n && n->hasChildren())  
            myStack.push (n);
        n = node.mChildren[ 1 ][ 1 ][ 1 ];
        if (n && n->hasChildren())  
            myStack.push (n);

        //traverse nearer child first
        while (!myStack.empty ())
        {
	        OcclusionElement& nstacked = *myStack.top ();
	        myStack.pop ();
            nstacked.traversal(*this, visibleBounds);
        }
    }
    //-----------------------------------------------------------------------
    void CHCTraversal::onTree(PagingLandScapeOctree& node, VisibleObjectsBoundsInfo * const visibleBounds) const 
    {
    	#ifdef _VISIBILITYDEBUG
            assert (node.getNodeData (occlusion.mCurrentCam)->viewFrustumVisible);
		    occlusion.traversed_nodes_cnt++;       
        #endif //_VISIBILITYDEBUG    
                
        if (!node.mNodes.empty())
        {	
            PagingLandScapeOctreeNodeList::iterator it =  node.mNodes.begin();  
            while (it != node.mNodes.end())
            { 
                stack.push (*it);
                ++it;
            }
        }

        PagingLandScapeOctree *n = 
            node.mChildren[ 0 ][ 0 ][ 0 ];
        if (n && n->hasChildren())  
           stack.push(n);
        n = node.mChildren[ 1 ][ 0 ][ 0 ];
        if (n && n->hasChildren())  
            stack.push(n);
        n = node.mChildren[ 0 ][ 1 ][ 0 ];
        if (n && n->hasChildren())  
            stack.push(n);
        n = node.mChildren[ 1 ][ 1 ][ 0 ];
        if (n && n->hasChildren())  
            stack.push(n);
        n = node.mChildren[ 0 ][ 0 ][ 1 ];
        if (n && n->hasChildren())  
            stack.push(n);
        n = node.mChildren[ 1 ][ 0 ][ 1 ];
        if (n && n->hasChildren())  
            stack.push(n);
        n = node.mChildren[ 0 ][ 1 ][ 1 ];
        if (n && n->hasChildren())  
            stack.push(n);
        n = node.mChildren[ 1 ][ 1 ][ 1 ];
        if (n && n->hasChildren())  
            stack.push(n);
	}