Index: trunk/VUT/work/TestCullingTerrain/TestCullingTerrainApplication.cpp
===================================================================
--- trunk/VUT/work/TestCullingTerrain/TestCullingTerrainApplication.cpp	(revision 87)
+++ trunk/VUT/work/TestCullingTerrain/TestCullingTerrainApplication.cpp	(revision 93)
@@ -25,19 +25,38 @@
 TestCullingTerrainApplication::~TestCullingTerrainApplication()
 {
-	delete mTerrainContentGenerator;
-}
-//-----------------------------------------------------------------------
-void TestCullingTerrainApplication::createCamera( void )
+	if(mTerrainContentGenerator)
+		delete mTerrainContentGenerator;
+	//if(mCullCamera) delete mCullCamera;
+}
+//-----------------------------------------------------------------------
+void TestCullingTerrainApplication::createCamera()
 {
 	// 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);
+	
+	// Set a nice viewpoint
+	mCamera->setPosition(707, 2500, 528);
+	mCamera->setOrientation(Quaternion(-0.3486, 0.0122, 0.9365, 0.0329));
+	
+	//--create cull camera
+	mCullCamera = mSceneMgr->createCamera("CullCamera");
+	mCullCamera->setPosition(707, 2500, 528);
+	mCullCamera->setOrientation(Quaternion(-0.3486, 0.0122, 0.9365, 0.0329));
+
+	mCullCamera->setNearClipDistance(1);
+	mCamera->setNearClipDistance(1);
+
+	// Infinite far plane?
+	if (mRoot->getRenderSystem()->getCapabilities()->hasCapability(RSC_INFINITE_FAR_PLANE))
+	{
+		mCullCamera->setFarClipDistance(0);
+		mCamera->setFarClipDistance(0);
+	}
+	else
+	{
+		 mCullCamera->setFarClipDistance(1000);
+		 mCamera->setFarClipDistance(1000);
+	}
+	
 }
 //-----------------------------------------------------------------------
@@ -60,7 +79,8 @@
 	mWindow->getViewport(0)->setBackgroundColour(fadeColour);
 	//mSceneMgr->setFog( FOG_LINEAR, fadeColour, .001, 500, 1000);
+	mWindow->addViewport(mCullCamera, 10, 0.5, 0.5, 1, 1);
 
 	// Create a skybox
-    //mSceneMgr->setSkyBox(true, "Examples/SpaceSkyBox", 500, false);
+    mSceneMgr->setSkyBox(true, "Examples/SpaceSkyBox", 5000, false);
 	//mSceneMgr->setSkyDome( true, "Examples/CloudySky", 5, 8, 500, false );
 
@@ -79,13 +99,4 @@
 #endif
 	mSceneMgr->setWorldGeometry(terrain_cfg);
-	// Infinite far plane?
-	if (mRoot->getRenderSystem()->getCapabilities()->hasCapability(RSC_INFINITE_FAR_PLANE))
-	{
-		mCamera->setFarClipDistance(0);
-	}
-
-	// Set a nice viewpoint
-	mCamera->setPosition(707, 2500, 528);
-	mCamera->setOrientation(Quaternion(-0.3486, 0.0122, 0.9365, 0.0329));
 	
 	// CEGUI setup
@@ -122,5 +133,5 @@
 {
 	mFrameListener= new MouseQueryListener(mWindow, mCamera, mSceneMgr, 
-		mGUIRenderer, mTerrainContentGenerator);
+		mGUIRenderer, mTerrainContentGenerator, mCullCamera);
 	mFrameListener->showDebugOverlay(true);
 	mRoot->addFrameListener(mFrameListener);
@@ -138,9 +149,9 @@
 									   SceneManager *sceneManager, 
 									   CEGUI::Renderer *renderer,
-									   TerrainContentGenerator *sceneGenerator): 
+									   TerrainContentGenerator *sceneGenerator,
+									   Camera *cullCamera): 
 ExampleFrameListener(win, cam, false, true), 
 mGUIRenderer(renderer), 
 mShutdownRequested(false), 
-mUseOptimization(false),
 mLMouseDown(false),
 mRMouseDown(false),
@@ -150,6 +161,9 @@
 mVisibilityThreshold(0),
 mCurrentAlgorithm(GtpVisibility::VisibilityEnvironment::COHERENT_HIERARCHICAL_CULLING),
-mShowOctree(true),
-mUseCulling(false)
+mShowOctree(false),
+mUseCulling(true),
+mUseOptimization(false),
+mUseCullCamera(false),
+mCullCamera(cullCamera)
 {
 	// Reduce move speed
@@ -191,7 +205,9 @@
 
 	setAlgorithm(mCurrentAlgorithm);
-	toggleUseOptimization();
-	toggleShowOctree();
-	toggleUseCulling();
+
+	mSceneMgr->setOption("UseOptimization", &mUseOptimization);
+	mSceneMgr->setOption("UseCulling", &mUseCulling);
+	mSceneMgr->setOption("CullCamera", &mUseCullCamera);
+	mSceneMgr->setOption("ShowOctree", &mShowOctree);
 
     pOver->show();
@@ -287,5 +303,14 @@
 			mCamera->getPosition().z);
 	}
-	
+
+	camPos = mCullCamera->getPosition();
+
+	if(mRayQueryExecutor->executeRayQuery(&queryResult, 
+		Vector3(camPos.x, 5000.0f, camPos.z), Vector3::NEGATIVE_UNIT_Y))
+	{
+		mCullCamera->setPosition(mCullCamera->getPosition().x, queryResult.y + 10, 
+			mCullCamera->getPosition().z);
+	}
+
 	return ExampleFrameListener::frameStarted(evt);
 }
@@ -306,5 +331,7 @@
 	KEY_PRESSED(KC_S, 0.3, toggleShowOctree());
 	KEY_PRESSED(KC_C, 0.3, toggleUseCulling());
-	      
+	KEY_PRESSED(KC_V, 0.3, toggleCullCamera());
+	KEY_PRESSED(KC_X, 0.3, fixCullCamera());
+
 	updateStats();
 
@@ -389,4 +416,17 @@
 	mSceneMgr->setOption("UseCulling", &mUseCulling);
 }
+//-----------------------------------------------------------------------
+void MouseQueryListener::toggleCullCamera()
+{
+	mUseCullCamera = !mUseCullCamera;
+	mSceneMgr->setOption("CullCamera", &mUseCullCamera);
+}
+//-----------------------------------------------------------------------
+void MouseQueryListener::fixCullCamera()
+{
+	mCullCamera->setPosition(mCamera->getPosition());
+	mCullCamera->setOrientation(mCamera->getOrientation());
+}
+
 //-----------------------------------------------------------------------
 void MouseQueryListener::keyPressed(KeyEvent* e)
Index: trunk/VUT/work/TestCullingTerrain/TestCullingTerrainApplication.h
===================================================================
--- trunk/VUT/work/TestCullingTerrain/TestCullingTerrainApplication.h	(revision 87)
+++ trunk/VUT/work/TestCullingTerrain/TestCullingTerrainApplication.h	(revision 93)
@@ -30,5 +30,5 @@
 
     MouseQueryListener(RenderWindow* win, Camera* cam, SceneManager *sceneManager, 
-		CEGUI::Renderer *renderer, TerrainContentGenerator *contentGenerator);
+		CEGUI::Renderer *renderer, TerrainContentGenerator *contentGenerator, Camera *cullCamera);
 
     ~MouseQueryListener();
@@ -66,4 +66,6 @@
 	void toggleShowOctree();
 	void toggleUseCulling();
+	void toggleCullCamera();
+	void fixCullCamera();
 
 protected:
@@ -97,4 +99,7 @@
 	bool mShowOctree;
 	bool mUseCulling;
+	bool mUseCullCamera;
+
+	Camera *mCullCamera;
 };
 
@@ -113,5 +118,4 @@
 	CEGUI::OgreCEGUIRenderer *mGUIRenderer;
 	CEGUI::System *mGUISystem;
-//	RayQueryExecutor *mRayQueryExecutor;
 
 	Vector3 mMinTranslation;
@@ -123,4 +127,6 @@
 	TerrainContentGenerator *mTerrainContentGenerator;
 
+	Camera *mCullCamera;
+	
 private:
 	void chooseSceneManager(void);
Index: trunk/VUT/work/TestCulling/TestCullingApplication.cpp
===================================================================
--- trunk/VUT/work/TestCulling/TestCullingApplication.cpp	(revision 87)
+++ trunk/VUT/work/TestCulling/TestCullingApplication.cpp	(revision 93)
@@ -105,5 +105,4 @@
 mGUIRenderer(renderer), 
 mShutdownRequested(false), 
-mUseOptimization(false),
 mLMouseDown(false),
 mRMouseDown(false),
@@ -111,6 +110,8 @@
 mVisibilityThreshold(0),
 mCurrentAlgorithm(GtpVisibility::VisibilityEnvironment::COHERENT_HIERARCHICAL_CULLING),
-mShowOctree(true),
-mUseCulling(false)
+mShowOctree(false),
+mUseCulling(true),
+mUseOptimization(false),
+mUseCullCamera(false)
 {
     // Reduce move speed
@@ -150,5 +151,9 @@
 
 	setAlgorithm(mCurrentAlgorithm);
-	toggleUseOptimization();
+	
+	mSceneMgr->setOption("UseOptimization", &mUseOptimization);
+	mSceneMgr->setOption("UseCulling", &mUseCulling);
+	mSceneMgr->setOption("CullCamera", &mUseCullCamera);
+	mSceneMgr->setOption("ShowOctree", &mShowOctree);
 
     pOver->show();
@@ -231,5 +236,6 @@
 	KEY_PRESSED(KC_O, 0.3, toggleUseOptimization());
 	KEY_PRESSED(KC_C, 0.3, toggleUseCulling());
-	      
+	KEY_PRESSED(KC_V, 0.3, toggleCullCamera());
+
 	updateStats();
 
@@ -280,4 +286,11 @@
 
 	mSceneMgr->setOption("UseCulling", &mUseCulling);
+}
+//-----------------------------------------------------------------------
+void MouseQueryListener::toggleCullCamera()
+{
+	mUseCullCamera = !mUseCullCamera;
+
+	mSceneMgr->setOption("CullCamera", &mUseCullCamera);
 }
 //-----------------------------------------------------------------------
Index: trunk/VUT/work/TestCulling/TestCullingApplication.h
===================================================================
--- trunk/VUT/work/TestCulling/TestCullingApplication.h	(revision 87)
+++ trunk/VUT/work/TestCulling/TestCullingApplication.h	(revision 93)
@@ -67,4 +67,5 @@
 	void toggleShowOctree();
 	void toggleUseCulling();
+	void toggleCullCamera();
 
 protected:
@@ -94,4 +95,7 @@
 	bool mShowOctree;
 	bool mUseCulling;
+	bool mUseCullCamera;
+
+	Camera *mCullCamera;
 };
 
