Index: trunk/VUT/OcclusionCullingSceneManager/include/OgreOcclusionCullingSceneManager.h
===================================================================
--- trunk/VUT/OcclusionCullingSceneManager/include/OgreOcclusionCullingSceneManager.h	(revision 12)
+++ trunk/VUT/OcclusionCullingSceneManager/include/OgreOcclusionCullingSceneManager.h	(revision 19)
@@ -17,10 +17,12 @@
 	{
 	public:
-	
+		myless(Camera *cam) { mCamera = cam; }
 		//bool operator() (HierarchyNode *v1, HierarchyNode *v2) const
 		bool operator() (T v1, T v2) const
 		{
-			return true;//(v1->getSquaredViewDepth(cam) > v2->getSquaredViewDepth(cam));
+			return v1->getSquaredViewDepth(mCamera) > v2->getSquaredViewDepth(mCamera);
 		}
+	private:
+		Camera *mCamera;
 	};
 
@@ -39,15 +41,18 @@
 		/** Overriden from SceneManager. */
 		void _renderVisibleObjects(void);
-
+		void _findVisibleObjects(Camera* cam, bool onlyShadowCasters);
+	
 	protected:
 
-		void walkTree(SceneNode *node);
-
+		void renderZPass();
+		void traverseNode(SceneNode *node);
+		void renderSceneNode(SceneNode *node);
 		/** renders the scene with view frustum culling only */
 		void renderCullFrustum();
 
 		/** we use a priority queue rather than a renderstack */
-		PriorityQueue mDistanceQueue; 
-	
+		PriorityQueue *mDistanceQueue; 
+		// RenderQueue* mDistanceQueue;
+
 		int mFrameID;	
 	};
Index: trunk/VUT/OcclusionCullingSceneManager/src/OgreOcclusionCullingSceneManager.cpp
===================================================================
--- trunk/VUT/OcclusionCullingSceneManager/src/OgreOcclusionCullingSceneManager.cpp	(revision 18)
+++ trunk/VUT/OcclusionCullingSceneManager/src/OgreOcclusionCullingSceneManager.cpp	(revision 19)
@@ -2,4 +2,6 @@
 #include "OgreMath.h"
 #include "OgreIteratorWrappers.h"
+#include "OgreRenderSystem.h"
+#include "OgreCamera.h"
 #include <windows.h>
 
@@ -8,6 +10,11 @@
 	//-----------------------------------------------------------------------
 	OcclusionCullingSceneManager::OcclusionCullingSceneManager(): 
-	mFrameID(1)
+	mFrameID(1), mDistanceQueue(NULL)
 	{		
+	}
+
+	void OcclusionCullingSceneManager::_findVisibleObjects(Camera* cam, bool onlyShadowCasters)
+	{
+		// empty because we have to find in _renderVisibleObjects
 	}
 
@@ -15,11 +22,16 @@
 	void OcclusionCullingSceneManager::_renderVisibleObjects(void)
 	{
-		//RenderZPass();
-		SceneManager::_renderVisibleObjects();
+		mDistanceQueue = new PriorityQueue(myless<SceneNode *>(mCameraInProgress));
+		mDistanceQueue->push(mSceneRoot);
+		//renderZPass();
+		renderCullFrustum();
+		delete mDistanceQueue;
+		//mDestRenderSystem->_setDepthBufferParams(true, false, CMPF_LESS);
+		//SceneManager::_renderVisibleObjects();
+		//mDestRenderSystem->_setDepthBufferParams();
         //mDistanceQueue.push(mSceneRoot);
 		//Preprocess();
-		//printf("registered my plugin!!\n");
-		//MessageBox( NULL, "myplugin", "this is my plugin", MB_OK | MB_ICONERROR | MB_TASKMODAL);
-		renderCullFrustum();
+		
+		//renderCullFrustum();
 
 		//mFrameID ++;
@@ -28,56 +40,69 @@
 
 	//-----------------------------------------------------------------------
+	void OcclusionCullingSceneManager::renderZPass()
+	{
+		traverseNode(mSceneRoot);
+	}
+
+	//-----------------------------------------------------------------------
 	void OcclusionCullingSceneManager::renderCullFrustum()
 	{
-		//RenderQueue::QueueGroupIterator queueIt = getRenderQueue()->_getQueueGroupIterator();
-
-		 //while (queueIt.hasMoreElements())
-		if(! mDistanceQueue.empty())
+		while(!mDistanceQueue->empty())
 		{
-			SceneNode *node = mDistanceQueue.top();
-			mDistanceQueue.pop();
-
-			 //walkTree(
-
-		}
-			 /*
-			HierarchyNode *node = mDistanceQueue.top();
-			mDistanceQueue.pop();
+			SceneNode *node = mDistanceQueue->top();
+			mDistanceQueue->pop();
 	
 			// interesting for the visualization, so rest and set
-			node->SetVisible(false);
-			
-			// We don't need to know about near plane intersection 
-			// for frustum culling only, but we have to pass a parameter
-			bool intersectsNearplane;
-			if(InsideViewFrustum(node, intersectsNearplane))
+			//node->SetVisible(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);
-				TraverseNode(node);
+				//node->SetLastVisited(mFrameID);
+				//node->SetVisible(true);
+				traverseNode(node);
 			}
-		}*/
+			//else
+			//MessageBox( NULL, "myplugin registered", "this is my plugin", MB_OK | MB_ICONERROR | MB_TASKMODAL);
+		}
 	}
 
 	//-----------------------------------------------------------------------
-	void OcclusionCullingSceneManager::walkTree(SceneNode *node)
+	void OcclusionCullingSceneManager::traverseNode(SceneNode *node)
 	{
-		if(node->numChildren() > 0)
+		if(node->numChildren() == 0) // reached leaf
 		{
-			//node->Render();
+			renderSceneNode(node);
 		}
 		else // internal node: add children to priority queue for further processing
 		{
 			Node::ChildNodeIterator it = node->getChildIterator();
+			char str[100]; sprintf(str, "number of children: %d", node->numChildren());
 		
 			while (it.hasMoreElements())
-			{
+			{ 
 				SceneNode* sceneChild = static_cast<SceneNode*>(it.getNext());
-				//getRenderQueue()->addRenderable(sceneChild);
-                mDistanceQueue.push(sceneChild);
+				//mDistanceQueue->addRenderable(sceneChild);
+                mDistanceQueue->push(sceneChild);
 			}
-		}
+		 }
+
+		 /*
+		 static RenderOperation ro;
+		 node->getRenderOperation(ro);
+		 ro.srcRenderable = node; 
+		 mDestRenderSystem->_render(ro);
+		 Pass pass();
+		 renderSingleObject(node, &pass, true);
+		 */
+	}
+
+	void OcclusionCullingSceneManager::renderSceneNode(SceneNode *node)
+	{
+		node->_findVisibleObjects(mCameraInProgress, getRenderQueue(), false, 
+								  mDisplayNodes, false);
+		SceneManager::_renderVisibleObjects();
+		getRenderQueue()->clear();
 	}
 }	
