Index: trunk/VUT/OcclusionCullingSceneManager/TestCulling/TestCullingApplication.cpp
===================================================================
--- trunk/VUT/OcclusionCullingSceneManager/TestCulling/TestCullingApplication.cpp	(revision 33)
+++ trunk/VUT/OcclusionCullingSceneManager/TestCulling/TestCullingApplication.cpp	(revision 34)
@@ -20,22 +20,83 @@
 #include "windows.h"
 
+RaySceneQuery* raySceneQuery = 0;
+
 /***********************************************/
 /* TestCullingApplication implementation       */
 /***********************************************/
-
-
+TestCullingApplication::~TestCullingApplication()
+{
+	delete raySceneQuery;
+}
+//-----------------------------------------------------------------------
+void TestCullingApplication::createCamera( void )
+{
+	// Create the camera
+	mCamera = mSceneMgr->createCamera("PlayerCam");
+
+	// Position it at 500 in Z direction
+	mCamera->setPosition(Vector3(128,25,128));
+
+	// Look back along -Z
+    mCamera->lookAt(Vector3(0,0,-300));
+    mCamera->setNearClipDistance( 1 );
+    mCamera->setFarClipDistance( 1000 );
+}
 //-----------------------------------------------------------------------
 void TestCullingApplication::createScene(void)
 {
+	Plane waterPlane;
+	// Set ambient light
+	mSceneMgr->setAmbientLight(ColourValue(0.5, 0.5, 0.5));
+	
+	// Create a light
+	Light* l = mSceneMgr->createLight("MainLight");
+	// Accept default settings: point light, white diffuse, just set position
+	// NB I could attach the light to a SceneNode if I wanted it to move automatically with
+	//  other objects, but I don't
+	l->setPosition(20,80,50);
+
+	// Fog
+	// NB it's VERY important to set this before calling setWorldGeometry 
+	// because the vertex program picked will be different
+	ColourValue fadeColour(0.93, 0.86, 0.76);
+	mSceneMgr->setFog( FOG_LINEAR, fadeColour, .001, 500, 1000);
+	mWindow->getViewport(0)->setBackgroundColour(fadeColour);
+
+	std::string terrain_cfg("terrain.cfg");
+#if OGRE_PLATFORM == OGRE_PLATFORM_APPLE
+	terrain_cfg = mResourcePath + terrain_cfg;
+#endif
+	mSceneMgr -> setWorldGeometry( terrain_cfg );
+	// Infinite far plane?
+	if (mRoot->getRenderSystem()->getCapabilities()->hasCapability(RSC_INFINITE_FAR_PLANE))
+	{
+		mCamera->setFarClipDistance(0);
+	}
+
+	// Define the required skyplane
+	Plane plane;
+	// 5000 world units from the camera
+	plane.d = 5000;
+	// Above the camera, facing down
+	plane.normal = -Vector3::UNIT_Y;
+
+	// Set a nice viewpoint
+	mCamera->setPosition(707,2500,528);
+	mCamera->setOrientation(Quaternion(-0.3486, 0.0122, 0.9365, 0.0329));
+
+	raySceneQuery = mSceneMgr->createRayQuery(
+	Ray(mCamera->getPosition(), Vector3::NEGATIVE_UNIT_Y));
+
      // Create a skybox
-     mSceneMgr->setSkyBox(true, "Examples/SpaceSkyBox");
-	 mShip = mSceneMgr->createEntity("razor", "razor.mesh");
-	 mShipNode = mSceneMgr->getRootSceneNode()->createChildSceneNode();
-	 mShipNode->attachObject(mShip);
-
-	 mSceneMgr->setAmbientLight(ColourValue(0.5, 0.5, 0.5));
+  //   mSceneMgr->setSkyBox(true, "Examples/SpaceSkyBox");
 
 	 // CEGUI setup
-     mGUIRenderer = new CEGUI::OgreCEGUIRenderer(mWindow, Ogre::RENDER_QUEUE_OVERLAY, false, 3000, ST_GENERIC);
+	 setupGui();
+}
+//-----------------------------------------------------------------------
+void TestCullingApplication::setupGui( void )
+{
+	 mGUIRenderer = new CEGUI::OgreCEGUIRenderer(mWindow, Ogre::RENDER_QUEUE_OVERLAY, false, 3000, ST_EXTERIOR_CLOSE);
      mGUISystem = new CEGUI::System(mGUIRenderer);
 
@@ -57,5 +118,5 @@
 void TestCullingApplication::createFrameListener(void)
 {
-	mFrameListener= new MouseQueryListener(mWindow, mCamera, mSceneMgr, mGUIRenderer, mShipNode);
+	mFrameListener= new MouseQueryListener(mWindow, mCamera, mSceneMgr, mGUIRenderer);
 	mFrameListener->showDebugOverlay(true);
 	mRoot->addFrameListener(mFrameListener);
@@ -73,11 +134,11 @@
 
 //-----------------------------------------------------------------------
-MouseQueryListener::MouseQueryListener(RenderWindow* win, Camera* cam, SceneManager *sceneManager, CEGUI::Renderer *renderer,
-					   SceneNode* shipNode)
-        : ExampleFrameListener(win, cam, false, true), mGUIRenderer(renderer), mShipNode(shipNode)//,  mShutdownRequested(false)
+MouseQueryListener::MouseQueryListener(RenderWindow* win, Camera* cam, SceneManager *sceneManager, CEGUI::Renderer *renderer)
+        : ExampleFrameListener(win, cam, false, true), mGUIRenderer(renderer), 
+		mShutdownRequested(false)
 {
 
 	// Setup default variables
-	mCurrentObject = NULL;
+//	mCurrentObject = NULL;
 	mLMouseDown = false;
 	mRMouseDown = false;
@@ -144,5 +205,5 @@
 		CEGUI::MouseCursor::getSingleton().show( );
         mLMouseDown = false;
-    } // if
+    }
     // Right mouse button up
     else if (e->getButtonID() & InputEvent::BUTTON1_MASK)
@@ -150,22 +211,45 @@
         CEGUI::MouseCursor::getSingleton().show( );
         mRMouseDown = false;
-    } // else if
-} // mouseReleased
+    }
+} 
 //-----------------------------------------------------------------------
 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);
-     } // if
-
-    // If we are dragging the right mouse button.
-    else if ( mRMouseDown )
-    {
-        mCamera->yaw( -e->getRelX() * mRotateSpeed );
-        mCamera->pitch( -e->getRelY() * mRotateSpeed );
-    } // else if
-} // mouseDragged
+	 /*
+	 // If we are dragging the left mouse button.	 
+	 if ( mLMouseDown )
+	 {
+		mShipNode->translate(-e->getRelX() * 200, -e->getRelY() * 200, 0.0);
+     }
+	 */
+	 
+	 // If we are dragging the right mouse button.
+	 if ( mRMouseDown )
+	 {
+		 mCamera->yaw( -e->getRelX() * mRotateSpeed );
+		 mCamera->pitch( -e->getRelY() * mRotateSpeed );
+	 }
+}
+//-----------------------------------------------------------------------
+bool MouseQueryListener::frameStarted(const FrameEvent &evt)
+{
+	// 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)
+	{
+		SceneQuery::WorldFragment* wf = i->worldFragment;
+		mCamera->setPosition(mCamera->getPosition().x, 
+			i->worldFragment->singleIntersection.y + 10, 
+			mCamera->getPosition().z);
+	}
+	 
+	return ExampleFrameListener::frameStarted(evt);
+}
 //-----------------------------------------------------------------------
 bool MouseQueryListener::frameEnded(const FrameEvent& evt)
@@ -252,7 +336,10 @@
     TestCullingApplication app;
 
-	try {
+	try 
+	{
         app.go();
-    } catch( Ogre::Exception& e ) {
+    } 
+	catch( Ogre::Exception& e ) 
+	{
         MessageBox( NULL, e.getFullDescription().c_str(), "An exception has occured!", MB_OK | MB_ICONERROR | MB_TASKMODAL);
     }	
Index: trunk/VUT/OcclusionCullingSceneManager/TestCulling/TestCullingApplication.h
===================================================================
--- trunk/VUT/OcclusionCullingSceneManager/TestCulling/TestCullingApplication.h	(revision 33)
+++ trunk/VUT/OcclusionCullingSceneManager/TestCulling/TestCullingApplication.h	(revision 34)
@@ -29,6 +29,5 @@
 public:
 
-    MouseQueryListener(RenderWindow* win, Camera* cam, SceneManager *sceneManager, CEGUI::Renderer *renderer,
-					   SceneNode* shipNode);
+    MouseQueryListener(RenderWindow* win, Camera* cam, SceneManager *sceneManager, CEGUI::Renderer *renderer);
 
 
@@ -37,5 +36,7 @@
     }
 
+	bool frameStarted(const FrameEvent& evt);
 	bool frameEnded(const FrameEvent& evt);
+
     /* MouseListener callbacks. */
     virtual void mouseClicked(MouseEvent* e) { }
@@ -67,7 +68,7 @@
     bool mLMouseDown, mRMouseDown;     // True if the mouse buttons are down
     SceneManager *mSceneMgr;           // A pointer to the scene manager
-    SceneNode *mCurrentObject;         // The newly created object
-    CEGUI::Renderer *mGUIRenderer;     // cegui renderer
-	SceneNode* mShipNode;
+    
+	CEGUI::Renderer *mGUIRenderer;     // cegui renderer
+	
 	bool mShutdownRequested;
 	int mCurrentAlgorithm;
@@ -79,5 +80,4 @@
 	OverlayElement *mQueryCulledNodesInfo;
     OverlayElement *mTraversedNodesInfo;
-
 };
 
@@ -86,11 +86,11 @@
 {
 public:
-    /*TestCullingApplication()
-    {
-    }*/
+	~TestCullingApplication();
 
 protected:
 	void createScene(void);
 	void createFrameListener(void);
+	void setupGui(void);
+	virtual void createCamera(void);
 
 	CEGUI::OgreCEGUIRenderer *mGUIRenderer;
@@ -100,26 +100,6 @@
 	void chooseSceneManager(void);
 
-	Entity* mShip;
-	SceneNode* mShipNode;
-
-/*    String mQuakePk3;
-    String mQuakeLevel;
-
-    // Override resource sources (include Quake3 archives)
-    void setupResources(void)
-    {
-
-        // Load Quake3 locations from a file
-        ConfigFile cf;
-
-        cf.load("quake3settings.cfg");
-
-        mQuakePk3 = cf.getSetting("Pak0Location");
-        mQuakeLevel = cf.getSetting("Map");
-
-		ExampleApplication::setupResources();
-        ResourceManager::addCommonArchiveEx(mQuakePk3, "Zip");
-
-    }*/
+	//Entity* mShip;
+	//SceneNode* mShipNode;
 };
 
