Index: trunk/VUT/OcclusionCullingSceneManager/TestCullingDotScene/TestCullingDotSceneApplication.cpp
===================================================================
--- trunk/VUT/OcclusionCullingSceneManager/TestCullingDotScene/TestCullingDotSceneApplication.cpp	(revision 39)
+++ trunk/VUT/OcclusionCullingSceneManager/TestCullingDotScene/TestCullingDotSceneApplication.cpp	(revision 42)
@@ -423,5 +423,5 @@
 
 	// show overlay
-	Overlay* pOver = OverlayManager::getSingleton().getByName("Example/OcclusionDemoOverlay"); 
+	Overlay* pOver = OverlayManager::getSingleton().getByName("Example/OcclusionCullingDemoOverlay"); 
 
 	mAlgorithmInfo = OverlayManager::getSingleton().getOverlayElement("Example/Occlusion/AlgorithmInfo");
Index: trunk/VUT/OcclusionCullingSceneManager/TestCullingDotScene/TestCullingDotSceneApplication.h
===================================================================
--- trunk/VUT/OcclusionCullingSceneManager/TestCullingDotScene/TestCullingDotSceneApplication.h	(revision 37)
+++ trunk/VUT/OcclusionCullingSceneManager/TestCullingDotScene/TestCullingDotSceneApplication.h	(revision 42)
@@ -80,4 +80,5 @@
 	OverlayElement *mQueryCulledNodesInfo;
     OverlayElement *mTraversedNodesInfo;
+	OverlayElement *mSceneNodesInfo;
 };
 
Index: trunk/VUT/OcclusionCullingSceneManager/include/OgreOcclusionCullingTerrainSceneTraverser.h
===================================================================
--- trunk/VUT/OcclusionCullingSceneManager/include/OgreOcclusionCullingTerrainSceneTraverser.h	(revision 41)
+++ trunk/VUT/OcclusionCullingSceneManager/include/OgreOcclusionCullingTerrainSceneTraverser.h	(revision 42)
@@ -41,5 +41,5 @@
 	typedef pair<Octree *, HardwareOcclusionQuery *> OctreeQueryPair;
 	typedef priority_queue<Octree *, vector<Octree *>, octreeless<vector<Octree *>::value_type> > OctreePriorityQueue;
-	//typedef queue<QueryPair> QueryQueue;
+	typedef queue<OctreeQueryPair> OctreeQueryQueue;
 
 	class OcclusionCullingTerrainSceneTraverser: public OcclusionCullingSceneTraverser
@@ -47,5 +47,20 @@
 	public:
 		OcclusionCullingTerrainSceneTraverser(SceneManager *sm, RenderSystem *rsys);
-		void renderScene( Camera *cam, Octree *root );
+		~OcclusionCullingTerrainSceneTraverser();
+		//void renderScene( Camera *cam );
+		void setSceneRoot(Octree *root);
+		/** Sets the number of nodes in this octree 
+		@remark do not confuse this with the OctreeNode class 
+		which is derived from SceneNode
+		@param num number of nodes in the octree
+		*/
+		void setNumOctreeNodes( unsigned int num );
+	
+		/** Gets the given option for the scene traverser.
+	        @remarks
+		    See setOption
+		*/
+		bool getOption( const String &, void * );
+		bool getOptionKeys( StringVector &refKeys );
 		
 	protected:
@@ -58,9 +73,16 @@
 		/** Issue a occlusion query for this node. */
 		
-		void pullUpVisibility( Octree *octree );
+		void initDistanceQueue(Camera *cam);
+		void pullUpVisibility( Camera *cam, Octree *octree );
 		void traverseOctant(Camera *cam, Octree *octant );
 		void renderOctant( Camera *cam, Octree *octant );
+		bool isLeaf(Octree *octant);
 
-		OctreePriorityQueue *mDistanceQueue;
+	private:
+		OctreePriorityQueue *mOctreeDistanceQueue;
+		// the octree root
+		Octree *mOctreeSceneRoot;
+
+		unsigned int mNumOctreeNodes;
 	};
 
Index: trunk/VUT/OcclusionCullingSceneManager/include/OgreOcclusionCullingSceneTraverser.h
===================================================================
--- trunk/VUT/OcclusionCullingSceneManager/include/OgreOcclusionCullingSceneTraverser.h	(revision 41)
+++ trunk/VUT/OcclusionCullingSceneManager/include/OgreOcclusionCullingSceneTraverser.h	(revision 42)
@@ -58,9 +58,7 @@
 			
 			@param cam current camera
-			@param root root of hierarchy 
 		*/
-		void renderScene( Camera *cam, SceneNode *root );
+		void renderScene( Camera *cam );
 	
-		
 		/** Sets the given option for the scene traverser.
 			       @remarks
@@ -84,8 +82,4 @@
 		void setRenderSystem( RenderSystem *rsys );
 		
-		/** Doing some necessary preprocessing.
-		@comment e.g., initialises occlusion queries */
-		void preprocess( void );
-
 		/** Sets the current number of scene nodes in the scene.
 		@param num number of scene nodes
@@ -93,8 +87,15 @@
 		void setNumSceneNodes(int num );
 
+		/** Sets the root of the scene hierarchy. */
+		void setSceneRoot(SceneNode *root);
+
 		/** Sets the required number of occlusion queries.
 		@param num number occlusion queries
 		*/
-		void setNumQueries( int num );
+		//void setNumQueries( int num );
+
+		/** Doing some necessary preprocessing.
+		@comment e.g., initialises occlusion queries */
+		//void preprocess( void );
 
 	protected:
@@ -113,10 +114,13 @@
 		/** Sets rendering mode, e.g. query mode or render mode*/
 		void setRenderingMode( int mode );
+		
+		
 		/** Renders the scene with view frustum culling only. */
-		void renderCullFrustum( Camera *cam );
+		virtual void renderCullFrustum( Camera *cam );
 		/** Renders the scene with the hierarchical stop and wait algorithm. */
-		void renderStopAndWait( Camera *cam );
+		virtual void renderStopAndWait( Camera *cam );
 		/** Renders the scene with the coherent hierarchical algorithm and the query queye. */
-		void renderCoherentWithQueue( Camera *cam );
+		virtual void renderCoherentWithQueue( Camera *cam );
+
 		/** Issue a occlusion query for this node. 
 		@param box the axis aligned bounding box of the node
@@ -124,6 +128,10 @@
 		*/
 		HardwareOcclusionQuery *issueOcclusionQuery( AxisAlignedBox *box, bool wasVisible );
+		/** Returns next available occlusion query or creates new one.
+		@return the next occlusion query
+		*/
+		HardwareOcclusionQuery *getNextOcclusionQuery(void);
 		/** Pulls up the visibility from the child nodes. */
-		void pullUpVisibility( SceneNode *node );
+		void pullUpVisibility( Camera *cam, SceneNode *node );
 		/** delete all previously defined occlusion queries */
 		void deleteQueries();
@@ -136,6 +144,6 @@
 		SolidHalfBoundingBox *getSolidHalfBoundingBox( int half );
 
-		// we use a priority queue rather than a renderstack
-		PriorityQueue *mDistanceQueue; 
+		/** Initialises the distance queue. */
+		virtual void initDistanceQueue(Camera *cam);
 		
 		std::vector<HardwareOcclusionQuery *> mOcclusionQueries;
@@ -150,5 +158,5 @@
 		SceneManager *mSceneManager;
 		RenderSystem *mRenderSystem;
-
+	
 		int mCurrentTestIdx;
 		int mQueryMode;
@@ -162,4 +170,10 @@
 		unsigned int mNumFrustumCulledNodes;
 		unsigned int mNumRenderedGeometry;
+
+	private:
+		// the scene root
+		SceneNode *mSceneRoot;
+		// we use a priority queue ordered by distance
+		PriorityQueue *mDistanceQueue; 
 	};
 
Index: trunk/VUT/OcclusionCullingSceneManager/include/OgreOcclusionCullingTerrainSceneManager.h
===================================================================
--- trunk/VUT/OcclusionCullingSceneManager/include/OgreOcclusionCullingTerrainSceneManager.h	(revision 41)
+++ trunk/VUT/OcclusionCullingSceneManager/include/OgreOcclusionCullingTerrainSceneManager.h	(revision 42)
@@ -58,8 +58,7 @@
 		@param root current octree
 		*/
-		unsigned int countOctreeSize(Octree *root);
+		//unsigned int countOctreeSize(Octree *root);
 
 		OcclusionCullingTerrainSceneTraverser *mOcclusionCullingTerrainSceneTraverser;
-		//OcclusionCullingSceneTraverser *mOcclusionCullingTerrainSceneTraverser;
 	};
 
Index: trunk/VUT/OcclusionCullingSceneManager/scripts/OcclusionCullingDemo.overlay
===================================================================
--- trunk/VUT/OcclusionCullingSceneManager/scripts/OcclusionCullingDemo.overlay	(revision 42)
+++ trunk/VUT/OcclusionCullingSceneManager/scripts/OcclusionCullingDemo.overlay	(revision 42)
@@ -0,0 +1,234 @@
+Example/OcclusionCullingDemoOverlay
+{
+	zorder 500
+	// Stats block
+	container BorderPanel(Example/Occlusion/OcclusionPanel)
+	{
+		metrics_mode pixels
+		vert_align top
+		left 5 
+		top 5
+		width 450
+		height 55
+		material Core/StatsBlockCenter
+        	border_size 1 1 1 1
+        	border_material Core/StatsBlockBorder
+        	border_topleft_uv     0.0000 1.0000 0.0039 0.9961
+	    	border_top_uv         0.0039 1.0000 0.9961 0.9961
+	    	border_topright_uv    0.9961 1.0000 1.0000 0.9961
+	    	border_left_uv        0.0000 0.9961 0.0039 0.0039
+	    	border_right_uv       0.9961 0.9961 1.0000 0.0039
+	    	border_bottomleft_uv  0.0000 0.0039 0.0039 0.0000
+        	border_bottom_uv      0.0039 0.0039 0.9961 0.0000
+	    	border_bottomright_uv 0.9961 0.0039 1.0000 0.0000
+
+
+		element TextArea(Example/Occlusion/Algorithm)
+		{
+			metrics_mode pixels
+			left 5
+			top 5
+			width 180
+			height 30
+			font_name TrebuchetMSBold
+			char_height 16
+			caption [A] Algorithm
+			colour_top 0.5 0.7 0.5
+			colour_bottom 0.3 0.5 0.3
+		}
+		element TextArea(Example/Occlusion/AlgorithmInfo)
+		{
+			metrics_mode pixels
+			left 155
+			top 5
+			width 90
+			height 30
+			font_name TrebuchetMSBold
+			char_height 16
+			caption :
+			colour_top 0.5 0.7 0.5
+			colour_bottom 0.3 0.5 0.3
+		}
+
+		element TextArea(Example/Occlusion/Threshold)
+		{
+			metrics_mode pixels
+			left 5
+			top 20
+			width 90
+			height 30
+			font_name TrebuchetMSBold
+			char_height 16
+			caption [-][+] Threshold
+			colour_top 0.5 0.7 0.5
+			colour_bottom 0.3 0.5 0.3
+		}
+		element TextArea(Example/Occlusion/ThresholdInfo)
+		{
+			metrics_mode pixels
+			left 155
+			top 20
+			width 90
+			height 30
+			font_name TrebuchetMSBold
+			char_height 16
+			caption :
+			colour_top 0.5 0.7 0.5
+			colour_bottom 0.3 0.5 0.3
+		}
+	}
+
+	container BorderPanel(Example/Occlusion/OcclusionStatsPanel)
+	{
+		metrics_mode pixels
+		vert_align top
+		horz_align right
+		left -355 
+		top 5
+		width 450
+		height 90
+		material Core/StatsBlockCenter
+        	border_size 1 1 1 1
+        	border_material Core/StatsBlockBorder
+        	border_topleft_uv     0.0000 1.0000 0.0039 0.9961
+	    	border_top_uv         0.0039 1.0000 0.9961 0.9961
+	    	border_topright_uv    0.9961 1.0000 1.0000 0.9961
+	    	border_left_uv        0.0000 0.9961 0.0039 0.0039
+	    	border_right_uv       0.9961 0.9961 1.0000 0.0039
+	    	border_bottomleft_uv  0.0000 0.0039 0.0039 0.0000
+        	border_bottom_uv      0.0039 0.0039 0.9961 0.0000
+	    	border_bottomright_uv 0.9961 0.0039 1.0000 0.0000
+
+		element TextArea(Example/Occlusion/FrustumCulledNodes)
+		{
+			metrics_mode pixels
+			left 5
+			top 5
+			width 180
+			height 30
+			font_name TrebuchetMSBold
+			char_height 16
+			caption Frustum Culled Nodes
+			colour_top 0.5 0.7 0.5
+			colour_bottom 0.3 0.5 0.3
+		}
+		element TextArea(Example/Occlusion/FrustumCulledNodesInfo)
+		{
+			metrics_mode pixels
+			left 180
+			top 5
+			width 90
+			height 30
+			font_name TrebuchetMSBold
+			char_height 16
+			caption :
+			colour_top 0.5 0.7 0.5
+			colour_bottom 0.3 0.5 0.3
+		}
+		element TextArea(Example/Occlusion/QueryCulledNodes)
+		{
+			metrics_mode pixels
+			left 5
+			top 20
+			width 180
+			height 30
+			font_name TrebuchetMSBold
+			char_height 16
+			caption Query Culled Nodes
+			colour_top 0.5 0.7 0.5
+			colour_bottom 0.3 0.5 0.3
+		}	
+		element TextArea(Example/Occlusion/QueryCulledNodesInfo)
+		{
+			metrics_mode pixels
+			left 180
+			top 20
+			width 90
+			height 30
+			font_name TrebuchetMSBold
+			char_height 16
+			caption :
+			colour_top 0.5 0.7 0.5
+			colour_bottom 0.3 0.5 0.3
+		}
+		element TextArea(Example/Occlusion/TraversedNodes)
+		{
+			metrics_mode pixels
+			left 5
+			top 35
+			width 180
+			height 30
+			font_name TrebuchetMSBold
+			char_height 16
+			caption Traversed Nodes
+			colour_top 0.5 0.7 0.5
+			colour_bottom 0.3 0.5 0.3
+		}	
+		element TextArea(Example/Occlusion/TraversedNodesInfo)
+		{
+			metrics_mode pixels
+			left 180
+			top 35
+			width 90
+			height 30
+			font_name TrebuchetMSBold
+			char_height 16
+			caption :
+			colour_top 0.5 0.7 0.5
+			colour_bottom 0.3 0.5 0.3
+		}
+		element TextArea(Example/Occlusion/SceneNodes)
+		{
+			metrics_mode pixels
+			left 5
+			top 50
+			width 180
+			height 30
+			font_name TrebuchetMSBold
+			char_height 16
+			caption Scene Nodes
+			colour_top 0.5 0.7 0.5
+			colour_bottom 0.3 0.5 0.3
+		}	
+		element TextArea(Example/Occlusion/SceneNodesInfo)
+		{
+			metrics_mode pixels
+			left 180
+			top 50
+			width 90
+			height 30
+			font_name TrebuchetMSBold
+			char_height 16
+			caption :
+			colour_top 0.5 0.7 0.5
+			colour_bottom 0.3 0.5 0.3
+		}
+		element TextArea(Example/Occlusion/HierarchyNodes)
+		{
+			metrics_mode pixels
+			left 5
+			top 65
+			width 180
+			height 30
+			font_name TrebuchetMSBold
+			char_height 16
+			caption Hierarchy Nodes
+			colour_top 0.5 0.7 0.5
+			colour_bottom 0.3 0.5 0.3
+		}	
+		element TextArea(Example/Occlusion/HierarchyNodesInfo)
+		{
+			metrics_mode pixels
+			left 180
+			top 65
+			width 90
+			height 30
+			font_name TrebuchetMSBold
+			char_height 16
+			caption :
+			colour_top 0.5 0.7 0.5
+			colour_bottom 0.3 0.5 0.3
+		}
+
+	}
+}
Index: trunk/VUT/OcclusionCullingSceneManager/scripts/OcclusionDemo.overlay
===================================================================
--- trunk/VUT/OcclusionCullingSceneManager/scripts/OcclusionDemo.overlay	(revision 32)
+++ 	(revision )
@@ -1,207 +1,0 @@
-Example/OcclusionDemoOverlay
-{
-	zorder 500
-	// Stats block
-	container BorderPanel(Example/Occlusion/OcclusionPanel)
-	{
-		metrics_mode pixels
-		vert_align top
-		left 5 
-		top 5
-		width 450
-		height 55
-		material Core/StatsBlockCenter
-        	border_size 1 1 1 1
-        	border_material Core/StatsBlockBorder
-        	border_topleft_uv     0.0000 1.0000 0.0039 0.9961
-	    	border_top_uv         0.0039 1.0000 0.9961 0.9961
-	    	border_topright_uv    0.9961 1.0000 1.0000 0.9961
-	    	border_left_uv        0.0000 0.9961 0.0039 0.0039
-	    	border_right_uv       0.9961 0.9961 1.0000 0.0039
-	    	border_bottomleft_uv  0.0000 0.0039 0.0039 0.0000
-        	border_bottom_uv      0.0039 0.0039 0.9961 0.0000
-	    	border_bottomright_uv 0.9961 0.0039 1.0000 0.0000
-
-
-		element TextArea(Example/Occlusion/Algorithm)
-		{
-			metrics_mode pixels
-			left 5
-			top 5
-			width 180
-			height 30
-			font_name TrebuchetMSBold
-			char_height 16
-			caption [A] Algorithm
-			colour_top 0.5 0.7 0.5
-			colour_bottom 0.3 0.5 0.3
-		}
-		element TextArea(Example/Occlusion/AlgorithmInfo)
-		{
-			metrics_mode pixels
-			left 155
-			top 5
-			width 90
-			height 30
-			font_name TrebuchetMSBold
-			char_height 16
-			caption :
-			colour_top 0.5 0.7 0.5
-			colour_bottom 0.3 0.5 0.3
-		}
-
-		element TextArea(Example/Occlusion/Threshold)
-		{
-			metrics_mode pixels
-			left 5
-			top 20
-			width 90
-			height 30
-			font_name TrebuchetMSBold
-			char_height 16
-			caption [-][+] Threshold
-			colour_top 0.5 0.7 0.5
-			colour_bottom 0.3 0.5 0.3
-		}
-		element TextArea(Example/Occlusion/ThresholdInfo)
-		{
-			metrics_mode pixels
-			left 155
-			top 20
-			width 90
-			height 30
-			font_name TrebuchetMSBold
-			char_height 16
-			caption :
-			colour_top 0.5 0.7 0.5
-			colour_bottom 0.3 0.5 0.3
-		}
-	}
-
-	container BorderPanel(Example/Occlusion/OcclusionStatsPanel)
-	{
-		metrics_mode pixels
-		vert_align top
-		horz_align right
-		left -355 
-		top 5
-		width 450
-		height 70
-		material Core/StatsBlockCenter
-        	border_size 1 1 1 1
-        	border_material Core/StatsBlockBorder
-        	border_topleft_uv     0.0000 1.0000 0.0039 0.9961
-	    	border_top_uv         0.0039 1.0000 0.9961 0.9961
-	    	border_topright_uv    0.9961 1.0000 1.0000 0.9961
-	    	border_left_uv        0.0000 0.9961 0.0039 0.0039
-	    	border_right_uv       0.9961 0.9961 1.0000 0.0039
-	    	border_bottomleft_uv  0.0000 0.0039 0.0039 0.0000
-        	border_bottom_uv      0.0039 0.0039 0.9961 0.0000
-	    	border_bottomright_uv 0.9961 0.0039 1.0000 0.0000
-
-		element TextArea(Example/Occlusion/FrustumCulledNodes)
-		{
-			metrics_mode pixels
-			left 5
-			top 5
-			width 180
-			height 30
-			font_name TrebuchetMSBold
-			char_height 16
-			caption Frustum Culled Nodes
-			colour_top 0.5 0.7 0.5
-			colour_bottom 0.3 0.5 0.3
-		}
-		element TextArea(Example/Occlusion/FrustumCulledNodesInfo)
-		{
-			metrics_mode pixels
-			left 180
-			top 5
-			width 90
-			height 30
-			font_name TrebuchetMSBold
-			char_height 16
-			caption :
-			colour_top 0.5 0.7 0.5
-			colour_bottom 0.3 0.5 0.3
-		}
-		element TextArea(Example/Occlusion/QueryCulledNodes)
-		{
-			metrics_mode pixels
-			left 5
-			top 20
-			width 180
-			height 30
-			font_name TrebuchetMSBold
-			char_height 16
-			caption Query Culled Nodes
-			colour_top 0.5 0.7 0.5
-			colour_bottom 0.3 0.5 0.3
-		}	
-		element TextArea(Example/Occlusion/QueryCulledNodesInfo)
-		{
-			metrics_mode pixels
-			left 180
-			top 20
-			width 90
-			height 30
-			font_name TrebuchetMSBold
-			char_height 16
-			caption :
-			colour_top 0.5 0.7 0.5
-			colour_bottom 0.3 0.5 0.3
-		}
-		element TextArea(Example/Occlusion/TraversedNodes)
-		{
-			metrics_mode pixels
-			left 5
-			top 35
-			width 180
-			height 30
-			font_name TrebuchetMSBold
-			char_height 16
-			caption Traversed Nodes
-			colour_top 0.5 0.7 0.5
-			colour_bottom 0.3 0.5 0.3
-		}	
-		element TextArea(Example/Occlusion/TraversedNodesInfo)
-		{
-			metrics_mode pixels
-			left 180
-			top 35
-			width 90
-			height 30
-			font_name TrebuchetMSBold
-			char_height 16
-			caption :
-			colour_top 0.5 0.7 0.5
-			colour_bottom 0.3 0.5 0.3
-		}
-		element TextArea(Example/Occlusion/SceneNodes)
-		{
-			metrics_mode pixels
-			left 5
-			top 50
-			width 180
-			height 30
-			font_name TrebuchetMSBold
-			char_height 16
-			caption Scene Nodes
-			colour_top 0.5 0.7 0.5
-			colour_bottom 0.3 0.5 0.3
-		}	
-		element TextArea(Example/Occlusion/SceneNodesInfo)
-		{
-			metrics_mode pixels
-			left 180
-			top 50
-			width 90
-			height 30
-			font_name TrebuchetMSBold
-			char_height 16
-			caption :
-			colour_top 0.5 0.7 0.5
-			colour_bottom 0.3 0.5 0.3
-		}
-	}
-}
Index: trunk/VUT/OcclusionCullingSceneManager/src/OgreOcclusionCullingSceneManager.cpp
===================================================================
--- trunk/VUT/OcclusionCullingSceneManager/src/OgreOcclusionCullingSceneManager.cpp	(revision 41)
+++ trunk/VUT/OcclusionCullingSceneManager/src/OgreOcclusionCullingSceneManager.cpp	(revision 42)
@@ -30,6 +30,28 @@
 	void OcclusionCullingSceneManager::_renderVisibleObjects( void )
 	{
-		mOcclusionCullingSceneTraverser->renderScene(mCameraInProgress, mSceneRoot);
+			//-- render background
+		clearSpecialCaseRenderQueues();
+		addSpecialCaseRenderQueue(RENDER_QUEUE_BACKGROUND);
+		addSpecialCaseRenderQueue(RENDER_QUEUE_SKIES_EARLY);
+	
+		setSpecialCaseRenderQueueMode(SceneManager::SCRQM_INCLUDE);
 		SceneManager::_renderVisibleObjects( );
+		_deleteRenderedQueueGroups();
+
+		//-- render visible objects (i.e., all but overlay)
+		clearSpecialCaseRenderQueues();
+		addSpecialCaseRenderQueue(RENDER_QUEUE_OVERLAY);
+		setSpecialCaseRenderQueueMode(SceneManager::SCRQM_EXCLUDE);
+
+		mOcclusionCullingSceneTraverser->setSceneRoot(mSceneRoot);
+		mOcclusionCullingSceneTraverser->renderScene(mCameraInProgress);
+
+		_deleteRenderedQueueGroups();
+
+		//-- render overlay
+		clearSpecialCaseRenderQueues();
+		SceneManager::_renderVisibleObjects( );
+	
+		clearSpecialCaseRenderQueues();
 	}
 	//-----------------------------------------------------------------------
@@ -41,9 +63,9 @@
 	void OcclusionCullingSceneManager::_updateSceneGraph( Camera* cam )
 	{
-		mOcclusionCullingSceneTraverser->setNumSceneNodes(mSceneNodes.size());
-		mOcclusionCullingSceneTraverser->setNumQueries(mSceneNodes.size());
+		mOcclusionCullingSceneTraverser->setNumSceneNodes((int)mSceneNodes.size());
 		mOcclusionCullingSceneTraverser->setRenderSystem(mDestRenderSystem);
-
-        mOcclusionCullingSceneTraverser->preprocess();
+		
+		//mOcclusionCullingSceneTraverser->setNumQueries((int)mSceneNodes.size());
+        //mOcclusionCullingSceneTraverser->preprocess();
 		
 		SceneManager::_updateSceneGraph(cam);
Index: trunk/VUT/OcclusionCullingSceneManager/src/OgreOcclusionCullingSceneTraverser.cpp
===================================================================
--- trunk/VUT/OcclusionCullingSceneManager/src/OgreOcclusionCullingSceneTraverser.cpp	(revision 41)
+++ trunk/VUT/OcclusionCullingSceneManager/src/OgreOcclusionCullingSceneTraverser.cpp	(revision 42)
@@ -17,5 +17,5 @@
 	mQueryMode(MODE_RENDER), mNumSceneNodes(0), mCurrentAlgorithm(RENDER_COHERENT),
 	mNumQueries(0), mNumTraversedNodes(0), mNumQueryCulledNodes(0), mNumFrustumCulledNodes(0), 
-	mNumRenderedGeometry(0), mSceneManager(sm), mRenderSystem(rsys)
+	mNumRenderedGeometry(0), mSceneManager(sm), mRenderSystem(rsys), mSceneRoot(NULL)
 	{		
 		mHalfBoundingBox[0] = mHalfBoundingBox[1] = 0;
@@ -28,8 +28,11 @@
 
 		deleteQueries();
+
+		if(mDistanceQueue)
+			delete mDistanceQueue;
 		//SceneManager::~SceneManager();
 	}
 	//-----------------------------------------------------------------------
-	void OcclusionCullingSceneTraverser::renderScene( Camera *cam, SceneNode *root )
+	void OcclusionCullingSceneTraverser::renderScene( Camera *cam )
 	{
 		mNumTraversedNodes = 0;
@@ -38,7 +41,7 @@
 		mNumRenderedGeometry = 0;
 		
-		mDistanceQueue = new PriorityQueue(myless<SceneNode *>(cam));
-		mDistanceQueue->push(root);
 		mCurrentTestIdx = 0;
+
+		initDistanceQueue(cam);
 
 //mCurrentAlgorithm = RENDER_CULL_FRUSTUM;
@@ -59,6 +62,4 @@
 		}	
 		
-		delete mDistanceQueue;
-
 		mFrameId ++;
 	}
@@ -85,5 +86,5 @@
 				if(visiblePixels > mVisibilityThreshold)
 				{
-					pullUpVisibility(node);
+					pullUpVisibility(cam, node);
 					traverseNode(cam, node);
 				}
@@ -100,8 +101,20 @@
 				mDistanceQueue->pop();
 				
+				bool intersects = false;
 				//TODO: Isvisible also checked inside scenenode::findvisibleobjects
-				if(!cam->isVisible(node->_getWorldAABB()))
+				if(!cam->isVisible(node->_getWorldAABB(), intersects))
 				{
                     mNumFrustumCulledNodes ++;
+					continue;
+				}
+
+				// if intersects near plane => skip occlusion query because wrong results possible
+				if(intersects)
+				{
+					// update node's visited flag
+					node->setLastVisited(mFrameId);
+					pullUpVisibility(cam, node);			
+					traverseNode(cam, node);
+
 					continue;
 				}
@@ -152,8 +165,4 @@
 			if(!cam->isVisible(node->_getWorldAABB()))
 			{			
-				char msg2[100];
-				sprintf(msg2,"no, invisible\n");
-				OutputDebugString(msg2);
-
 				mNumFrustumCulledNodes ++;
 				continue;
@@ -164,8 +173,4 @@
 			node->setNodeVisible(true);
 			traverseNode(cam, node);
-
-			char msg2[100];
-			sprintf(msg2,"yes, visible\n");
-			OutputDebugString(msg2);
 		}
 	}	
@@ -182,8 +187,18 @@
 			node->setLastVisited(mFrameId);
 
+			bool intersects = false;
 			//TODO: Isvisible also checked inside scenenode::findvisibleobjects
-			if(!cam->isVisible(node->_getWorldAABB()))
+			if(!cam->isVisible(node->_getWorldAABB(), intersects))
 			{
 				mNumFrustumCulledNodes ++;
+				continue;
+			}
+
+			// if intersects near plane => skip occlusion query because wrong results possible
+			if(intersects)
+			{
+				node->setNodeVisible(true);
+				traverseNode(cam, node);
+
 				continue;
 			}
@@ -198,4 +213,5 @@
 			if(visiblePixels > mVisibilityThreshold)
 			{
+				node->setNodeVisible(true);
 				traverseNode(cam, node);
 			}
@@ -215,10 +231,6 @@
 		//setRenderingMode(MODE_RENDER);
 
-		char msg2[100];
-		sprintf(msg2,"this is query %d of overall %d\n", mCurrentTestIdx, mNumQueries);
-		OutputDebugString(msg2);
-
 		// get next available test id
-		HardwareOcclusionQuery *query = mOcclusionQueries[mCurrentTestIdx++];
+		HardwareOcclusionQuery *query = getNextOcclusionQuery();
 
 		//-- the actual query test
@@ -275,5 +287,5 @@
 	}
 	//-----------------------------------------------------------------------
-	void OcclusionCullingSceneTraverser::preprocess( void )
+/*	void OcclusionCullingSceneTraverser::preprocess( void )
 	{
 		//-- initialise occlusion queries.
@@ -284,5 +296,5 @@
 			mOcclusionQueries.push_back(mRenderSystem->createHardwareOcclusionQuery());
 		}	
-	}
+	}*/
 	//-----------------------------------------------------------------------
 	void OcclusionCullingSceneTraverser::setSceneManager( SceneManager *sm )
@@ -316,10 +328,16 @@
 	}
 	//-----------------------------------------------------------------------
-	void OcclusionCullingSceneTraverser::pullUpVisibility( SceneNode *node )
+	void OcclusionCullingSceneTraverser::pullUpVisibility( Camera *cam, SceneNode *node )
 	{
 		while(node && !node->isNodeVisible())
 		{
+			// if we come across some renderable geometry => render it
+			if(node->numAttachedObjects() > 0)
+			{
+				renderSceneNode(cam, node);
+			}
+
 			node->setNodeVisible(true);
-			node = static_cast<SceneNode *>(node->getParent());
+			node = node->getParentSceneNode();
 		}
 	}
@@ -327,5 +345,5 @@
 	void OcclusionCullingSceneTraverser::deleteQueries( void )
 	{
-		for(unsigned int i=0; i < mOcclusionQueries.size(); i++)
+		for(unsigned int i=0; i < (unsigned int)mOcclusionQueries.size(); i++)
 			delete mOcclusionQueries[i];
 
@@ -363,4 +381,35 @@
 
 		return mHalfBoundingBox[half];	
+	}
+	//-----------------------------------------------------------------------
+	void OcclusionCullingSceneTraverser::setNumSceneNodes(int num)
+	{
+		mNumSceneNodes = num;
+	}
+	//-----------------------------------------------------------------------
+	/*void OcclusionCullingSceneTraverser::setNumQueries(int num)
+	{
+		mNumQueries = num;
+	}*/
+	//-----------------------------------------------------------------------
+	void OcclusionCullingSceneTraverser::setSceneRoot(SceneNode *root)
+	{
+		mSceneRoot = root;
+	}
+	//-----------------------------------------------------------------------
+	void OcclusionCullingSceneTraverser::initDistanceQueue(Camera *cam)
+	{
+		mDistanceQueue = new PriorityQueue(myless<SceneNode *>(cam));
+		mDistanceQueue->push(mSceneRoot);
+	}
+	//-----------------------------------------------------------------------
+	HardwareOcclusionQuery *OcclusionCullingSceneTraverser::getNextOcclusionQuery(void)
+	{
+		if(mCurrentTestIdx == mOcclusionQueries.size())
+		{
+			mOcclusionQueries.push_back(mRenderSystem->createHardwareOcclusionQuery());
+		}
+		
+		return mOcclusionQueries[mCurrentTestIdx ++];
 	}
 	//-----------------------------------------------------------------------
@@ -428,13 +477,3 @@
 		return true;
 	}
-	//-----------------------------------------------------------------------
-	void OcclusionCullingSceneTraverser::setNumSceneNodes(int num)
-	{
-		mNumSceneNodes = num;
-	}
-	//-----------------------------------------------------------------------
-	void OcclusionCullingSceneTraverser::setNumQueries(int num)
-	{
-		mNumQueries = num;
-	}
 }	
Index: trunk/VUT/OcclusionCullingSceneManager/src/OgreOcclusionCullingTerrainSceneManager.cpp
===================================================================
--- trunk/VUT/OcclusionCullingSceneManager/src/OgreOcclusionCullingTerrainSceneManager.cpp	(revision 41)
+++ trunk/VUT/OcclusionCullingSceneManager/src/OgreOcclusionCullingTerrainSceneManager.cpp	(revision 42)
@@ -16,10 +16,9 @@
 		mOcclusionCullingTerrainSceneTraverser = 
 			new OcclusionCullingTerrainSceneTraverser(this, mDestRenderSystem);
-			//new OcclusionCullingSceneTraverser(this, mDestRenderSystem);
 
 		//mDisplayNodes = true;
 		//mShowBoundingBoxes = true;
 		mShowBoxes = true;
-		mMaxDepth = 20;
+		//mMaxDepth = 20;
 	}
 	//-----------------------------------------------------------------------
@@ -45,7 +44,7 @@
 		setSpecialCaseRenderQueueMode(SceneManager::SCRQM_EXCLUDE);
 
-		mOcclusionCullingTerrainSceneTraverser->renderScene(mCameraInProgress, mOctree);
-		//mOcclusionCullingTerrainSceneTraverser->renderScene(mCameraInProgress, mTerrainRoot);
-		//mOcclusionCullingTerrainSceneTraverser->renderScene(mCameraInProgress, mSceneRoot);
+		mOcclusionCullingTerrainSceneTraverser->setSceneRoot(mOctree);
+		mOcclusionCullingTerrainSceneTraverser->renderScene(mCameraInProgress);
+		
 		_deleteRenderedQueueGroups();
 
@@ -61,15 +60,15 @@
 		// must be empty because objects are found and rendered in an interleaved fashion
 		// in _renderVisibibleObjects 
+		//char *msg = "now finding visible objects\n"; OutputDebugString(msg);
 	}
 	//-----------------------------------------------------------------------
 	void OcclusionCullingTerrainSceneManager::_updateSceneGraph(Camera* cam)
 	{
-     	mOcclusionCullingTerrainSceneTraverser->setNumSceneNodes(mSceneNodes.size());
-		//HACK
-		mOcclusionCullingTerrainSceneTraverser->setNumQueries(countOctreeSize(mOctree));
+		//char *msg = "now updating scenegraph\n"; OutputDebugString(msg);
+     	mOcclusionCullingTerrainSceneTraverser->setNumSceneNodes((int)mSceneNodes.size());
 		mOcclusionCullingTerrainSceneTraverser->setRenderSystem(mDestRenderSystem);
+        //mOcclusionCullingTerrainSceneTraverser->preprocess();
+		mOcclusionCullingTerrainSceneTraverser->setNumOctreeNodes(mNumOctreeNodes);
 
-        mOcclusionCullingTerrainSceneTraverser->preprocess();
-		
 		TerrainSceneManager::_updateSceneGraph(cam);
 	}
@@ -132,17 +131,17 @@
 	}
 	//-----------------------------------------------------------------------
-	unsigned int OcclusionCullingTerrainSceneManager::countOctreeSize(Octree *root)
+	/*unsigned int OcclusionCullingTerrainSceneManager::countNumOctrees(Octree *root)
 	{
 		unsigned int result = 1;
 				
-		for(int i=0; i<8; i++)
+		for(int i=0; i<8; ++i)
 		{
 			Octree *nextChild = root->mChildren[(i & 4) >> 2][(i & 2) >> 1][i & 1];
 		
 			if(nextChild != 0)
-				result += countOctreeSize(nextChild);
+				result += countNumOctrees(nextChild);
 		}
 		
 		return result;
-	}
+	}*/
 }	
Index: trunk/VUT/OcclusionCullingSceneManager/src/OgreOcclusionCullingDotSceneManager.cpp
===================================================================
--- trunk/VUT/OcclusionCullingSceneManager/src/OgreOcclusionCullingDotSceneManager.cpp	(revision 39)
+++ trunk/VUT/OcclusionCullingSceneManager/src/OgreOcclusionCullingDotSceneManager.cpp	(revision 42)
@@ -41,5 +41,6 @@
 		setSpecialCaseRenderQueueMode(SceneManager::SCRQM_EXCLUDE);
 
-		mOcclusionCullingSceneTraverser->renderScene(mCameraInProgress, mSceneRoot);
+		mOcclusionCullingSceneTraverser->setSceneRoot(mSceneRoot);
+		mOcclusionCullingSceneTraverser->renderScene(mCameraInProgress);
 		_deleteRenderedQueueGroups();
 
@@ -59,8 +60,8 @@
 	void OcclusionCullingDotSceneManager::_updateSceneGraph(Camera* cam)
 	{
-		mOcclusionCullingSceneTraverser->setNumSceneNodes(mSceneNodes.size());
+		mOcclusionCullingSceneTraverser->setNumSceneNodes((int)mSceneNodes.size());
 		mOcclusionCullingSceneTraverser->setRenderSystem(mDestRenderSystem);
 
-        mOcclusionCullingSceneTraverser->preprocess();
+        //mOcclusionCullingSceneTraverser->preprocess();
 		
 		DotSceneManager::_updateSceneGraph(cam);
Index: trunk/VUT/OcclusionCullingSceneManager/src/OgreOcclusionCullingTerrainSceneTraverser.cpp
===================================================================
--- trunk/VUT/OcclusionCullingSceneManager/src/OgreOcclusionCullingTerrainSceneTraverser.cpp	(revision 41)
+++ trunk/VUT/OcclusionCullingSceneManager/src/OgreOcclusionCullingTerrainSceneTraverser.cpp	(revision 42)
@@ -8,6 +8,12 @@
 	//-----------------------------------------------------------------------
 	OcclusionCullingTerrainSceneTraverser::OcclusionCullingTerrainSceneTraverser(SceneManager *sm, RenderSystem *rsys): 
-	OcclusionCullingSceneTraverser(sm, rsys)
-	{
+	OcclusionCullingSceneTraverser(sm, rsys), mOctreeSceneRoot(0), mOctreeDistanceQueue(0)
+	{
+	}
+	//-----------------------------------------------------------------------
+	OcclusionCullingTerrainSceneTraverser::~OcclusionCullingTerrainSceneTraverser()
+	{		
+		if(mOctreeDistanceQueue)
+			delete mOctreeDistanceQueue;
 	}
 	//-----------------------------------------------------------------------
@@ -16,6 +22,9 @@
 		mNumTraversedNodes ++;
 	
-		//if(octant->numNodes() > 0)
+		// if we come across some renderable geometry => render it
+		if(octant->numNodes() > 0)
+		{
 			renderOctant(cam, octant);
+		}
 
 		for(int i=0; i<8; i++)
@@ -23,42 +32,7 @@
 			Octree *nextChild = octant->mChildren[(i & 4) >> 2][(i & 2) >> 1][i & 1];
 		
-			if(nextChild != 0)
-				mDistanceQueue->push(nextChild);
-		}
-	}
-	//-----------------------------------------------------------------------
-	void OcclusionCullingTerrainSceneTraverser::renderScene( Camera *cam, Octree *root )
-		//TODO: Renderscene independent from hierarchynode => implement only once
-	{
-		mNumTraversedNodes = 0;
-		mNumQueryCulledNodes = 0;
-		mNumFrustumCulledNodes = 0;
-		mNumRenderedGeometry = 0;
-		
-		mDistanceQueue = new OctreePriorityQueue(octreeless<Octree *>(cam));
-		mDistanceQueue->push(root);
-		mCurrentTestIdx = 0;
-		
-//mCurrentAlgorithm = RENDER_CULL_FRUSTUM;
-		switch(mCurrentAlgorithm)
-		{
-			case RENDER_CULL_FRUSTUM:
-				renderCullFrustum(cam);
-		        break;
-			case RENDER_STOP_AND_WAIT:
-				renderStopAndWait(cam);
-				break;
-			case RENDER_COHERENT:
-				//renderCoherentWithQueue(cam);
-				renderStopAndWait(cam);
-				break;
-			default:
-				renderCullFrustum(cam);
-				break;
-		}	
-		
-		delete mDistanceQueue;
-
-		mFrameId ++;
+			if(nextChild)
+				mOctreeDistanceQueue->push(nextChild);
+		}
 	}
 	//-----------------------------------------------------------------------
@@ -67,8 +41,8 @@
 		AxisAlignedBox box;
 
-		while(!mDistanceQueue->empty())
-		{
-			Octree *octant = mDistanceQueue->top();
-			mDistanceQueue->pop();
+		while(!mOctreeDistanceQueue->empty())
+		{
+			Octree *octant = mOctreeDistanceQueue->top();
+			mOctreeDistanceQueue->pop();
 	
 			// interesting for visualization purpose
@@ -76,5 +50,5 @@
 			octant->_getCullBounds(&box);
 			
-			if(static_cast<OctreeCamera *>(cam)->getVisibility(box) == OctreeCamera::NONE)
+			//if(static_cast<OctreeCamera *>(cam)->getVisibility(box) == OctreeCamera::NONE)
 			if(!cam->isVisible(box))
 			{
@@ -84,6 +58,6 @@
 
 			// update node's visited flag 
-			//TODO: octree->setLastVisited(mFrameId);
-			//TODO: octree->setNodeVisible(true);
+			octant->setLastVisited(mFrameId);
+			octant->setOctreeVisible(true);
 		
 			traverseOctant(cam, octant);
@@ -96,27 +70,29 @@
 		AxisAlignedBox box;
 
-		while(!mDistanceQueue->empty())
-		{
-			Octree *octant = mDistanceQueue->top();
-			mDistanceQueue->pop();
+		while(!mOctreeDistanceQueue->empty())
+		{
+			Octree *octant = mOctreeDistanceQueue->top();
+			mOctreeDistanceQueue->pop();
 		
 			// interesting for visualization purpose
-			//octant->setNodeVisible(false);
-			//octant->setLastVisited(mFrameId);
+			octant->setOctreeVisible(false);
+			octant->setLastVisited(mFrameId);
 
 			//TODO: Isvisible also checked inside scenenode::findvisibleobjects
 			octant->_getCullBounds(&box);
 
-			char msg[100]; 
-			Vector3 max = box.getMaximum();
-			Vector3 min = box.getMinimum();
-
-			sprintf(msg, "box max: %3.3f, %3.3f, %3.3f, min: %3.3f, %3.3f, %3.3f\n",max.x,max.y,max.z,min.x,min.y,min.z);
-			OutputDebugString(msg);
-
-			if(static_cast<OctreeCamera *>(cam)->getVisibility(box) == OctreeCamera::NONE)
-			//if(!cam->isVisible(box))
+			bool intersects = false;
+
+			//if(vis == OctreeCamera::NONE)
+			if(!cam->isVisible(box, intersects))
 			{
 				mNumFrustumCulledNodes ++;
+				continue;
+			}
+			// if intersects near plane => skip occlusion query because wrong results possible
+			if(intersects)
+			{
+				octant->setOctreeVisible(true);
+				traverseOctant(cam, octant);
 				continue;
 			}
@@ -127,10 +103,9 @@
 			// wait if result not available
 			query->pullOcclusionQuery(&visiblePixels);
-//traverseOctant(cam, octant);			
+			
 			// node visible
 			if(visiblePixels > mVisibilityThreshold)
 			{
 				traverseOctant(cam, octant);
-				//mNumQueryCulledNodes ++;
 			}
 			else
@@ -144,14 +119,165 @@
 	void OcclusionCullingTerrainSceneTraverser::renderCoherentWithQueue( Camera *cam )
 	{
-	}
-	//-----------------------------------------------------------------------
-	void OcclusionCullingTerrainSceneTraverser::pullUpVisibility( Octree *node )
-	{
-	}
-	//-----------------------------------------------------------------------
-	void OcclusionCullingTerrainSceneTraverser::renderOctant( Camera *cam, Octree *octree )
-	{
-		setRenderingMode(MODE_RENDER);
-		((OcclusionCullingTerrainSceneManager *)mSceneManager)->_renderOctant(cam, octree);
+		OctreeQueryQueue queryQueue;
+		AxisAlignedBox box;
+
+		//-- PART 1: process finished occlusion queries
+		while(!mOctreeDistanceQueue->empty() || !queryQueue.empty())
+		{
+			while(!queryQueue.empty() && 
+				  ((queryQueue.front().second)->resultAvailable() || mOctreeDistanceQueue->empty()))
+			{
+				Octree *octant = queryQueue.front().first;
+				HardwareOcclusionQuery *query = queryQueue.front().second;
+
+				queryQueue.pop();
+			
+				// wait until result available
+				unsigned int visiblePixels;
+				query->pullOcclusionQuery(&visiblePixels);
+
+				if(visiblePixels > mVisibilityThreshold)
+				{
+					pullUpVisibility(cam, octant);
+					traverseOctant(cam, octant);
+				}
+				else
+				{
+					mNumQueryCulledNodes ++;
+				}
+			}	
+
+			//-- PART 2: hierarchical traversal
+			if(!mOctreeDistanceQueue->empty())
+			{
+				Octree *octant = mOctreeDistanceQueue->top();
+				mOctreeDistanceQueue->pop();
+					
+				octant->_getCullBounds(&box);
+
+				bool intersects = false;
+				//TODO: Isvisible also checked inside scenenode::findvisibleobjects
+				if(!cam->isVisible(box, intersects))
+				{
+                    mNumFrustumCulledNodes ++;
+					continue;
+				}
+
+				// if intersects near plane => skip occlusion query because wrong results possible
+				if(intersects)
+				{
+					// update node's visited flag
+					octant->setLastVisited(mFrameId);
+					pullUpVisibility(cam, octant);			
+					traverseOctant(cam, octant);
+
+					continue;
+				}
+
+				// identify previously visible nodes
+				bool wasVisible = octant->isOctreeVisible() && (octant->lastVisited() == mFrameId - 1);
+					
+				// identify nodes that we cannot skip queries for
+				bool leafOrWasInvisible = !wasVisible || isLeaf(octant);
+
+				// reset node's visibility classification 
+				octant->setOctreeVisible(false);
+
+				// update node's visited flag
+				octant->setLastVisited(mFrameId);
+			
+				// skip testing previously visible interior nodes
+				if(leafOrWasInvisible)
+				{
+					HardwareOcclusionQuery *query = issueOcclusionQuery(&box, wasVisible);
+					queryQueue.push(OctreeQueryPair(octant, query));
+				}
+					
+				// always traverse a node if it was visible
+				if(wasVisible)
+				{
+					traverseOctant(cam, octant);
+				}
+				else
+				{
+					mNumFrustumCulledNodes ++;
+				}
+			}
+		}
+	}
+	//-----------------------------------------------------------------------
+	void OcclusionCullingTerrainSceneTraverser::pullUpVisibility( Camera *cam, Octree *octant )
+	{
+		while(octant && !octant->isOctreeVisible())
+		{
+			// if we come across some renderable geometry => render it
+			if(octant->numNodes() > 0)
+			{
+				renderOctant(cam, octant);
+			}
+
+			octant->setOctreeVisible(true);
+			octant = octant->getParent();
+		}
+	}
+	//-----------------------------------------------------------------------
+	void OcclusionCullingTerrainSceneTraverser::renderOctant( Camera *cam, Octree *octant )
+	{
+		if(octant->lastVisited() != octant->lastRendered())
+		{
+			setRenderingMode(MODE_RENDER);
+
+			octant->setLastRendered(octant->lastVisited());
+			((OcclusionCullingTerrainSceneManager *)mSceneManager)->_renderOctant(cam, octant);
+		}
+		else OutputDebugString("already rendered");
+	}
+	//-----------------------------------------------------------------------
+	void OcclusionCullingTerrainSceneTraverser::setSceneRoot(Octree *root)
+	{
+		mOctreeSceneRoot = root;
+	}
+	//-----------------------------------------------------------------------
+	void OcclusionCullingTerrainSceneTraverser::initDistanceQueue(Camera *cam)
+	{
+		if(mOctreeDistanceQueue)
+			delete mOctreeDistanceQueue;
+
+		mOctreeDistanceQueue = new OctreePriorityQueue(octreeless<Octree *>(cam));
+		mOctreeDistanceQueue->push(mOctreeSceneRoot);
+	}
+	//-----------------------------------------------------------------------
+	bool OcclusionCullingTerrainSceneTraverser::isLeaf(Octree *octant)
+	{
+		for(int i=0; i<8; i++)
+		{
+			if(octant->mChildren[(i & 4) >> 2][(i & 2) >> 1][i & 1])
+				return false;
+		}
+
+		return true;
+	}
+	//-----------------------------------------------------------------------
+	void OcclusionCullingTerrainSceneTraverser::setNumOctreeNodes(unsigned int num)
+	{
+		mNumOctreeNodes = num;
+	}
+	//-----------------------------------------------------------------------
+	bool OcclusionCullingTerrainSceneTraverser::getOption( const String & key, void *val )
+	{
+		if ( key == "NumOctreeNodes" )
+		{
+			* static_cast < unsigned int * > ( val ) = mNumOctreeNodes;
+			return true;
+		}
+
+		return OcclusionCullingSceneTraverser::getOption(key, val);
+	}
+	//-----------------------------------------------------------------------
+	bool OcclusionCullingTerrainSceneTraverser::getOptionKeys( StringVector & refKeys )
+	{
+		refKeys.push_back( "NumOctreeNodes" );
+		
+		return OcclusionCullingSceneTraverser::getOptionKeys(refKeys);		
 	}
 }	
Index: trunk/VUT/OcclusionCullingSceneManager/TestCulling/TestCullingApplication.cpp
===================================================================
--- trunk/VUT/OcclusionCullingSceneManager/TestCulling/TestCullingApplication.cpp	(revision 41)
+++ trunk/VUT/OcclusionCullingSceneManager/TestCulling/TestCullingApplication.cpp	(revision 42)
@@ -61,6 +61,7 @@
 	// because the vertex program picked will be different
 	ColourValue fadeColour(0.93, 0.86, 0.76);
-	mSceneMgr->setFog( FOG_LINEAR, fadeColour, .001, 500, 1000);
- //mSceneMgr->setFog( FOG_EXP, fadeColour, 0.005 );
+	//mSceneMgr->setFog( FOG_LINEAR, fadeColour, .001, 500, 1000);
+    //mSceneMgr->setFog( FOG_EXP, fadeColour, 0.005 );
+
 	mWindow->getViewport(0)->setBackgroundColour(fadeColour);
 
@@ -75,8 +76,8 @@
 	mSceneMgr -> setWorldGeometry( terrain_cfg );
 	// Infinite far plane?
-/*	if (mRoot->getRenderSystem()->getCapabilities()->hasCapability(RSC_INFINITE_FAR_PLANE))
+	if (mRoot->getRenderSystem()->getCapabilities()->hasCapability(RSC_INFINITE_FAR_PLANE))
 	{
 		mCamera->setFarClipDistance(0);
-	}*/
+	}
 
 /*	// Define the required skyplane
@@ -180,5 +181,5 @@
 
 	// show overlay
-	Overlay* pOver = OverlayManager::getSingleton().getByName("Example/OcclusionDemoOverlay"); 
+	Overlay* pOver = OverlayManager::getSingleton().getByName("Example/OcclusionCullingDemoOverlay"); 
 
 	mAlgorithmInfo = OverlayManager::getSingleton().getOverlayElement("Example/Occlusion/AlgorithmInfo");
@@ -187,4 +188,6 @@
 	mQueryCulledNodesInfo = OverlayManager::getSingleton().getOverlayElement("Example/Occlusion/QueryCulledNodesInfo");
     mTraversedNodesInfo = OverlayManager::getSingleton().getOverlayElement("Example/Occlusion/TraversedNodesInfo");
+	mSceneNodesInfo = OverlayManager::getSingleton().getOverlayElement("Example/Occlusion/SceneNodesInfo");
+	mHierarchyNodesInfo = OverlayManager::getSingleton().getOverlayElement("Example/Occlusion/HierarchyNodesInfo");
 
 	mAlgorithmInfo->setCaption(": " + mCurrentAlgorithmCaptions[mCurrentAlgorithm]);
@@ -193,4 +196,6 @@
 	mQueryCulledNodesInfo->setCaption(": 0");
 	mTraversedNodesInfo->setCaption(": 0");
+	mSceneNodesInfo->setCaption(": 0");
+	mHierarchyNodesInfo->setCaption(": 0");
 
     pOver->show();
@@ -325,4 +330,10 @@
 	mSceneMgr->getOption("NumTraversedNodes", &opt); sprintf(str,": %d", opt); 
 	mTraversedNodesInfo->setCaption(str);
+
+	mSceneMgr->getOption("NumSceneNodes", &opt); sprintf(str,": %d", opt); 
+	mSceneNodesInfo->setCaption(str);
+
+	mSceneMgr->getOption("NumOctreeNodes", &opt); sprintf(str,": %d", opt); 
+	mHierarchyNodesInfo->setCaption(str);
 }
 //-----------------------------------------------------------------------
Index: trunk/VUT/OcclusionCullingSceneManager/TestCulling/TestCullingApplication.h
===================================================================
--- trunk/VUT/OcclusionCullingSceneManager/TestCulling/TestCullingApplication.h	(revision 34)
+++ trunk/VUT/OcclusionCullingSceneManager/TestCulling/TestCullingApplication.h	(revision 42)
@@ -80,4 +80,6 @@
 	OverlayElement *mQueryCulledNodesInfo;
     OverlayElement *mTraversedNodesInfo;
+	OverlayElement *mHierarchyNodesInfo;
+	OverlayElement *mSceneNodesInfo;
 };
 
