Index: trunk/VUT/work/TestCullingTerrain/TerrainMouseQueryListener.h
===================================================================
--- trunk/VUT/work/TestCullingTerrain/TerrainMouseQueryListener.h	(revision 115)
+++ trunk/VUT/work/TestCullingTerrain/TerrainMouseQueryListener.h	(revision 120)
@@ -71,23 +71,9 @@
    //enum {NODEVIZ_NONE, NODEVIZ_RENDER_GEOMETRY, NODEVIZ_MODES_NUM};
 
-   void nextAlgorithm();
-   void changeThreshold(int incr);
-   void updateStats();
-
-   void toggleUseOptimization();
-   void toggleShowOctree();
-   void toggleUseDepthPass();
-   void toggleShowViz();
-   void nextNodeVizMode();
-   void toggleRecord();
-
-   void zoomVizCamera(int zoom);
+  void zoomVizCamera(int zoom);
 	
    void addFrameInfo(SceneNode *camNode, Real timeElapsed);
    void setCurrentFrameInfo(Real timeElapsed);
 
-   void setAppState(int state);
-   void nextAppState();
-
    void setAlgorithm(int algorithm);
 
@@ -97,5 +83,4 @@
    void loadFrames();
 
-   void toggleUseShadows();
   
 
@@ -106,5 +91,26 @@
     bool processUnbufferedMouseInput(const FrameEvent& evt);
 
-    void showDebugOverlay(bool show);
+    void showStats(bool show);
+
+	void updateStats();
+
+	void toggleShowHelp();
+	void toggleShowStats();
+
+	void toggleUseShadows();
+	void toggleDisplayCameraDetails();
+	void takeScreenShot();
+	void nextSceneDetailLevel();
+	void nextFilter();
+	void nextAlgorithm();
+	void nextNodeVizMode();
+	void nextAppState();
+    void changeThreshold(int incr);
+	
+	void toggleUseOptimization();
+	void toggleShowOctree();
+	void toggleUseDepthPass();
+	void toggleShowViz();
+	void toggleRecord();
 
 protected:
@@ -114,13 +120,21 @@
 	void Clamp2Terrain();
 	
-    bool mLMouseDown, mRMouseDown;     // True if the mouse buttons are down
-    SceneManager *mSceneMgr;           // A pointer to the scene manager
+	SceneManager *mSceneMgr;           // A pointer to the scene manager
     
 	CEGUI::Renderer *mGUIRenderer;     // cegui renderer
 	
-	bool mShutdownRequested;
 	int mCurrentAlgorithm;
 	int mVisibilityThreshold;
-	
+	// the current frame number
+	int mCurrentFrame;
+	// the current application state
+	int mAppState;
+	// The number of objects on the screen
+	int mObjectCount;            
+	// visualization mode
+	int mNodeVizMode;
+
+	SceneNode *mCurrentObject;    // the newly created object
+
 	OverlayElement *mAlgorithmInfo;
 	OverlayElement *mThresholdInfo;
@@ -135,7 +149,4 @@
 	OverlayElement *mQueriesIssuedInfo;
 
-	SceneNode *mCurrentObject;    // the newly created object
-	int mObjectCount;             // The number of objects on the screen
-
 	RayQueryExecutor *mRayQueryExecutor;
 	TerrainContentGenerator *mTerrainContentGenerator;
@@ -145,6 +156,13 @@
 	bool mUseDepthPass;
 	bool mShowVisualization;
-	int mNodeVizMode;
 	bool mCullCamera;
+	bool mRecord;
+	bool mUseShadows;
+	bool mVisualizeCulledNodes;
+	bool mShowHelp;
+	bool mStatsOn;
+	bool mLMouseDown, mRMouseDown;     // True if the mouse buttons are down
+	bool mShutdownRequested;
+	bool mDisplayCameraDetails;
 
 	Real mVizCameraHeight;
@@ -156,14 +174,5 @@
 	std::vector<frame_info> mFrameInfo;
 		
-	int mCurrentFrame;
-	// the current application state
-	int mAppState;
-	bool mRecord;
 	Real mTimeElapsed;
-	bool mUseShadows;
-
-	bool mVisualizeCulledNodes;
-
-
 	//EventProcessor* mEventProcessor;
     InputReader* mInputDevice;
@@ -172,19 +181,23 @@
     Vector3 mTranslateVector;
     RenderWindow* mWindow;
-    bool mStatsOn;
-    bool mUseBufferedInputKeys, mUseBufferedInputMouse, mInputTypeSwitchingOn;
+   
+    //bool mUseBufferedInputKeys, mUseBufferedInputMouse, mInputTypeSwitchingOn;
 	unsigned int mNumScreenShots;
-    float mMoveScale;
+    int mSceneDetailIndex;
+	int mAniso;
+
+	float mMoveScale;
     Degree mRotScale;
     // just to stop toggles flipping too fast
-    Real mTimeUntilNextToggle;
+    Real mTimeDelay;
     Radian mRotX, mRotY;
     TextureFilterOptions mFiltering;
-    int mAniso;
-
-	int mSceneDetailIndex;
-    Real mMoveSpeed;
+  
+	Real mMoveSpeed;
     Degree mRotateSpeed;
-    Overlay* mDebugOverlay;
+    
+	Overlay* mDebugOverlay;
+	Overlay* mHelpOverlay;
+	Overlay* mCullStatsOverlay;
 };
 
Index: trunk/VUT/work/TestCullingTerrain/TestCullingTerrainApplication.cpp
===================================================================
--- trunk/VUT/work/TestCullingTerrain/TestCullingTerrainApplication.cpp	(revision 115)
+++ trunk/VUT/work/TestCullingTerrain/TestCullingTerrainApplication.cpp	(revision 120)
@@ -163,7 +163,7 @@
 
 		// the objects are generated on the whole terrain
+		mTerrainContentGenerator->GenerateScene(1500, "robot");
 		//mTerrainContentGenerator->GenerateScene(1500, "athene");
-		mTerrainContentGenerator->GenerateScene(1500, "robot");
-		//	mTerrainContentGenerator->GenerateScene(500, "ninja");
+		//mTerrainContentGenerator->GenerateScene(500, "ninja");
 	}
 
@@ -192,5 +192,5 @@
 	mTerrainFrameListener = new TerrainMouseQueryListener(mWindow, mCamera, mSceneMgr, 
 		mGUIRenderer, mTerrainContentGenerator, mVizCamera, mCamNode);
-	mTerrainFrameListener->showDebugOverlay(true);
+	
 	mRoot->addFrameListener(mTerrainFrameListener);
 }
Index: trunk/VUT/work/TestCullingTerrain/TerrainMouseQueryListener.cpp
===================================================================
--- trunk/VUT/work/TestCullingTerrain/TerrainMouseQueryListener.cpp	(revision 115)
+++ trunk/VUT/work/TestCullingTerrain/TerrainMouseQueryListener.cpp	(revision 120)
@@ -13,10 +13,9 @@
 
 
-Real timeDelay = 0;
-#define KEY_PRESSED(_key,_timeDelay, _macro) \
+#define KEY_PRESSED(_key, _timeDelay, _macro) \
 { \
-    if (mInputDevice->isKeyDown(_key) && timeDelay <= 0) \
+    if (mInputDevice->isKeyDown(_key) && mTimeDelay <= 0) \
 { \
-    timeDelay = _timeDelay; \
+    mTimeDelay = _timeDelay; \
     _macro ; \
 } \
@@ -41,7 +40,6 @@
 mCamera(cam),
 mWindow(win),
-mStatsOn(true),
 mNumScreenShots(0),
-mTimeUntilNextToggle(0),
+mTimeDelay(0),
 mSceneDetailIndex(0),
 mMoveScale(0.0f),
@@ -51,7 +49,4 @@
 mFiltering(TFO_BILINEAR), 
 mGUIRenderer(renderer), 
-mShutdownRequested(false), 
-mLMouseDown(false),
-mRMouseDown(false),
 mSceneMgr(sceneManager),
 mCurrentObject(NULL),
@@ -60,31 +55,33 @@
 mCurrentAlgorithm(GtpVisibility::VisibilityEnvironment::COHERENT_HIERARCHICAL_CULLING),
 //mCurrentAlgorithm(GtpVisibility::VisibilityEnvironment::FRUSTUM_CULLING),
+mNodeVizMode(NODEVIZ_NONE),
+mVizCameraHeight(Real(2500.0)),
+mCamNode(camNode),
+mAppState(WALKTHROUGH),
+mCurrentFrame(0),
+mTimeElapsed(0),
+mRotateSpeed(72),
+mMoveSpeed(50),
+mVizCamera(vizCamera),
+mStatsOn(true),
+mShutdownRequested(false), 
+mLMouseDown(false),
+mRMouseDown(false),
 mShowOctree(false),
 mUseDepthPass(false),
 mUseOptimization(true),
-mVizCamera(vizCamera),
 mShowVisualization(false),
-mNodeVizMode(NODEVIZ_NONE),
-mVizCameraHeight(Real(2500.0)),
-mCamNode(camNode),
 mCullCamera(false),
-mAppState(WALKTHROUGH),
-mCurrentFrame(0),
 mRecord(false),
-mTimeElapsed(0),
 mUseShadows(false),
-mVisualizeCulledNodes(false),
-mRotateSpeed(72),
-mMoveSpeed(50)
-{
-	mDebugOverlay = OverlayManager::getSingleton().getByName("Core/DebugOverlay");
-	
-    mInputDevice = PlatformManager::getSingleton().createInputReader();
+mShowHelp(false),
+mDisplayCameraDetails(false),
+mVisualizeCulledNodes(false)
+{
+	mInputDevice = PlatformManager::getSingleton().createInputReader();
 	mInputDevice->initialise(win, true, true);
 
-    showDebugOverlay(true);
-    
-	// Register this so that we get mouse events.
-	/*mEventProcessor->addMouseListener(this);
+	/*
+	mEventProcessor->addMouseListener(this);
 	mEventProcessor->addMouseMotionListener(this);
 	mEventProcessor->addKeyListener(this);
@@ -94,7 +91,11 @@
 	mRayQueryExecutor = new RayQueryExecutor(mSceneMgr);
 	
-	//-- show visibility overlay
-	Overlay* pOver = OverlayManager::getSingleton().getByName("Example/VisibilityDemoOverlay"); 
-
+	mHelpOverlay = OverlayManager::getSingleton().getByName("Example/Visibility/HelpOverlay"); 
+	mDebugOverlay = OverlayManager::getSingleton().getByName("Core/DebugOverlay");
+
+
+	//-- visibility culling stats overlay
+	mCullStatsOverlay = OverlayManager::getSingleton().getByName("Example/Visibility/DemoOverlay"); 
+	
 	mAlgorithmInfo = OverlayManager::getSingleton().getOverlayElement("Example/Visibility/AlgorithmInfo");
 	mThresholdInfo = OverlayManager::getSingleton().getOverlayElement("Example/Visibility/ThresholdInfo");
@@ -121,17 +122,22 @@
 	mUseDepthPassInfo->setCaption(": false");
 	mQueriesIssuedInfo->setCaption(": 0");
-	
-	pOver->show();
-
+
+	// show stats overlays
+	showStats(true);
+	//mHelpOverlay->show();
 
 	// set culling algorithm type
 	setAlgorithm(mCurrentAlgorithm);
 
-
 	// set scene manager options
 	mSceneMgr->setOption("UseOptimization", &mUseOptimization);
-	bool delayedRendering = !mUseOptimization;
-	mSceneMgr->setOption("DelayRenderTransparents", &delayedRendering);
+
+	// apply delayed rendering (i.e., transparents after hierarchical culling pass)
+	// only if optimization is not used 
+	bool delayRenderTransparents = !mUseOptimization;
+
+	mSceneMgr->setOption("DelayRenderTransparents", &delayRenderTransparents);
 	mSceneMgr->setOption("UseDepthPass", &mUseDepthPass);
+	
 	mSceneMgr->setOption("ShowOctree", &mShowOctree);
 	mSceneMgr->setOption("CullCamera", &mCullCamera);
@@ -229,6 +235,6 @@
 		 
 	 //-- setup what is needed for immediate mouse/key movement
-	 if (mTimeUntilNextToggle >= 0) 
-		 mTimeUntilNextToggle -= evt.timeSinceLastFrame;
+	 if (mTimeDelay >= 0) 
+		 mTimeDelay -= evt.timeSinceLastFrame;
 
 	 // If this is the first frame, pick a speed
@@ -329,29 +335,5 @@
 		return false;
 
-    if (timeDelay >= 0) 
-        timeDelay -= evt.timeSinceLastFrame;
-
-	KEY_PRESSED(KC_SPACE, 0.3, nextAlgorithm());
-
-	KEY_PRESSED(KC_O, 0.3, toggleUseOptimization());
-	KEY_PRESSED(KC_T, 0.3, toggleShowOctree());
-	KEY_PRESSED(KC_X, 0.3, toggleUseDepthPass());
-	KEY_PRESSED(KC_1, 0.3, toggleShowViz());
-	KEY_PRESSED(KC_2, 0.3, nextNodeVizMode());
-	
-	KEY_PRESSED(KC_SUBTRACT, 0, changeThreshold(-10));
-	KEY_PRESSED(KC_ADD, 0, changeThreshold(10));
-	
-	KEY_PRESSED(KC_4, 0, zoomVizCamera(50));
-	KEY_PRESSED(KC_5, 0, zoomVizCamera(-50));
-
-	KEY_PRESSED(KC_F1, 0.3, nextAppState());
-	KEY_PRESSED(KC_F2, 0.3, toggleRecord());
-	KEY_PRESSED(KC_F3, 0.3, mTerrainContentGenerator->WriteObjects(objects_out_filename));
-	KEY_PRESSED(KC_F4, 0.3, toggleUseShadows());
-	//KEY_PRESSED(KC_F3, 0.3, writeFrames());
-	//KEY_PRESSED(KC_F4, 0.3, loadFrames());
-
-	updateStats();
+    updateStats();
 
 	return true;
@@ -408,9 +390,4 @@
 	}
 	ifstr.close();
-}
-//-----------------------------------------------------------------------
-void TerrainMouseQueryListener::setAppState(int state)
-{
-	mAppState = state;
 }
 //-----------------------------------------------------------------------
@@ -608,7 +585,11 @@
 	
 	if (mUseDepthPass)
+	{
 		mUseDepthPassInfo->setCaption(": true");
+	}
 	else
+	{
 		mUseDepthPassInfo->setCaption(": false");
+	}
 }
 //-----------------------------------------------------------------------
@@ -673,5 +654,6 @@
 	mNodeVizMode = (mNodeVizMode + 1) % NODEVIZ_MODES_NUM;
 
-	bool renderNodesForViz = (mNodeVizMode == NODEVIZ_RENDER_NODES) || (mNodeVizMode == NODEVIZ_RENDER_NODES_AND_CONTENT);
+	bool renderNodesForViz = (mNodeVizMode == NODEVIZ_RENDER_NODES) || 
+		(mNodeVizMode == NODEVIZ_RENDER_NODES_AND_CONTENT);
 	bool renderNodesContentForViz = (mNodeVizMode == NODEVIZ_RENDER_NODES_AND_CONTENT);
 	//bool renderNodesContentForViz = mNodeVizMode == NODEVIZ_RENDER_GEOMETRY;
@@ -752,38 +734,19 @@
 bool TerrainMouseQueryListener::processUnbufferedKeyInput(const FrameEvent& evt)
 {
-    if (mInputDevice->isKeyDown(KC_A))
+	if (mInputDevice->isKeyDown(KC_ESCAPE))
+    {            
+        return false;
+    }
+
+	/* Move camera forward by keypress. */
+    if (mInputDevice->isKeyDown(KC_UP))
+	{
+		mTranslateVector.z = -mMoveScale;
+	}
+
+    /* Move camera backward by keypress. */
+    if (mInputDevice->isKeyDown(KC_DOWN))
     {
-        // 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;
+		mTranslateVector.z = mMoveScale;
     }
 
@@ -798,73 +761,34 @@
     }
 
-    if( mInputDevice->isKeyDown( KC_ESCAPE) )
-    {            
-        return false;
-    }
-	
-	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)
+	KEY_PRESSED(KC_SPACE, 0.3, nextAlgorithm());
+	KEY_PRESSED(KC_F, 0.3, nextFilter());
+	KEY_PRESSED(KC_R, 0.3, nextSceneDetailLevel());
+
+	KEY_PRESSED(KC_P, 0.3, toggleDisplayCameraDetails());
+	KEY_PRESSED(KC_O, 0.3, toggleUseOptimization());
+	KEY_PRESSED(KC_T, 0.3, toggleShowOctree());
+	KEY_PRESSED(KC_X, 0.3, toggleUseDepthPass());
+	KEY_PRESSED(KC_S, 0.3, toggleUseShadows());
+
+	KEY_PRESSED(KC_SUBTRACT, 0, changeThreshold(-10));
+	KEY_PRESSED(KC_ADD, 0, changeThreshold(10));
+	
+	//-- visualization
+	KEY_PRESSED(KC_1, 0.3, toggleShowViz());
+	KEY_PRESSED(KC_2, 0.3, nextNodeVizMode());
+	KEY_PRESSED(KC_3, 0, zoomVizCamera(50));
+	KEY_PRESSED(KC_4, 0, zoomVizCamera(-50));
+
+	KEY_PRESSED(KC_F1, 0.3, toggleShowHelp());
+	KEY_PRESSED(KC_F2, 0.3, toggleShowStats());
+	KEY_PRESSED(KC_F3, 0.3, nextAppState());
+	
+	KEY_PRESSED(KC_F10, 0.3, toggleRecord());
+	KEY_PRESSED(KC_F11, 0.3, takeScreenShot());
+	KEY_PRESSED(KC_F12, 0.3, mTerrainContentGenerator->WriteObjects(objects_out_filename));
+	//KEY_PRESSED(KC_F3, 0.3, writeFrames());
+	//KEY_PRESSED(KC_F4, 0.3, loadFrames());
+
+	if (mDisplayCameraDetails)
     {
         // Print camera details
@@ -877,4 +801,57 @@
 }
 //-----------------------------------------------------------------------
+void TerrainMouseQueryListener::nextFilter()
+{
+	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);
+
+    showStats(mStatsOn);
+}
+//-----------------------------------------------------------------------
+void TerrainMouseQueryListener::nextSceneDetailLevel()
+{
+	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 ;
+	}
+}
+//-----------------------------------------------------------------------
+void TerrainMouseQueryListener::takeScreenShot()
+{
+	char tmp[20];
+	sprintf(tmp, "screenshot_%d.png", ++mNumScreenShots);
+    mWindow->writeContentsToFile(tmp);
+    mWindow->setDebugText(String("Wrote ") + tmp);
+}
+//-----------------------------------------------------------------------
+void TerrainMouseQueryListener::toggleDisplayCameraDetails()
+{
+	mDisplayCameraDetails = !mDisplayCameraDetails;
+        
+    if (!mDisplayCameraDetails)
+		mWindow->setDebugText("");
+}
+//-----------------------------------------------------------------------
 bool TerrainMouseQueryListener::processUnbufferedMouseInput(const FrameEvent& evt)
 {
@@ -897,21 +874,42 @@
 	return true;
 }
-
-void TerrainMouseQueryListener::showDebugOverlay(bool show)
-{
-	if (mDebugOverlay)
+//-----------------------------------------------------------------------
+void TerrainMouseQueryListener::showStats(bool show)
+{
+	if (mDebugOverlay && mCullStatsOverlay)
 	{
 		if (show)
 		{
 			mDebugOverlay->show();
+			mCullStatsOverlay->show();
 		}
 		else
 		{
 			mDebugOverlay->hide();
+			mCullStatsOverlay->hide();
 		}
 	}
 }
-
-
-	
-	
+//-----------------------------------------------------------------------
+void TerrainMouseQueryListener::toggleShowStats()
+{
+	mStatsOn = !mStatsOn;
+
+	showStats(mStatsOn);
+}
+//-----------------------------------------------------------------------
+void TerrainMouseQueryListener::toggleShowHelp()
+{
+	mShowHelp = !mShowHelp;
+
+	if (mShowHelp)
+	{
+		mHelpOverlay->show();
+	}
+	else
+	{
+		mHelpOverlay->hide();
+	}
+}
+
+	
