Index: /trunk/VUT/OcclusionCullingSceneManager/TestCullingDotScene/TestCullingDotSceneApplication.cpp
===================================================================
--- /trunk/VUT/OcclusionCullingSceneManager/TestCullingDotScene/TestCullingDotSceneApplication.cpp	(revision 37)
+++ /trunk/VUT/OcclusionCullingSceneManager/TestCullingDotScene/TestCullingDotSceneApplication.cpp	(revision 39)
@@ -481,17 +481,19 @@
 void MouseQueryListener::mouseDragged (MouseEvent *e)
  {
-	 /*
 	 // If we are dragging the left mouse button.	 
 	 if ( mLMouseDown )
 	 {
-		mShipNode->translate(-e->getRelX() * 200, -e->getRelY() * 200, 0.0);
+		mCamera->yaw( -e->getRelX() * mRotateSpeed );
+		mCamera->pitch( -e->getRelY() * mRotateSpeed );
      }
-	 */
-	 
+	 	 
 	 // If we are dragging the right mouse button.
 	 if ( mRMouseDown )
 	 {
-		 mCamera->yaw( -e->getRelX() * mRotateSpeed );
-		 mCamera->pitch( -e->getRelY() * mRotateSpeed );
+		 Vector3 translation;
+		 translation.x += -e->getRelX() * 0.13;
+		 translation.y -= -e->getRelY() * 0.13;
+
+		 mCamera->moveRelative(translation);		
 	 }
 }
Index: /trunk/VUT/OcclusionCullingSceneManager/include/OgreOcclusionCullingTerrainSceneTraverser.h
===================================================================
--- /trunk/VUT/OcclusionCullingSceneManager/include/OgreOcclusionCullingTerrainSceneTraverser.h	(revision 36)
+++ /trunk/VUT/OcclusionCullingSceneManager/include/OgreOcclusionCullingTerrainSceneTraverser.h	(revision 39)
@@ -2,4 +2,5 @@
 #define _OcclusionCullingTerrainSceneTraverser_H__
 
+#include "OgreOctree.h"
 #include "OgreOcclusionCullingSceneTraverser.h"
 
@@ -7,8 +8,18 @@
 
 namespace Ogre {
+void Octree::_getCullBounds( AxisAlignedBox *b )
+	typedef pair<Octree *, HardwareOcclusionQuery *> OctreeQueryPair;
+	typedef priority_queue<Octree *, vector<Octree *>, myless<vector<Octree *>::value_type> > OctreePriorityQueue;
+	//typedef queue<QueryPair> QueryQueue;
 
 	class OcclusionCullingTerrainSceneTraverser: OcclusionCullingSceneTraverser
 	{
-		void traverseNode( Camera *cam, SceneNode *node );
+		void renderScene( Camera *cam, Octree *root );
+		void renderCullFrustum( Camera *cam );
+		void pullUpVisibility( Octree *node );
+		void traverseNode( Camera *cam, Octree *node );
+
+	protected:
+		OctreePriorityQueue *mDistanceQueue;
 	};
 
Index: /trunk/VUT/OcclusionCullingSceneManager/include/OgreOcclusionCullingSceneTraverser.h
===================================================================
--- /trunk/VUT/OcclusionCullingSceneManager/include/OgreOcclusionCullingSceneTraverser.h	(revision 36)
+++ /trunk/VUT/OcclusionCullingSceneManager/include/OgreOcclusionCullingSceneTraverser.h	(revision 39)
@@ -30,7 +30,7 @@
 	};
 
-	typedef pair<SceneNode *, HardwareOcclusionQuery *> query_pair;
+	typedef pair<SceneNode *, HardwareOcclusionQuery *> QueryPair;
 	typedef priority_queue<SceneNode *, vector<SceneNode *>, myless<vector<SceneNode *>::value_type> > PriorityQueue;
-	typedef queue<query_pair> QueryQueue;
+	typedef queue<QueryPair> QueryQueue;
 	/**
 		Class which implements a scene mangager which uses occlusion queries for culling occluded objects
@@ -100,5 +100,5 @@
 		//HACK
 		//unsigned int countSceneNodes(SceneNode *node);
-		virtual void traverseNode( Camera *cam, SceneNode *node );
+		void traverseNode( Camera *cam, SceneNode *node );
 		/** Renders current scene node 
 		@param cam current camera
Index: /trunk/VUT/OcclusionCullingSceneManager/include/OgreOcclusionCullingTerrainSceneManager.h
===================================================================
--- /trunk/VUT/OcclusionCullingSceneManager/include/OgreOcclusionCullingTerrainSceneManager.h	(revision 34)
+++ /trunk/VUT/OcclusionCullingSceneManager/include/OgreOcclusionCullingTerrainSceneManager.h	(revision 39)
@@ -16,5 +16,20 @@
 
 namespace Ogre {
-	
+	template <typename T> class octreeless
+	{
+	public:
+		myless(Camera *cam) { mCamera = cam; }
+		//bool operator() (HierarchyNode *v1, HierarchyNode *v2) const
+		bool operator() (T v1, T v2) const
+		{
+			v1->getCullBounds(&mAabb);
+			return mAabb->getSquaredViewDepth(mCamera) > v2->getSquaredViewDepth(mCamera);
+		}
+
+	private:
+		Camera *mCamera;
+		AxisAlignedBox mAabb;
+	};
+
 	/**
 		Class which implements a scene mangager which uses occlusion queries for culling occluded objects
Index: /trunk/VUT/OcclusionCullingSceneManager/src/OgreOcclusionCullingSceneTraverser.cpp
===================================================================
--- /trunk/VUT/OcclusionCullingSceneManager/src/OgreOcclusionCullingSceneTraverser.cpp	(revision 38)
+++ /trunk/VUT/OcclusionCullingSceneManager/src/OgreOcclusionCullingSceneTraverser.cpp	(revision 39)
@@ -118,5 +118,5 @@
 					{
 						HardwareOcclusionQuery *query = issueOcclusionQuery(node, wasVisible);
-						queryQueue.push(query_pair(node, query));
+						queryQueue.push(QueryPair(node, query));
 					}
 					
@@ -322,9 +322,13 @@
 		for(int half = 0; half < 2; half ++)
 		{
+			//static Matrix4 xform[256];
+
 			SolidHalfBoundingBox *box = getSolidHalfBoundingBox(half);
+			box->setupBoundingBox(node->_getWorldAABB());
+
+			mRenderSystem->_setWorldMatrix(Matrix4::IDENTITY);
 			
-			box->setupBoundingBox(node->_getWorldAABB());
-
 			static RenderOperation ro;
+
 			mSceneManager->useRenderableViewProjMode(box);
 			box->getRenderOperation(ro);
Index: /trunk/VUT/OcclusionCullingSceneManager/src/OgreOcclusionCullingDotSceneManager.cpp
===================================================================
--- /trunk/VUT/OcclusionCullingSceneManager/src/OgreOcclusionCullingDotSceneManager.cpp	(revision 38)
+++ /trunk/VUT/OcclusionCullingSceneManager/src/OgreOcclusionCullingDotSceneManager.cpp	(revision 39)
@@ -31,7 +31,7 @@
 		addSpecialCaseRenderQueue(RENDER_QUEUE_BACKGROUND);
 		addSpecialCaseRenderQueue(RENDER_QUEUE_SKIES_EARLY);
-		
+	
 		setSpecialCaseRenderQueueMode(SceneManager::SCRQM_INCLUDE);
-		//DotSceneManager::_renderVisibleObjects( );
+		DotSceneManager::_renderVisibleObjects( );
 		_deleteRenderedQueueGroups();
 
Index: /trunk/VUT/OcclusionCullingSceneManager/src/OgreOcclusionCullingTerrainSceneTraverser.cpp
===================================================================
--- /trunk/VUT/OcclusionCullingSceneManager/src/OgreOcclusionCullingTerrainSceneTraverser.cpp	(revision 37)
+++ /trunk/VUT/OcclusionCullingSceneManager/src/OgreOcclusionCullingTerrainSceneTraverser.cpp	(revision 39)
@@ -4,64 +4,84 @@
 namespace Ogre {
 	//-----------------------------------------------------------------------
-	void OcclusionCullingTerrainSceneTraverser::traverseNode( Camera *cam, SceneNode *node )
+	void OcclusionCullingTerrainSceneTraverser::traverseNode( Camera *cam, Octree *node )
 	{
 		mNumTraversedNodes ++;
-		
-		if(node->numAttachedObjects() > 0)
+	
+	/*	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 OcclusionCullingTerrainSceneTraverser::renderSceneNode( Camera *cam, SceneNode *node )
-	{
-		setRenderingMode(MODE_RENDER);
-		
-		//HACK (too slow)
-		mSceneManager->_renderSceneNode(cam, node);
-		//MessageBox( NULL, "myplugin registered", "this is my plugin", MB_OK | MB_ICONERROR | MB_TASKMODAL);
-	}
-	//-----------------------------------------------------------------------
-	bool OcclusionCullingTerrainSceneTraverser::isLeaf( SceneNode *node )
-	{
-		return (node->numChildren() == 0);
-	}
-	//-----------------------------------------------------------------------
-	void OcclusionCullingTerrainSceneTraverser::pullUpVisibility( SceneNode *node )
-	{
-		while(node && !node->isNodeVisible())
+		for(int i=0; i<8; i++)
 		{
-			node->setNodeVisible(true);
-			node = static_cast<SceneNode *>(node->getParent());
+			if(node->mChildren[i & 4][i & 2][i & 1] != 0)
+				traverseNode(cam, node->mChildren[i & 4][i & 2][i & 1]);
 		}
 	}
 	//-----------------------------------------------------------------------
-	void OcclusionCullingTerrainSceneTraverser::renderBoundingBox( SceneNode *node )
+	void OcclusionCullingTerrainSceneTraverser::renderScene( Camera *cam, Octree *root )
 	{
-		// Render two halfes of the bounding box (using triangle fans)
-		for(int half = 0; half < 2; half ++)
+		mNumTraversedNodes = 0;
+		mNumQueryCulledNodes = 0;
+		mNumFrustumCulledNodes = 0;
+		mNumRenderedGeometry = 0;
+		
+		mDistanceQueue = new OctreePriorityQueue(myless<Octree *>(cam));
+//		mDistanceQueue->push(root);
+		mCurrentTestIdx = 0;
+
+mCurrentAlgorithm = RENDER_CULL_FRUSTUM;
+		switch(mCurrentAlgorithm)
 		{
-			SolidHalfBoundingBox *box = getSolidHalfBoundingBox(half);
-			
-			box->setupBoundingBox(node->_getWorldAABB());
+			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;
 
-			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);
-		}
+		mFrameId ++;
+	}
+	//-----------------------------------------------------------------------
+	void OcclusionCullingTerrainSceneTraverser::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 ++;
+			}
+		}*/
+	}	
+	//-----------------------------------------------------------------------
+/*	bool OcclusionCullingTerrainSceneTraverser::isLeaf( SceneNode *node )
+	{
+		return (node->numChildren() == 0);
 	}*/
+	//-----------------------------------------------------------------------
+	void OcclusionCullingTerrainSceneTraverser::pullUpVisibility( Octree *node )
+	{
+	}
 }	
