Index: trunk/VUT/OcclusionCullingSceneManager/src/OgreSolidHalfBoundingBox.cpp
===================================================================
--- trunk/VUT/OcclusionCullingSceneManager/src/OgreSolidHalfBoundingBox.cpp	(revision 26)
+++ trunk/VUT/OcclusionCullingSceneManager/src/OgreSolidHalfBoundingBox.cpp	(revision 26)
@@ -0,0 +1,92 @@
+#include "OgreStableHeaders.h"
+#include "OgreSolidHalfBoundingBox.h"
+
+#include "OgreSimpleRenderable.h"
+#include "OgreHardwareBufferManager.h"
+#include "OgreCamera.h"
+//#include <windows.h>
+
+namespace Ogre {
+    #define POSITION_BINDING 0
+	//-----------------------------------------------------------------------
+	SolidHalfBoundingBox::SolidHalfBoundingBox(bool isFirstHalf)
+		:WireBoundingBox(), mIsFirstHalf(isFirstHalf)
+    {
+		mRenderOp.vertexData->vertexCount = 8;
+        mRenderOp.operationType = RenderOperation::OT_TRIANGLE_FAN; 
+	}
+	//-----------------------------------------------------------------------
+	void SolidHalfBoundingBox::setupBoundingBoxVertices(const AxisAlignedBox& aab) {
+
+		Vector3 vmax = aab.getMaximum();
+		Vector3 vmin = aab.getMinimum();
+		
+		
+		Real sqLen = std::max(vmax.squaredLength(), vmin.squaredLength());
+        mRadius = Math::Sqrt(sqLen);
+		
+		Real maxx = vmax.x;
+		Real maxy = vmax.y;
+		Real maxz = vmax.z;
+		
+		Real minx = vmin.x;
+		Real miny = vmin.y;
+		Real minz = vmin.z;
+		
+		// fill in the Vertex buffer: 12 lines with 2 endpoints each make up a box
+        HardwareVertexBufferSharedPtr vbuf =
+            mRenderOp.vertexData->vertexBufferBinding->getBuffer(POSITION_BINDING);     
+
+        float* pPos = static_cast<float*>(
+            vbuf->lock(HardwareBuffer::HBL_DISCARD));
+
+		//     5+------+7
+		//     /|     /|
+		//    / |    / |
+		//   / 1+---/--+3
+		// 2+------+6 /    y   z
+		//  | /    | /     |  /
+		//  |/     |/      |/
+		// 0+------+4      *---x
+
+		// fan 1
+		if(mIsFirstHalf)
+		{
+			*pPos++ = minx; *pPos++ = maxy; *pPos++ = maxz; //011
+			*pPos++ = minx; *pPos++ = miny; *pPos++ = maxz; //001
+			*pPos++ = maxx; *pPos++ = miny; *pPos++ = maxz; //101
+			*pPos++ = maxx; *pPos++ = maxy; *pPos++ = maxz; //111
+			
+			*pPos++ = maxx; *pPos++ = maxy; *pPos++ = minz; //110
+			*pPos++ = minx; *pPos++ = maxy; *pPos++ = minz; //010
+			*pPos++ = minx; *pPos++ = miny; *pPos++ = minz; //000
+			*pPos++ = minx; *pPos++ = miny; *pPos++ = maxz; //001
+
+		}
+		else
+		// fan 2
+		{
+			*pPos++ = maxx; *pPos++ = miny; *pPos++ = minz; //100
+			*pPos++ = minx; *pPos++ = miny; *pPos++ = minz; //000 					
+			*pPos++ = minx; *pPos++ = maxy; *pPos++ = minz; //010
+			*pPos++ = maxx; *pPos++ = maxy; *pPos++ = minz; //110
+
+			*pPos++ = maxx; *pPos++ = maxy; *pPos++ = maxz; //111
+			*pPos++ = maxx; *pPos++ = miny; *pPos++ = maxz; //101
+			*pPos++ = minx; *pPos++ = miny; *pPos++ = maxz; //001
+			*pPos++ = minx; *pPos++ = miny; *pPos++ = minz; //000
+		}
+
+        vbuf->unlock();
+	}
+
+	void SolidHalfBoundingBox::setupBoundingBox(const AxisAlignedBox& aabb) 
+    {
+		// init the vertices to the aabb
+		SolidHalfBoundingBox::setupBoundingBoxVertices(aabb);
+
+    	// setup the bounding box of this SimpleRenderable
+		setBoundingBox(aabb);
+	}
+}
+
Index: trunk/VUT/OcclusionCullingSceneManager/src/OgreOcclusionCullingSceneManager.cpp
===================================================================
--- trunk/VUT/OcclusionCullingSceneManager/src/OgreOcclusionCullingSceneManager.cpp	(revision 24)
+++ trunk/VUT/OcclusionCullingSceneManager/src/OgreOcclusionCullingSceneManager.cpp	(revision 26)
@@ -6,5 +6,5 @@
 #include "OgreHardwareOcclusionQuery.h"
 //#include "OgreWireBoundingBox.h"
-#include "OgreSolidBoundingBox.h"
+#include "OgreSolidHalfBoundingBox.h"
 
 #include <windows.h>
@@ -15,6 +15,7 @@
 	OcclusionCullingSceneManager::OcclusionCullingSceneManager(): 
 	mFrameId(1), mDistanceQueue(NULL), mVisibilityThreshold(0), mCurrentTestIdx(0),
-	mQueryMode(MODE_RENDER), mNumSceneNodes(0)
+	mQueryMode(MODE_RENDER), mNumSceneNodes(0), mAlgorithmType(RENDER_COHERENT)
 	{		
+		mHalfBoundingBox[0] = mHalfBoundingBox[1] = 0;
 	}
 	//-----------------------------------------------------------------------
@@ -26,4 +27,7 @@
 	OcclusionCullingSceneManager::~OcclusionCullingSceneManager()
 	{		
+		delete mHalfBoundingBox[0];
+		delete mHalfBoundingBox[1];
+
 		deleteQueries();
 		//SceneManager::~SceneManager();
@@ -37,8 +41,23 @@
 
 		mCurrentTestIdx = 0;
+
 		//renderZPass();
-		//renderCullFrustum();
-		//renderCoherentWithQueue();
-		renderStopAndWait();
+
+		switch(mAlgorithmType)
+		{
+			case RENDER_CULL_FRUSTUM:
+				renderCullFrustum();
+		        break;
+			case RENDER_STOP_AND_WAIT:
+				renderStopAndWait();
+				break;
+			case RENDER_COHERENT:
+				renderCoherentWithQueue();
+				break;
+			default:
+				renderCullFrustum();
+				break;
+		}	
+		
 		delete mDistanceQueue;
 
@@ -67,12 +86,14 @@
 		{
 			while(!queryQueue.empty() && 
-				  (queryQueue.front()->getOcclusionQuery()->resultAvailable() || mDistanceQueue->empty()))
-			{
-				SceneNode *node = queryQueue.front();
+				  ((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;
-				node->getOcclusionQuery()->pullOcclusionQuery(&visiblePixels);
+				query->pullOcclusionQuery(&visiblePixels);
 
 				if(visiblePixels > mVisibilityThreshold)
@@ -99,5 +120,5 @@
 
 					// reset node's visibility classification 
-					node->setVisible(false);
+					node->setNodeVisible(false);
 
 					// update node's visited flag
@@ -107,6 +128,6 @@
 					if(leafOrWasInvisible)
 					{
-						issueOcclusionQuery(node, wasVisible);
-						queryQueue.push(node);
+						HardwareOcclusionQuery *query = issueOcclusionQuery(node, wasVisible);
+						queryQueue.push(query_pair(node, query));
 					}
 					
@@ -126,13 +147,12 @@
 			mDistanceQueue->pop();
 	
-			// interesting for the visualization, so rest and set
-			//node->SetVisible(false);
+			// interesting for visualization purpose
+			node->setNodeVisible(false);
 				
 			if(mCameraInProgress->isVisible(node->_getWorldAABB()))
 			{
-				// update node's visited flag => needed for rendering
-				// so set it also here
-				//node->SetLastVisited(mFrameID);
-				//node->SetVisible(true);
+				// update node's visited flag 
+				node->setLastVisited(mFrameId);
+				node->setNodeVisible(true);
 				traverseNode(node);
 			}
@@ -148,14 +168,14 @@
 		
 			// interesting for the visualization
-			//node->SetVisible(false);
+			node->setNodeVisible(false);
 			node->setLastVisited(mFrameId);
 
 			if(mCameraInProgress->isVisible(node->_getWorldAABB()))
 			{
-				issueOcclusionQuery(node, false);
+				HardwareOcclusionQuery *query = issueOcclusionQuery(node, false);
 				
 				unsigned int visiblePixels;
 				// wait if result not available
-				node->getOcclusionQuery()->pullOcclusionQuery(&visiblePixels);
+				query->pullOcclusionQuery(&visiblePixels);
 				
 				//char str[100]; sprintf(str, "number: %d, id: %d", (int)visiblePixels, mCurrentTestIdx);
@@ -171,5 +191,5 @@
 	}
 	//-----------------------------------------------------------------------
-	void OcclusionCullingSceneManager::issueOcclusionQuery(SceneNode *node, bool wasVisible)
+	HardwareOcclusionQuery *OcclusionCullingSceneManager::issueOcclusionQuery(SceneNode *node, bool wasVisible)
 	{
 		// change state so the bounding box gets not actually rendered on the screen
@@ -178,11 +198,7 @@
 		// get next available test id
 		HardwareOcclusionQuery *query = mOcclusionQueries[mCurrentTestIdx++];
-		node->setOcclusionQuery(query);
-
+		
 		query->beginOcclusionQuery();
 		
-		SolidBoundingBox boxHalf[2];
-		boxHalf[1].mIsFirstHalf = false;
-
 		/*
 		static RenderOperation ro;
@@ -193,13 +209,12 @@
 		box.getRenderOperation(ro);
 		ro.srcRenderable = &box; 
-		mDestRenderSystem->_render(ro);*/
-		for(int i = 0; i < 2; i++)
-		{
-			boxHalf[i].setupBoundingBox(node->_getWorldAABB());
-			//setPass(boxHalf[i].getTechnique()->getPass(0)); //setRenderingMode(MODE_QUERY);
-			SceneManager::renderSingleObject(&boxHalf[i], boxHalf[i].getTechnique()->getPass(0), false);
-		}
+		mDestRenderSystem->_render(ro);
+		*/
+				
+		renderBoundingBox(node);
 
 		query->endOcclusionQuery();
+
+		return query;
 	}
 
@@ -212,6 +227,4 @@
 			bool enabled = (mode == MODE_RENDER);
 			
-		//	char str[100]; sprintf(str, "number: %d", mode);
-		//	MessageBox( NULL, str, "this is my plugin", MB_OK | MB_ICONERROR | MB_TASKMODAL);
 			mDestRenderSystem->_setColourBufferWriteEnabled(enabled, 
 				enabled, enabled, enabled);
@@ -224,5 +237,5 @@
 	void OcclusionCullingSceneManager::traverseNode(SceneNode *node)
 	{
-		if(isLeaf(node)) // reached leaf
+		if(isLeaf(node))
 		{
 			render(node);
@@ -235,6 +248,5 @@
 			{ 
 				SceneNode* sceneChild = static_cast<SceneNode*>(it.getNext());
-				//mDistanceQueue->addRenderable(sceneChild);
-                mDistanceQueue->push(sceneChild);
+				mDistanceQueue->push(sceneChild);
 			}
 		 }
@@ -243,6 +255,6 @@
 	void OcclusionCullingSceneManager::render(SceneNode *node)
 	{
-		setRenderingMode(MODE_RENDER);
-
+		//setRenderingMode(MODE_RENDER);
+		//MessageBox( NULL, "harhar", "this is my plugin", MB_OK | MB_ICONERROR | MB_TASKMODAL);
 		//HACK (too slow)
 		node->_findVisibleObjects(mCameraInProgress, getRenderQueue(), false, 
@@ -267,6 +279,4 @@
 				mOcclusionQueries.push_back(hw);
 			}
-			//char str[100]; sprintf(str, "number: %d", mNumSceneNodes);
-			//MessageBox( NULL, str, "this is my plugin", MB_OK | MB_ICONERROR | MB_TASKMODAL);
 		}
 
@@ -300,8 +310,10 @@
 	void OcclusionCullingSceneManager::pullUpVisibility(SceneNode *node)
 	{
-		while(node && !node->isNodeVisible())
+		while(!node->isNodeVisible())
 		{
 			node->setNodeVisible(true);
-			node = static_cast<SceneNode *>(node->getParent());
+			
+			if(node != mSceneRoot)
+				node = static_cast<SceneNode *>(node->getParent());
 		}
 	}
@@ -314,3 +326,32 @@
 		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];	
+	}
+	//-----------------------------------------------------------------------
+	void OcclusionCullingSceneManager::setAlgorithmType(int type)
+	{
+		mAlgorithmType = type;
+	}
+	//-----------------------------------------------------------------------
+	int OcclusionCullingSceneManager::getAlgorithmType()
+	{
+		return mAlgorithmType;
+	}
 }	
Index: trunk/VUT/OcclusionCullingSceneManager/src/OgreSolidBoundingBox.cpp
===================================================================
--- trunk/VUT/OcclusionCullingSceneManager/src/OgreSolidBoundingBox.cpp	(revision 25)
+++ 	(revision )
@@ -1,92 +1,0 @@
-#include "OgreStableHeaders.h"
-#include "OgreSolidBoundingBox.h"
-
-#include "OgreSimpleRenderable.h"
-#include "OgreHardwareBufferManager.h"
-#include "OgreCamera.h"
-//#include <windows.h>
-
-namespace Ogre {
-    #define POSITION_BINDING 0
-
-	SolidBoundingBox::SolidBoundingBox(): mIsFirstHalf(true)
-    {
-		mRenderOp.vertexData->vertexCount = 8;
-        mRenderOp.operationType = RenderOperation::OT_TRIANGLE_FAN; 
-	}
-	//-----------------------------------------------------------------------
-	void SolidBoundingBox::setupBoundingBoxVertices(const AxisAlignedBox& aab) {
-
-		Vector3 vmax = aab.getMaximum();
-		Vector3 vmin = aab.getMinimum();
-		
-		
-		Real sqLen = std::max(vmax.squaredLength(), vmin.squaredLength());
-        mRadius = Math::Sqrt(sqLen);
-		
-		Real maxx = vmax.x;
-		Real maxy = vmax.y;
-		Real maxz = vmax.z;
-		
-		Real minx = vmin.x;
-		Real miny = vmin.y;
-		Real minz = vmin.z;
-		
-		// fill in the Vertex buffer: 12 lines with 2 endpoints each make up a box
-        HardwareVertexBufferSharedPtr vbuf =
-            mRenderOp.vertexData->vertexBufferBinding->getBuffer(POSITION_BINDING);     
-
-        float* pPos = static_cast<float*>(
-            vbuf->lock(HardwareBuffer::HBL_DISCARD));
-
-		//     5+------+7
-		//     /|     /|
-		//    / |    / |
-		//   / 1+---/--+3
-		// 2+------+6 /    y   z
-		//  | /    | /     |  /
-		//  |/     |/      |/
-		// 0+------+4      *---x
-
-		// fan 1
-		if(mIsFirstHalf)
-		{
-			*pPos++ = minx; *pPos++ = maxy; *pPos++ = maxz; //011
-			*pPos++ = minx; *pPos++ = miny; *pPos++ = maxz; //001
-			*pPos++ = maxx; *pPos++ = miny; *pPos++ = maxz; //101
-			*pPos++ = maxx; *pPos++ = maxy; *pPos++ = maxz; //111
-			
-			*pPos++ = maxx; *pPos++ = maxy; *pPos++ = minz; //110
-			*pPos++ = minx; *pPos++ = maxy; *pPos++ = minz; //010
-			*pPos++ = minx; *pPos++ = miny; *pPos++ = minz; //000
-			*pPos++ = minx; *pPos++ = miny; *pPos++ = maxz; //001
-
-		}
-		else
-		// fan 2
-		{
-			*pPos++ = maxx; *pPos++ = miny; *pPos++ = minz; //100
-			*pPos++ = minx; *pPos++ = miny; *pPos++ = minz; //000 					
-			*pPos++ = minx; *pPos++ = maxy; *pPos++ = minz; //010
-			*pPos++ = maxx; *pPos++ = maxy; *pPos++ = minz; //110
-
-			*pPos++ = maxx; *pPos++ = maxy; *pPos++ = maxz; //111
-			*pPos++ = maxx; *pPos++ = miny; *pPos++ = maxz; //101
-			*pPos++ = minx; *pPos++ = miny; *pPos++ = maxz; //001
-			*pPos++ = minx; *pPos++ = miny; *pPos++ = minz; //000
-		}
-
-        vbuf->unlock();
-	}
-
-	void SolidBoundingBox::setupBoundingBox(const AxisAlignedBox& aabb) 
-    {
-		// init the vertices to the aabb
-		SolidBoundingBox::setupBoundingBoxVertices(aabb);
-
-    	// setup the bounding box of this SimpleRenderable
-		setBoundingBox(aabb);
-
-	}
-}
-
