Index: /trunk/VUT/OcclusionCullingSceneManager/include/OgreOcclusionCullingOctreeSceneManager.h
===================================================================
--- /trunk/VUT/OcclusionCullingSceneManager/include/OgreOcclusionCullingOctreeSceneManager.h	(revision 44)
+++ /trunk/VUT/OcclusionCullingSceneManager/include/OgreOcclusionCullingOctreeSceneManager.h	(revision 44)
@@ -0,0 +1,66 @@
+#ifndef _OcclusionCullingTerrainSceneManager_H__
+#define _OcclusionCullingTerrainSceneManager_H__
+
+#include <OgreSceneNode.h>
+#include <OgreOctreeSceneManager.h>
+#include <OgreTerrainSceneManager.h>
+#include <OgreOctreeSceneQuery.h>
+#include <OgreOctreeNode.h>
+#include <OgreOctreeCamera.h>
+
+#include "OgrePrerequisites.h"
+#include "OgreOcclusionCullingTerrainSceneTraverser.h"
+//#include "OgreSolidHalfBoundingBox.h"
+
+using namespace std;
+
+namespace Ogre {
+	/**
+		Class which implements a scene mangager which uses occlusion queries for culling occluded objects
+	*/
+	class OcclusionCullingTerrainSceneManager: public TerrainSceneManager
+	{
+	public:
+		OcclusionCullingTerrainSceneManager();
+		~OcclusionCullingTerrainSceneManager();
+	
+		void _renderVisibleObjects(void);
+		void _findVisibleObjects(Camera* cam, bool onlyShadowCasters);
+		void _updateSceneGraph(Camera* cam);
+
+		/** Sets the given option for the SceneManager
+			       @remarks
+			Options are:
+			"Algorithm", int *;			
+		*/
+		
+		virtual bool setOption( const String &, const void * );
+		/** Gets the given option for the Scene Manager.
+	        @remarks
+		    See setOption
+		*/
+		virtual bool getOption( const String &, void * );
+
+		bool getOptionValues( const String & key, StringVector &refValueList );
+		bool getOptionKeys( StringVector &refKeys );
+
+		/** Renders one octant of an octree, i.e., renders current octant
+			node and does not traverse deeper into the tree.
+			@remark Note that OctreeNode instances are NOT part of the octree 
+			hierarchy, instead one octant of an Octree contains many OctreeNode instances.
+			@param octree the octree to be rendered
+			@param cam current camera
+		*/
+		void _renderOctant(Camera* cam, Octree *octree);
+
+	protected:
+		/** Recursively counts octree size (i.e., number of octree instances)
+		@param root current octree
+		*/
+		//unsigned int countOctreeSize(Octree *root);
+
+		OcclusionCullingTerrainSceneTraverser *mOcclusionCullingTerrainSceneTraverser;
+	};
+
+}
+#endif // OcclusionCullingTerrainSceneManager_H
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());
Index: /trunk/VUT/OcclusionCullingSceneManager/TestCulling/TestCulling.vcproj
===================================================================
--- /trunk/VUT/OcclusionCullingSceneManager/TestCulling/TestCulling.vcproj	(revision 33)
+++ /trunk/VUT/OcclusionCullingSceneManager/TestCulling/TestCulling.vcproj	(revision 44)
@@ -122,4 +122,7 @@
 			UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}">
 			<File
+				RelativePath=".\TerrainContentGenerator.cpp">
+			</File>
+			<File
 				RelativePath=".\TestCullingApplication.cpp">
 			</File>
@@ -129,4 +132,7 @@
 			Filter="h;hpp;hxx;hm;inl;inc;xsd"
 			UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}">
+			<File
+				RelativePath=".\TerrainContentGenerator.h">
+			</File>
 			<File
 				RelativePath=".\TestCullingApplication.h">
Index: /trunk/VUT/OcclusionCullingSceneManager/TestCulling/TestCullingApplication.cpp
===================================================================
--- /trunk/VUT/OcclusionCullingSceneManager/TestCulling/TestCullingApplication.cpp	(revision 42)
+++ /trunk/VUT/OcclusionCullingSceneManager/TestCulling/TestCullingApplication.cpp	(revision 44)
@@ -20,13 +20,13 @@
 #include "windows.h"
 
-RaySceneQuery* raySceneQuery = 0;
+//RaySceneQuery* mRaySceneQuery = 0;
 
 /***********************************************/
 /* TestCullingApplication implementation       */
 /***********************************************/
-TestCullingApplication::~TestCullingApplication()
-{
-	delete raySceneQuery;
-}
+/*TestCullingApplication::~TestCullingApplication()
+{
+	delete mRaySceneQuery;
+}*/
 //-----------------------------------------------------------------------
 void TestCullingApplication::createCamera( void )
@@ -57,5 +57,5 @@
 	l->setPosition(20,80,50);
 
-	// Fog
+	// --Fog
 	// NB it's VERY important to set this before calling setWorldGeometry 
 	// because the vertex program picked will be different
@@ -66,7 +66,7 @@
 	mWindow->getViewport(0)->setBackgroundColour(fadeColour);
 
-	 // Create a skybox
-     //mSceneMgr->setSkyBox(true, "Examples/SpaceSkyBox", 500, false);
-	 //mSceneMgr->setSkyDome( true, "Examples/CloudySky", 5, 8, 500, false );
+	// Create a skybox
+    //mSceneMgr->setSkyBox(true, "Examples/SpaceSkyBox", 500, false);
+	//mSceneMgr->setSkyDome( true, "Examples/CloudySky", 5, 8, 500, false );
 
 	std::string terrain_cfg("terrain.cfg");
@@ -94,8 +94,8 @@
 	mCamera->setOrientation(Quaternion(-0.3486, 0.0122, 0.9365, 0.0329));
 
-	raySceneQuery = mSceneMgr->createRayQuery(
-	Ray(mCamera->getPosition(), Vector3::NEGATIVE_UNIT_Y));
-
-	Entity *robotEnt = mSceneMgr->createEntity( "Robot", "robot.mesh" );
+	//mRaySceneQuery = mSceneMgr->createRayQuery(
+	//	Ray(mCamera->getPosition(), Vector3::NEGATIVE_UNIT_Y));
+
+	/*Entity *robotEnt = mSceneMgr->createEntity( "Robot", "robot.mesh" );
 	SceneNode *robotNode = mSceneMgr->getRootSceneNode()->createChildSceneNode( "RobotNode", Vector3( 750, 25, 600 ));
 	robotNode->attachObject( robotEnt );
@@ -113,5 +113,5 @@
     ogreNode2->attachObject( ogreEnt2 );
 	ogreNode2->scale(.05,.05,.05);
-	ogreNode->yaw( Degree( 40 ) );
+	ogreNode->yaw( Degree( 40 ) );*/
 
 	// CEGUI setup
@@ -131,10 +131,4 @@
 
 	 CEGUI::MouseCursor::getSingleton().show( );
-     
-	/* CEGUI::Window* sheet = 
-            CEGUI::WindowManager::getSingleton().loadWindowLayout(
-                (CEGUI::utf8*)"ogregui.layout"); 
-
-     mGUISystem->setGUISheet(sheet);*/
 }
 //-----------------------------------------------------------------------
@@ -155,5 +149,4 @@
 /* MouseQueryListener implementation           */
 /***********************************************/
-
 //-----------------------------------------------------------------------
 MouseQueryListener::MouseQueryListener(RenderWindow* win, Camera* cam, SceneManager *sceneManager, CEGUI::Renderer *renderer)
@@ -163,5 +156,5 @@
 
 	// Setup default variables
-//	mCurrentObject = NULL;
+	mCurrentObject = NULL;
 	mLMouseDown = false;
 	mRMouseDown = false;
@@ -180,4 +173,6 @@
 	mEventProcessor->addKeyListener(this);
 
+	mRaySceneQuery = mSceneMgr->createRayQuery( Ray() );
+
 	// show overlay
 	Overlay* pOver = OverlayManager::getSingleton().getByName("Example/OcclusionCullingDemoOverlay"); 
@@ -200,5 +195,10 @@
 
     pOver->show();
-} // MouseQueryListener
+} 
+//-----------------------------------------------------------------------
+MouseQueryListener::~MouseQueryListener( )
+{
+	delete mRaySceneQuery;
+}
 //-----------------------------------------------------------------------
 void MouseQueryListener::mouseMoved (MouseEvent *e)
@@ -214,6 +214,27 @@
      {
 		 CEGUI::MouseCursor::getSingleton().hide( );
-		 mLMouseDown = true;
-     } // if
+
+		 // Setup the ray scene query
+         Ray mouseRay = mCamera->getCameraToViewportRay( e->getX(), e->getY() );
+         mRaySceneQuery->setRay( mouseRay );
+
+         // Execute query
+         RaySceneQueryResult &result = mRaySceneQuery->execute();
+         RaySceneQueryResult::iterator itr = result.begin( );
+
+         // Get results, create a node/entity on the position
+         if ( itr != result.end() && itr->worldFragment )
+         {
+			 char name[16];
+             sprintf( name, "Robot%d", mCount++ );
+
+             Entity *ent = mSceneMgr->createEntity( name, "robot.mesh" );
+             mCurrentObject = mSceneMgr->getRootSceneNode( )->createChildSceneNode( String(name) + "Node", itr->worldFragment->singleIntersection );
+             mCurrentObject->attachObject( ent );
+             mCurrentObject->setScale( 0.1f, 0.1f, 0.1f );
+         }
+
+         mLMouseDown = true; 
+     }
      // Right mouse button down
      else if (e->getButtonID() & InputEvent::BUTTON1_MASK)
@@ -243,12 +264,18 @@
 void MouseQueryListener::mouseDragged (MouseEvent *e)
  {
-	 /*
-	 // If we are dragging the left mouse button.	 
+	 // If we are dragging the left mouse button.	 	 
 	 if ( mLMouseDown )
-	 {
-		mShipNode->translate(-e->getRelX() * 200, -e->getRelY() * 200, 0.0);
+     {
+		 Ray mouseRay = mCamera->getCameraToViewportRay( e->getX(), e->getY() );
+		 mRaySceneQuery->setRay( mouseRay );
+
+		 RaySceneQueryResult &result = mRaySceneQuery->execute();
+		 RaySceneQueryResult::iterator itr = result.begin( );
+
+		 if ( itr != result.end() && itr->worldFragment )
+		 {
+			 mCurrentObject->setPosition( itr->worldFragment->singleIntersection );
+		 } 
      }
-	 */
-	 
 	 // If we are dragging the right mouse button.
 	 if ( mRMouseDown )
@@ -262,16 +289,17 @@
 {
 	// clamp to terrain
-	static Ray updateRay;
-	updateRay.setOrigin(mCamera->getPosition());
-	updateRay.setDirection(Vector3::NEGATIVE_UNIT_Y);
-	raySceneQuery->setRay(updateRay);
-	RaySceneQueryResult& qryResult = raySceneQuery->execute();
-	RaySceneQueryResult::iterator i = qryResult.begin();
-	 
-	if (i != qryResult.end() && i->worldFragment)
+	Vector3 camPos = mCamera->getPosition( );
+    Ray cameraRay( Vector3(camPos.x, 5000.0f, camPos.z), Vector3::NEGATIVE_UNIT_Y );
+    mRaySceneQuery->setRay( cameraRay );
+
+    // Perform the scene query
+    RaySceneQueryResult &queryResult = mRaySceneQuery->execute();
+    RaySceneQueryResult::iterator it = queryResult.begin( );
+
+	if (it != queryResult.end() && it->worldFragment)
 	{
-		SceneQuery::WorldFragment* wf = i->worldFragment;
-		mCamera->setPosition(mCamera->getPosition().x, 
-			i->worldFragment->singleIntersection.y + 10, 
+		SceneQuery::WorldFragment* wf = it->worldFragment;
+
+		mCamera->setPosition(mCamera->getPosition().x, wf->singleIntersection.y + 10, 
 			mCamera->getPosition().z);
 	}
@@ -290,5 +318,5 @@
     KEY_PRESSED(KC_SPACE, 0.3, changeAlgorithm());
 
-	KEY_PRESSED(KC_SUBTRACT, 0.3, changeThreshold(-10));
+	KEY_PRESSED(KC_SUBTRACT, 0, changeThreshold(-10));
 	KEY_PRESSED(KC_ADD, 0, changeThreshold(10));
 	//KEY_PRESSED(KC_T, 1, change);
Index: /trunk/VUT/OcclusionCullingSceneManager/TestCulling/TerrainContentGenerator.cpp
===================================================================
--- /trunk/VUT/OcclusionCullingSceneManager/TestCulling/TerrainContentGenerator.cpp	(revision 44)
+++ /trunk/VUT/OcclusionCullingSceneManager/TestCulling/TerrainContentGenerator.cpp	(revision 44)
@@ -0,0 +1,14 @@
+/**
+    \file 
+        TerrainContentGenerator.cpp
+    \brief
+        Creates content for the terrain,
+*/
+
+#include "TerrainContentGenerator.h"
+
+//-----------------------------------------------------------------------
+TerrainContentGenerator::TerrainContentGenerator( void )
+{
+}
+
Index: /trunk/VUT/OcclusionCullingSceneManager/TestCulling/TestCullingApplication.h
===================================================================
--- /trunk/VUT/OcclusionCullingSceneManager/TestCulling/TestCullingApplication.h	(revision 42)
+++ /trunk/VUT/OcclusionCullingSceneManager/TestCulling/TestCullingApplication.h	(revision 44)
@@ -5,5 +5,4 @@
 #include "CEGUIForwardRefs.h"
 #include "ExampleApplication.h"
-//#include "OgreOcclusionCullingSceneManager.h"
 #include "OgreOcclusionCullingSceneTraverser.h"
 
@@ -32,7 +31,5 @@
 
 
-    ~MouseQueryListener( )
-    {
-    }
+    ~MouseQueryListener( );
 
 	bool frameStarted(const FrameEvent& evt);
@@ -82,4 +79,8 @@
 	OverlayElement *mHierarchyNodesInfo;
 	OverlayElement *mSceneNodesInfo;
+
+	SceneNode *mCurrentObject;         // The newly created object
+	int mCount;                        // The number of robots on the screen
+	RaySceneQuery *mRaySceneQuery;     // The ray scene query pointer
 };
 
@@ -88,5 +89,5 @@
 {
 public:
-	~TestCullingApplication();
+	//~TestCullingApplication();
 
 protected:
@@ -101,7 +102,4 @@
 private:
 	void chooseSceneManager(void);
-
-	//Entity* mShip;
-	//SceneNode* mShipNode;
 };
 
Index: /trunk/VUT/OcclusionCullingSceneManager/TestCulling/TerrainContentGenerator.h
===================================================================
--- /trunk/VUT/OcclusionCullingSceneManager/TestCulling/TerrainContentGenerator.h	(revision 44)
+++ /trunk/VUT/OcclusionCullingSceneManager/TestCulling/TerrainContentGenerator.h	(revision 44)
@@ -0,0 +1,14 @@
+/**
+    \file 
+        TerrainContentGenerator.h
+*/
+
+class TerrainContentGenerator
+{
+public:
+	TerrainContentGenerator();
+
+protected:
+
+};
+
