Index: trunk/VUT/OcclusionCullingSceneManager/include/OgreOcclusionCullingSceneManager.h
===================================================================
--- trunk/VUT/OcclusionCullingSceneManager/include/OgreOcclusionCullingSceneManager.h	(revision 30)
+++ trunk/VUT/OcclusionCullingSceneManager/include/OgreOcclusionCullingSceneManager.h	(revision 32)
@@ -4,4 +4,5 @@
 #include "OgreSceneNode.h"
 #include "OgreSceneManager.h"
+#include "OgreOcclusionCullingSceneTraverser.h"
 #include "OgrePrerequisites.h"
 #include "OgreSolidHalfBoundingBox.h"
@@ -11,24 +12,5 @@
 
 namespace Ogre {
-	/**
-		This class implements the compare operator for the priority queue.
-		a lower distance has a higher value in the queue
-	*/
-	template <typename T> class myless
-	{
-	public:
-		myless(Camera *cam) { mCamera = cam; }
-		//bool operator() (HierarchyNode *v1, HierarchyNode *v2) const
-		bool operator() (T v1, T v2) const
-		{
-			return v1->getSquaredViewDepth(mCamera) > v2->getSquaredViewDepth(mCamera);
-		}
-	private:
-		Camera *mCamera;
-	};
-
-	typedef pair<SceneNode *, HardwareOcclusionQuery *> query_pair;
-	typedef priority_queue<SceneNode *, vector<SceneNode *>, myless<vector<SceneNode *>::value_type> > PriorityQueue;
-	typedef queue<query_pair> QueryQueue;
+	
 	/**
 		Class which implements a scene mangager which uses occlusion queries for culling occluded objects
@@ -38,8 +20,6 @@
 	public:
 		OcclusionCullingSceneManager();
-		~OcclusionCullingSceneManager();
+		//~OcclusionCullingSceneManager();
 	
-		enum {RENDER_CULL_FRUSTUM, RENDER_STOP_AND_WAIT, RENDER_COHERENT, NUM_RENDERMODES};
-		
 		/** Overriden from SceneManager. Renders the scene with the specified algorithm
 		/**
@@ -69,57 +49,6 @@
 
 	protected:
-		enum {MODE_QUERY, MODE_RENDER};
-
-		bool isLeaf(SceneNode *node);
-		unsigned int countSceneNodes(SceneNode *node);
-		void renderZPass();
-		void traverseNode(SceneNode *node);
-		/** Renders current node */
-		void render(SceneNode *node);
-		/** Sets rendering mode, e.g. query mode or render mode*/
-		void setRenderingMode(int mode);
-		
-		/** Renders the scene with view frustum culling only. */
-		void renderCullFrustum();
-		/** Renders the scene with the hierarchical stop and wait algorithm. */
-		void renderStopAndWait();
-		/** Renders the scene with the coherent hierarchical algorithm and the query queye. */
-		void renderCoherentWithQueue();
-		/** Issue a occlusion query for this node. */
-		HardwareOcclusionQuery *issueOcclusionQuery(SceneNode *node, bool wasVisible);
-		/** Pulls up the visibility from the child nodes. */
-		void pullUpVisibility(SceneNode *node);
-		/** delete all previously defined occlusion queries */
-		void deleteQueries();
-		/** Renders bounding box of specified node.
-		@param the node which bounding box is to be rendered
-		*/
-		void renderBoundingBox(SceneNode *node);
-		/** Returns one half of the bounding box.
-		@param the half of the bouding box
-		*/
-		SolidHalfBoundingBox *getSolidHalfBoundingBox(int half);
-		
-
-		// we use a priority queue rather than a renderstack
-		PriorityQueue *mDistanceQueue; 
-		
-			std::vector<HardwareOcclusionQuery *> mOcclusionQueries;
-		// two halfes of a aabb
-		SolidHalfBoundingBox *mHalfBoundingBox[2];	
-		int mCurrentAlgorithm;
-
-		unsigned int mFrameId;
-		unsigned int mVisibilityThreshold;
-		
-		int mCurrentTestIdx;
-		int mQueryMode;
-
-		//--- statistics
-		unsigned int mNumSceneNodes;
-		unsigned int mNumTraversedNodes;
-		unsigned int mNumQueryCulledNodes;
-		unsigned int mNumFrustumCulledNodes;
-		unsigned int mNumRenderedGeometry;
+		OcclusionCullingSceneTraverser mSceneTraverser;
+	
 	};
 
Index: trunk/VUT/OcclusionCullingSceneManager/include/OgreOcclusionCullingSceneTraverser.h
===================================================================
--- trunk/VUT/OcclusionCullingSceneManager/include/OgreOcclusionCullingSceneTraverser.h	(revision 32)
+++ trunk/VUT/OcclusionCullingSceneManager/include/OgreOcclusionCullingSceneTraverser.h	(revision 32)
@@ -0,0 +1,140 @@
+#ifndef _OcclusionCullingSceneTraverser_H__
+#define _OcclusionCullingSceneTraverser_H__
+
+#include "OgreSceneNode.h"
+#include "OgreSceneManager.h"
+#include "OgrePrerequisites.h"
+#include "OgreSolidHalfBoundingBox.h"
+#include "OgreCamera.h"
+#include "OgreRenderSystem.h"
+#include <queue>
+
+using namespace std;
+
+namespace Ogre {
+	/**
+		This class implements the compare operator for the priority queue.
+		a lower distance has a higher value in the queue
+	*/
+	template <typename T> class myless
+	{
+	public:
+		myless(Camera *cam) { mCamera = cam; }
+		//bool operator() (HierarchyNode *v1, HierarchyNode *v2) const
+		bool operator() (T v1, T v2) const
+		{
+			return v1->getSquaredViewDepth(mCamera) > v2->getSquaredViewDepth(mCamera);
+		}
+	private:
+		Camera *mCamera;
+	};
+
+	typedef pair<SceneNode *, HardwareOcclusionQuery *> query_pair;
+	typedef priority_queue<SceneNode *, vector<SceneNode *>, myless<vector<SceneNode *>::value_type> > PriorityQueue;
+	typedef queue<query_pair> QueryQueue;
+	/**
+		Class which implements a scene mangager which uses occlusion queries for culling occluded objects
+	*/
+	class OcclusionCullingSceneTraverser
+	{
+	public:
+		OcclusionCullingSceneTraverser();
+		~OcclusionCullingSceneTraverser();
+	
+		enum {RENDER_CULL_FRUSTUM, RENDER_STOP_AND_WAIT, RENDER_COHERENT, NUM_RENDERMODES};
+		
+		/** Overriden from SceneManager. Renders the scene with the specified algorithm
+		/**
+			The algorithm is one of
+			RENDER_CULL_FRUSTUM: renders the scene with view frustum culling only
+			RENDER_STOP_AND_WAIT: renders the scene with the hierarchical stop and wait algorithm
+			RENDER_COHERENT: renders the scene with the coherent hierarchical algorithm
+		*/
+		
+		/** Sets the given option for the SceneTraverser
+			       @remarks
+			Options are:
+			"Algorithm", int *;			
+		*/
+		bool setOption( const String &, const void * );
+		/** Gets the given option for the SceneTraverser.
+	        @remarks
+		    See setOption
+		*/
+		bool getOption( const String &, void * );
+
+		/** Renders current scene 
+		@param cam current camera
+		@param root root of hierarchy */
+		void renderScene(  Camera *cam, SceneNode *root );
+
+		/** Sets the scene manager */
+		void setSceneManager( SceneManager *sm );
+		/** Sets the render system */
+		void setRenderSystem( RenderSystem *rsys );
+
+		void preprocess( void );
+
+	protected:
+		enum {MODE_QUERY, MODE_RENDER};
+		/** returns true if node is leaf of the hierarchy */
+		bool isLeaf( SceneNode *node );
+		//HACK
+		//unsigned int countSceneNodes(SceneNode *node);
+		void traverseNode( Camera *cam, SceneNode *node );
+		/** Renders current scene node 
+		@param cam current camera
+		@param node current scene node to be rendered
+		*/
+		void renderSceneNode( Camera *cam, SceneNode *node);
+		/** 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 );
+		/** Renders the scene with the hierarchical stop and wait algorithm. */
+		void renderStopAndWait( Camera *cam );
+		/** Renders the scene with the coherent hierarchical algorithm and the query queye. */
+		void renderCoherentWithQueue( Camera *cam );
+		/** Issue a occlusion query for this node. */
+		HardwareOcclusionQuery *issueOcclusionQuery( SceneNode *node, bool wasVisible );
+		/** Pulls up the visibility from the child nodes. */
+		void pullUpVisibility( SceneNode *node );
+		/** delete all previously defined occlusion queries */
+		void deleteQueries();
+		/** Renders bounding box of specified node.
+		@param the scene node contained in the bounding box to be rendered
+		*/
+		void renderBoundingBox( SceneNode *node );
+		/** Returns one half of the bounding box.
+		@param the half of the bouding box
+		*/
+		SolidHalfBoundingBox *getSolidHalfBoundingBox( int half );
+
+		// we use a priority queue rather than a renderstack
+		PriorityQueue *mDistanceQueue; 
+		
+		std::vector<HardwareOcclusionQuery *> mOcclusionQueries;
+		// two halfes of a aabb
+		SolidHalfBoundingBox *mHalfBoundingBox[2];	
+
+		int mCurrentAlgorithm;
+
+		unsigned int mFrameId;
+		unsigned int mVisibilityThreshold;
+		
+		SceneManager *mSceneManager;
+		RenderSystem *mRenderSystem;
+
+		int mCurrentTestIdx;
+		int mQueryMode;
+
+		//--- statistics
+		unsigned int mNumSceneNodes;
+		unsigned int mNumTraversedNodes;
+		unsigned int mNumQueryCulledNodes;
+		unsigned int mNumFrustumCulledNodes;
+		unsigned int mNumRenderedGeometry;
+	};
+
+}
+#endif // OCCLUSIONCULLINGSCENEMANAGER_H
Index: trunk/VUT/OcclusionCullingSceneManager/include/OgreTerrainOcclusionCullingSceneManager.h
===================================================================
--- trunk/VUT/OcclusionCullingSceneManager/include/OgreTerrainOcclusionCullingSceneManager.h	(revision 32)
+++ trunk/VUT/OcclusionCullingSceneManager/include/OgreTerrainOcclusionCullingSceneManager.h	(revision 32)
@@ -0,0 +1,45 @@
+#ifndef _TerrainOcclusionCullingSceneManager_H__
+#define _TerrainOcclusionCullingSceneManager_H__
+
+#include "OgreSceneNode.h"
+#include "OgreTerrainSceneManager.h"
+//#include "OgreOcclusionCullingSceneManager.h"
+#include "OgrePrerequisites.h"
+//#include "OgreSolidHalfBoundingBox.h"
+
+using namespace std;
+
+namespace Ogre {
+	
+	/**
+		Class which implements a scene mangager which uses occlusion queries for culling occluded objects
+	*/
+	class TerrainOcclusionCullingSceneManager: public TerrainSceneManager
+	{
+	public:
+		TerrainOcclusionCullingSceneManager();
+		//~OcclusionCullingSceneManager();
+	
+	/*	void _renderVisibleObjects(void);
+		void _findVisibleObjects(Camera* cam, bool onlyShadowCasters);
+		void _updateSceneGraph(Camera* cam);
+*/
+		/** Sets the given option for the SceneManager
+			       @remarks
+			Options are:
+			"Algorithm", int *;			
+		*/
+//		virtual bool setOption( const String &, const void * );
+		/** Gets the given option for the Scene Manager.
+	        @remarks
+		    See setOption
+		*/
+/*		virtual bool getOption( const String &, void * );
+
+		bool getOptionValues( const String & key, StringVector &refValueList );
+		bool getOptionKeys( StringVector &refKeys );*/
+
+	};
+
+}
+#endif // TERRAINOCCLUSIONCULLINGSCENEMANAGER_H
Index: trunk/VUT/OcclusionCullingSceneManager/scripts/OcclusionDemo.overlay
===================================================================
--- trunk/VUT/OcclusionCullingSceneManager/scripts/OcclusionDemo.overlay	(revision 30)
+++ trunk/VUT/OcclusionCullingSceneManager/scripts/OcclusionDemo.overlay	(revision 32)
@@ -33,5 +33,5 @@
 			font_name TrebuchetMSBold
 			char_height 16
-			caption [O] Algorithm
+			caption [A] Algorithm
 			colour_top 0.5 0.7 0.5
 			colour_bottom 0.3 0.5 0.3
@@ -60,5 +60,5 @@
 			font_name TrebuchetMSBold
 			char_height 16
-			caption [-][+] Thresholdz
+			caption [-][+] Threshold
 			colour_top 0.5 0.7 0.5
 			colour_bottom 0.3 0.5 0.3
@@ -73,5 +73,5 @@
 			font_name TrebuchetMSBold
 			char_height 16
-			caption :dddd
+			caption :
 			colour_top 0.5 0.7 0.5
 			colour_bottom 0.3 0.5 0.3
@@ -84,8 +84,8 @@
 		vert_align top
 		horz_align right
-		left -455 
+		left -355 
 		top 5
 		width 450
-		height 55
+		height 70
 		material Core/StatsBlockCenter
         	border_size 1 1 1 1
@@ -116,11 +116,11 @@
 		{
 			metrics_mode pixels
-			left 155
-			top 5
-			width 90
-			height 30
-			font_name TrebuchetMSBold
-			char_height 16
-			caption :jjkj
+			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
@@ -135,5 +135,5 @@
 			font_name TrebuchetMSBold
 			char_height 16
-			caption Query Query Culled Nodes
+			caption Query Culled Nodes
 			colour_top 0.5 0.7 0.5
 			colour_bottom 0.3 0.5 0.3
@@ -142,5 +142,5 @@
 		{
 			metrics_mode pixels
-			left 155
+			left 180
 			top 20
 			width 90
@@ -168,5 +168,5 @@
 		{
 			metrics_mode pixels
-			left 155
+			left 180
 			top 35
 			width 90
@@ -187,5 +187,5 @@
 			font_name TrebuchetMSBold
 			char_height 16
-			caption Traversed Scene Nodes
+			caption Scene Nodes
 			colour_top 0.5 0.7 0.5
 			colour_bottom 0.3 0.5 0.3
@@ -194,5 +194,5 @@
 		{
 			metrics_mode pixels
-			left 155
+			left 180
 			top 50
 			width 90
Index: trunk/VUT/OcclusionCullingSceneManager/scripts/Plugin_OcclusionCullingSceneManager.vcproj
===================================================================
--- trunk/VUT/OcclusionCullingSceneManager/scripts/Plugin_OcclusionCullingSceneManager.vcproj	(revision 26)
+++ trunk/VUT/OcclusionCullingSceneManager/scripts/Plugin_OcclusionCullingSceneManager.vcproj	(revision 32)
@@ -20,5 +20,5 @@
 				Name="VCCLCompilerTool"
 				Optimization="0"
-				AdditionalIncludeDirectories="&quot;$(OGRE_PATH)\Samples\Common\include&quot;;&quot;$(OGRE_PATH)\Dependencies\include\CEGUI&quot;;&quot;$(OGRE_PATH)\Samples\Common\CEGUIRenderer\include&quot;;&quot;$(OGRE_PATH)\OgreMain\include&quot;;&quot;$(OGRE_PATH)\Dependencies\include&quot;;..\include"
+				AdditionalIncludeDirectories="&quot;$(OGRE_PATH)\PlugIns\OctreeSceneManager\include&quot;;&quot;$(OGRE_PATH)\Samples\Common\include&quot;;&quot;$(OGRE_PATH)\Dependencies\include\CEGUI&quot;;&quot;$(OGRE_PATH)\Samples\Common\CEGUIRenderer\include&quot;;&quot;$(OGRE_PATH)\OgreMain\include&quot;;&quot;$(OGRE_PATH)\Dependencies\include&quot;;..\include"
 				PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;PLUGIN_OCCLUSIONCULLINGSCENEMANAGER_EXPORTS;OGRE_COHERENT_OCCLUSION_CULLING"
 				MinimalRebuild="TRUE"
@@ -35,15 +35,15 @@
 				Name="VCLinkerTool"
 				IgnoreImportLibrary="TRUE"
-				AdditionalDependencies="OgreMain_d.lib CEGUIBase_d.lib OgreGUIRenderer_d.lib"
+				AdditionalDependencies="OgreMain_d.lib CEGUIBase_d.lib OgreGUIRenderer_d.lib Plugin_OctreeSceneManager.lib"
 				OutputFile="$(OutDir)/Plugin_OcclusionCullingSceneManager.dll"
 				Version="0.99"
 				LinkIncremental="2"
 				SuppressStartupBanner="TRUE"
-				AdditionalLibraryDirectories="&quot;$(OGRE_PATH)\OgreMain\lib\$(ConfigurationName)&quot;;&quot;$(OGRE_PATH)\Dependencies\lib\$(ConfigurationName)&quot;;&quot;$(OGRE_PATH)\Samples\Common\CEGUIRenderer\lib&quot;"
+				AdditionalLibraryDirectories="&quot;$(OGRE_PATH)\OgreMain\lib\$(ConfigurationName)&quot;;&quot;$(OGRE_PATH)\Dependencies\lib\$(ConfigurationName)&quot;;&quot;$(OGRE_PATH)\PlugIns\OctreeSceneManager\bin\$(ConfigurationName)&quot;;&quot;$(OGRE_PATH)\Samples\Common\CEGUIRenderer\lib&quot;"
 				ModuleDefinitionFile="..\misc\OgreOcclusionCullingSceneManager.def"
 				GenerateDebugInformation="TRUE"
 				ProgramDatabaseFile="$(OutDir)/Plugin_OcclusionCullingSceneManager.pdb"
 				SubSystem="2"
-				ImportLibrary="$(OutDir)/Plugin_OcclusionCullingSceneManager.lib"
+				ImportLibrary=""
 				TargetMachine="1"/>
 			<Tool
@@ -154,4 +154,7 @@
 			</File>
 			<File
+				RelativePath="..\src\OgreOcclusionCullingSceneTraverser.cpp">
+			</File>
+			<File
 				RelativePath="..\src\OgreSolidHalfBoundingBox.cpp">
 			</File>
@@ -170,4 +173,7 @@
 			</File>
 			<File
+				RelativePath="..\include\OgreOcclusionCullingSceneTraverser.h">
+			</File>
+			<File
 				RelativePath="..\include\OgreSolidHalfBoundingBox.h">
 			</File>
Index: trunk/VUT/OcclusionCullingSceneManager/src/OgreOcclusionCullingSceneManagerDll.cpp
===================================================================
--- trunk/VUT/OcclusionCullingSceneManager/src/OgreOcclusionCullingSceneManagerDll.cpp	(revision 18)
+++ trunk/VUT/OcclusionCullingSceneManager/src/OgreOcclusionCullingSceneManagerDll.cpp	(revision 32)
@@ -24,25 +24,37 @@
 */
 
-#include "OgreOcclusionCullingSceneManager.h"
-#include "OgreRoot.h"
+//#include "OgreOcclusionCullingSceneManager.h"
+//#include "OgreTerrainOcclusionCullingSceneManager.h"
+#include <OgreOctreeSceneManager.h>
+#include <OgreTerrainSceneManager.h>
+#include <OgreRoot.h>
+#include "OgreHeightmapTerrainPageSource.h"
 //#include <windows.h>
 
 namespace Ogre {
 
-    OcclusionCullingSceneManager* occlusionPlugin;
+    //OcclusionCullingSceneManager *occlusionPlugin;
+	//TerrainOcclusionCullingSceneManager *terrainOcclusionPlugin;
+	OctreeSceneManager *ocPlugin;
+
     //-----------------------------------------------------------------------
     extern "C" void dllStartPlugin(void)
     {
-        // Create new scene manager
-        occlusionPlugin = new OcclusionCullingSceneManager();
-		
-		// Register
-        Root::getSingleton().setSceneManager(ST_GENERIC, occlusionPlugin);
-		
+		// Create new scene manager
+	//	occlusionPlugin = new OcclusionCullingSceneManager();
+		ocPlugin = new OctreeSceneManager();
+    
+	    // Register
+		//Root::getSingleton().setSceneManager( ST_GENERIC, occlusionPlugin );
+//		Root::getSingleton().setSceneManager( ST_EXTERIOR_CLOSE, terrainOcclusionPlugin );
+		Root::getSingleton().setSceneManager( ST_EXTERIOR_CLOSE, ocPlugin );
+
 		//MessageBox( NULL, "myplugin registered", "this is my plugin", MB_OK | MB_ICONERROR | MB_TASKMODAL);
     }
     extern "C" void dllStopPlugin(void)
     {
-        delete occlusionPlugin;
+      //  delete occlusionPlugin;
+		delete ocPlugin;
+		//delete terrainOcclusionPlugin;
     }
 }
Index: trunk/VUT/OcclusionCullingSceneManager/src/OgreOcclusionCullingSceneManager.cpp
===================================================================
--- trunk/VUT/OcclusionCullingSceneManager/src/OgreOcclusionCullingSceneManager.cpp	(revision 31)
+++ trunk/VUT/OcclusionCullingSceneManager/src/OgreOcclusionCullingSceneManager.cpp	(revision 32)
@@ -13,357 +13,34 @@
 	
 	//-----------------------------------------------------------------------
-	OcclusionCullingSceneManager::OcclusionCullingSceneManager(): 
-	mFrameId(1), mDistanceQueue(NULL), mVisibilityThreshold(0), mCurrentTestIdx(0),
-	mQueryMode(MODE_RENDER), mNumSceneNodes(0), mCurrentAlgorithm(RENDER_COHERENT),
-	mNumTraversedNodes(0), mNumQueryCulledNodes(0), mNumFrustumCulledNodes(0), mNumRenderedGeometry(0)
-	{		
-		mHalfBoundingBox[0] = mHalfBoundingBox[1] = 0;
+	OcclusionCullingSceneManager::OcclusionCullingSceneManager()
+	{
 	}
 	//-----------------------------------------------------------------------
-	void OcclusionCullingSceneManager::_findVisibleObjects(Camera* cam, bool onlyShadowCasters)
+	void OcclusionCullingSceneManager::_findVisibleObjects( Camera* cam, bool onlyShadowCasters )
 	{
-		// empty because we have to find in _renderVisibleObjects
+		// empty because we have to find objects in _renderVisibleObjects
 	}
 	//-----------------------------------------------------------------------
-	OcclusionCullingSceneManager::~OcclusionCullingSceneManager()
-	{		
-		if(mHalfBoundingBox[0]) delete mHalfBoundingBox[0];
-		if(mHalfBoundingBox[1]) delete mHalfBoundingBox[1];
-
-		deleteQueries();
-		//SceneManager::~SceneManager();
+	void OcclusionCullingSceneManager::_renderVisibleObjects( void )
+	{
+		mSceneTraverser.renderScene(mCameraInProgress, mSceneRoot);
 	}
 	//-----------------------------------------------------------------------
-	void OcclusionCullingSceneManager::_renderVisibleObjects(void)
-	{
-		mNumTraversedNodes = 0;
-		mNumQueryCulledNodes = 0;
-		mNumFrustumCulledNodes = 0;
-		mNumRenderedGeometry = 0;
-		
-		mDistanceQueue = new PriorityQueue(myless<SceneNode *>(mCameraInProgress));
-		mDistanceQueue->push(mSceneRoot);
-		mCurrentTestIdx = 0;
-		//renderZPass();
-
-		switch(mCurrentAlgorithm)
-		{
-			case RENDER_CULL_FRUSTUM:
-				renderCullFrustum();
-		        break;
-			case RENDER_STOP_AND_WAIT:
-				renderStopAndWait();
-				break;
-			case RENDER_COHERENT:
-				renderCoherentWithQueue();
-				break;
-			default:
-				renderCullFrustum();
-				break;
-		}	
-		
-		delete mDistanceQueue;
-
-		mFrameId ++;
-	}
-	//-----------------------------------------------------------------------
-	void OcclusionCullingSceneManager::renderZPass()
+	/*void OcclusionCullingSceneManager::renderZPass()
 	{
 		traverseNode(mSceneRoot);
-	}
+	}*/
 	//-----------------------------------------------------------------------
-	void OcclusionCullingSceneManager::renderCoherentWithQueue()
+	void OcclusionCullingSceneManager::_updateSceneGraph( Camera* cam )
 	{
-		QueryQueue queryQueue;
-
-		//-- PART 1: process finished occlusion queries
-		while(!mDistanceQueue->empty() || !queryQueue.empty())
-		{
-			while(!queryQueue.empty() && 
-				  ((queryQueue.front().second)->resultAvailable() || mDistanceQueue->empty()))
-			{
-				SceneNode *node = queryQueue.front().first;
-				HardwareOcclusionQuery *query = queryQueue.front().second;
-
-				queryQueue.pop();
-			
-				// wait until result available
-				unsigned int visiblePixels;
-				query->pullOcclusionQuery(&visiblePixels);
-
-				if(visiblePixels > mVisibilityThreshold)
-				{
-					pullUpVisibility(node);
-					traverseNode(node);
-				}
-				else
-				{
-					mNumQueryCulledNodes ++;
-				}
-			}	
-
-			//-- PART 2: hierarchical traversal
-			if(!mDistanceQueue->empty())
-			{
-				SceneNode *node = mDistanceQueue->top();
-				mDistanceQueue->pop();
-	
-				if(mCameraInProgress->isVisible(node->_getWorldAABB()))
-				{
-					// identify previously visible nodes
-					bool wasVisible = node->isNodeVisible() && (node->lastVisited() == mFrameId - 1);
-					
-					// identify nodes that we cannot skip queries for
-					bool leafOrWasInvisible = !wasVisible || isLeaf(node);
-
-					// reset node's visibility classification 
-					node->setNodeVisible(false);
-
-					// update node's visited flag
-					node->setLastVisited(mFrameId);
-				
-					// skip testing previously visible interior nodes
-					if(leafOrWasInvisible)
-					{
-						HardwareOcclusionQuery *query = issueOcclusionQuery(node, wasVisible);
-						queryQueue.push(query_pair(node, query));
-					}
-					
-					// always traverse a node if it was visible
-					if(wasVisible)
-					{
-						traverseNode(node);
-					}
-				}
-				else
-				{
-					mNumFrustumCulledNodes ++;
-				}
-			}
-		}
-	}
-	//-----------------------------------------------------------------------
-	void OcclusionCullingSceneManager::renderCullFrustum()
-	{
-		while(!mDistanceQueue->empty())
-		{
-			SceneNode *node = mDistanceQueue->top();
-			mDistanceQueue->pop();
-	
-			// interesting for visualization purpose
-			node->setNodeVisible(false);
-				
-			if(mCameraInProgress->isVisible(node->_getWorldAABB()))
-			{
-				// update node's visited flag 
-				node->setLastVisited(mFrameId);
-				node->setNodeVisible(true);
-				traverseNode(node);
-			}
-			else
-			{			
-				mNumFrustumCulledNodes ++;
-			}
-		}
-	}	
-	//-----------------------------------------------------------------------
-	void OcclusionCullingSceneManager::renderStopAndWait()
-	{
-		while(!mDistanceQueue->empty())
-		{
-			SceneNode *node = mDistanceQueue->top();
-			mDistanceQueue->pop();
+		mSceneTraverser.preprocess();
 		
-			// interesting for the visualization
-			node->setNodeVisible(false);
-			node->setLastVisited(mFrameId);
-
-			if(mCameraInProgress->isVisible(node->_getWorldAABB()))
-			{
-				HardwareOcclusionQuery *query = issueOcclusionQuery(node, false);
-				
-				unsigned int visiblePixels;
-				// wait if result not available
-				query->pullOcclusionQuery(&visiblePixels);
-				
-				// node visible
-				if(visiblePixels > mVisibilityThreshold)
-				{
-					traverseNode(node);
-				}
-				else
-				{
-					mNumQueryCulledNodes ++;
-				}
-			}
-			else
-			{
-				mNumFrustumCulledNodes ++;
-			}
-		}
-	}
-	//-----------------------------------------------------------------------
-	HardwareOcclusionQuery *OcclusionCullingSceneManager::issueOcclusionQuery(SceneNode *node, bool wasVisible)
-	{
-		// change state so the bounding box gets not actually rendered on the screen
-		setRenderingMode(MODE_QUERY);
-
-		// get next available test id
-		HardwareOcclusionQuery *query = mOcclusionQueries[mCurrentTestIdx++];
-		
-		query->beginOcclusionQuery();
-		
-		/*
-		static RenderOperation ro;
-		useRenderableViewProjMode(&box);
-		box.getRenderOperation(ro);
-		ro.srcRenderable = &box; 
-		mDestRenderSystem->_render(ro);
-		*/
-				
-		renderBoundingBox(node);
-
-		query->endOcclusionQuery();
-
-		return query;
-	}
-
-	//-----------------------------------------------------------------------
-	void OcclusionCullingSceneManager::setRenderingMode(int mode)
-	{	
-		// avoid unnecessary state changes
-		if(mode != mQueryMode)
-		{
-			bool enabled = (mode == MODE_RENDER);
-			
-			mDestRenderSystem->_setColourBufferWriteEnabled(enabled, 
-				enabled, enabled, enabled);
-			mDestRenderSystem->_setDepthBufferWriteEnabled(enabled);
-			mDestRenderSystem->setLightingEnabled(enabled);
-			mQueryMode = mode;
-		}
-	}
-	//-----------------------------------------------------------------------
-	void OcclusionCullingSceneManager::traverseNode(SceneNode *node)
-	{
-		mNumTraversedNodes ++;
-
-		if(node->numAttachedObjects() > 0)
-		{
-			render(node);
-		}
-
-		// internal node: add children to priority queue for further processing
-		Node::ChildNodeIterator it = node->getChildIterator();
-					
-		while (it.hasMoreElements())			
-		{ 
-			SceneNode* sceneChild = static_cast<SceneNode*>(it.getNext());
-			mDistanceQueue->push(sceneChild);
-		}
-	}
-	//-----------------------------------------------------------------------
-	void OcclusionCullingSceneManager::render(SceneNode *node)
-	{
-		setRenderingMode(MODE_RENDER);
-		
-		//HACK (too slow)
-		node->_findVisibleObjects(mCameraInProgress, getRenderQueue(), false, 
-								  mDisplayNodes, false);
-		SceneManager::_renderVisibleObjects();
-		getRenderQueue()->clear();
-	}
-	//-----------------------------------------------------------------------
-	void OcclusionCullingSceneManager::_updateSceneGraph(Camera* cam)
-	{
-		unsigned int numnodes = countSceneNodes(mSceneRoot);
-	
-		//-- initialise occlusion queries.
-		if(numnodes != mNumSceneNodes)
-		{
-			deleteQueries();
-			
-			mNumSceneNodes = numnodes;
-
-			for(unsigned int i=0; i < mNumSceneNodes; i++)
-			{
-				mOcclusionQueries.push_back(mDestRenderSystem->createHardwareOcclusionQuery());
-			}	
-		}
-
 		SceneManager::_updateSceneGraph(cam);
-	}
-	//-----------------------------------------------------------------------
-	unsigned int OcclusionCullingSceneManager::countSceneNodes(SceneNode *node)
-	{
-		unsigned int result = 1;
-		
-		Node::ChildNodeIterator it = node->getChildIterator();
-		
-		while (it.hasMoreElements())
-		{ 
-			SceneNode* sceneChild = static_cast<SceneNode*>(it.getNext());
-			result += countSceneNodes(sceneChild);
-        }
-
-		return result;
-	}
-	//-----------------------------------------------------------------------
-	bool OcclusionCullingSceneManager::isLeaf(SceneNode *node)
-	{
-		return (node->numChildren() == 0);
-	}
-	//-----------------------------------------------------------------------
-	void OcclusionCullingSceneManager::pullUpVisibility(SceneNode *node)
-	{
-		while(!node->isNodeVisible())
-		{
-			node->setNodeVisible(true);
-			
-			if(node != mSceneRoot)
-				node = static_cast<SceneNode *>(node->getParent());
-		}
-	}
-	//-----------------------------------------------------------------------
-	void OcclusionCullingSceneManager::deleteQueries()
-	{
-		for(unsigned int i=0; i < mNumSceneNodes; i++)
-			delete mOcclusionQueries[i];
-
-		mOcclusionQueries.clear();
-	}
-	//-----------------------------------------------------------------------
-	void OcclusionCullingSceneManager::renderBoundingBox(SceneNode *node)
-	{
-		// Render two halfes of the bounding box (using triangle fans)
-		for(int half=0; half < 2; half ++)
-		{
-			getSolidHalfBoundingBox(half)->setupBoundingBox(node->_getWorldAABB());
-			SceneManager::renderSingleObject(getSolidHalfBoundingBox(half), 
-				getSolidHalfBoundingBox(half)->getTechnique()->getPass(0), false);
-		}
-	}
-	//-----------------------------------------------------------------------
-	SolidHalfBoundingBox *OcclusionCullingSceneManager::getSolidHalfBoundingBox(int half)
-	{
-		if(!mHalfBoundingBox[half])
-			mHalfBoundingBox[half] = new SolidHalfBoundingBox(half == 1);
-
-		return mHalfBoundingBox[half];	
 	}
 	//-----------------------------------------------------------------------
 	bool OcclusionCullingSceneManager::setOption( const String & key, const void * val )
 	{
-		if ( key == "Algorithm" )
-		{
-			mCurrentAlgorithm = * static_cast < const int * > ( val );
-			return true;
-		}
-		if ( key == "Threshold" )
-		{
-			mCurrentAlgorithm = * static_cast < const int * > ( val );
-			return true;
-		}
-		
+		mSceneTraverser.setOption(key, val);
+			
 		return SceneManager::setOption( key, val );
 	}
@@ -371,35 +48,6 @@
 	bool OcclusionCullingSceneManager::getOption( const String & key, void *val )
 	{
-		if ( key == "Algorithm" )
-		{
-			* static_cast < int * > ( val ) = mCurrentAlgorithm;
-			return true;
-		}
-		if ( key == "Threshold" )
-		{
-			* static_cast < unsigned int * > ( val ) = mVisibilityThreshold;
-			return true;
-		}
-		if ( key == "NumSceneNodes" )
-		{
-			* static_cast < unsigned int * > ( val ) = mNumSceneNodes;
-			return true;
-		}
-		if ( key == "NumTraversedNodes" )
-		{
-			* static_cast < unsigned int * > ( val ) = mNumTraversedNodes;
-			return true;
-		}
-		if ( key == "NumQueryCulledNodes" )
-		{
-			* static_cast < unsigned int * > ( val ) = mNumQueryCulledNodes;
-			return true;
-		}
-		if ( key == "NumFrustumCulledNodes" )
-		{
-			* static_cast < unsigned int * > ( val ) = mNumFrustumCulledNodes;
-			return true;
-		}
-
+		mSceneTraverser.getOption(key, val);
+		
 		return SceneManager::getOption( key, val );
 	}
@@ -413,4 +61,5 @@
 	{
 		SceneManager::getOptionKeys( refKeys );
+
 		refKeys.push_back( "Algorithm" );
 		refKeys.push_back( "Threshold" );
Index: trunk/VUT/OcclusionCullingSceneManager/src/OgreOcclusionCullingSceneTraverser.cpp
===================================================================
--- trunk/VUT/OcclusionCullingSceneManager/src/OgreOcclusionCullingSceneTraverser.cpp	(revision 32)
+++ trunk/VUT/OcclusionCullingSceneManager/src/OgreOcclusionCullingSceneTraverser.cpp	(revision 32)
@@ -0,0 +1,391 @@
+#include "OgreOcclusionCullingSceneTraverser.h"
+#include "OgreMath.h"
+#include "OgreIteratorWrappers.h"
+#include "OgreCamera.h"
+#include "OgreHardwareOcclusionQuery.h"
+//#include "OgreWireBoundingBox.h"
+#include "OgreSolidHalfBoundingBox.h"
+
+#include <windows.h>
+
+namespace Ogre {
+	
+	//-----------------------------------------------------------------------
+	OcclusionCullingSceneTraverser::OcclusionCullingSceneTraverser(): 
+	mFrameId(1), mDistanceQueue(NULL), mVisibilityThreshold(0), mCurrentTestIdx(0),
+	mQueryMode(MODE_RENDER), mNumSceneNodes(0), mCurrentAlgorithm(RENDER_COHERENT),
+	mNumTraversedNodes(0), mNumQueryCulledNodes(0), mNumFrustumCulledNodes(0), 
+	mNumRenderedGeometry(0), mSceneManager(0), mRenderSystem(0)
+	{		
+		mHalfBoundingBox[0] = mHalfBoundingBox[1] = 0;
+	}
+	//-----------------------------------------------------------------------
+	OcclusionCullingSceneTraverser::~OcclusionCullingSceneTraverser()
+	{		
+		if(mHalfBoundingBox[0]) delete mHalfBoundingBox[0];
+		if(mHalfBoundingBox[1]) delete mHalfBoundingBox[1];
+
+		deleteQueries();
+		//SceneManager::~SceneManager();
+	}
+	//-----------------------------------------------------------------------
+	void OcclusionCullingSceneTraverser::renderScene( Camera *cam, SceneNode *root )
+	{
+		mNumTraversedNodes = 0;
+		mNumQueryCulledNodes = 0;
+		mNumFrustumCulledNodes = 0;
+		mNumRenderedGeometry = 0;
+		
+		mDistanceQueue = new PriorityQueue(myless<SceneNode *>(cam));
+		mDistanceQueue->push(root);
+		mCurrentTestIdx = 0;
+		
+		switch(mCurrentAlgorithm)
+		{
+			case RENDER_CULL_FRUSTUM:
+				renderCullFrustum(cam);
+		        break;
+			case RENDER_STOP_AND_WAIT:
+				renderStopAndWait(cam);
+				break;
+			case RENDER_COHERENT:
+				renderCoherentWithQueue(cam);
+				break;
+			default:
+				renderCullFrustum(cam);
+				break;
+		}	
+		
+		delete mDistanceQueue;
+
+		mFrameId ++;
+	}
+	//-----------------------------------------------------------------------
+	void OcclusionCullingSceneTraverser::renderCoherentWithQueue(Camera *cam)
+	{
+		QueryQueue queryQueue;
+
+		//-- PART 1: process finished occlusion queries
+		while(!mDistanceQueue->empty() || !queryQueue.empty())
+		{
+			while(!queryQueue.empty() && 
+				  ((queryQueue.front().second)->resultAvailable() || mDistanceQueue->empty()))
+			{
+				SceneNode *node = queryQueue.front().first;
+				HardwareOcclusionQuery *query = queryQueue.front().second;
+
+				queryQueue.pop();
+			
+				// wait until result available
+				unsigned int visiblePixels;
+				query->pullOcclusionQuery(&visiblePixels);
+
+				if(visiblePixels > mVisibilityThreshold)
+				{
+					pullUpVisibility(node);
+					traverseNode(cam, node);
+				}
+				else
+				{
+					mNumQueryCulledNodes ++;
+				}
+			}	
+
+			//-- PART 2: hierarchical traversal
+			if(!mDistanceQueue->empty())
+			{
+				SceneNode *node = mDistanceQueue->top();
+				mDistanceQueue->pop();
+	
+				if(cam->isVisible(node->_getWorldAABB()))
+				{
+					// identify previously visible nodes
+					bool wasVisible = node->isNodeVisible() && (node->lastVisited() == mFrameId - 1);
+					
+					// identify nodes that we cannot skip queries for
+					bool leafOrWasInvisible = !wasVisible || isLeaf(node);
+
+					// reset node's visibility classification 
+					node->setNodeVisible(false);
+
+					// update node's visited flag
+					node->setLastVisited(mFrameId);
+				
+					// skip testing previously visible interior nodes
+					if(leafOrWasInvisible)
+					{
+						HardwareOcclusionQuery *query = issueOcclusionQuery(node, wasVisible);
+						queryQueue.push(query_pair(node, query));
+					}
+					
+					// always traverse a node if it was visible
+					if(wasVisible)
+					{
+						traverseNode(cam, node);
+					}
+				}
+				else
+				{
+					mNumFrustumCulledNodes ++;
+				}
+			}
+		}
+	}
+	//-----------------------------------------------------------------------
+	void OcclusionCullingSceneTraverser::renderCullFrustum(Camera *cam)
+	{
+		while(!mDistanceQueue->empty())
+		{
+			SceneNode *node = mDistanceQueue->top();
+			mDistanceQueue->pop();
+	
+			// interesting for visualization purpose
+			node->setNodeVisible(false);
+				
+			if(cam->isVisible(node->_getWorldAABB()))
+			{
+				// update node's visited flag 
+				node->setLastVisited(mFrameId);
+				node->setNodeVisible(true);
+				traverseNode(cam, node);
+			}
+			else
+			{			
+				mNumFrustumCulledNodes ++;
+			}
+		}
+	}	
+	//-----------------------------------------------------------------------
+	void OcclusionCullingSceneTraverser::renderStopAndWait(Camera *cam)
+	{
+		while(!mDistanceQueue->empty())
+		{
+			SceneNode *node = mDistanceQueue->top();
+			mDistanceQueue->pop();
+		
+			// interesting for the visualization
+			node->setNodeVisible(false);
+			node->setLastVisited(mFrameId);
+
+			if(cam->isVisible(node->_getWorldAABB()))
+			{
+				HardwareOcclusionQuery *query = issueOcclusionQuery(node, false);
+				
+				unsigned int visiblePixels;
+				// wait if result not available
+				query->pullOcclusionQuery(&visiblePixels);
+				
+				// node visible
+				if(visiblePixels > mVisibilityThreshold)
+				{
+					traverseNode(cam, node);
+				}
+				else
+				{
+					mNumQueryCulledNodes ++;
+				}
+			}
+			else
+			{
+				mNumFrustumCulledNodes ++;
+			}
+		}
+	}
+	//-----------------------------------------------------------------------
+	HardwareOcclusionQuery *OcclusionCullingSceneTraverser::issueOcclusionQuery( SceneNode *node, bool wasVisible )
+	{
+		// change state so the bounding box gets not actually rendered on the screen
+		setRenderingMode(MODE_QUERY);
+
+		// get next available test id
+		HardwareOcclusionQuery *query = mOcclusionQueries[mCurrentTestIdx++];
+		
+		query->beginOcclusionQuery();
+				
+		renderBoundingBox(node);
+
+		query->endOcclusionQuery();
+
+		return query;
+	}
+	//-----------------------------------------------------------------------
+	void OcclusionCullingSceneTraverser::setRenderingMode( int mode )
+	{	
+		// avoid unnecessary state changes
+		if(mode != mQueryMode)
+		{
+			bool enabled = (mode == MODE_RENDER);
+			
+			mRenderSystem->_setColourBufferWriteEnabled(enabled, 
+				enabled, enabled, enabled);
+			mRenderSystem->_setDepthBufferWriteEnabled(enabled);
+			mRenderSystem->setLightingEnabled(enabled);
+
+			mQueryMode = mode;
+		}
+	}
+	//-----------------------------------------------------------------------
+	void OcclusionCullingSceneTraverser::traverseNode( Camera *cam, SceneNode *node )
+	{
+		mNumTraversedNodes ++;
+
+		if(node->numAttachedObjects() > 0)
+		{
+			renderSceneNode(cam, node);
+		}
+
+		// internal node: add children to priority queue for further processing
+		Node::ChildNodeIterator it = node->getChildIterator();
+					
+		while (it.hasMoreElements())			
+		{ 
+			SceneNode* sceneChild = static_cast<SceneNode*>(it.getNext());
+			mDistanceQueue->push(sceneChild);
+		}
+	}
+	//-----------------------------------------------------------------------
+	void OcclusionCullingSceneTraverser::renderSceneNode( Camera *cam, SceneNode *node )
+	{
+		setRenderingMode(MODE_RENDER);
+		
+		//HACK (too slow)
+		mSceneManager->_renderSceneNode(cam, node);
+	}
+	//-----------------------------------------------------------------------
+	void OcclusionCullingSceneTraverser::preprocess( void )
+	{
+		//-- initialise occlusion queries.
+		deleteQueries();
+			
+		for(unsigned int i=0; i < mNumSceneNodes; i++)
+		{
+			mOcclusionQueries.push_back(mRenderSystem->createHardwareOcclusionQuery());
+		}	
+	}
+	//-----------------------------------------------------------------------
+	void OcclusionCullingSceneTraverser::setSceneManager( SceneManager *sm )
+	{
+		mSceneManager = sm;
+	}
+	//-----------------------------------------------------------------------
+	void OcclusionCullingSceneTraverser::setRenderSystem( RenderSystem *rsys )
+	{
+		mRenderSystem = rsys;
+	}
+	//-----------------------------------------------------------------------
+	/*unsigned int OcclusionCullingSceneManager::countSceneNodes(SceneNode *node)
+	{
+		unsigned int result = 1;
+		
+		Node::ChildNodeIterator it = node->getChildIterator();
+		
+		while (it.hasMoreElements())
+		{ 
+			SceneNode* sceneChild = static_cast<SceneNode*>(it.getNext());
+			result += countSceneNodes(sceneChild);
+        }
+
+		return result;
+	}*/
+	//-----------------------------------------------------------------------
+	bool OcclusionCullingSceneTraverser::isLeaf( SceneNode *node )
+	{
+		return (node->numChildren() == 0);
+	}
+	//-----------------------------------------------------------------------
+	void OcclusionCullingSceneTraverser::pullUpVisibility( SceneNode *node )
+	{
+		while(node && !node->isNodeVisible())
+		{
+			node->setNodeVisible(true);
+			node = static_cast<SceneNode *>(node->getParent());
+		}
+	}
+	//-----------------------------------------------------------------------
+	void OcclusionCullingSceneTraverser::deleteQueries( void )
+	{
+		for(unsigned int i=0; i < mNumSceneNodes; i++)
+			delete mOcclusionQueries[i];
+
+		mOcclusionQueries.clear();
+	}
+	//-----------------------------------------------------------------------
+	void OcclusionCullingSceneTraverser::renderBoundingBox( SceneNode *node )
+	{
+		// Render two halfes of the bounding box (using triangle fans)
+		for(int half = 0; half < 2; half ++)
+		{
+			SolidHalfBoundingBox *box = getSolidHalfBoundingBox(half);
+			
+			box->setupBoundingBox(node->_getWorldAABB());
+
+			static RenderOperation ro;
+			mSceneManager->useRenderableViewProjMode(box);
+			box->getRenderOperation(ro);
+			ro.srcRenderable = box; 
+			mRenderSystem->_render(ro);
+
+			//mSceneManager->renderSingleObject(getSolidHalfBoundingBox(half), 
+			//	getSolidHalfBoundingBox(half)->getTechnique()->getPass(0), false);
+		}
+	}
+	//-----------------------------------------------------------------------
+	SolidHalfBoundingBox *OcclusionCullingSceneTraverser::getSolidHalfBoundingBox( int half )
+	{
+		if(!mHalfBoundingBox[half])
+			mHalfBoundingBox[half] = new SolidHalfBoundingBox(half == 1);
+
+		return mHalfBoundingBox[half];	
+	}
+	//-----------------------------------------------------------------------
+	bool OcclusionCullingSceneTraverser::setOption( const String & key, const void * val )
+	{
+		if ( key == "Algorithm" )
+		{
+			mCurrentAlgorithm = * static_cast < const int * > ( val );
+			return true;
+		}
+		if ( key == "Threshold" )
+		{
+			mVisibilityThreshold = * static_cast < const int * > ( val );
+			return true;
+		}
+
+		return false;
+	}
+	//-----------------------------------------------------------------------
+	bool OcclusionCullingSceneTraverser::getOption( const String & key, void *val )
+	{
+		if ( key == "Algorithm" )
+		{
+			* static_cast < int * > ( val ) = mCurrentAlgorithm;
+			return true;
+		}
+		if ( key == "Threshold" )
+		{
+			* static_cast < unsigned int * > ( val ) = mVisibilityThreshold;
+			return true;
+		}
+		if ( key == "NumSceneNodes" )
+		{
+			* static_cast < unsigned int * > ( val ) = mNumSceneNodes;
+			return true;
+		}
+		if ( key == "NumTraversedNodes" )
+		{
+			* static_cast < unsigned int * > ( val ) = mNumTraversedNodes;
+			return true;
+		}
+		if ( key == "NumQueryCulledNodes" )
+		{
+			* static_cast < unsigned int * > ( val ) = mNumQueryCulledNodes;
+			return true;
+		}
+		if ( key == "NumFrustumCulledNodes" )
+		{
+			* static_cast < unsigned int * > ( val ) = mNumFrustumCulledNodes;
+			return true;
+		}
+		return false;
+	}
+}	
Index: trunk/VUT/OcclusionCullingSceneManager/src/OgreTerrainOcclusionCullingSceneManager.cpp
===================================================================
--- trunk/VUT/OcclusionCullingSceneManager/src/OgreTerrainOcclusionCullingSceneManager.cpp	(revision 32)
+++ trunk/VUT/OcclusionCullingSceneManager/src/OgreTerrainOcclusionCullingSceneManager.cpp	(revision 32)
@@ -0,0 +1,52 @@
+#include "OgreTerrainOcclusionCullingSceneManager.h"
+#include "OgreMath.h"
+#include "OgreIteratorWrappers.h"
+#include "OgreRenderSystem.h"
+#include "OgreCamera.h"
+#include "OgreHardwareOcclusionQuery.h"
+//#include "OgreWireBoundingBox.h"
+#include "OgreSolidHalfBoundingBox.h"
+
+#include <windows.h>
+
+namespace Ogre {
+	//-----------------------------------------------------------------------
+	TerrainOcclusionCullingSceneManager::TerrainOcclusionCullingSceneManager()
+	{
+	}
+	/*//-----------------------------------------------------------------------
+	void TerrainOcclusionCullingSceneManager::_renderVisibleObjects(void)
+	{
+		//OcclusionCullingSceneManager::_renderVisibleObjects();
+	}
+	//-----------------------------------------------------------------------
+	void TerrainOcclusionCullingSceneManager::_findVisibleObjects(Camera* cam, bool onlyShadowCasters)
+	{
+	}
+	//-----------------------------------------------------------------------
+	void TerrainOcclusionCullingSceneManager::_updateSceneGraph(Camera* cam)
+	{
+    //    OcclusionCullingSceneManager::_updateSceneGraph(cam);
+	//	TerrainSceneManager::_updateSceneGraph(cam);
+	}
+	//-----------------------------------------------------------------------
+	bool TerrainOcclusionCullingSceneManager::setOption( const String & key, const void * val )
+	{
+		return TerrainSceneManager::setOption( key, val );
+	}
+	//-----------------------------------------------------------------------
+	bool TerrainOcclusionCullingSceneManager::getOption( const String & key, void *val )
+	{
+		return TerrainSceneManager::getOption( key, val );
+	}
+	//-----------------------------------------------------------------------
+	bool TerrainOcclusionCullingSceneManager::getOptionValues( const String & key, StringVector  &refValueList )
+	{
+		return TerrainSceneManager::getOptionValues( key, refValueList );
+	}
+	//-----------------------------------------------------------------------
+	bool TerrainOcclusionCullingSceneManager::getOptionKeys( StringVector & refKeys )
+	{
+		return TerrainSceneManager::getOptionKeys( refKeys );
+	}*/
+}	
Index: trunk/VUT/OcclusionCullingSceneManager/TestCulling/TestCulling.vcproj
===================================================================
--- trunk/VUT/OcclusionCullingSceneManager/TestCulling/TestCulling.vcproj	(revision 29)
+++ trunk/VUT/OcclusionCullingSceneManager/TestCulling/TestCulling.vcproj	(revision 32)
@@ -34,8 +34,8 @@
 			<Tool
 				Name="VCLinkerTool"
-				AdditionalDependencies="OGREMain_d.LIB CEGUIBase_d.lib OgreGUIRenderer_d.lib"
+				AdditionalDependencies="OGREMain_d.LIB CEGUIBase_d.lib OgreGUIRenderer_d.lib Plugin_OctreeSceneManager.lib"
 				OutputFile="$(OGRE_PATH)/Samples/Common/bin/Debug/TestCulling.exe"
 				LinkIncremental="2"
-				AdditionalLibraryDirectories="&quot;$(OGRE_PATH)\Dependencies\Lib\Debug&quot;;&quot;$(OGRE_PATH)\OgreMain\Lib\Debug&quot;;&quot;$(OGRE_PATH)\Samples\Common\CEGUIRenderer\lib&quot;"
+				AdditionalLibraryDirectories="&quot;$(OGRE_PATH)\Dependencies\Lib\Debug&quot;;&quot;$(OGRE_PATH)\OgreMain\Lib\Debug&quot;;&quot;$(OGRE_PATH)\Samples\Common\CEGUIRenderer\lib&quot;;&quot;$(OGRE_PATH)\PlugIns\OctreeSceneManager\bin\$(ConfigurationName)&quot;"
 				GenerateDebugInformation="TRUE"
 				ProgramDatabaseFile="$(OutDir)/TestCulling.pdb"
Index: trunk/VUT/OcclusionCullingSceneManager/TestCulling/TestCullingApplication.cpp
===================================================================
--- trunk/VUT/OcclusionCullingSceneManager/TestCulling/TestCullingApplication.cpp	(revision 31)
+++ trunk/VUT/OcclusionCullingSceneManager/TestCulling/TestCullingApplication.cpp	(revision 32)
@@ -106,5 +106,6 @@
         mRotateSpeed *= 2;
 	
-		mCurrentAlgorithm = OcclusionCullingSceneManager::RENDER_COHERENT;
+		mCurrentAlgorithm = OcclusionCullingSceneTraverser::RENDER_COHERENT;
+		mThreshold = 0;
 
 		// Register this so that we get mouse events.
@@ -121,10 +122,7 @@
 		mQueryCulledNodesInfo = OverlayManager::getSingleton().getOverlayElement("Example/Occlusion/QueryCulledNodesInfo");
         mTraversedNodesInfo = OverlayManager::getSingleton().getOverlayElement("Example/Occlusion/TraversedNodesInfo");
-		
-		//mMaterialInfo = OverlayManager::getSingleton().getOverlayElement("Example/Shadows/MaterialInfo");
-        //mInfo = OverlayManager::getSingleton().getOverlayElement("Example/Shadows/Info");
-
+	
 		mAlgorithmInfo->setCaption(": " + mCurrentAlgorithmCaptions[mCurrentAlgorithm]);
-		mThresholdInfo->setCaption(": dfddfdffdfd0");
+		mThresholdInfo->setCaption(": 0");
 		mFrustumCulledNodesInfo->setCaption(": 0");
 		mQueryCulledNodesInfo->setCaption(": 0");
@@ -191,9 +189,15 @@
 bool MouseQueryListener::frameEnded(const FrameEvent& evt)
 {
+	if (mShutdownRequested)
+		return false;
+
     if (timeDelay >= 0) 
         timeDelay -= evt.timeSinceLastFrame;
 
-    KEY_PRESSED(KC_O, 1, changeAlgorithm());
-	//KEY_PRESSED(KC_T, 1, changeAlgorithm());
+    KEY_PRESSED(KC_SPACE, 0.3, changeAlgorithm());
+
+	KEY_PRESSED(KC_SUBTRACT, 0.3, changeThreshold(-10));
+	KEY_PRESSED(KC_ADD, 0, changeThreshold(10));
+	//KEY_PRESSED(KC_T, 1, change);
       
 	changeStats();
@@ -202,7 +206,17 @@
 }
 //-----------------------------------------------------------------------
+void MouseQueryListener::changeThreshold(int incr)
+{
+	mThreshold += incr; if(mThreshold < 0) mThreshold = 0;
+	
+	char str[100]; sprintf(str,": %d", mThreshold);
+
+	mSceneMgr->setOption("Threshold", &mThreshold); 
+	mThresholdInfo->setCaption(str);
+}
+//-----------------------------------------------------------------------
 void MouseQueryListener::changeAlgorithm()
 {
-    mCurrentAlgorithm = ++mCurrentAlgorithm % OcclusionCullingSceneManager::NUM_RENDERMODES;
+    mCurrentAlgorithm = ++mCurrentAlgorithm % OcclusionCullingSceneTraverser::NUM_RENDERMODES;
 
 	mAlgorithmInfo->setCaption(": " + mCurrentAlgorithmCaptions[mCurrentAlgorithm]);
@@ -214,8 +228,39 @@
 	unsigned int opt = 0;
 	char str[100];
-	mSceneMgr->getOption("Threshold", &opt); sprintf(str,"%d",opt);mThresholdInfo->setCaption(str);
-	mSceneMgr->getOption("NumFrustumCulledNodes", &opt); sprintf(str,"%d",opt); mFrustumCulledNodesInfo->setCaption(str);
-	mSceneMgr->getOption("NumQueryCulledNodes", &opt); sprintf(str,"%d",opt);mQueryCulledNodesInfo->setCaption(str);
-	mSceneMgr->getOption("NumTraversedNodes", &opt); sprintf(str,"%d",opt);mTraversedNodesInfo->setCaption(str);
+	
+	mSceneMgr->getOption("NumFrustumCulledNodes", &opt); sprintf(str,": %d", opt); 
+	mFrustumCulledNodesInfo->setCaption(str);
+	
+	mSceneMgr->getOption("NumQueryCulledNodes", &opt); sprintf(str,": %d", opt); 
+	mQueryCulledNodesInfo->setCaption(str);
+	
+	mSceneMgr->getOption("NumTraversedNodes", &opt); sprintf(str,": %d", opt); 
+	mTraversedNodesInfo->setCaption(str);
+}
+//-----------------------------------------------------------------------
+void MouseQueryListener::keyPressed(KeyEvent* e)
+{
+	if(e->getKey() == KC_ESCAPE)
+    {
+		mShutdownRequested = true;
+		e->consume();
+		return;
+	}
+
+	CEGUI::System::getSingleton().injectKeyDown(e->getKey());
+	CEGUI::System::getSingleton().injectChar(e->getKeyChar());
+	e->consume();
+}
+//-----------------------------------------------------------------------
+void MouseQueryListener::keyReleased(KeyEvent* e)
+{
+	CEGUI::System::getSingleton().injectKeyUp(e->getKey());
+	e->consume();
+}
+//-----------------------------------------------------------------------
+void MouseQueryListener::keyClicked(KeyEvent* e) 
+{
+	// Do nothing
+	e->consume();
 }
 //-----------------------------------------------------------------------
Index: trunk/VUT/OcclusionCullingSceneManager/TestCulling/TestCullingApplication.h
===================================================================
--- trunk/VUT/OcclusionCullingSceneManager/TestCulling/TestCullingApplication.h	(revision 30)
+++ trunk/VUT/OcclusionCullingSceneManager/TestCulling/TestCullingApplication.h	(revision 32)
@@ -6,4 +6,5 @@
 #include "ExampleApplication.h"
 #include "OgreOcclusionCullingSceneManager.h"
+#include "OgreOcclusionCullingSceneTraverser.h"
 
 Real timeDelay = 0;
@@ -17,5 +18,5 @@
 }
 
-String mCurrentAlgorithmCaptions[OcclusionCullingSceneManager::NUM_RENDERMODES] = 
+String mCurrentAlgorithmCaptions[OcclusionCullingSceneTraverser::NUM_RENDERMODES] = 
 {
     "Cull Frustum", 
@@ -53,39 +54,12 @@
     // This is when the mouse is clicked, held and dragged.
     virtual void mouseDragged (MouseEvent *e);
-/*
-    void keyPressed(KeyEvent* e)
-    {
-        if(e->getKey() == KC_ESCAPE)
-        {
-            mShutdownRequested = true;
-            e->consume();
-            return;
-        }
 
-        CEGUI::System::getSingleton().injectKeyDown(e->getKey());
-		CEGUI::System::getSingleton().injectChar(e->getKeyChar());
-        e->consume();
-    }
+    void keyPressed(KeyEvent* e);
 
-	void keyReleased(KeyEvent* e)
-	{
-		CEGUI::System::getSingleton().injectKeyUp(e->getKey());
-		e->consume();
-	}
-	void keyClicked(KeyEvent* e) 
-	{
-		// Do nothing
-		e->consume();
-	}
+	void keyReleased(KeyEvent* e);
+	void keyClicked(KeyEvent* e);
 
-    bool frameEnded(const FrameEvent& evt)
-    {
-        if (mShutdownRequested)
-            return false;
-        else
-            return ExampleFrameListener::frameEnded(evt);
-    }
-*/
 	void changeAlgorithm();
+	void changeThreshold(int incr);
 	void changeStats();
 
@@ -96,7 +70,8 @@
     CEGUI::Renderer *mGUIRenderer;     // cegui renderer
 	SceneNode* mShipNode;
-//	bool mShutdownRequested;
+	bool mShutdownRequested;
 	int mCurrentAlgorithm;
-	
+	int mThreshold;
+
 	OverlayElement *mAlgorithmInfo;
 	OverlayElement *mThresholdInfo;
@@ -113,5 +88,4 @@
     /*TestCullingApplication()
     {
-
     }*/
 
@@ -148,7 +122,4 @@
 
     }*/
-    
-
-	
 };
 
