Index: trunk/VUT/GtpVisibility/src/VisibilityManager.cpp
===================================================================
--- trunk/VUT/GtpVisibility/src/VisibilityManager.cpp	(revision 99)
+++ trunk/VUT/GtpVisibility/src/VisibilityManager.cpp	(revision 100)
@@ -10,13 +10,11 @@
 //-----------------------------------------------------------------------
 VisibilityManager::VisibilityManager(VisibilityEnvironment *visEnvironment):
-mVisibilityThreshold(0), mCullingManager(NULL) 
+mVisibilityThreshold(0), mCullingManager(NULL),
+mQueryManager(new DummyQueryManager(NULL)),
+mPreprocessingManager(new DummyPreprocessingManager(NULL)),
+mVisibilityEnvironment(visEnvironment)
 {
-	mVisibilityEnvironment = visEnvironment;
-	
-	//SetCullingManager(VisibilityEnvironment::COHERENT_HIERARCHICAL_CULLING);
-	SetCullingManager(VisibilityEnvironment::FRUSTUM_CULLING);
-
-	mQueryManager = new DummyQueryManager(0);
-	mPreprocessingManager = new DummyPreprocessingManager(0);
+	SetCullingManager(VisibilityEnvironment::COHERENT_HIERARCHICAL_CULLING);
+	//SetCullingManager(VisibilityEnvironment::FRUSTUM_CULLING);
 }
 //-----------------------------------------------------------------------
@@ -33,5 +31,5 @@
 	{
 		// delete old culling manager
-		if(mCullingManager)
+		if (mCullingManager)
 			delete mCullingManager;
 
@@ -73,8 +71,9 @@
 	mCullingManager->RenderScene();
 }
+//-----------------------------------------------------------------------
 VisibilityEnvironment::CullingManagerType VisibilityManager::GetCullingManagerType()
 {
 	return mCullingManagerType;
 }
-//-----------------------------------------------------------------------
+
 } // namespace GtpVisibility
Index: trunk/VUT/GtpVisibility/src/StopAndWaitCullingManager.cpp
===================================================================
--- trunk/VUT/GtpVisibility/src/StopAndWaitCullingManager.cpp	(revision 96)
+++ trunk/VUT/GtpVisibility/src/StopAndWaitCullingManager.cpp	(revision 100)
@@ -39,5 +39,6 @@
 			unsigned int visiblePixels = 0;
 
-			mHierarchyInterface->IssueOcclusionQuery(node)->GetQueryResult(visiblePixels, true);
+			mHierarchyInterface->IssueOcclusionQuery(node)->
+				GetQueryResult(visiblePixels, true);
 			
 			// node visible
Index: trunk/VUT/GtpVisibility/src/VisibilityEnvironment.cpp
===================================================================
--- trunk/VUT/GtpVisibility/src/VisibilityEnvironment.cpp	(revision 74)
+++ trunk/VUT/GtpVisibility/src/VisibilityEnvironment.cpp	(revision 100)
@@ -2,4 +2,5 @@
 
 namespace GtpVisibility {
+
 //-----------------------------------------------------------------------
 VisibilityEnvironment::VisibilityEnvironment()
Index: trunk/VUT/work/TestCullingTerrain/TestCullingTerrain.vcproj
===================================================================
--- trunk/VUT/work/TestCullingTerrain/TestCullingTerrain.vcproj	(revision 83)
+++ trunk/VUT/work/TestCullingTerrain/TestCullingTerrain.vcproj	(revision 100)
@@ -72,5 +72,5 @@
 			<Tool
 				Name="VCCLCompilerTool"
-				AdditionalIncludeDirectories="&quot;$(OGRE_PATH)\Dependencies\include&quot;;&quot;$(OGRE_PATH)\OgreMain\include&quot;;&quot;$(OGRE_PATH)\Samples\Common\include&quot;;&quot;$(OGRE_PATH)\Dependencies\include\CEGUI&quot;;&quot;$(OGRE_PATH)\PlugIns\OctreeSceneManager\include&quot;;&quot;$(OGRE_ADDONS_PATH)\dotsceneoctree\PlugIns\DotSceneManager\include&quot;;&quot;$(OGRE_PATH)\Samples\Common\CEGUIRenderer\include&quot;;..\..\GtpVisibility\include;..\include;..\TestCulling"
+				AdditionalIncludeDirectories="&quot;$(OGRE_PATH)\Dependencies\include&quot;;&quot;$(OGRE_PATH)\OgreMain\include&quot;;&quot;$(OGRE_PATH)\Samples\Common\include&quot;;&quot;$(OGRE_PATH)\Dependencies\include\CEGUI&quot;;&quot;$(OGRE_PATH)\ReferenceApplication\ReferenceAppLayer\include&quot;;&quot;$(OGRE_PATH)\PlugIns\OctreeSceneManager\include&quot;;&quot;$(OGRE_ADDONS_PATH)\dotsceneoctree\PlugIns\DotSceneManager\include&quot;;&quot;$(OGRE_PATH)\Samples\Common\CEGUIRenderer\include&quot;;..\..\GtpVisibility\include;..\include;..\TestCulling"
 				PreprocessorDefinitions="_WINDOWS;_STLP_USE_DYNAMIC_LIB;OGRE_LIBRARY_IMPORTS;_RELEASE;WIN32;_STLP_RELEASE;GTP_VISIBILITY_MODIFIED_OGRE"
 				RuntimeLibrary="2"
Index: trunk/VUT/work/TestCullingTerrain/TestCullingTerrainApplication.cpp
===================================================================
--- trunk/VUT/work/TestCullingTerrain/TestCullingTerrainApplication.cpp	(revision 99)
+++ trunk/VUT/work/TestCullingTerrain/TestCullingTerrainApplication.cpp	(revision 100)
@@ -13,5 +13,7 @@
 #include <OgreMemoryMacros.h>
 
-#include "Ogre.h"
+#include <Ogre.h>
+#include "OgreReferenceAppLayer.h"
+//#include "OgreRefAppWorld.h"
 #include "TestCullingTerrainApplication.h"
 
@@ -19,8 +21,11 @@
 #include <windows.h>
 
+#define VIZ_VIEWPORT_Z_ORDER 10
 
 /*******************************************************/
 /*     TestCullingTerrainApplication implementation    */
 /*******************************************************/
+
+//-----------------------------------------------------------------------
 TestCullingTerrainApplication::~TestCullingTerrainApplication()
 {
@@ -33,16 +38,24 @@
 {
 	// create the camera
-	mCamera = mSceneMgr->createCamera("PlayerCam");
-	
-	// set a nice viewpoint
-	mCamera->setPosition(707, 2500, 528);
-	mCamera->setOrientation(Quaternion(-0.3486, 0.0122, 0.9365, 0.0329));
-	
-	//--create visualization camera
-	mVisualizationCamera = mSceneMgr->createCamera("VizCam");
-	mVisualizationCamera->setPosition(mCamera->getPosition());
-	mVisualizationCamera->setOrientation(mCamera->getOrientation());
-
-	mVisualizationCamera->setNearClipDistance(1);
+	mCamera = mSceneMgr->createCamera("CullCamera");
+	
+	/** set a nice viewpoint
+	*	we use a camera node here and apply all transformations on it instead
+	*	of applying all transformations directly to the camera
+	*	because then the camera is displayed correctly in the visualization
+	*/
+	
+	mCamNode = mSceneMgr->getRootSceneNode()->createChildSceneNode(
+		"CamNode1", Vector3(707, 5000, 528));
+	//mCamera->setPosition(707, 5000, 528);
+	mCamNode->setOrientation(Quaternion(-0.3486, 0.0122, 0.9365, 0.0329));
+	
+	mCamNode->attachObject(mCamera);
+
+	//-- create visualization camera
+	mVizCamera = mSceneMgr->createCamera("VizCam");
+	mVizCamera->setPosition(mCamNode->getPosition());
+
+	mVizCamera->setNearClipDistance(1);
 	mCamera->setNearClipDistance(1);
 
@@ -50,10 +63,10 @@
 	if (mRoot->getRenderSystem()->getCapabilities()->hasCapability(RSC_INFINITE_FAR_PLANE))
 	{
-		mVisualizationCamera->setFarClipDistance(0);
+		mVizCamera->setFarClipDistance(0);
 		mCamera->setFarClipDistance(0);
 	}
 	else
 	{
-		 mVisualizationCamera->setFarClipDistance(1000);
+		 mVizCamera->setFarClipDistance(1000);
 		 mCamera->setFarClipDistance(1000);
 	}	
@@ -84,5 +97,5 @@
 	// 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
+	// other objects, but I don't
 	l->setPosition(20,80,50);
 
@@ -95,5 +108,5 @@
 	
 	// Create a skybox
-    mSceneMgr->setSkyBox(true, "Examples/SpaceSkyBox", 3500, false);
+	mSceneMgr->setSkyBox(true, "Examples/SpaceSkyBox", 7000, false);
 	//mSceneMgr->setSkyDome( true, "Examples/CloudySky", 5, 8, 500, false );
 
@@ -104,6 +117,9 @@
 	mSceneMgr->setWorldGeometry(terrain_cfg);
 	
-	// CEGUI setup
+	//-- CEGUI setup
 	setupGui();
+
+	//-- terrain content setup
+
 	// HACK: necessary to call once before the content creation for
 	// terrain initialisation
@@ -138,5 +154,5 @@
 {
 	mFrameListener= new MouseQueryListener(mWindow, mCamera, mSceneMgr, 
-		mGUIRenderer, mTerrainContentGenerator, mVisualizationCamera);
+		mGUIRenderer, mTerrainContentGenerator, mVizCamera, mCamNode);
 	mFrameListener->showDebugOverlay(true);
 	mRoot->addFrameListener(mFrameListener);
@@ -155,5 +171,6 @@
 									   CEGUI::Renderer *renderer,
 									   TerrainContentGenerator *sceneGenerator,
-									   Camera *vizCamera): 
+									   Camera *vizCamera,
+									   SceneNode *camNode): 
 ExampleFrameListener(win, cam, false, true), 
 mGUIRenderer(renderer), 
@@ -169,5 +186,9 @@
 mUseVisibilityCulling(true),
 mUseOptimization(true),
-mVisualizationCamera(vizCamera)
+mVizCamera(vizCamera),
+mShowVisualization(false),
+mVizCameraHeight(Real(2500.0)),
+mCamNode(camNode),
+mCullCamera(true)
 {
 	// Reduce move speed
@@ -213,18 +234,19 @@
 	mSceneMgr->setOption("UseVisibilityCulling", &mUseVisibilityCulling);
 	mSceneMgr->setOption("ShowOctree", &mShowOctree);
+	mSceneMgr->setOption("CullCamera", &mCullCamera);
 	
     pOver->show();
 } 
 //-----------------------------------------------------------------------
-MouseQueryListener::~MouseQueryListener( )
+MouseQueryListener::~MouseQueryListener()
 {
 	delete mRayQueryExecutor;
 }
 //-----------------------------------------------------------------------
-void MouseQueryListener::mouseMoved (MouseEvent *e)
+void MouseQueryListener::mouseMoved(MouseEvent *e)
 {
 	// Update CEGUI with the mouse motion
-    CEGUI::System::getSingleton().injectMouseMove(e->getRelX() * mGUIRenderer->getWidth(), 
-		e->getRelY() * mGUIRenderer->getHeight());
+    CEGUI::System::getSingleton().injectMouseMove(e->getRelX() * 
+		mGUIRenderer->getWidth(), e->getRelY() * mGUIRenderer->getHeight());
 }
 //-----------------------------------------------------------------------
@@ -252,5 +274,5 @@
          CEGUI::MouseCursor::getSingleton().hide();
          mRMouseDown = true;
-     } // else if
+     }
 } // mousePressed
 //-----------------------------------------------------------------------
@@ -279,8 +301,10 @@
 		 Ray mouseRay = mCamera->getCameraToViewportRay(e->getX(), e->getY());
 
-		 if(mRayQueryExecutor->executeRayQuery(&queryResult, mouseRay))
+		 if (mRayQueryExecutor->executeRayQuery(&queryResult, mouseRay))
 		 {
-			 if(mCurrentObject)
+			 if (mCurrentObject)
+			 {
 				 mCurrentObject->setPosition(queryResult);
+			 }
 		 }
      }
@@ -288,6 +312,8 @@
 	 if (mRMouseDown)
 	 {
-		 mCamera->yaw( -e->getRelX() * mRotateSpeed );
-		 mCamera->pitch( -e->getRelY() * mRotateSpeed );
+		 //mCamera->yaw(-e->getRelX() * mRotateSpeed);
+		 //mCamera->pitch(-e->getRelY() * mRotateSpeed);
+		 mCamNode->yaw(-e->getRelX() * mRotateSpeed);
+		 mCamNode->pitch(-e->getRelY() * mRotateSpeed);
 	 }
 }
@@ -295,20 +321,39 @@
 bool MouseQueryListener::frameStarted(const FrameEvent &evt)
 {
-	clamp2Terrain(mCamera);
-	clamp2Terrain(mVisualizationCamera);
+	clamp2Terrain();
+
+	if (mShowVisualization)
+	{
+		// important for visualization => draw octree bounding boxes
+		mSceneMgr->setOption("ShowOctree", &mShowVisualization);
+
+		// -- setup visualization camera
+		mVizCamera->setPosition(0, 0, 0);
+		mVizCamera->setOrientation(Quaternion::IDENTITY);
+
+		Vector3 camPos = mCamNode->getPosition();
+		mVizCamera->setPosition(camPos.x, mVizCameraHeight, camPos.z);
+
+		// Point down -Z axis
+		mVizCamera->pitch(Radian(Degree(270.0)));
+	
+		// Rotation arounnd X axis
+		mVizCamera->yaw(Math::ATan2(-mCamera->getDerivedDirection().x, 
+			-mCamera->getDerivedDirection().z));
+	}
 
 	return ExampleFrameListener::frameStarted(evt);
 }
-void MouseQueryListener::clamp2Terrain(Camera *cam)
+//-----------------------------------------------------------------------
+void MouseQueryListener::clamp2Terrain()
 {
 	// clamp to terrain
-	Vector3 camPos = cam->getPosition();
+	Vector3 camPos = mCamNode->getPosition();
 	Vector3 queryResult;
 
-	if(mRayQueryExecutor->executeRayQuery(&queryResult, 
+	if (mRayQueryExecutor->executeRayQuery(&queryResult, 
 			Vector3(camPos.x, 5000.0f, camPos.z), Vector3::NEGATIVE_UNIT_Y))
 	{
-		cam->setPosition(cam->getPosition().x, queryResult.y + 10, 
-			cam->getPosition().z);
+		mCamNode->setPosition(camPos.x, queryResult.y + 10, camPos.z);
 	}
 }
@@ -324,16 +369,29 @@
     KEY_PRESSED(KC_SPACE, 0.3, nextAlgorithm());
 
-	KEY_PRESSED(KC_SUBTRACT, 0, changeThreshold(-10));
-	KEY_PRESSED(KC_ADD, 0, changeThreshold(10));
 	KEY_PRESSED(KC_O, 0.3, toggleUseOptimization());
-	KEY_PRESSED(KC_Y, 0.3, toggleShowOctree());
+	KEY_PRESSED(KC_E, 0.3, toggleShowOctree());
 	KEY_PRESSED(KC_C, 0.3, toggleUseVisibilityCulling());
 	KEY_PRESSED(KC_V, 0.3, toggleShowViz());
-	KEY_PRESSED(KC_X, 0.3, FixVizCamera());
+
+	if (!mShowVisualization)
+	{
+		KEY_PRESSED(KC_SUBTRACT, 0, changeThreshold(-10));
+		KEY_PRESSED(KC_ADD, 0, changeThreshold(10));
+	}
+	else
+	{
+		KEY_PRESSED(KC_SUBTRACT, 0, zoomVizCamera(50));
+		KEY_PRESSED(KC_ADD, 0, zoomVizCamera(-50));
+	}
 
 	updateStats();
-	//if(mWindow->getViewport(1))	mWindow->getViewport(1)->update();
-
-    return ExampleFrameListener::frameStarted(evt) && ExampleFrameListener::frameEnded(evt);        
+
+	return ExampleFrameListener::frameStarted(evt) && ExampleFrameListener::frameEnded(evt);
+}
+void MouseQueryListener::moveCamera()
+{
+	mCamNode->yaw(mRotX);
+	mCamNode->pitch(mRotY);
+	mCamNode->translate(mCamNode->getLocalAxes(), mTranslateVector);
 }
 //-----------------------------------------------------------------------
@@ -349,4 +407,26 @@
 }
 //-----------------------------------------------------------------------
+bool MouseQueryListener::processUnbufferedKeyInput(const FrameEvent& evt)
+{    
+	if (mInputDevice->isKeyDown(KC_RIGHT))
+	{
+		mCamNode->yaw(-mRotScale);
+		return true;
+	}
+	if (mInputDevice->isKeyDown(KC_LEFT))
+	{
+		mCamNode->yaw(mRotScale);
+		return true;
+	}
+
+	return ExampleFrameListener::processUnbufferedKeyInput(evt);
+}
+//-----------------------------------------------------------------------
+void MouseQueryListener::zoomVizCamera(int zoom)
+{
+	mVizCameraHeight += zoom; 
+	if(mVizCameraHeight < 0) mVizCameraHeight = 0;
+}
+//-----------------------------------------------------------------------
 void MouseQueryListener::nextAlgorithm()
 {
@@ -396,5 +476,5 @@
 	mSceneMgr->setOption("UseOptimization", &mUseOptimization);
 
-	if(mUseOptimization)
+	if (mUseOptimization)
 		mUseOptimizationInfo->setCaption(": true");
 	else
@@ -420,23 +500,34 @@
 	mShowVisualization = !mShowVisualization;
 
-	// create viewport with priority 10: will be rendered over standard viewport
-	if(mShowVisualization)
+	// create viewport with priority VIZ_VIEWPORT_Z_ORDER: 
+	// will be rendered over standard viewport
+	if (mShowVisualization)
 	{	
-		mWindow->addViewport(mVisualizationCamera, 10, 0.5, 0.5, 1, 1);
-		mWindow->getViewport(1)->setClearEveryFrame(true);
+		Viewport *vizvp = mWindow->addViewport(mVizCamera, 
+			VIZ_VIEWPORT_Z_ORDER, 0.6, 0, 0.4, 0.4);
+				
+		vizvp->setBackgroundColour(ColourValue(0.0, 0.3, 0.2, 1));
+
+		vizvp->setOverlaysEnabled(false);
+		// Alter the camera aspect ratio to match the viewport
+        mVizCamera->setAspectRatio(Real(vizvp->getActualWidth()) / 
+			Real(vizvp->getActualHeight()));
+
+		//vizvp->setClearEveryFrame(false);
+
+		// Create a skyplane (for visualization)
+		/*Plane plane;
+		plane.d = 1000;
+		plane.normal = Vector3::UNIT_Y;
+		mSceneMgr->setSkyPlane( true, plane, "Examples/MyTransparentTest", 4000, 75, true);*/
+		
 	}
 	else
 	{
-		mWindow->removeViewport(10);
-	}
-}
-//-----------------------------------------------------------------------
-void MouseQueryListener::FixVizCamera()
-{
-	mVisualizationCamera->setPosition(mCamera->getPosition());
-	mVisualizationCamera->setOrientation(mCamera->getOrientation());
-	clamp2Terrain(mVisualizationCamera);
-}
-
+		mWindow->removeViewport(VIZ_VIEWPORT_Z_ORDER);
+		// if octree was enabled for visualization purpose
+		mSceneMgr->setOption("ShowOctree", &mShowOctree);
+	}
+}
 //-----------------------------------------------------------------------
 void MouseQueryListener::keyPressed(KeyEvent* e)
@@ -475,7 +566,10 @@
 void VisualizationRenderTargetListener::preViewportUpdate(const RenderTargetViewportEvent &evt)
 {
-	const bool b = evt.source->getZOrder() == 10; // visualization viewport
-			
-	mSceneMgr->setOption("ShowVisualization", &b);
+	const bool showViz = evt.source->getZOrder() == VIZ_VIEWPORT_Z_ORDER; // visualization viewport
+	const bool nShowViz = !showViz;
+
+    mSceneMgr->setOption("ShowVisualization", &showViz);
+	mSceneMgr->setOption("SkyBoxEnabled", &nShowViz);
+	//mSceneMgr->setOption("SkyPlaneEnabled", &showViz);
 	
 	RenderTargetListener::preViewportUpdate(evt);
Index: trunk/VUT/work/TestCullingTerrain/TestCullingTerrainApplication.h
===================================================================
--- trunk/VUT/work/TestCullingTerrain/TestCullingTerrainApplication.h	(revision 99)
+++ trunk/VUT/work/TestCullingTerrain/TestCullingTerrainApplication.h	(revision 100)
@@ -8,4 +8,5 @@
 #include "VisibilityEnvironment.h"
 #include <OgreRenderTargetListener.h>
+
 
 Real timeDelay = 0;
@@ -43,5 +44,6 @@
 
     MouseQueryListener(RenderWindow* win, Camera* cam, SceneManager *sceneManager, 
-		CEGUI::Renderer *renderer, TerrainContentGenerator *contentGenerator, Camera *vizCamera);
+		CEGUI::Renderer *renderer, TerrainContentGenerator *contentGenerator, Camera *vizCamera,
+		SceneNode *camNode);
 
     ~MouseQueryListener();
@@ -49,4 +51,6 @@
 	bool frameStarted(const FrameEvent& evt);
 	bool frameEnded(const FrameEvent& evt);
+	bool processUnbufferedKeyInput(const FrameEvent& evt);
+    
 
     /* MouseListener callbacks. */
@@ -80,8 +84,9 @@
 	void toggleUseVisibilityCulling();
 	void toggleShowViz();
-	void FixVizCamera();
+	void zoomVizCamera(int zoom);
+	void moveCamera();
 
 protected:
-	void clamp2Terrain(Camera *cam);
+	void clamp2Terrain();
 
     bool mLMouseDown, mRMouseDown;     // True if the mouse buttons are down
@@ -115,6 +120,11 @@
 	bool mUseVisibilityCulling;
 	bool mShowVisualization;
+	bool mCullCamera;
 
-	Camera *mVisualizationCamera;
+	Real mVizCameraHeight;
+
+	Camera *mVizCamera;
+	SceneNode *mCamNode;
+
 };
 
@@ -149,5 +159,6 @@
 	TerrainContentGenerator *mTerrainContentGenerator;
 	
-	Camera *mVisualizationCamera;
+	Camera *mVizCamera;
+	SceneNode *mCamNode;
 	VisualizationRenderTargetListener *mRenderTargetListener;
 
Index: trunk/VUT/work/ogre_changes/Samples/Common/include/ExampleFrameListener.h
===================================================================
--- trunk/VUT/work/ogre_changes/Samples/Common/include/ExampleFrameListener.h	(revision 100)
+++ trunk/VUT/work/ogre_changes/Samples/Common/include/ExampleFrameListener.h	(revision 100)
@@ -0,0 +1,459 @@
+/*
+-----------------------------------------------------------------------------
+This source file is part of OGRE
+    (Object-oriented Graphics Rendering Engine)
+For the latest info, see http://www.ogre3d.org/
+
+Copyright (c) 2000-2005 The OGRE Team
+Also see acknowledgements in Readme.html
+
+You may use this sample code for anything you like, it is not covered by the
+LGPL like the rest of the engine.
+-----------------------------------------------------------------------------
+*/
+/*
+-----------------------------------------------------------------------------
+Filename:    ExampleFrameListener.h
+Description: Defines an example frame listener which responds to frame events.
+This frame listener just moves a specified camera around based on
+keyboard and mouse movements.
+Mouse:    Freelook
+W or Up:  Forward
+S or Down:Backward
+A:        Step left
+D:        Step right
+             PgUp:     Move upwards
+             PgDown:   Move downwards
+             F:        Toggle frame rate stats on/off
+			 R:        Render mode
+             T:        Cycle texture filtering
+                       Bilinear, Trilinear, Anisotropic(8)
+             P:        Toggle on/off display of camera position / orientation
+-----------------------------------------------------------------------------
+*/
+
+#ifndef __ExampleFrameListener_H__
+#define __ExampleFrameListener_H__
+
+#include "Ogre.h"
+#include "OgreKeyEvent.h"
+#include "OgreEventListeners.h"
+#include "OgreStringConverter.h"
+#include "OgreException.h"
+
+using namespace Ogre;
+
+class ExampleFrameListener: public FrameListener, public KeyListener
+{
+protected:
+	int mSceneDetailIndex ;
+    Real mMoveSpeed;
+    Degree mRotateSpeed;
+    Overlay* mDebugOverlay;
+
+    void updateStats(void)
+    {
+        static String currFps = "Current FPS: ";
+        static String avgFps = "Average FPS: ";
+        static String bestFps = "Best FPS: ";
+        static String worstFps = "Worst FPS: ";
+        static String tris = "Triangle Count: ";
+
+        // update stats when necessary
+        try {
+            OverlayElement* guiAvg = OverlayManager::getSingleton().getOverlayElement("Core/AverageFps");
+            OverlayElement* guiCurr = OverlayManager::getSingleton().getOverlayElement("Core/CurrFps");
+            OverlayElement* guiBest = OverlayManager::getSingleton().getOverlayElement("Core/BestFps");
+            OverlayElement* guiWorst = OverlayManager::getSingleton().getOverlayElement("Core/WorstFps");
+
+            const RenderTarget::FrameStats& stats = mWindow->getStatistics();
+
+            guiAvg->setCaption(avgFps + StringConverter::toString(stats.avgFPS));
+            guiCurr->setCaption(currFps + StringConverter::toString(stats.lastFPS));
+            guiBest->setCaption(bestFps + StringConverter::toString(stats.bestFPS)
+                +" "+StringConverter::toString(stats.bestFrameTime)+" ms");
+            guiWorst->setCaption(worstFps + StringConverter::toString(stats.worstFPS)
+                +" "+StringConverter::toString(stats.worstFrameTime)+" ms");
+
+            OverlayElement* guiTris = OverlayManager::getSingleton().getOverlayElement("Core/NumTris");
+            guiTris->setCaption(tris + StringConverter::toString(stats.triangleCount));
+
+            OverlayElement* guiDbg = OverlayManager::getSingleton().getOverlayElement("Core/DebugText");
+            guiDbg->setCaption(mWindow->getDebugText());
+        }
+        catch(...)
+        {
+            // ignore
+        }
+    }
+
+public:
+    // Constructor takes a RenderWindow because it uses that to determine input context
+    ExampleFrameListener(RenderWindow* win, Camera* cam, bool useBufferedInputKeys = false, bool useBufferedInputMouse = false)
+    {
+        mDebugOverlay = OverlayManager::getSingleton().getByName("Core/DebugOverlay");
+        mUseBufferedInputKeys = useBufferedInputKeys;
+		mUseBufferedInputMouse = useBufferedInputMouse;
+		mInputTypeSwitchingOn = mUseBufferedInputKeys || mUseBufferedInputMouse;
+        mRotateSpeed = 36;
+        mMoveSpeed = 100;
+
+		if (mInputTypeSwitchingOn)
+		{
+            mEventProcessor = new EventProcessor();
+			mEventProcessor->initialise(win);
+			mEventProcessor->startProcessingEvents();
+			mEventProcessor->addKeyListener(this);
+			mInputDevice = mEventProcessor->getInputReader();
+
+		}
+        else
+        {
+            mInputDevice = PlatformManager::getSingleton().createInputReader();
+            mInputDevice->initialise(win,true, true);
+        }
+
+        mCamera = cam;
+        mWindow = win;
+        mStatsOn = true;
+		mNumScreenShots = 0;
+		mTimeUntilNextToggle = 0;
+        mSceneDetailIndex = 0;
+        mMoveScale = 0.0f;
+        mRotScale = 0.0f;
+	    mTranslateVector = Vector3::ZERO;
+        mAniso = 1;
+        mFiltering = TFO_BILINEAR;
+
+        showDebugOverlay(true);
+    }
+    virtual ~ExampleFrameListener()
+    {
+		if (mInputTypeSwitchingOn)
+		{
+            delete mEventProcessor;
+		}
+        else
+        {
+            PlatformManager::getSingleton().destroyInputReader( mInputDevice );
+        }
+    }
+
+    virtual bool processUnbufferedKeyInput(const FrameEvent& evt)
+    {
+        if (mInputDevice->isKeyDown(KC_A))
+        {
+            // Move camera left
+            mTranslateVector.x = -mMoveScale;
+        }
+
+        if (mInputDevice->isKeyDown(KC_D))
+        {
+            // Move camera RIGHT
+            mTranslateVector.x = mMoveScale;
+        }
+
+        /* Move camera forward by keypress. */
+        if (mInputDevice->isKeyDown(KC_UP) || mInputDevice->isKeyDown(KC_W) )
+        {
+            mTranslateVector.z = -mMoveScale;
+        }
+
+        /* Move camera backward by keypress. */
+        if (mInputDevice->isKeyDown(KC_DOWN) || mInputDevice->isKeyDown(KC_S) )
+        {
+            mTranslateVector.z = mMoveScale;
+        }
+
+        if (mInputDevice->isKeyDown(KC_PGUP))
+        {
+            // Move camera up
+            mTranslateVector.y = mMoveScale;
+        }
+
+        if (mInputDevice->isKeyDown(KC_PGDOWN))
+        {
+            // Move camera down
+            mTranslateVector.y = -mMoveScale;
+        }
+
+        if (mInputDevice->isKeyDown(KC_RIGHT))
+        {
+            mCamera->yaw(-mRotScale);
+        }
+		
+        if (mInputDevice->isKeyDown(KC_LEFT))
+        {
+            mCamera->yaw(mRotScale);
+        }
+
+        if( mInputDevice->isKeyDown( KC_ESCAPE) )
+        {            
+            return false;
+        }
+
+		// see if switching is on, and you want to toggle 
+        if (mInputTypeSwitchingOn && mInputDevice->isKeyDown(KC_M) && mTimeUntilNextToggle <= 0)
+        {
+			switchMouseMode();
+            mTimeUntilNextToggle = 1;
+        }
+
+        if (mInputTypeSwitchingOn && mInputDevice->isKeyDown(KC_K) && mTimeUntilNextToggle <= 0)
+        {
+			// must be going from immediate keyboard to buffered keyboard
+			switchKeyMode();
+            mTimeUntilNextToggle = 1;
+        }
+        if (mInputDevice->isKeyDown(KC_F) && mTimeUntilNextToggle <= 0)
+        {
+            mStatsOn = !mStatsOn;
+            showDebugOverlay(mStatsOn);
+
+            mTimeUntilNextToggle = 1;
+        }
+        if (mInputDevice->isKeyDown(KC_T) && mTimeUntilNextToggle <= 0)
+        {
+            switch(mFiltering)
+            {
+            case TFO_BILINEAR:
+                mFiltering = TFO_TRILINEAR;
+                mAniso = 1;
+                break;
+            case TFO_TRILINEAR:
+                mFiltering = TFO_ANISOTROPIC;
+                mAniso = 8;
+                break;
+            case TFO_ANISOTROPIC:
+                mFiltering = TFO_BILINEAR;
+                mAniso = 1;
+                break;
+            default:
+                break;
+            }
+            MaterialManager::getSingleton().setDefaultTextureFiltering(mFiltering);
+            MaterialManager::getSingleton().setDefaultAnisotropy(mAniso);
+
+
+            showDebugOverlay(mStatsOn);
+
+            mTimeUntilNextToggle = 1;
+        }
+
+        if (mInputDevice->isKeyDown(KC_SYSRQ) && mTimeUntilNextToggle <= 0)
+        {
+			char tmp[20];
+			sprintf(tmp, "screenshot_%d.png", ++mNumScreenShots);
+            mWindow->writeContentsToFile(tmp);
+            mTimeUntilNextToggle = 0.5;
+			mWindow->setDebugText(String("Wrote ") + tmp);
+        }
+		
+		if (mInputDevice->isKeyDown(KC_R) && mTimeUntilNextToggle <=0)
+		{
+			mSceneDetailIndex = (mSceneDetailIndex+1)%3 ;
+			switch(mSceneDetailIndex) {
+				case 0 : mCamera->setDetailLevel(SDL_SOLID) ; break ;
+				case 1 : mCamera->setDetailLevel(SDL_WIREFRAME) ; break ;
+				case 2 : mCamera->setDetailLevel(SDL_POINTS) ; break ;
+			}
+			mTimeUntilNextToggle = 0.5;
+		}
+
+        static bool displayCameraDetails = false;
+        if (mInputDevice->isKeyDown(KC_P) && mTimeUntilNextToggle <= 0)
+        {
+            displayCameraDetails = !displayCameraDetails;
+            mTimeUntilNextToggle = 0.5;
+            if (!displayCameraDetails)
+                mWindow->setDebugText("");
+        }
+        if (displayCameraDetails)
+        {
+            // Print camera details
+            mWindow->setDebugText("P: " + StringConverter::toString(mCamera->getDerivedPosition()) + " " + 
+                "O: " + StringConverter::toString(mCamera->getDerivedOrientation()));
+        }
+
+        // Return true to continue rendering
+        return true;
+    }
+
+    bool processUnbufferedMouseInput(const FrameEvent& evt)
+    {
+        /* Rotation factors, may not be used if the second mouse button is pressed. */
+
+        /* If the second mouse button is pressed, then the mouse movement results in 
+           sliding the camera, otherwise we rotate. */
+        if( mInputDevice->getMouseButton( 1 ) )
+        {
+            mTranslateVector.x += mInputDevice->getMouseRelativeX() * 0.13;
+            mTranslateVector.y -= mInputDevice->getMouseRelativeY() * 0.13;
+        }
+        else
+        {
+            mRotX = Degree(-mInputDevice->getMouseRelativeX() * 0.13);
+            mRotY = Degree(-mInputDevice->getMouseRelativeY() * 0.13);
+        }
+
+
+		return true;
+	}
+#ifdef GTP_VISIBILITY_MODIFIED_OGRE
+	virtual void moveCamera() // made virtual by matt (16.05.05)
+#else
+	void moveCamera()
+#endif // GTP_VISIBILTIY_MODIFIED_OGRE
+	{
+
+        // Make all the changes to the camera
+        // Note that YAW direction is around a fixed axis (freelook style) rather than a natural YAW (e.g. airplane)
+        mCamera->yaw(mRotX);
+        mCamera->pitch(mRotY);
+        mCamera->moveRelative(mTranslateVector);
+
+
+	}
+
+    void showDebugOverlay(bool show)
+    {
+        if (mDebugOverlay)
+        {
+            if (show)
+            {
+                mDebugOverlay->show();
+            }
+            else
+            {
+                mDebugOverlay->hide();
+            }
+        }
+    }
+
+    // Override frameStarted event to process that (don't care about frameEnded)
+    bool frameStarted(const FrameEvent& evt)
+    {
+        if(mWindow->isClosed())
+            return false;
+
+        if (!mInputTypeSwitchingOn)
+    	{
+            mInputDevice->capture();
+        }
+
+
+		if ( !mUseBufferedInputMouse || !mUseBufferedInputKeys)
+		{
+			// one of the input modes is immediate, so setup what is needed for immediate mouse/key movement
+			if (mTimeUntilNextToggle >= 0) 
+				mTimeUntilNextToggle -= evt.timeSinceLastFrame;
+
+			// If this is the first frame, pick a speed
+			if (evt.timeSinceLastFrame == 0)
+			{
+				mMoveScale = 1;
+				mRotScale = 0.1;
+			}
+			// Otherwise scale movement units by time passed since last frame
+			else
+			{
+				// Move about 100 units per second,
+				mMoveScale = mMoveSpeed * evt.timeSinceLastFrame;
+				// Take about 10 seconds for full rotation
+				mRotScale = mRotateSpeed * evt.timeSinceLastFrame;
+			}
+			mRotX = 0;
+            mRotY = 0;
+	        mTranslateVector = Vector3::ZERO;
+		}
+
+        if (mUseBufferedInputKeys)
+        {
+            // no need to do any processing here, it is handled by event processor and 
+			// you get the results as KeyEvents
+        }
+        else
+        {
+            if (processUnbufferedKeyInput(evt) == false)
+			{
+				return false;
+			}
+        }
+        if (mUseBufferedInputMouse)
+        {
+            // no need to do any processing here, it is handled by event processor and 
+			// you get the results as MouseEvents
+        }
+        else
+        {
+            if (processUnbufferedMouseInput(evt) == false)
+			{
+				return false;
+			}
+        }
+
+		if ( !mUseBufferedInputMouse || !mUseBufferedInputKeys)
+		{
+			// one of the input modes is immediate, so update the movement vector
+
+			moveCamera();
+
+		}
+
+		return true;
+    }
+
+    bool frameEnded(const FrameEvent& evt)
+    {
+        updateStats();
+        return true;
+    }
+
+	void switchMouseMode() 
+	{
+        mUseBufferedInputMouse = !mUseBufferedInputMouse;
+		mInputDevice->setBufferedInput(mUseBufferedInputKeys, mUseBufferedInputMouse);
+	}
+	void switchKeyMode() 
+	{
+        mUseBufferedInputKeys = !mUseBufferedInputKeys;
+		mInputDevice->setBufferedInput(mUseBufferedInputKeys, mUseBufferedInputMouse);
+	}
+
+	void keyClicked(KeyEvent* e) 
+	{
+		if (e->getKeyChar() == 'm')
+		{
+			switchMouseMode();
+		}
+		else if (e->getKeyChar() == 'k')
+		{
+
+			switchKeyMode();
+		}
+
+	}
+	void keyPressed(KeyEvent* e) {}
+	void keyReleased(KeyEvent* e) {}
+
+protected:
+    EventProcessor* mEventProcessor;
+    InputReader* mInputDevice;
+    Camera* mCamera;
+
+    Vector3 mTranslateVector;
+    RenderWindow* mWindow;
+    bool mStatsOn;
+    bool mUseBufferedInputKeys, mUseBufferedInputMouse, mInputTypeSwitchingOn;
+	unsigned int mNumScreenShots;
+    float mMoveScale;
+    Degree mRotScale;
+    // just to stop toggles flipping too fast
+    Real mTimeUntilNextToggle ;
+    Radian mRotX, mRotY;
+    TextureFilterOptions mFiltering;
+    int mAniso;
+
+};
+
+#endif
Index: trunk/VUT/work/TestCulling/TestCullingApplication.cpp
===================================================================
--- trunk/VUT/work/TestCulling/TestCullingApplication.cpp	(revision 99)
+++ trunk/VUT/work/TestCulling/TestCullingApplication.cpp	(revision 100)
@@ -292,5 +292,5 @@
 	mShowVisualization = !mShowVisualization;
 
-	mSceneMgr->setOption("CullCamera", &mShowVisualization);
+	mSceneMgr->setOption("ShowVisualization", &mShowVisualization);
 }
 //-----------------------------------------------------------------------
Index: trunk/VUT/work/TestCulling/TestCullingApplication.h
===================================================================
--- trunk/VUT/work/TestCulling/TestCullingApplication.h	(revision 99)
+++ trunk/VUT/work/TestCulling/TestCullingApplication.h	(revision 100)
@@ -97,5 +97,5 @@
 	bool mShowVisualization;
 
-	Camera *mVisualizationCamera;
+	Camera *mVizCamera;
 };
 
Index: trunk/VUT/Ogre/include/OgreVisibilityOctreeSceneManager.h
===================================================================
--- trunk/VUT/Ogre/include/OgreVisibilityOctreeSceneManager.h	(revision 99)
+++ trunk/VUT/Ogre/include/OgreVisibilityOctreeSceneManager.h	(revision 100)
@@ -57,5 +57,7 @@
 	OctreeHierarchyInterface *mHierarchyInterface;
 	GtpVisibility::VisibilityManager *mVisibilityManager;
+	
 	bool mUseVisibilityCulling;
+	bool mShowVisualization;
 };
 
Index: trunk/VUT/Ogre/include/OgreVisibilityTerrainSceneManager.h
===================================================================
--- trunk/VUT/Ogre/include/OgreVisibilityTerrainSceneManager.h	(revision 99)
+++ trunk/VUT/Ogre/include/OgreVisibilityTerrainSceneManager.h	(revision 100)
@@ -56,5 +56,9 @@
 	void WriteLog();
 	void SetShowVisualization(bool showViz);
-	
+
+/*	void SetSkyBoxEnabled(bool enabled);
+	void SetSkyPlaneEnabled(bool enabled);
+	void SetSkyDomeEnabled(bool enabled);*/
+
 protected:
 	
Index: trunk/VUT/Ogre/scripts/Plugin_VisibilitySceneManager.vcproj
===================================================================
--- trunk/VUT/Ogre/scripts/Plugin_VisibilitySceneManager.vcproj	(revision 92)
+++ trunk/VUT/Ogre/scripts/Plugin_VisibilitySceneManager.vcproj	(revision 100)
@@ -88,5 +88,5 @@
 				OptimizeForProcessor="2"
 				AdditionalIncludeDirectories="&quot;$(OGRE_PATH)\PlugIns\OctreeSceneManager\include&quot;;&quot;$(OGRE_ADDONS_PATH)\dotsceneoctree\PlugIns\DotSceneManager\include&quot;;&quot;$(OGRE_PATH)\Samples\Common\include&quot;;&quot;$(OGRE_PATH)\Dependencies\include\CEGUI&quot;;&quot;$(OGRE_PATH)\Samples\Common\CEGUIRenderer\include&quot;;&quot;$(OGRE_PATH)\OgreMain\include&quot;;&quot;$(OGRE_PATH)\Dependencies\include&quot;;..\include;..\..\GtpVisibility\include"
-				PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;PLUGIN_OCCLUSIONCULLINGSCENEMANAGER_EXPORTS;GTP_VISIBILITY_MODIFIED_OGRE"
+				PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;GTP_VISIBILITY_MODIFIED_OGRE"
 				StringPooling="TRUE"
 				RuntimeLibrary="2"
Index: trunk/VUT/Ogre/src/OgreVisibilityOctreeSceneManager.cpp
===================================================================
--- trunk/VUT/Ogre/src/OgreVisibilityOctreeSceneManager.cpp	(revision 99)
+++ trunk/VUT/Ogre/src/OgreVisibilityOctreeSceneManager.cpp	(revision 100)
@@ -12,5 +12,6 @@
 VisibilityOctreeSceneManager::VisibilityOctreeSceneManager(
 	GtpVisibility::VisibilityManager *visManager)
-: mVisibilityManager(visManager), mUseVisibilityCulling(true)
+: mVisibilityManager(visManager), mUseVisibilityCulling(true),
+mShowVisualization(false)
 {
 	mHierarchyInterface = 
@@ -35,5 +36,5 @@
 	mHierarchyInterface->InitFrame(mOctree, mCameraInProgress, 
 							mCullCamera ? getCamera("CullCamera") : NULL);
-	mVisibilityManager->GetCullingManager()->InitFrame();
+	//mVisibilityManager->GetCullingManager()->InitFrame();
 
 	// standard scenemanager rendering without hierarchical culling
@@ -65,6 +66,10 @@
 	setSpecialCaseRenderQueueMode(SceneManager::SCRQM_EXCLUDE);
 
-	//-- the hierarchical culling algorithm
+
+	/** 
+	* the hierarchical culling algorithm
+	**/
 	mVisibilityManager->ApplyVisibilityCulling();
+
 
 #ifdef GTP_VISIBILITY_MODIFIED_OGRE
@@ -84,12 +89,22 @@
 	// we interleave identification and rendering of objects 
 	// in _renderVisibibleObjects 
+	if (!mUseVisibilityCulling)
+	{
+		OctreeSceneManager::_findVisibleObjects(cam, onlyShadowCasters);
+		return;	
+	}
+	
+	if (mShowVisualization)
+    {
+		
+		for ( BoxList::iterator it = mBoxes.begin(); it != mBoxes.end(); ++it )
+		{
+			getRenderQueue()->addRenderable(*it);
+		}
+	}
+
 	getRenderQueue()->clear();
     mBoxes.clear();
     mVisible.clear();
-
-	if(!mUseVisibilityCulling)
-	{
-		OctreeSceneManager::_findVisibleObjects(cam, onlyShadowCasters);
-	}
 }
 //-----------------------------------------------------------------------
@@ -112,5 +127,9 @@
 		return true;
 	}
-	
+	if (key == "ShowVisualization")
+	{
+		mShowVisualization = (*static_cast<const bool *>(val));
+		return true;
+	}
 	return VisibilityOptionsManager(mVisibilityManager, mHierarchyInterface).
 		setOption(key, val) || OctreeSceneManager::setOption(key, val);
Index: trunk/VUT/Ogre/src/OgreSceneNodeHierarchyInterface.cpp
===================================================================
--- trunk/VUT/Ogre/src/OgreSceneNodeHierarchyInterface.cpp	(revision 94)
+++ trunk/VUT/Ogre/src/OgreSceneNodeHierarchyInterface.cpp	(revision 100)
@@ -62,5 +62,5 @@
 	SceneNode *sceneNode = static_cast<SceneNode *>(node);
 
-	while(sceneNode && !sceneNode->isNodeVisible())
+	while (sceneNode && !sceneNode->isNodeVisible())
 	{
 		sceneNode->setNodeVisible(true);
@@ -115,8 +115,7 @@
 AxisAlignedBox *SceneNodeHierarchyInterface::GetBoundingBox(GtpVisibility::HierarchyNode *node)
 {
-	if(node != mPreviousNode)
+	if (node != mPreviousNode)
 	{
 		mPreviousNode = node;
-
 		mBox = static_cast<SceneNode *>(node)->_getWorldAABB();
 	}
Index: trunk/VUT/Ogre/src/OgrePlatformHierarchyInterface.cpp
===================================================================
--- trunk/VUT/Ogre/src/OgrePlatformHierarchyInterface.cpp	(revision 94)
+++ trunk/VUT/Ogre/src/OgrePlatformHierarchyInterface.cpp	(revision 100)
@@ -20,5 +20,5 @@
 	DeleteQueries();
 
-	if(mSolidBoundingBox)
+	if (mSolidBoundingBox)
 		delete mSolidBoundingBox;
 }
@@ -26,5 +26,5 @@
 void PlatformHierarchyInterface::DeleteQueries()
 {
-	for(int i=0; i < (int)mOcclusionQueries.size(); ++i)
+	for (int i=0; i < (int)mOcclusionQueries.size(); ++i)
 		delete mOcclusionQueries[i];
 
@@ -72,5 +72,5 @@
 GtpVisibility::OcclusionQuery *PlatformHierarchyInterface::GetNextOcclusionQuery()
 {
-	if(mCurrentTestIdx == mOcclusionQueries.size())
+	if (mCurrentTestIdx == mOcclusionQueries.size())
 	{
 		mOcclusionQueries.push_back(new PlatformOcclusionQuery(mRenderSystem));
@@ -87,5 +87,5 @@
 	SetCamera(cam);
 
-	if(cullCam)
+	if (cullCam)
 		SetCullCamera(cullCam);
 	else
@@ -143,5 +143,5 @@
 SolidBoundingBox *PlatformHierarchyInterface::GetSolidBoundingBox()
 {
-	if(!mSolidBoundingBox)
+	if (!mSolidBoundingBox)
 		mSolidBoundingBox = new SolidBoundingBox;
 
Index: trunk/VUT/Ogre/src/OgreSolidHalfBoundingBox.cpp
===================================================================
--- trunk/VUT/Ogre/src/OgreSolidHalfBoundingBox.cpp	(revision 97)
+++ trunk/VUT/Ogre/src/OgreSolidHalfBoundingBox.cpp	(revision 100)
@@ -42,5 +42,5 @@
 
 	// fan 1
-	if(isFirstHalf)
+	if (isFirstHalf)
 	{
 		*pPos++ = min.x; *pPos++ = max.y; *pPos++ = max.z; //011
@@ -89,5 +89,5 @@
 	m_pMaterial = MaterialManager::getSingleton().getByName("QueryMaterial");
 
-	if(m_pMaterial.isNull())
+	if (m_pMaterial.isNull())
 	{
 		m_pMaterial = MaterialManager::getSingleton().
Index: trunk/VUT/Ogre/src/OgreVisibilityTerrainSceneManager.cpp
===================================================================
--- trunk/VUT/Ogre/src/OgreVisibilityTerrainSceneManager.cpp	(revision 99)
+++ trunk/VUT/Ogre/src/OgreVisibilityTerrainSceneManager.cpp	(revision 100)
@@ -7,4 +7,5 @@
 #include <OgreCamera.h>
 #include <OgreLogManager.h>
+#include <OgreStringConverter.h>
 
 #include <windows.h>
@@ -36,5 +37,5 @@
 	mHierarchyInterface->InitFrame(mOctree, mCameraInProgress, 
 							mCullCamera ? getCamera("CullCamera") : NULL);
-	mVisibilityManager->GetCullingManager()->InitFrame();
+	//mVisibilityManager->GetCullingManager()->InitFrame();
 	
 	// standard scenemanager rendering without hierarchical culling
@@ -56,4 +57,5 @@
 	setSpecialCaseRenderQueueMode(SceneManager::SCRQM_INCLUDE);
 	SceneManager::_renderVisibleObjects();
+
 #ifdef GTP_VISIBILITY_MODIFIED_OGRE
 	_deleteRenderedQueueGroups();
@@ -65,6 +67,10 @@
 	setSpecialCaseRenderQueueMode(SceneManager::SCRQM_EXCLUDE);
 
-	//-- the hierarchical culling algorithm
+
+	/** 
+	* the hierarchical culling algorithm
+	**/
 	mVisibilityManager->ApplyVisibilityCulling();
+
 
 #ifdef GTP_VISIBILITY_MODIFIED_OGRE
@@ -83,21 +89,38 @@
 	// does nothing if hierarchical culling is used =>
 	// we interleave identification and rendering of objects 
-	// in _renderVisibibleObjects 
+	// in _renderVisibibleObjects
+	getRenderQueue()->clear();
+	
+	if (!mUseVisibilityCulling)
+	{
+		OctreeSceneManager::_findVisibleObjects(cam, onlyShadowCasters);
+		return;	
+	}
+	
+	//-- show visibile scene nodes and octree bounding boxes from last frame
 	if (mShowVisualization)
     {
-		for ( BoxList::iterator it = mBoxes.begin(); it != mBoxes.end(); ++it )
+		// add cull camera for visualization purpose
+		if (mCullCamera)
+		{
+			Camera *c;
+			if ((c = getCamera("CullCamera")) != NULL)
+			{
+				getRenderQueue()->addRenderable(c);
+			}
+		}
+
+		for (NodeList::iterator it = mVisible.begin(); it != mVisible.end(); ++it)
 		{
 			getRenderQueue()->addRenderable(*it);
 		}
-	}
-
-	getRenderQueue()->clear();
+		for (BoxList::iterator it = mBoxes.begin(); it != mBoxes.end(); ++it)
+		{
+			getRenderQueue()->addRenderable(*it);
+		}
+	}
+	
+	mVisible.clear();
     mBoxes.clear();
-    mVisible.clear();
-
-	if(!mUseVisibilityCulling)
-	{
-		OctreeSceneManager::_findVisibleObjects(cam, onlyShadowCasters);
-	}
 }
 //-----------------------------------------------------------------------
@@ -126,5 +149,19 @@
 		return true;
 	}
-
+	if (key == "SkyBoxEnabled")
+	{
+		mSkyBoxEnabled = (*static_cast<const bool *>(val));
+		return true;
+	}
+	if (key == "SkyPlaneEnabled")
+	{
+		mSkyPlaneEnabled = (*static_cast<const bool *>(val));
+		return true;
+	}
+	if (key == "SkyDomeEnabled")
+	{
+		mSkyDomeEnabled = (*static_cast<const bool *>(val));
+		return true;
+	}
 	return VisibilityOptionsManager(mVisibilityManager, mHierarchyInterface).
 		setOption(key, val) || TerrainSceneManager::setOption(key, val);
@@ -139,5 +176,4 @@
 	}
 	
-
 	return VisibilityOptionsManager(mVisibilityManager, mHierarchyInterface).
 		getOption(key, val) && TerrainSceneManager::getOption(key, val);
@@ -169,4 +205,20 @@
 	mShowVisualization = showViz;
 }
+/*
+//-----------------------------------------------------------------------
+void SetSkyBoxEnabled(bool enabled)
+{
+	mSkyBoxEnabled = enabled;
+}
+//-----------------------------------------------------------------------
+void SetSkyPlaneEnabled(bool enabled)
+{
+	mSkyPlaneEnabled = enabled;
+}
+//-----------------------------------------------------------------------
+void SetSkyDomeEnabled(bool enabled)
+{
+	mSkyDomeEnabled = enabled;
+} */
 //-----------------------------------------------------------------------
 void VisibilityTerrainSceneManager::WriteLog()
Index: trunk/VUT/Ogre/src/OgreSolidBoundingBox.cpp
===================================================================
--- trunk/VUT/Ogre/src/OgreSolidBoundingBox.cpp	(revision 97)
+++ trunk/VUT/Ogre/src/OgreSolidBoundingBox.cpp	(revision 100)
@@ -121,5 +121,5 @@
 	m_pMaterial = MaterialManager::getSingleton().getByName("QueryMaterial");
 
-	if(m_pMaterial.isNull())
+	if (m_pMaterial.isNull())
 	{
 		m_pMaterial = MaterialManager::getSingleton().
Index: trunk/VUT/Ogre/src/OgreVisibilitySceneManagerDll.cpp
===================================================================
--- trunk/VUT/Ogre/src/OgreVisibilitySceneManagerDll.cpp	(revision 94)
+++ trunk/VUT/Ogre/src/OgreVisibilitySceneManagerDll.cpp	(revision 100)
@@ -28,9 +28,9 @@
 //#include <OgreVisibilityDotSceneManager.h>
 #include <OgreHeightmapTerrainPageSource.h>
+#include <OgreRoot.h>
+
 #include "VisibilityManager.h"
 #include "StopAndWaitCullingManager.h"
 #include "VisibilityEnvironment.h"
-
-#include <OgreRoot.h>
 
 GtpVisibility::VisibilityEnvironment *visEnv;
Index: trunk/VUT/Ogre/src/OgreVisibilityOptionsManager.cpp
===================================================================
--- trunk/VUT/Ogre/src/OgreVisibilityOptionsManager.cpp	(revision 87)
+++ trunk/VUT/Ogre/src/OgreVisibilityOptionsManager.cpp	(revision 100)
@@ -3,7 +3,9 @@
 namespace Ogre {
 //-----------------------------------------------------------------------
-VisibilityOptionsManager::VisibilityOptionsManager(GtpVisibility::VisibilityManager *visManager, 
-										GtpVisibility::HierarchyInterface *hierarchyInterface):
-mVisibilityManager(visManager), mHierarchyInterface(hierarchyInterface)
+VisibilityOptionsManager::VisibilityOptionsManager(
+	GtpVisibility::VisibilityManager *visManager, 
+	GtpVisibility::HierarchyInterface *hierarchyInterface):
+mVisibilityManager(visManager), 
+mHierarchyInterface(hierarchyInterface)
 {
 }
@@ -11,5 +13,5 @@
 bool VisibilityOptionsManager::setOption( const String & key, const void * val )
 {
-	if( key == "Algorithm" )
+	if (key == "Algorithm")
 	{
 		mVisibilityManager->SetCullingManager(*static_cast<const 
@@ -17,5 +19,5 @@
 		return true;
 	}
-	if(key == "Threshold")
+	if (key == "Threshold")
 	{
 		mVisibilityManager->SetVisibilityCullingThreshold(*static_cast<const int *>(val));
@@ -67,10 +69,10 @@
 }
 //-----------------------------------------------------------------------
-bool VisibilityOptionsManager::getOptionKeys( StringVector & refKeys )
+bool VisibilityOptionsManager::getOptionKeys(StringVector & refKeys)
 {
-	refKeys.push_back( "NumRenderedNodes" );
-	refKeys.push_back( "NumTraversedNodes" );
-	refKeys.push_back( "NumQueryCulledNodes" );
-	refKeys.push_back( "NumFrustumCulledNodes" );
+	refKeys.push_back("NumRenderedNodes");
+	refKeys.push_back("NumTraversedNodes");
+	refKeys.push_back("NumQueryCulledNodes");
+	refKeys.push_back("NumFrustumCulledNodes");
 	
 	return true;
Index: trunk/VUT/Ogre/src/OgreVisibilitySceneManager.cpp
===================================================================
--- trunk/VUT/Ogre/src/OgreVisibilitySceneManager.cpp	(revision 99)
+++ trunk/VUT/Ogre/src/OgreVisibilitySceneManager.cpp	(revision 100)
@@ -27,5 +27,5 @@
 	// we interleave identification and rendering of objects 
 	// in _renderVisibibleObjects 
-	if(!mUseVisibilityCulling)
+	if (!mUseVisibilityCulling)
 	{
 		SceneManager::_findVisibleObjects(cam, onlyShadowCasters);
@@ -38,5 +38,5 @@
 	mVisibilityManager->GetCullingManager()->InitFrame();
 
-	if(!mUseVisibilityCulling)
+	if (!mUseVisibilityCulling)
 	{	
 		SceneManager::_renderVisibleObjects();
