Index: trunk/VUT/work/TestCullingTerrain/TestCullingTerrainApplication.cpp
===================================================================
--- trunk/VUT/work/TestCullingTerrain/TestCullingTerrainApplication.cpp	(revision 93)
+++ trunk/VUT/work/TestCullingTerrain/TestCullingTerrainApplication.cpp	(revision 94)
@@ -17,5 +17,5 @@
 
 #define WIN32_LEAN_AND_MEAN
-#include "windows.h"
+#include <windows.h>
 
 
@@ -27,5 +27,5 @@
 	if(mTerrainContentGenerator)
 		delete mTerrainContentGenerator;
-	//if(mCullCamera) delete mCullCamera;
+	//if(mVisualizationCamera) delete mVisualizationCamera;
 }
 //-----------------------------------------------------------------------
@@ -33,5 +33,5 @@
 {
 	// Create the camera
-	mCamera = mSceneMgr->createCamera("PlayerCam");
+	mCamera = mSceneMgr->createCamera("CullCamera");
 	
 	// Set a nice viewpoint
@@ -40,9 +40,9 @@
 	
 	//--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);
+	mVisualizationCamera = mSceneMgr->createCamera("VisualizationCamera");
+	mVisualizationCamera->setPosition(707, 2500, 528);
+	mVisualizationCamera->setOrientation(Quaternion(-0.3486, 0.0122, 0.9365, 0.0329));
+
+	mVisualizationCamera->setNearClipDistance(1);
 	mCamera->setNearClipDistance(1);
 
@@ -50,10 +50,10 @@
 	if (mRoot->getRenderSystem()->getCapabilities()->hasCapability(RSC_INFINITE_FAR_PLANE))
 	{
-		mCullCamera->setFarClipDistance(0);
+		mVisualizationCamera->setFarClipDistance(0);
 		mCamera->setFarClipDistance(0);
 	}
 	else
 	{
-		 mCullCamera->setFarClipDistance(1000);
+		 mVisualizationCamera->setFarClipDistance(1000);
 		 mCamera->setFarClipDistance(1000);
 	}
@@ -79,6 +79,5 @@
 	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", 5000, false);
@@ -133,5 +132,5 @@
 {
 	mFrameListener= new MouseQueryListener(mWindow, mCamera, mSceneMgr, 
-		mGUIRenderer, mTerrainContentGenerator, mCullCamera);
+		mGUIRenderer, mTerrainContentGenerator, mVisualizationCamera);
 	mFrameListener->showDebugOverlay(true);
 	mRoot->addFrameListener(mFrameListener);
@@ -150,5 +149,5 @@
 									   CEGUI::Renderer *renderer,
 									   TerrainContentGenerator *sceneGenerator,
-									   Camera *cullCamera): 
+									   Camera *vizCamera): 
 ExampleFrameListener(win, cam, false, true), 
 mGUIRenderer(renderer), 
@@ -163,7 +162,7 @@
 mShowOctree(false),
 mUseCulling(true),
-mUseOptimization(false),
+mUseOptimization(true),
 mUseCullCamera(false),
-mCullCamera(cullCamera)
+mVisualizationCamera(vizCamera)
 {
 	// Reduce move speed
@@ -293,25 +292,21 @@
 bool MouseQueryListener::frameStarted(const FrameEvent &evt)
 {
+	clamp2Terrain(mCamera);
+	clamp2Terrain(mVisualizationCamera);
+
+	return ExampleFrameListener::frameStarted(evt);
+}
+void MouseQueryListener::clamp2Terrain(Camera *cam)
+{
 	// clamp to terrain
-	Vector3 camPos = mCamera->getPosition();
+	Vector3 camPos = cam->getPosition();
 	Vector3 queryResult;
 
-    if(mRayQueryExecutor->executeRayQuery(&queryResult, 
-		Vector3(camPos.x, 5000.0f, camPos.z), Vector3::NEGATIVE_UNIT_Y))
+	if(mRayQueryExecutor->executeRayQuery(&queryResult, 
+			Vector3(camPos.x, 5000.0f, camPos.z), Vector3::NEGATIVE_UNIT_Y))
 	{
-		mCamera->setPosition(mCamera->getPosition().x, queryResult.y + 10, 
-			mCamera->getPosition().z);
+		cam->setPosition(cam->getPosition().x, queryResult.y + 10, 
+			cam->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);
 }
 //-----------------------------------------------------------------------
@@ -332,7 +327,8 @@
 	KEY_PRESSED(KC_C, 0.3, toggleUseCulling());
 	KEY_PRESSED(KC_V, 0.3, toggleCullCamera());
-	KEY_PRESSED(KC_X, 0.3, fixCullCamera());
+	KEY_PRESSED(KC_X, 0.3, FixVizCamera());
 
 	updateStats();
+	//if(mWindow->getViewport(1))	mWindow->getViewport(1)->update();
 
     return ExampleFrameListener::frameStarted(evt) && ExampleFrameListener::frameEnded(evt);        
@@ -420,11 +416,21 @@
 {
 	mUseCullCamera = !mUseCullCamera;
+
+	if(mUseCullCamera)
+	{	
+		mWindow->addViewport(mVisualizationCamera, 10, 0.5, 0.5, 1, 1);
+		mWindow->getViewport(1)->setClearEveryFrame(true);
+	}
+	else
+		mWindow->removeViewport(10);
+
 	mSceneMgr->setOption("CullCamera", &mUseCullCamera);
 }
 //-----------------------------------------------------------------------
-void MouseQueryListener::fixCullCamera()
-{
-	mCullCamera->setPosition(mCamera->getPosition());
-	mCullCamera->setOrientation(mCamera->getOrientation());
+void MouseQueryListener::FixVizCamera()
+{
+	mVisualizationCamera->setPosition(mCamera->getPosition());
+	mVisualizationCamera->setOrientation(mCamera->getOrientation());
+	clamp2Terrain(mVisualizationCamera);
 }
 
Index: trunk/VUT/work/TestCullingTerrain/TestCullingTerrainApplication.h
===================================================================
--- trunk/VUT/work/TestCullingTerrain/TestCullingTerrainApplication.h	(revision 93)
+++ trunk/VUT/work/TestCullingTerrain/TestCullingTerrainApplication.h	(revision 94)
@@ -30,5 +30,5 @@
 
     MouseQueryListener(RenderWindow* win, Camera* cam, SceneManager *sceneManager, 
-		CEGUI::Renderer *renderer, TerrainContentGenerator *contentGenerator, Camera *cullCamera);
+		CEGUI::Renderer *renderer, TerrainContentGenerator *contentGenerator, Camera *vizCamera);
 
     ~MouseQueryListener();
@@ -67,7 +67,9 @@
 	void toggleUseCulling();
 	void toggleCullCamera();
-	void fixCullCamera();
+	void FixVizCamera();
 
 protected:
+	void clamp2Terrain(Camera *cam);
+
     bool mLMouseDown, mRMouseDown;     // True if the mouse buttons are down
     SceneManager *mSceneMgr;           // A pointer to the scene manager
@@ -101,5 +103,5 @@
 	bool mUseCullCamera;
 
-	Camera *mCullCamera;
+	Camera *mVisualizationCamera;
 };
 
@@ -127,5 +129,5 @@
 	TerrainContentGenerator *mTerrainContentGenerator;
 
-	Camera *mCullCamera;
+	Camera *mVisualizationCamera;
 	
 private:
Index: trunk/VUT/work/TestCulling/SceneContentGenerator.cpp
===================================================================
--- trunk/VUT/work/TestCulling/SceneContentGenerator.cpp	(revision 87)
+++ trunk/VUT/work/TestCulling/SceneContentGenerator.cpp	(revision 94)
@@ -6,5 +6,4 @@
 */
 #include "SceneContentGenerator.h"
-#include <windows.h>
 
 namespace Ogre {
Index: trunk/VUT/work/TestCulling/TestCullingApplication.cpp
===================================================================
--- trunk/VUT/work/TestCulling/TestCullingApplication.cpp	(revision 93)
+++ trunk/VUT/work/TestCulling/TestCullingApplication.cpp	(revision 94)
@@ -17,5 +17,5 @@
 
 #define WIN32_LEAN_AND_MEAN
-#include "windows.h"
+#include <windows.h>
 
 
@@ -28,5 +28,5 @@
 {
 	// Create the camera
-	mCamera = mSceneMgr->createCamera("PlayerCam");
+	mCamera = mSceneMgr->createCamera("CullCamera");
 
 	// Position it at 500 in Z direction
@@ -112,5 +112,5 @@
 mShowOctree(false),
 mUseCulling(true),
-mUseOptimization(false),
+mUseOptimization(true),
 mUseCullCamera(false)
 {
Index: trunk/VUT/work/TestCulling/TestCullingApplication.h
===================================================================
--- trunk/VUT/work/TestCulling/TestCullingApplication.h	(revision 93)
+++ trunk/VUT/work/TestCulling/TestCullingApplication.h	(revision 94)
@@ -97,5 +97,5 @@
 	bool mUseCullCamera;
 
-	Camera *mCullCamera;
+	Camera *mVisualizationCamera;
 };
 
