Index: trunk/VUT/OcclusionCullingSceneManager/src/OgreOcclusionCullingOctreeSceneManager.cpp
===================================================================
--- trunk/VUT/OcclusionCullingSceneManager/src/OgreOcclusionCullingOctreeSceneManager.cpp	(revision 44)
+++ trunk/VUT/OcclusionCullingSceneManager/src/OgreOcclusionCullingOctreeSceneManager.cpp	(revision 44)
@@ -0,0 +1,148 @@
+#include "OgreOcclusionCullingTerrainSceneManager.h"
+#include "OgreMath.h"
+#include "OgreIteratorWrappers.h"
+#include "OgreRenderSystem.h"
+#include "OgreCamera.h"
+#include "OgreHardwareOcclusionQuery.h"
+#include "OgreSolidHalfBoundingBox.h"
+
+#include <windows.h>
+
+namespace Ogre {
+	//-----------------------------------------------------------------------
+	OcclusionCullingTerrainSceneManager::OcclusionCullingTerrainSceneManager()
+	{
+		mOcclusionCullingTerrainSceneTraverser = 
+			new OcclusionCullingTerrainSceneTraverser(this, mDestRenderSystem);
+
+		//mDisplayNodes = true;
+		//mShowBoundingBoxes = true;
+		//mShowBoxes = true;
+		mMaxDepth = 20;
+	}
+	//-----------------------------------------------------------------------
+	OcclusionCullingTerrainSceneManager::~OcclusionCullingTerrainSceneManager()
+	{
+		delete mOcclusionCullingTerrainSceneTraverser;
+	}
+	//-----------------------------------------------------------------------
+	void OcclusionCullingTerrainSceneManager::_renderVisibleObjects(void)
+	{
+		//-- 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);
+
+		mOcclusionCullingTerrainSceneTraverser->setSceneRoot(mOctree);
+		mOcclusionCullingTerrainSceneTraverser->renderScene(mCameraInProgress);
+		
+		_deleteRenderedQueueGroups();
+
+		//-- render overlay
+		clearSpecialCaseRenderQueues();
+		SceneManager::_renderVisibleObjects( );
+	
+		clearSpecialCaseRenderQueues();
+	}
+	//-----------------------------------------------------------------------
+	void OcclusionCullingTerrainSceneManager::_findVisibleObjects(Camera* cam, bool onlyShadowCasters)
+	{
+		// 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)
+	{
+		//char *msg = "now updating scenegraph\n"; OutputDebugString(msg);
+		//mOcclusionCullingTerrainSceneTraverser->preprocess();
+
+     	mOcclusionCullingTerrainSceneTraverser->setNumSceneNodes((int)mSceneNodes.size());
+		mOcclusionCullingTerrainSceneTraverser->setRenderSystem(mDestRenderSystem);
+        
+		mOcclusionCullingTerrainSceneTraverser->setNumOctreeNodes(mNumOctreeNodes);
+
+		TerrainSceneManager::_updateSceneGraph(cam);
+	}
+	//-----------------------------------------------------------------------
+	bool OcclusionCullingTerrainSceneManager::setOption( const String & key, const void * val )
+	{
+		return mOcclusionCullingTerrainSceneTraverser->setOption( key, val) || TerrainSceneManager::setOption( key, val );
+	}
+	//-----------------------------------------------------------------------
+	bool OcclusionCullingTerrainSceneManager::getOption( const String & key, void *val )
+	{
+		return mOcclusionCullingTerrainSceneTraverser->getOption( key, val) || TerrainSceneManager::getOption( key, val ) ;
+	}
+	//-----------------------------------------------------------------------
+	bool OcclusionCullingTerrainSceneManager::getOptionValues( const String & key, StringVector  &refValueList )
+	{
+		return TerrainSceneManager::getOptionValues( key, refValueList );
+	}
+	//-----------------------------------------------------------------------
+	bool OcclusionCullingTerrainSceneManager::getOptionKeys( StringVector & refKeys )
+	{
+		return mOcclusionCullingTerrainSceneTraverser->getOptionKeys ( refKeys ) || TerrainSceneManager::getOptionKeys( refKeys );
+	}
+	//-----------------------------------------------------------------------
+	void OcclusionCullingTerrainSceneManager::_renderOctant(Camera *cam, Octree *octant)
+	{
+		//Add stuff to be rendered;
+        NodeList::iterator it = octant->mNodes.begin();
+         
+        while(it != octant->mNodes.end())
+        {
+            OctreeNode *sn = *it;
+
+            mNumObjects++;
+
+			// check bounding box visibility of scene nodes
+			if (cam->isVisible(sn->_getWorldAABB()))
+			{
+				sn->_addToRenderQueue(cam, getRenderQueue(), false);
+				//node->_findVisibleObjects(cam, getRenderQueue(), false, mDisplayNodes, false);
+				mVisible.push_back(sn);
+
+				if (mDisplayNodes)
+					getRenderQueue()->addRenderable(sn);
+
+				// check if the scene manager or this node wants the bounding box shown.
+				if (sn->getShowBoundingBox() || mShowBoundingBoxes)
+					sn->_addBoundingBoxToQueue(getRenderQueue());
+
+				if (mShowBoxes)
+					getRenderQueue()->addRenderable(octant->getWireBoundingBox());
+			}
+            ++it;
+        }
+
+		SceneManager::_renderVisibleObjects();
+	
+		// delete all rendered objects from renderqueue
+		_deleteRenderedQueueGroups();
+	}
+	//-----------------------------------------------------------------------
+	/*unsigned int OcclusionCullingTerrainSceneManager::countNumOctrees(Octree *root)
+	{
+		unsigned int result = 1;
+				
+		for(int i=0; i<8; ++i)
+		{
+			Octree *nextChild = root->mChildren[(i & 4) >> 2][(i & 2) >> 1][i & 1];
+		
+			if(nextChild != 0)
+				result += countNumOctrees(nextChild);
+		}
+		
+		return result;
+	}*/
+}	
Index: trunk/VUT/OcclusionCullingSceneManager/src/OgreOcclusionCullingSceneTraverser.cpp
===================================================================
--- trunk/VUT/OcclusionCullingSceneManager/src/OgreOcclusionCullingSceneTraverser.cpp	(revision 42)
+++ trunk/VUT/OcclusionCullingSceneManager/src/OgreOcclusionCullingSceneTraverser.cpp	(revision 44)
@@ -4,5 +4,4 @@
 #include "OgreCamera.h"
 #include "OgreHardwareOcclusionQuery.h"
-//#include "OgreWireBoundingBox.h"
 #include "OgreSolidHalfBoundingBox.h"
 
@@ -55,5 +54,6 @@
 				break;
 			case RENDER_COHERENT:
-				renderCoherentWithQueue(cam);
+				//renderCoherentWithQueue(cam);
+renderStopAndWait(cam);
 				break;
 			default:
@@ -228,6 +228,7 @@
 		// change state so the bounding box gets not actually rendered on the screen
 		// TODO: in rendervisibleobjects, the rendermode is changed by ogre itself => change this!!
-		setRenderingMode(MODE_QUERY);
-		//setRenderingMode(MODE_RENDER);
+		
+		//setRenderingMode(MODE_QUERY);
+		setRenderingMode(MODE_RENDER);
 
 		// get next available test id
@@ -247,6 +248,6 @@
 	{	
 		// avoid unnecessary state changes
-		if(mode != mQueryMode)
-		{
+		//if(mode != mQueryMode)
+		//{
 			bool enabled = (mode == MODE_RENDER);
 			
@@ -257,5 +258,5 @@
 
 			mQueryMode = mode;
-		}
+		//}
 	}
 	//-----------------------------------------------------------------------
Index: trunk/VUT/OcclusionCullingSceneManager/src/OgreOcclusionCullingTerrainSceneManager.cpp
===================================================================
--- trunk/VUT/OcclusionCullingSceneManager/src/OgreOcclusionCullingTerrainSceneManager.cpp	(revision 42)
+++ trunk/VUT/OcclusionCullingSceneManager/src/OgreOcclusionCullingTerrainSceneManager.cpp	(revision 44)
@@ -5,5 +5,4 @@
 #include "OgreCamera.h"
 #include "OgreHardwareOcclusionQuery.h"
-//#include "OgreWireBoundingBox.h"
 #include "OgreSolidHalfBoundingBox.h"
 
@@ -19,6 +18,6 @@
 		//mDisplayNodes = true;
 		//mShowBoundingBoxes = true;
-		mShowBoxes = true;
-		//mMaxDepth = 20;
+		//mShowBoxes = true;
+		mMaxDepth = 20;
 	}
 	//-----------------------------------------------------------------------
@@ -66,7 +65,9 @@
 	{
 		//char *msg = "now updating scenegraph\n"; OutputDebugString(msg);
+		//mOcclusionCullingTerrainSceneTraverser->preprocess();
+
      	mOcclusionCullingTerrainSceneTraverser->setNumSceneNodes((int)mSceneNodes.size());
 		mOcclusionCullingTerrainSceneTraverser->setRenderSystem(mDestRenderSystem);
-        //mOcclusionCullingTerrainSceneTraverser->preprocess();
+        
 		mOcclusionCullingTerrainSceneTraverser->setNumOctreeNodes(mNumOctreeNodes);
 
@@ -99,5 +100,5 @@
         NodeList::iterator it = octant->mNodes.begin();
          
-        while ( it != octant->mNodes.end() )
+        while(it != octant->mNodes.end())
         {
             OctreeNode *sn = *it;
@@ -106,12 +107,12 @@
 
 			// check bounding box visibility of scene nodes
-			if( cam->isVisible( sn->_getWorldAABB() ) )
+			if (cam->isVisible(sn->_getWorldAABB()))
 			{
-				sn->_addToRenderQueue(cam, getRenderQueue(), false );
+				sn->_addToRenderQueue(cam, getRenderQueue(), false);
 				//node->_findVisibleObjects(cam, getRenderQueue(), false, mDisplayNodes, false);
-				mVisible.push_back( sn );
+				mVisible.push_back(sn);
 
-				if ( mDisplayNodes )
-					getRenderQueue()->addRenderable( sn );
+				if (mDisplayNodes)
+					getRenderQueue()->addRenderable(sn);
 
 				// check if the scene manager or this node wants the bounding box shown.
@@ -119,5 +120,5 @@
 					sn->_addBoundingBoxToQueue(getRenderQueue());
 
-				if ( mShowBoxes )
+				if (mShowBoxes)
 					getRenderQueue()->addRenderable(octant->getWireBoundingBox());
 			}
Index: trunk/VUT/OcclusionCullingSceneManager/src/OgreOcclusionCullingDotSceneManager.cpp
===================================================================
--- trunk/VUT/OcclusionCullingSceneManager/src/OgreOcclusionCullingDotSceneManager.cpp	(revision 42)
+++ trunk/VUT/OcclusionCullingSceneManager/src/OgreOcclusionCullingDotSceneManager.cpp	(revision 44)
@@ -5,5 +5,4 @@
 #include "OgreCamera.h"
 #include "OgreHardwareOcclusionQuery.h"
-//#include "OgreWireBoundingBox.h"
 #include "OgreSolidHalfBoundingBox.h"
 
Index: trunk/VUT/OcclusionCullingSceneManager/src/OgreOcclusionCullingTerrainSceneTraverser.cpp
===================================================================
--- trunk/VUT/OcclusionCullingSceneManager/src/OgreOcclusionCullingTerrainSceneTraverser.cpp	(revision 42)
+++ trunk/VUT/OcclusionCullingSceneManager/src/OgreOcclusionCullingTerrainSceneTraverser.cpp	(revision 44)
@@ -23,9 +23,6 @@
 	
 		// if we come across some renderable geometry => render it
-		if(octant->numNodes() > 0)
-		{
-			renderOctant(cam, octant);
-		}
-
+		renderOctant(cam, octant);
+		
 		for(int i=0; i<8; i++)
 		{
@@ -90,5 +87,5 @@
 				continue;
 			}
-			// if intersects near plane => skip occlusion query because wrong results possible
+			//if intersects near plane => skip occlusion query because wrong results possible
 			if(intersects)
 			{
@@ -212,9 +209,6 @@
 		{
 			// if we come across some renderable geometry => render it
-			if(octant->numNodes() > 0)
-			{
-				renderOctant(cam, octant);
-			}
-
+			renderOctant(cam, octant);
+			
 			octant->setOctreeVisible(true);
 			octant = octant->getParent();
@@ -224,7 +218,8 @@
 	void OcclusionCullingTerrainSceneTraverser::renderOctant( Camera *cam, Octree *octant )
 	{
+		//if(octant->numNodes() > 0)
 		if(octant->lastVisited() != octant->lastRendered())
 		{
-			setRenderingMode(MODE_RENDER);
+			//setRenderingMode(MODE_RENDER);
 
 			octant->setLastRendered(octant->lastVisited());
