Index: trunk/VUT/OcclusionCullingSceneManager/src/OgreOcclusionCullingSceneTraverser.cpp
===================================================================
--- trunk/VUT/OcclusionCullingSceneManager/src/OgreOcclusionCullingSceneTraverser.cpp	(revision 39)
+++ trunk/VUT/OcclusionCullingSceneManager/src/OgreOcclusionCullingSceneTraverser.cpp	(revision 40)
@@ -42,5 +42,5 @@
 		mCurrentTestIdx = 0;
 
-//mCurrentAlgorithm = RENDER_CULL_FRUSTUM;
+mCurrentAlgorithm = RENDER_CULL_FRUSTUM;
 		switch(mCurrentAlgorithm)
 		{
@@ -148,4 +148,8 @@
 			{
 				// update node's visited flag 
+				char msg2[100];
+				sprintf(msg2,"yes, visible\n");
+				OutputDebugString(msg2);
+
 				node->setLastVisited(mFrameId);
 				node->setNodeVisible(true);
@@ -154,4 +158,8 @@
 			else
 			{			
+				char msg2[100];
+				sprintf(msg2,"no, invisible\n");
+				OutputDebugString(msg2);
+
 				mNumFrustumCulledNodes ++;
 			}
@@ -252,5 +260,4 @@
 		setRenderingMode(MODE_RENDER);
 		
-		//HACK (too slow)
 		mSceneManager->_renderSceneNode(cam, node);
 	}
@@ -260,7 +267,4 @@
 		//-- initialise occlusion queries.
 		deleteQueries();
-		
-		//char str[100];sprintf(str, "num nodes: %d", mNumSceneNodes);
-		//MessageBox( NULL, str, "this is my plugin", MB_OK | MB_ICONERROR | MB_TASKMODAL);
 
 		for(unsigned int i=0; i < mNumSceneNodes; i++)
Index: trunk/VUT/OcclusionCullingSceneManager/src/OgreOcclusionCullingTerrainSceneManager.cpp
===================================================================
--- trunk/VUT/OcclusionCullingSceneManager/src/OgreOcclusionCullingTerrainSceneManager.cpp	(revision 34)
+++ trunk/VUT/OcclusionCullingSceneManager/src/OgreOcclusionCullingTerrainSceneManager.cpp	(revision 40)
@@ -14,5 +14,10 @@
 	OcclusionCullingTerrainSceneManager::OcclusionCullingTerrainSceneManager()
 	{
-		mOcclusionCullingSceneTraverser = new OcclusionCullingSceneTraverser(this, mDestRenderSystem);
+		//mOcclusionCullingTerrainSceneTraverser = 
+		//	new OcclusionCullingTerrainSceneTraverser(this, mDestRenderSystem);
+
+		mOcclusionCullingTerrainSceneTraverser = 
+			new OcclusionCullingSceneTraverser(this, mDestRenderSystem);
+
 		mDisplayNodes = true;
 		//mShowBoundingBoxes = true;
@@ -22,10 +27,33 @@
 	OcclusionCullingTerrainSceneManager::~OcclusionCullingTerrainSceneManager()
 	{
-		delete mOcclusionCullingSceneTraverser;
+		delete mOcclusionCullingTerrainSceneTraverser;
 	}
 	//-----------------------------------------------------------------------
-	/*void OcclusionCullingTerrainSceneManager::_renderVisibleObjects(void)
+	void OcclusionCullingTerrainSceneManager::_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);
+
+		//mOcclusionCullingTerrainSceneTraverser->renderScene(mCameraInProgress, mOctree);
+		//mOcclusionCullingTerrainSceneTraverser->renderScene(mCameraInProgress, mTerrainRoot);
+		mOcclusionCullingTerrainSceneTraverser->renderScene(mCullCamera, mSceneRoot);
+		_deleteRenderedQueueGroups();
+
+		//-- render overlay
+		clearSpecialCaseRenderQueues();
+		SceneManager::_renderVisibleObjects( );
+	
+		clearSpecialCaseRenderQueues();
 	}
 	//-----------------------------------------------------------------------
@@ -38,17 +66,20 @@
 	void OcclusionCullingTerrainSceneManager::_updateSceneGraph(Camera* cam)
 	{
-        mOcclusionCullingSceneTraverser->preprocess();
+     	mOcclusionCullingTerrainSceneTraverser->setNumSceneNodes(mSceneNodes.size());
+		mOcclusionCullingTerrainSceneTraverser->setRenderSystem(mDestRenderSystem);
 
+        mOcclusionCullingTerrainSceneTraverser->preprocess();
+		
 		TerrainSceneManager::_updateSceneGraph(cam);
-	}*/
+	}
 	//-----------------------------------------------------------------------
 	bool OcclusionCullingTerrainSceneManager::setOption( const String & key, const void * val )
 	{
-		return mOcclusionCullingSceneTraverser->setOption( key, val) || TerrainSceneManager::setOption( key, val );
+		return mOcclusionCullingTerrainSceneTraverser->setOption( key, val) || TerrainSceneManager::setOption( key, val );
 	}
 	//-----------------------------------------------------------------------
 	bool OcclusionCullingTerrainSceneManager::getOption( const String & key, void *val )
 	{
-		return mOcclusionCullingSceneTraverser->getOption( key, val) || TerrainSceneManager::getOption( key, val ) ;
+		return mOcclusionCullingTerrainSceneTraverser->getOption( key, val) || TerrainSceneManager::getOption( key, val ) ;
 	}
 	//-----------------------------------------------------------------------
@@ -60,5 +91,46 @@
 	bool OcclusionCullingTerrainSceneManager::getOptionKeys( StringVector & refKeys )
 	{
-		return mOcclusionCullingSceneTraverser->getOptionKeys ( refKeys ) || TerrainSceneManager::getOptionKeys( 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();
+
+        if ( mShowBoxes )
+        {
+            mBoxes.push_back( octant->getWireBoundingBox() );
+        }
+
+        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());
+				}
+			}
+            ++it;
+        }
+
+		SceneManager::_renderVisibleObjects();
+	
+		// delete all rendered objects from renderqueue
+		_deleteRenderedQueueGroups();
 	}
 }	
Index: trunk/VUT/OcclusionCullingSceneManager/src/OgreOcclusionCullingTerrainSceneTraverser.cpp
===================================================================
--- trunk/VUT/OcclusionCullingSceneManager/src/OgreOcclusionCullingTerrainSceneTraverser.cpp	(revision 39)
+++ trunk/VUT/OcclusionCullingSceneManager/src/OgreOcclusionCullingTerrainSceneTraverser.cpp	(revision 40)
@@ -1,24 +1,36 @@
 #include "OgreOcclusionCullingTerrainSceneTraverser.h"
-//#include <windows.h>
+#include "OgreOcclusionCullingTerrainSceneManager.h"
+
+#include <windows.h>
 
 namespace Ogre {
 	//-----------------------------------------------------------------------
-	void OcclusionCullingTerrainSceneTraverser::traverseNode( Camera *cam, Octree *node )
+	OcclusionCullingTerrainSceneTraverser::OcclusionCullingTerrainSceneTraverser(SceneManager *sm, RenderSystem *rsys): 
+	OcclusionCullingSceneTraverser(sm, rsys)
+	{
+	}
+	//-----------------------------------------------------------------------
+	void OcclusionCullingTerrainSceneTraverser::traverseOctree( Camera *cam, Octree *octree )
 	{
 		mNumTraversedNodes ++;
 	
-	/*	if(node->numAttachedObjects() > 0)
+		if(octree->numNodes() > 0)
 		{
-			renderSceneNode(cam, node);
-		}*/
+			renderOctree(cam, octree);
+		}
 
 		for(int i=0; i<8; i++)
 		{
-			if(node->mChildren[i & 4][i & 2][i & 1] != 0)
-				traverseNode(cam, node->mChildren[i & 4][i & 2][i & 1]);
+			char msg[100];
+			sprintf(msg,"current node: %d\n", i);
+			OutputDebugString(msg);
+
+			if(octree->mChildren[i & 4][i & 2][i & 1] != 0)
+				traverseOctree(cam, octree->mChildren[i & 4][i & 2][i & 1]);			
 		}
 	}
 	//-----------------------------------------------------------------------
 	void OcclusionCullingTerrainSceneTraverser::renderScene( Camera *cam, Octree *root )
+		//TODO: Renderscene independent from hierarchynode => implement only once
 	{
 		mNumTraversedNodes = 0;
@@ -27,8 +39,8 @@
 		mNumRenderedGeometry = 0;
 		
-		mDistanceQueue = new OctreePriorityQueue(myless<Octree *>(cam));
-//		mDistanceQueue->push(root);
+		mDistanceQueue = new OctreePriorityQueue(octreeless<Octree *>(cam));
+		mDistanceQueue->push(root);
 		mCurrentTestIdx = 0;
-
+		
 mCurrentAlgorithm = RENDER_CULL_FRUSTUM;
 		switch(mCurrentAlgorithm)
@@ -37,10 +49,10 @@
 				renderCullFrustum(cam);
 		        break;
-		/*	case RENDER_STOP_AND_WAIT:
+			case RENDER_STOP_AND_WAIT:
 				renderStopAndWait(cam);
 				break;
 			case RENDER_COHERENT:
 				renderCoherentWithQueue(cam);
-				break;*/
+				break;
 			default:
 				renderCullFrustum(cam);
@@ -48,5 +60,5 @@
 		}	
 		
-//		delete mDistanceQueue;
+		delete mDistanceQueue;
 
 		mFrameId ++;
@@ -55,25 +67,40 @@
 	void OcclusionCullingTerrainSceneTraverser::renderCullFrustum(Camera *cam)
 	{
-		/*while(!mDistanceQueue->empty())
+		AxisAlignedBox box;
+		FrustumPlane plane;
+
+		while(!mDistanceQueue->empty())
 		{
-			SceneNode *node = mDistanceQueue->top();
+			Octree *octree = mDistanceQueue->top();
 			mDistanceQueue->pop();
 	
 			// interesting for visualization purpose
-			node->setNodeVisible(false);
-				
-			if(cam->isVisible(node->_getWorldAABB()))
-			{
+			//TODO: octree->setNodeVisible(false);
+			octree->_getCullBounds(&box);
+
+			//if(cam->isVisible(box, &plane))
+			//{
 				// update node's visited flag 
-				node->setLastVisited(mFrameId);
-				node->setNodeVisible(true);
-				traverseNode(cam, node);
-			}
+				//TODO: octree->setLastVisited(mFrameId);
+				//TODO: octree->setNodeVisible(true);
+				traverseOctree(cam, octree);
+			/*}
 			else
 			{			
 				mNumFrustumCulledNodes ++;
-			}
-		}*/
+			}*/
+		}
 	}	
+	
+	/** Renders the scene with the hierarchical stop and wait algorithm. */
+	void OcclusionCullingTerrainSceneTraverser::renderStopAndWait( Camera *cam )
+	{
+	}
+
+	/** Renders the scene with the coherent hierarchical algorithm and the query queye. */
+	void OcclusionCullingTerrainSceneTraverser::renderCoherentWithQueue( Camera *cam )
+	{
+	}
+	
 	//-----------------------------------------------------------------------
 /*	bool OcclusionCullingTerrainSceneTraverser::isLeaf( SceneNode *node )
@@ -85,3 +112,9 @@
 	{
 	}
+	//-----------------------------------------------------------------------
+	void OcclusionCullingTerrainSceneTraverser::renderOctree( Camera *cam, Octree *octree )
+	{
+		setRenderingMode(MODE_RENDER);
+		((OcclusionCullingTerrainSceneManager *)mSceneManager)->_renderOctant(cam, octree);
+	}
 }	
