Index: trunk/VUT/work/TestCullingTerrain/TestCullingTerrain.vcproj
===================================================================
--- trunk/VUT/work/TestCullingTerrain/TestCullingTerrain.vcproj	(revision 130)
+++ trunk/VUT/work/TestCullingTerrain/TestCullingTerrain.vcproj	(revision 133)
@@ -123,5 +123,5 @@
 			UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}">
 			<File
-				RelativePath=".\TerrainMouseQueryListener.cpp">
+				RelativePath=".\TerrainFrameListener.cpp">
 			</File>
 			<File
@@ -134,5 +134,5 @@
 			UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}">
 			<File
-				RelativePath=".\TerrainMouseQueryListener.h">
+				RelativePath=".\TerrainFrameListener.h">
 			</File>
 			<File
Index: trunk/VUT/work/TestCullingTerrain/TerrainFrameListener.cpp
===================================================================
--- trunk/VUT/work/TestCullingTerrain/TerrainFrameListener.cpp	(revision 133)
+++ trunk/VUT/work/TestCullingTerrain/TerrainFrameListener.cpp	(revision 133)
@@ -0,0 +1,1008 @@
+#include <OgreNoMemoryMacros.h>
+#include <CEGUI/CEGUI.h>
+#include <../CEGUIRenderer/include/OgreCEGUIRenderer.h>
+#include <../CEGUIRenderer/include/OgreCEGUIResourceProvider.h>
+#include <../CEGUIRenderer/include/OgreCEGUITexture.h>
+#include <OgreMemoryMacros.h>
+#include "TerrainFrameListener.h"
+#include "OgrePlatformQueryManager.h"
+#include "OgreVisibilityTerrainSceneManager.h"
+#include "VisibilityInfo.h"
+
+// output file for frame info
+const char* frames_out_filename = "frame.out";
+// output file for object positions / orientations
+const char* objects_out_filename = "objects.out";
+
+
+String mCurrentAlgorithmCaptions[GtpVisibility::VisibilityEnvironment::NUM_CULLING_MANAGERS] = 
+{
+    "View Frustum Culling", 
+	"Stop and Wait Culling", 
+	"Coherent Hierarchical Culling"
+};
+
+
+//-----------------------------------------------------------------------
+TerrainFrameListener::TerrainFrameListener(RenderWindow* win, Camera* cam, 
+									   SceneManager *sceneManager, 
+									   CEGUI::Renderer *renderer,
+									   TerrainContentGenerator *sceneGenerator,
+									   Camera *vizCamera,
+									   SceneNode *camNode,
+									   Light *sunLight): 
+mCamera(cam),
+mWindow(win),
+mNumScreenShots(0),
+mTimeDelay(0),
+mSceneDetailIndex(0),
+mMoveScale(0.0f),
+mRotScale(0.0f),
+mTranslateVector(Vector3::ZERO),
+mAniso(1),
+mFiltering(TFO_BILINEAR), 
+mGUIRenderer(renderer), 
+mSceneMgr(sceneManager),
+mCurrentObject(NULL),
+mTerrainContentGenerator(sceneGenerator),
+mVisibilityThreshold(0),
+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),
+mShowVisualization(false),
+mCullCamera(false),
+mRecord(false),
+mUseShadows(false),
+mShowHelp(false),
+mDisplayCameraDetails(false),
+mVisualizeCulledNodes(false),
+mSunLight(sunLight),
+mShiftPressed(false)
+{
+	//mInputDevice = PlatformManager::getSingleton().createInputReader();
+	
+	//mInputDevice->initialise(win, true, true);
+	mEventProcessor = new EventProcessor();
+	
+	mEventProcessor->initialise(win);
+	mEventProcessor->startProcessingEvents();
+	mEventProcessor->addMouseListener(this);
+	mEventProcessor->addMouseMotionListener(this);
+	mEventProcessor->addKeyListener(this);
+
+	mInputDevice = mEventProcessor->getInputReader();
+	
+
+	// create ray query executor, used to place objects in terrain
+	mRayQueryExecutor = new RayQueryExecutor(mSceneMgr);
+	
+	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");
+	
+	mFrustumCulledNodesInfo = OverlayManager::getSingleton().getOverlayElement("Example/Visibility/FrustumCulledNodesInfo");
+	mQueryCulledNodesInfo = OverlayManager::getSingleton().getOverlayElement("Example/Visibility/QueryCulledNodesInfo");
+    mTraversedNodesInfo = OverlayManager::getSingleton().getOverlayElement("Example/Visibility/TraversedNodesInfo");
+	mHierarchyNodesInfo = OverlayManager::getSingleton().getOverlayElement("Example/Visibility/HierarchyNodesInfo");
+	mRenderedNodesInfo = OverlayManager::getSingleton().getOverlayElement("Example/Visibility/RenderedNodesInfo");
+	mObjectsInfo = OverlayManager::getSingleton().getOverlayElement("Example/Visibility/ObjectsInfo");
+	mUseOptimizationInfo = OverlayManager::getSingleton().getOverlayElement("Example/Visibility/UseOptimizationInfo");
+	mUseDepthPassInfo = OverlayManager::getSingleton().getOverlayElement("Example/Visibility/UseDepthPassInfo");
+	mQueriesIssuedInfo = OverlayManager::getSingleton().getOverlayElement("Example/Visibility/QueriesIssuedInfo");
+	
+	mAlgorithmInfo->setCaption(": " + mCurrentAlgorithmCaptions[mCurrentAlgorithm]);
+	mThresholdInfo->setCaption(": 0");
+	mFrustumCulledNodesInfo->setCaption(": 0");
+	mQueryCulledNodesInfo->setCaption(": 0");
+	mTraversedNodesInfo->setCaption(": 0");
+	mHierarchyNodesInfo->setCaption(": 0");
+	mRenderedNodesInfo->setCaption(": 0");
+	mObjectsInfo->setCaption(": 0");
+	mUseOptimizationInfo->setCaption(": true");
+	mUseDepthPassInfo->setCaption(": false");
+	mQueriesIssuedInfo->setCaption(": 0");
+
+	// show stats overlays
+	showStats(true);
+	//mHelpOverlay->show();
+
+	// set culling algorithm type
+	setAlgorithm(mCurrentAlgorithm);
+
+	// set scene manager options
+	mSceneMgr->setOption("UseOptimization", &mUseOptimization);
+
+	// 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);
+	mSceneMgr->setOption("ShowVisualization", &mShowVisualization);
+
+	// TODO: change this
+	mVisibilityManager = dynamic_cast<VisibilityTerrainSceneManager *>(mSceneMgr)->
+		GetVisibilityManager();
+
+	dynamic_cast<PlatformQueryManager *>(mVisibilityManager->GetQueryManager())->
+		SetViewport(mWindow->getViewport(0));
+} 
+//-----------------------------------------------------------------------
+TerrainFrameListener::~TerrainFrameListener()
+{
+	//PlatformManager::getSingleton().destroyInputReader(mInputDevice);
+    
+	delete mRayQueryExecutor;
+	delete mEventProcessor;
+}
+//-----------------------------------------------------------------------
+void TerrainFrameListener::mouseMoved(MouseEvent *e)
+{
+	// Update CEGUI with the mouse motion
+    CEGUI::System::getSingleton().injectMouseMove(e->getRelX() * 
+		mGUIRenderer->getWidth(), e->getRelY() * mGUIRenderer->getHeight());
+}
+//-----------------------------------------------------------------------
+void TerrainFrameListener::mousePressed(MouseEvent* e)
+{
+     // Left mouse button down
+     if (e->getButtonID() & InputEvent::BUTTON0_MASK)
+     {
+		 CEGUI::MouseCursor::getSingleton().hide();
+
+		 // Setup the ray scene query
+         Ray mouseRay = mCamera->getCameraToViewportRay(e->getX(), e->getY());
+		 
+		 //Vector3 queryResult; mRayQueryExecutor->executeRayQuery(&queryResult, mouseRay);
+		 
+		 // Get results, create a node/entity on the position
+		 mCurrentObject = mTerrainContentGenerator->GenerateSceneObject(
+			 mouseRay.getOrigin(), Vector3::ZERO, "robot", false);
+		
+         mLMouseDown = true; 
+     }
+     // Right mouse button down
+     else if (e->getButtonID() & InputEvent::BUTTON1_MASK)
+     {
+         CEGUI::MouseCursor::getSingleton().hide();
+         mRMouseDown = true;
+     }
+} 
+//-----------------------------------------------------------------------
+void TerrainFrameListener::mouseReleased(MouseEvent* e)
+{
+    // Left mouse button up
+    if (e->getButtonID() & InputEvent::BUTTON0_MASK)
+    {
+		CEGUI::MouseCursor::getSingleton().show();
+        mLMouseDown = false;
+    }
+    // Right mouse button up
+    else if (e->getButtonID() & InputEvent::BUTTON1_MASK)
+    {
+        CEGUI::MouseCursor::getSingleton().show();
+        mRMouseDown = false;
+    }
+} 
+//-----------------------------------------------------------------------
+void TerrainFrameListener::mouseDragged(MouseEvent *e)
+ {
+	 // If we are dragging the left mouse button.	 	 
+	 if (mLMouseDown)
+     {
+		 Vector3 queryResult;
+		 Ray mouseRay = mCamera->getCameraToViewportRay(e->getX(), e->getY());
+
+		 if (mRayQueryExecutor->executeRayQuery(&queryResult, mouseRay))
+		 {
+			 if (mCurrentObject)
+			 {
+				 mCurrentObject->setPosition(queryResult);
+			 }
+		 }
+     }
+	 // If we are dragging the right mouse button.
+	 if (mRMouseDown)
+	 {
+		 //mCamera->yaw(-e->getRelX() * mRotateSpeed);
+		 //mCamera->pitch(-e->getRelY() * mRotateSpeed);
+		 mCamNode->yaw(-e->getRelX() * mRotateSpeed);
+		 mCamNode->pitch(-e->getRelY() * mRotateSpeed);
+	 }
+}
+//-----------------------------------------------------------------------
+bool TerrainFrameListener::frameStarted(const FrameEvent &evt)
+{
+	if (mWindow->isClosed())
+	{
+        return false;
+	}
+
+//	mInputDevice->capture();
+
+	//-- IMPORTANT: must be set, otherwise terrain is not rendered correctly
+	int terrainLevelIdx = 0;
+	mSceneMgr->setOption("TerrainLevelIdx", &terrainLevelIdx);
+
+	//-- setup what is needed for immediate mouse/key movement
+	if (mTimeDelay >= 0) 
+	{
+		mTimeDelay -= 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 (!processUnbufferedKeyInput(evt))
+	{
+		return false;
+	}
+/*	if (!processUnbufferedMouseInput(evt))
+	{	return false;	}*/
+
+	// --- set parameters for visualization
+	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));
+		
+		// move by a constant so view plane is on bottom of viewport
+		mVizCamera->moveRelative(Vector3(0, 800, 0));
+	}
+
+	//-- set application state
+	switch (mAppState)
+	{
+	case REPLAY:
+		setCurrentFrameInfo(evt.timeSinceLastFrame);
+		break;
+	case WALKTHROUGH:
+		//-- if we are recording camera status per frame
+		if (mRecord)
+		{
+			addFrameInfo(mCamNode, evt.timeSinceLastFrame);
+			// print recording message
+			mWindow->setDebugText("Recording frame " + 
+				StringConverter::toString(mFrameInfo.size() - 1));
+		}	
+		// move camera according to input
+		moveCamera();
+		// clamp camera so we always walk along the terrain
+		Clamp2Terrain();
+		break;
+
+	default:
+		break;
+	};	
+
+	return true;
+}
+//-----------------------------------------------------------------------
+void TerrainFrameListener::ApplyVisibilityQuery(bool fromPoint, bool relativeVisibility)
+{
+	InfoContainer<GtpVisibility::NodeInfo> visibleNodes;
+	InfoContainer<GtpVisibility::MeshInfo> visibleGeometry;
+
+	if (fromPoint)
+	{
+	}
+	else
+	{
+		mVisibilityManager->GetQueryManager()->ComputeCameraVisibility(*mCamera,
+			    &visibleNodes, &visibleGeometry, relativeVisibility);
+	}
+
+	for (int i=0; i < visibleGeometry.size(); ++i)
+	{
+		std::stringstream d; d << "Geometry visibility: " << visibleGeometry[i].GetVisibiliy();
+		LogManager::getSingleton().logMessage(d.str());
+	}
+	for (int i=0; i < visibleNodes.size(); ++i)
+	{
+		std::stringstream d; d << "Node visibility: " << visibleNodes[i].GetVisibiliy();
+		LogManager::getSingleton().logMessage(d.str());
+	}
+
+}
+//-----------------------------------------------------------------------
+void TerrainFrameListener::Clamp2Terrain()
+{
+	// clamp to terrain
+	Vector3 camPos = mCamNode->getPosition();
+	Vector3 queryResult;
+
+	if (mRayQueryExecutor->executeRayQuery(&queryResult, 
+			Vector3(camPos.x, 5000.0f, camPos.z), Vector3::NEGATIVE_UNIT_Y))
+	{
+		mCamNode->setPosition(camPos.x, queryResult.y + 10, camPos.z);
+	}
+}
+//-----------------------------------------------------------------------
+bool TerrainFrameListener::frameEnded(const FrameEvent& evt)
+{
+	if (mShutdownRequested)
+		return false;
+
+    updateStats();
+
+	return true;
+}
+//-----------------------------------------------------------------------
+void TerrainFrameListener::moveCamera()
+{
+	// move node rather than camera so orientation is right in the visualization
+	mCamNode->yaw(mRotX);
+	mCamNode->pitch(mRotY);
+	mCamNode->translate(mCamNode->getLocalAxes(), mTranslateVector);
+}
+//-----------------------------------------------------------------------
+void TerrainFrameListener::writeFrames()
+{
+	std::ofstream ofstr(frames_out_filename);
+	
+	std::vector<frame_info>::const_iterator it, it_end;
+
+	it_end = mFrameInfo.end();
+	for(it = mFrameInfo.begin(); it < it_end; ++it)
+	{
+		ofstr << StringConverter::toString((*it).position) << " " 
+			  << StringConverter::toString((*it).orientation) << " "
+			  << StringConverter::toString((*it).timeElapsed) << "\n";
+	}
+	ofstr.close();
+}
+//-----------------------------------------------------------------------
+void TerrainFrameListener::loadFrames()
+{
+	std::ifstream ifstr(frames_out_filename);
+	char line[256];
+	frame_info info;
+
+	// reset current values
+	mFrameInfo.clear();
+	mCurrentFrame = 0;
+	
+	while (!ifstr.eof()) 
+	{
+		ifstr.getline(line, 256);
+		sscanf(line, "%f %f %f %f %f %f %f %f", &info.position.x, &info.position.y, &info.position.z,
+				&info.orientation.w, &info.orientation.x, &info.orientation.y, &info.orientation.z,
+				&info.timeElapsed);
+		
+		mFrameInfo.push_back(info);
+		
+		/*	std::stringstream d;
+		d << StringConverter::toString(info.position) << " " << StringConverter::toString(info.orientation);
+		LogManager::getSingleton().logMessage(d.str());		*/
+	}
+	ifstr.close();
+}
+//-----------------------------------------------------------------------
+void TerrainFrameListener::nextAppState()
+{
+	mCurrentFrame = 0;
+
+	// if last state was replay state
+	if (mAppState == REPLAY)
+	{
+		// reset debug text and write frame info to file
+		mWindow->setDebugText("");
+		writeFrames();
+		
+		//-- write out stats for recorded walkthrough
+		std::stringstream d;
+		d << "Algorithm: " << mCurrentAlgorithmCaptions[mCurrentAlgorithm] << "\n"
+		  << "avg. FPS: " << mWindow->getAverageFPS() << "\n"
+		  << "best FPS: " << mWindow->getBestFPS() << "\n"
+		  << "worst FPS: " << mWindow->getWorstFPS() << "\n"
+		  << "best frame time: " <<	mWindow->getBestFrameTime() << "\n"
+		  << "worst frame time: " << mWindow->getWorstFrameTime();
+ 		
+		LogManager::getSingleton().logMessage(d.str());
+	}
+	
+	//-- set the next státe
+	mAppState = (mAppState + 1) % STATE_NUM;
+
+	// replay recorded walkthrough
+	if (mAppState == REPLAY)
+	{
+		// no recording during replay
+		mRecord = false;
+
+		// load recorded walkthrough
+		if (mFrameInfo.size() == 0)
+		{
+			loadFrames();
+		}
+
+		// if there are no recorded frames => set next state
+		if (mFrameInfo.size() == 0) 
+		{
+			nextAppState();
+		}
+		else
+		{
+			mWindow->setDebugText("Replay");
+			
+			// reset, because we measure fps stats during walkthrough
+			mWindow->resetStatistics();
+
+			//-- initialise frame data
+			mTimeElapsed = 0;
+
+			mCamNode->setPosition(mFrameInfo[0].position);
+			mCamNode->setOrientation(mFrameInfo[0].orientation);
+		}
+	}
+
+}
+//-----------------------------------------------------------------------
+void TerrainFrameListener::toggleRecord()
+{
+	mRecord = !mRecord;
+
+	// clear previous camera path
+	if (mRecord)
+		mFrameInfo.clear();
+	else
+		mWindow->setDebugText("");
+}
+//-----------------------------------------------------------------------
+void TerrainFrameListener::changeThreshold(int incr)
+{
+	mVisibilityThreshold += incr; 
+	if(mVisibilityThreshold < 0) mVisibilityThreshold = 0;
+	
+	char str[100]; sprintf(str,": %d", mVisibilityThreshold);
+
+	mSceneMgr->setOption("Threshold", &mVisibilityThreshold); 
+	mThresholdInfo->setCaption(str);
+}
+//-----------------------------------------------------------------------
+void TerrainFrameListener::zoomVizCamera(int zoom)
+{
+	mVizCameraHeight += zoom; 
+	if(mVizCameraHeight < 0) mVizCameraHeight = 0;
+}
+//-----------------------------------------------------------------------
+void TerrainFrameListener::nextAlgorithm()
+{
+	mCurrentAlgorithm = (mCurrentAlgorithm + 1) % 
+		GtpVisibility::VisibilityEnvironment::NUM_CULLING_MANAGERS,
+
+	setAlgorithm(mCurrentAlgorithm);
+}
+//-----------------------------------------------------------------------
+void TerrainFrameListener::setAlgorithm(int algorithm)
+{
+	mAlgorithmInfo->setCaption(": " + mCurrentAlgorithmCaptions[mCurrentAlgorithm]);
+	mSceneMgr->setOption("Algorithm", &mCurrentAlgorithm);
+}
+//-----------------------------------------------------------------------
+void TerrainFrameListener::updateStats()
+{
+	unsigned int opt = 0;
+	char str[100];
+	
+	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());
+
+		//-- culling stats
+		mSceneMgr->getOption("NumFrustumCulledNodes", &opt); sprintf(str,": %d", opt); 
+		mFrustumCulledNodesInfo->setCaption(str);
+	
+		mSceneMgr->getOption("NumQueriesIssued", &opt); sprintf(str,": %d", opt); 
+		mQueriesIssuedInfo->setCaption(str);
+
+		mSceneMgr->getOption("NumQueryCulledNodes", &opt); sprintf(str,": %d", opt); 
+		mQueryCulledNodesInfo->setCaption(str);
+	
+		mSceneMgr->getOption("NumTraversedNodes", &opt); sprintf(str,": %d", opt); 
+		mTraversedNodesInfo->setCaption(str);
+
+		mSceneMgr->getOption("NumHierarchyNodes", &opt); sprintf(str,": %d", opt); 
+		mHierarchyNodesInfo->setCaption(str);
+
+		mSceneMgr->getOption("NumRenderedNodes", &opt); sprintf(str,": %d", opt); 
+		mRenderedNodesInfo->setCaption(str);
+
+		sprintf(str,": %d", mTerrainContentGenerator->GetObjectCount()); 
+		mObjectsInfo->setCaption(str);
+	}
+	catch(...)
+	{
+            // ignore
+	}
+}
+//-----------------------------------------------------------------------
+void TerrainFrameListener::toggleUseOptimization()
+{
+	mUseOptimization = !mUseOptimization;
+	mSceneMgr->setOption("UseOptimization", &mUseOptimization);
+	
+	// disable optimization which tests geometry instead of aabb
+	// for delayed rendering (i.e., render transparents after all the solids)
+	// because otherwise visible transparents could be skipped
+	bool delayedRendering = !mUseOptimization;
+	mSceneMgr->setOption("DelayRenderTransparents", &delayedRendering);
+
+	if (mUseOptimization)
+	{
+		mUseOptimizationInfo->setCaption(": true");
+	}
+	else
+	{
+		mUseOptimizationInfo->setCaption(": false");
+	}
+}
+//-----------------------------------------------------------------------
+void TerrainFrameListener::toggleShowOctree()
+{
+	mShowOctree = !mShowOctree;
+
+	mSceneMgr->setOption("ShowOctree", &mShowOctree);
+}
+//-----------------------------------------------------------------------
+void TerrainFrameListener::toggleUseDepthPass()
+{
+	mUseDepthPass = !mUseDepthPass;
+
+	mSceneMgr->setOption("UseDepthPass", &mUseDepthPass);
+	
+	if (mUseDepthPass)
+	{
+		mUseDepthPassInfo->setCaption(": true");
+	}
+	else
+	{
+		mUseDepthPassInfo->setCaption(": false");
+	}
+}
+//-----------------------------------------------------------------------
+void TerrainFrameListener::toggleShowViz()
+{
+	mShowVisualization = !mShowVisualization;
+	mVisualizeCulledNodes = !mVisualizeCulledNodes;
+
+	// create viewport with priority VIZ_VIEWPORT_Z_ORDER: 
+	// will be rendered over standard viewport
+	if (mShowVisualization)
+	{	
+		Viewport *vizvp = mWindow->addViewport(mVizCamera, 
+			VIZ_VIEWPORT_Z_ORDER, 0.6, 0.6, 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()));
+		
+		mSceneMgr->setOption("VisualizeCulledNodes", &mVisualizeCulledNodes);
+		//vizvp->setClearEveryFrame(false);
+
+		// Create a skyplane (for visualization background)
+		/*
+		Plane plane;
+		plane.d = -1000;
+		plane.normal = Vector3::UNIT_Y;
+		mSceneMgr->setSkyPlane(true, plane, "Examples/TransparentTest", 4000, 75, false);
+		*/
+		
+	}
+	else
+	{
+		mWindow->removeViewport(VIZ_VIEWPORT_Z_ORDER);
+		// if octree was enabled for visualization purpose, reset now
+		mSceneMgr->setOption("ShowOctree", &mShowOctree);
+	}
+}
+//-----------------------------------------------------------------------
+void TerrainFrameListener::toggleUseShadows()
+{
+	mUseShadows = !mUseShadows;
+
+	mSunLight->setCastShadows(mUseShadows);
+
+	if (mUseShadows)
+	{
+		mSceneMgr->setShadowTechnique(SHADOWTYPE_TEXTURE_MODULATIVE);
+	}
+	else
+	{
+		mSceneMgr->setShadowTechnique(SHADOWTYPE_NONE);
+	}
+
+}
+//-----------------------------------------------------------------------
+void TerrainFrameListener::nextNodeVizMode()
+{
+	mNodeVizMode = (mNodeVizMode + 1) % NODEVIZ_MODES_NUM;
+
+	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;
+
+	mSceneMgr->setOption("RenderNodesForViz", &renderNodesForViz);
+	mSceneMgr->setOption("RenderNodesContentForViz", &renderNodesContentForViz);
+}
+//-----------------------------------------------------------------------
+void TerrainFrameListener::keyPressed(KeyEvent* e)
+{
+	switch(e->getKey())
+	{
+	case KC_ESCAPE:
+		mShutdownRequested = true;
+		e->consume();
+		return;
+
+	case KC_SPACE:
+		nextAlgorithm();
+		break;
+	
+	case KC_F:
+		nextFilter();
+		break;
+	case KC_R:
+		nextSceneDetailLevel();
+		break;
+	case KC_P:
+		toggleDisplayCameraDetails();
+		break;
+	case KC_O:
+		toggleUseOptimization();
+		break;
+	case KC_T:
+		toggleShowOctree();
+		break;
+	case KC_X:
+		toggleUseDepthPass();
+		break;
+	case KC_S:
+		toggleUseShadows();
+		break;
+
+	case KC_SUBTRACT:
+		changeThreshold(-10);
+		break;
+	case KC_ADD:
+		changeThreshold(10);
+		break;
+
+	//-- visualization
+	case KC_1:
+		toggleShowViz();
+		break;
+	case KC_2:
+		nextNodeVizMode();
+		break;
+
+	case KC_F1:
+		toggleShowHelp();
+		break;
+	case KC_F2:
+		toggleShowStats();
+		break;
+	case KC_F3:
+		nextAppState();
+		break;
+	case KC_F4:
+		toggleRecord();
+		break;
+	case KC_F5:
+		ApplyVisibilityQuery(false, mShiftPressed);
+		break;
+	case KC_F6:
+		ApplyVisibilityQuery(true, mShiftPressed);
+		break;
+
+	case KC_F11:
+		takeScreenShot();
+		break;
+	case KC_F12:
+		mTerrainContentGenerator->WriteObjects(objects_out_filename);
+		break;
+
+	case KC_LSHIFT:
+		mShiftPressed = !mShiftPressed;
+		break;
+	//KEY_PRESSED(KC_F3, 0.3, writeFrames());
+	//KEY_PRESSED(KC_F4, 0.3, loadFrames());
+	default:
+		break;
+	}
+
+	if (mDisplayCameraDetails)
+    {
+        // Print camera details
+        mWindow->setDebugText("P: " + StringConverter::toString(mCamera->getDerivedPosition()) + " " + 
+            "O: " + StringConverter::toString(mCamera->getDerivedOrientation()));
+    }
+
+	CEGUI::System::getSingleton().injectKeyDown(e->getKey());
+	CEGUI::System::getSingleton().injectChar(e->getKeyChar());
+	e->consume();
+}
+//-----------------------------------------------------------------------
+void TerrainFrameListener::keyReleased(KeyEvent* e)
+{
+	CEGUI::System::getSingleton().injectKeyUp(e->getKey());
+	e->consume();
+}
+//-----------------------------------------------------------------------
+void TerrainFrameListener::keyClicked(KeyEvent* e) 
+{
+	// Do nothing
+	e->consume();
+}
+//-----------------------------------------------------------------------
+void TerrainFrameListener::addFrameInfo(SceneNode *camNode, Real timeElapsed)
+{
+	frame_info info;
+	info.orientation = mCamNode->getOrientation();
+	info.position = mCamNode->getPosition();
+	info.timeElapsed = timeElapsed;
+
+	mFrameInfo.push_back(info);
+}
+//-----------------------------------------------------------------------
+void TerrainFrameListener::setCurrentFrameInfo(Real timeElapsed)
+{
+	//-- find current frame relative to elapsed frame time		
+	mTimeElapsed -= timeElapsed;
+
+	while ((mTimeElapsed <= 0) && (mCurrentFrame < (int)mFrameInfo.size() - 1))
+	{
+		mTimeElapsed += mFrameInfo[mCurrentFrame ++].timeElapsed;
+	}
+
+	frame_info new_frame = mFrameInfo[mCurrentFrame];
+	frame_info old_frame = mFrameInfo[mCurrentFrame - 1];
+		
+	//-- interpolate frames
+	Real factor = 1;
+
+	if (old_frame.timeElapsed > 0)
+	{
+		factor = mTimeElapsed / old_frame.timeElapsed;
+	}
+
+	Vector3 camPos = old_frame.position + factor 
+		* (new_frame.position - old_frame.position);
+	Quaternion camOrienation = Quaternion::Slerp(factor, old_frame.orientation, 
+		new_frame.orientation, true);
+
+	mCamNode->setPosition(camPos);
+	mCamNode->setOrientation(camOrienation);
+	
+	// stop replay after a full walkthrough
+	if (mCurrentFrame == (int)mFrameInfo.size() - 1)
+	{
+		nextAppState();
+	}
+}
+//-----------------------------------------------------------------------    
+bool TerrainFrameListener::processUnbufferedKeyInput(const FrameEvent& evt)
+{
+	/*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))
+    {
+		mTranslateVector.z = mMoveScale;
+    }
+
+    if (mInputDevice->isKeyDown(KC_RIGHT))
+    {
+        mCamNode->yaw(-mRotScale);
+    }
+	
+    if (mInputDevice->isKeyDown(KC_LEFT))
+    {
+        mCamNode->yaw(mRotScale);
+    }
+	// visualization camera
+	if (mInputDevice->isKeyDown(KC_3))
+	{
+		zoomVizCamera(50);
+	}
+	if (mInputDevice->isKeyDown(KC_4))
+	{
+		zoomVizCamera(-50);
+	}
+
+
+    // Return true to continue rendering
+    return true;
+}
+//-----------------------------------------------------------------------
+void TerrainFrameListener::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);
+
+	// reload stats
+    showStats(mStatsOn);
+}
+//-----------------------------------------------------------------------
+void TerrainFrameListener::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 TerrainFrameListener::takeScreenShot()
+{
+	char tmp[20];
+	sprintf(tmp, "screenshot_%d.png", ++mNumScreenShots);
+    mWindow->writeContentsToFile(tmp);
+    mWindow->setDebugText(String("Wrote ") + tmp);
+}
+//-----------------------------------------------------------------------
+void TerrainFrameListener::toggleDisplayCameraDetails()
+{
+	mDisplayCameraDetails = !mDisplayCameraDetails;
+        
+    if (!mDisplayCameraDetails)
+	{
+		mWindow->setDebugText("");
+	}
+}
+//-----------------------------------------------------------------------
+void TerrainFrameListener::showStats(bool show)
+{
+	if (mDebugOverlay && mCullStatsOverlay)
+	{
+		if (show)
+		{
+			mDebugOverlay->show();
+			mCullStatsOverlay->show();
+		}
+		else
+		{
+			mDebugOverlay->hide();
+			mCullStatsOverlay->hide();
+		}
+	}
+}
+//-----------------------------------------------------------------------
+void TerrainFrameListener::toggleShowStats()
+{
+	mStatsOn = !mStatsOn;
+
+	showStats(mStatsOn);
+}
+//-----------------------------------------------------------------------
+void TerrainFrameListener::toggleShowHelp()
+{
+	mShowHelp = !mShowHelp;
+
+	if (mShowHelp)
+	{
+		mHelpOverlay->show();
+	}
+	else
+	{
+		mHelpOverlay->hide();
+	}
+}
Index: trunk/VUT/work/TestCullingTerrain/TestCullingTerrainApplication.cpp
===================================================================
--- trunk/VUT/work/TestCullingTerrain/TestCullingTerrainApplication.cpp	(revision 122)
+++ trunk/VUT/work/TestCullingTerrain/TestCullingTerrainApplication.cpp	(revision 133)
@@ -187,6 +187,6 @@
      CEGUI::SchemeManager::getSingleton().loadScheme((CEGUI::utf8*)"TaharezLook.scheme");
      CEGUI::MouseCursor::getSingleton().setImage("TaharezLook", "MouseArrow");
-	 mGUISystem->setDefaultMouseCursor(
-                (CEGUI::utf8*)"TaharezLook", (CEGUI::utf8*)"MouseArrow");
+	 mGUISystem->setDefaultMouseCursor((CEGUI::utf8*)"TaharezLook", 
+									   (CEGUI::utf8*)"MouseArrow");
 
 	 CEGUI::MouseCursor::getSingleton().show();
@@ -195,5 +195,5 @@
 void TestCullingTerrainApplication::createFrameListener()
 {
-	mTerrainFrameListener = new TerrainMouseQueryListener(mWindow, mCamera, mSceneMgr, 
+	mTerrainFrameListener = new TerrainFrameListener(mWindow, mCamera, mSceneMgr, 
 		mGUIRenderer, mTerrainContentGenerator, mVizCamera, mCamNode, mSunLight);
 	
@@ -218,5 +218,6 @@
 void VisualizationRenderTargetListener::preViewportUpdate(const RenderTargetViewportEvent &evt)
 {
-	const bool showViz = evt.source->getZOrder() == VIZ_VIEWPORT_Z_ORDER; // visualization viewport
+	// visualization viewport
+	const bool showViz = evt.source->getZOrder() == VIZ_VIEWPORT_Z_ORDER;
 	const bool nShowViz = !showViz;
 
Index: trunk/VUT/work/TestCullingTerrain/TerrainFrameListener.h
===================================================================
--- trunk/VUT/work/TestCullingTerrain/TerrainFrameListener.h	(revision 133)
+++ trunk/VUT/work/TestCullingTerrain/TerrainFrameListener.h	(revision 133)
@@ -0,0 +1,220 @@
+#ifndef _TerrainFrameListener_H__
+#define _TerrainFrameListener_H__
+
+#include "CEGUIForwardRefs.h"
+#include <Ogre.h>
+#include <OgreKeyEvent.h>
+#include <OgreEventListeners.h>
+#include <OgreStringConverter.h>
+#include <OgreException.h>
+#include "VisibilityEnvironment.h"
+#include "VisibilityManager.h"
+#include "OgreTerrainContentGenerator.h"
+
+using namespace Ogre;
+
+// z order index of visualizaion viewport
+#define VIZ_VIEWPORT_Z_ORDER 10
+
+
+/** Mouse query listener for terrain 
+*/
+class TerrainFrameListener: public FrameListener, public MouseListener, public MouseMotionListener, public KeyListener
+{
+public:
+	
+   TerrainFrameListener(RenderWindow* win, Camera* cam, SceneManager *sceneManager, 
+		CEGUI::Renderer *renderer, TerrainContentGenerator *contentGenerator, Camera *vizCamera,
+		SceneNode *camNode, Light *sunLight);
+
+   ~TerrainFrameListener();
+
+
+   bool frameStarted(const FrameEvent& evt);
+   bool frameEnded(const FrameEvent& evt);
+   //bool processUnbufferedKeyInput(const FrameEvent& evt);
+    
+
+   /* MouseListener callbacks. */
+   virtual void mouseClicked(MouseEvent* e) { }
+   virtual void mouseEntered(MouseEvent* e) { }
+   virtual void mouseExited(MouseEvent* e)  { }
+
+   // This is when the mouse button goes DOWN.
+   virtual void mousePressed(MouseEvent* e);
+
+   // This is when the mouse button is let UP.
+   virtual void mouseReleased(MouseEvent* e);
+
+   /* MouseMotionListener callbacks */
+   virtual void mouseMoved (MouseEvent *e);
+   
+   // This is when the mouse is clicked, held and dragged.
+   virtual void mouseDragged (MouseEvent *e);
+
+   void keyPressed(KeyEvent* e);
+
+   void keyReleased(KeyEvent* e);
+   void keyClicked(KeyEvent* e);
+  
+   /** The information about camera position and orienation per frame */
+   typedef struct
+   {
+	   Vector3 position;
+	   Quaternion orientation;
+	   Real timeElapsed;
+   } frame_info;
+
+   enum  {WALKTHROUGH, REPLAY, STATE_NUM};
+
+   // visualization modes for scene nodes
+   enum {NODEVIZ_NONE, NODEVIZ_RENDER_NODES, NODEVIZ_RENDER_NODES_AND_CONTENT, NODEVIZ_MODES_NUM};
+   //enum {NODEVIZ_NONE, NODEVIZ_RENDER_GEOMETRY, NODEVIZ_MODES_NUM};
+
+  void zoomVizCamera(int zoom);
+	
+   void addFrameInfo(SceneNode *camNode, Real timeElapsed);
+   void setCurrentFrameInfo(Real timeElapsed);
+
+   void setAlgorithm(int algorithm);
+
+   void moveCamera();
+
+   void writeFrames();
+   void loadFrames();
+
+  
+    // Constructor takes a RenderWindow because it uses that to determine input context
+    //ExampleFrameListener(RenderWindow* win, Camera* cam, bool useBufferedInputKeys = false, bool useBufferedInputMouse = false)
+    
+    bool processUnbufferedKeyInput(const FrameEvent& evt);
+    bool processUnbufferedMouseInput(const FrameEvent& evt);
+
+    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();
+
+	/** Applies visibility query. Collects the visible objects 
+		and their visibility information.
+		@param fromnPoint if query should be from point or from camera
+		@param relativeVisibility if query should return number of visible pixels or the ratio
+		visible pixels / projected pixels.
+	*/
+	void ApplyVisibilityQuery(bool fromPoint, bool relativeVisibility);
+
+protected:
+
+	/** Clamp camera to terrain.
+	*/
+	void Clamp2Terrain();
+	
+	SceneManager *mSceneMgr;           // A pointer to the scene manager
+    
+	CEGUI::Renderer *mGUIRenderer;     // cegui renderer
+	
+	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;
+	OverlayElement *mFrustumCulledNodesInfo;
+	OverlayElement *mQueryCulledNodesInfo;
+    OverlayElement *mTraversedNodesInfo;
+	OverlayElement *mHierarchyNodesInfo;
+	OverlayElement *mUseOptimizationInfo;
+	OverlayElement *mUseDepthPassInfo;
+	OverlayElement *mRenderedNodesInfo;
+	OverlayElement *mObjectsInfo;
+	OverlayElement *mQueriesIssuedInfo;
+
+	RayQueryExecutor *mRayQueryExecutor;
+	TerrainContentGenerator *mTerrainContentGenerator;
+
+	bool mUseOptimization;
+	bool mShowOctree;
+	bool mUseDepthPass;
+	bool mShowVisualization;
+	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;
+
+	Camera *mVizCamera;
+	SceneNode *mCamNode;
+	
+	//std::deque<Vector3> mWalkList;   // The list of points we are walking to
+	std::vector<frame_info> mFrameInfo;
+		
+	Real mTimeElapsed;
+	//EventProcessor* mEventProcessor;
+    InputReader* mInputDevice;
+    Camera* mCamera;
+
+    Vector3 mTranslateVector;
+    RenderWindow* mWindow;
+   
+    //bool mUseBufferedInputKeys, mUseBufferedInputMouse, mInputTypeSwitchingOn;
+	unsigned int mNumScreenShots;
+    int mSceneDetailIndex;
+	int mAniso;
+
+	float mMoveScale;
+    Degree mRotScale;
+    // just to stop toggles flipping too fast
+    Real mTimeDelay;
+    Radian mRotX, mRotY;
+    TextureFilterOptions mFiltering;
+  
+	Real mMoveSpeed;
+    Degree mRotateSpeed;
+    
+	Overlay* mDebugOverlay;
+	Overlay* mHelpOverlay;
+	Overlay* mCullStatsOverlay;
+
+	Light *mSunLight;
+	GtpVisibility::VisibilityManager *mVisibilityManager;
+	EventProcessor* mEventProcessor;
+	
+	bool mShiftPressed;
+	//bool mUseBufferedInputKeys, mUseBufferedInputMouse, mInputTypeSwitchingOn;
+};
+
+
+#endif //_TerrainFrameListener_H__
Index: trunk/VUT/work/TestCullingTerrain/TestCullingTerrainApplication.h
===================================================================
--- trunk/VUT/work/TestCullingTerrain/TestCullingTerrainApplication.h	(revision 130)
+++ trunk/VUT/work/TestCullingTerrain/TestCullingTerrainApplication.h	(revision 133)
@@ -7,5 +7,5 @@
 
 #include <OgreRenderTargetListener.h>
-#include "TerrainMouseQueryListener.h"
+#include "TerrainFrameListener.h"
 
 class VisualizationRenderTargetListener: public RenderTargetListener
@@ -56,5 +56,5 @@
 	VisualizationRenderTargetListener *mRenderTargetListener;
 
-	TerrainMouseQueryListener *mTerrainFrameListener;
+	TerrainFrameListener *mTerrainFrameListener;
 	
 private:
Index: trunk/VUT/work/TestCullingTerrain/TerrainMouseQueryListener.h
===================================================================
--- trunk/VUT/work/TestCullingTerrain/TerrainMouseQueryListener.h	(revision 130)
+++ 	(revision )
@@ -1,219 +1,0 @@
-#ifndef _TerrainMouseQueryListener_H__
-#define _TerrainMouseQueryListener_H__
-
-#include "CEGUIForwardRefs.h"
-#include <Ogre.h>
-#include <OgreKeyEvent.h>
-#include <OgreEventListeners.h>
-#include <OgreStringConverter.h>
-#include <OgreException.h>
-#include "VisibilityEnvironment.h"
-#include "VisibilityManager.h"
-#include "OgreTerrainContentGenerator.h"
-
-using namespace Ogre;
-
-// z order index of visualizaion viewport
-#define VIZ_VIEWPORT_Z_ORDER 10
-
-
-/** Mouse query listener for terrain 
-*/
-class TerrainMouseQueryListener: public FrameListener, public MouseListener, public MouseMotionListener
-{
-public:
-	
-   TerrainMouseQueryListener(RenderWindow* win, Camera* cam, SceneManager *sceneManager, 
-		CEGUI::Renderer *renderer, TerrainContentGenerator *contentGenerator, Camera *vizCamera,
-		SceneNode *camNode, Light *sunLight);
-
-   ~TerrainMouseQueryListener();
-
-
-   bool frameStarted(const FrameEvent& evt);
-   bool frameEnded(const FrameEvent& evt);
-   //bool processUnbufferedKeyInput(const FrameEvent& evt);
-    
-
-   /* MouseListener callbacks. */
-   virtual void mouseClicked(MouseEvent* e) { }
-   virtual void mouseEntered(MouseEvent* e) { }
-   virtual void mouseExited(MouseEvent* e)  { }
-
-   // This is when the mouse button goes DOWN.
-   virtual void mousePressed(MouseEvent* e);
-
-   // This is when the mouse button is let UP.
-   virtual void mouseReleased(MouseEvent* e);
-
-   /* MouseMotionListener callbacks */
-   virtual void mouseMoved (MouseEvent *e);
-   
-   // This is when the mouse is clicked, held and dragged.
-   virtual void mouseDragged (MouseEvent *e);
-
-   void keyPressed(KeyEvent* e);
-
-   void keyReleased(KeyEvent* e);
-   void keyClicked(KeyEvent* e);
-  
-   /** The information about camera position and orienation per frame */
-   typedef struct
-   {
-	   Vector3 position;
-	   Quaternion orientation;
-	   Real timeElapsed;
-   } frame_info;
-
-   enum  {WALKTHROUGH, REPLAY, STATE_NUM};
-
-   // visualization modes for scene nodes
-   enum {NODEVIZ_NONE, NODEVIZ_RENDER_NODES, NODEVIZ_RENDER_NODES_AND_CONTENT, NODEVIZ_MODES_NUM};
-   //enum {NODEVIZ_NONE, NODEVIZ_RENDER_GEOMETRY, NODEVIZ_MODES_NUM};
-
-  void zoomVizCamera(int zoom);
-	
-   void addFrameInfo(SceneNode *camNode, Real timeElapsed);
-   void setCurrentFrameInfo(Real timeElapsed);
-
-   void setAlgorithm(int algorithm);
-
-   void moveCamera();
-
-   void writeFrames();
-   void loadFrames();
-
-  
-    // Constructor takes a RenderWindow because it uses that to determine input context
-    //ExampleFrameListener(RenderWindow* win, Camera* cam, bool useBufferedInputKeys = false, bool useBufferedInputMouse = false)
-    
-    bool processUnbufferedKeyInput(const FrameEvent& evt);
-    bool processUnbufferedMouseInput(const FrameEvent& evt);
-
-    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();
-
-	void ApplyVisibilityQuery();
-
-	void switchMouseMode() 
-	{
-        mUseBufferedInputMouse = !mUseBufferedInputMouse;
-		mInputDevice->setBufferedInput(mUseBufferedInputKeys, mUseBufferedInputMouse);
-	}
-protected:
-
-	/** Clamp camera to terrain.
-	*/
-	void Clamp2Terrain();
-	
-	SceneManager *mSceneMgr;           // A pointer to the scene manager
-    
-	CEGUI::Renderer *mGUIRenderer;     // cegui renderer
-	
-	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;
-	OverlayElement *mFrustumCulledNodesInfo;
-	OverlayElement *mQueryCulledNodesInfo;
-    OverlayElement *mTraversedNodesInfo;
-	OverlayElement *mHierarchyNodesInfo;
-	OverlayElement *mUseOptimizationInfo;
-	OverlayElement *mUseDepthPassInfo;
-	OverlayElement *mRenderedNodesInfo;
-	OverlayElement *mObjectsInfo;
-	OverlayElement *mQueriesIssuedInfo;
-
-	RayQueryExecutor *mRayQueryExecutor;
-	TerrainContentGenerator *mTerrainContentGenerator;
-
-	bool mUseOptimization;
-	bool mShowOctree;
-	bool mUseDepthPass;
-	bool mShowVisualization;
-	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;
-
-	Camera *mVizCamera;
-	SceneNode *mCamNode;
-	
-	//std::deque<Vector3> mWalkList;   // The list of points we are walking to
-	std::vector<frame_info> mFrameInfo;
-		
-	Real mTimeElapsed;
-	//EventProcessor* mEventProcessor;
-    InputReader* mInputDevice;
-    Camera* mCamera;
-
-    Vector3 mTranslateVector;
-    RenderWindow* mWindow;
-   
-    //bool mUseBufferedInputKeys, mUseBufferedInputMouse, mInputTypeSwitchingOn;
-	unsigned int mNumScreenShots;
-    int mSceneDetailIndex;
-	int mAniso;
-
-	float mMoveScale;
-    Degree mRotScale;
-    // just to stop toggles flipping too fast
-    Real mTimeDelay;
-    Radian mRotX, mRotY;
-    TextureFilterOptions mFiltering;
-  
-	Real mMoveSpeed;
-    Degree mRotateSpeed;
-    
-	Overlay* mDebugOverlay;
-	Overlay* mHelpOverlay;
-	Overlay* mCullStatsOverlay;
-
-	Light *mSunLight;
-	GtpVisibility::VisibilityManager *mVisibilityManager;
-	EventProcessor* mEventProcessor;
-	
-	bool mUseBufferedInputKeys, mUseBufferedInputMouse, mInputTypeSwitchingOn;
-	
-};
-
-
-#endif //_TerrainMouseQueryListener_H__
Index: trunk/VUT/work/TestCullingTerrain/TerrainMouseQueryListener.cpp
===================================================================
--- trunk/VUT/work/TestCullingTerrain/TerrainMouseQueryListener.cpp	(revision 130)
+++ 	(revision )
@@ -1,960 +1,0 @@
-#include <OgreNoMemoryMacros.h>
-#include <CEGUI/CEGUI.h>
-#include <../CEGUIRenderer/include/OgreCEGUIRenderer.h>
-#include <../CEGUIRenderer/include/OgreCEGUIResourceProvider.h>
-#include <../CEGUIRenderer/include/OgreCEGUITexture.h>
-#include <OgreMemoryMacros.h>
-#include "TerrainMouseQueryListener.h"
-#include "OgrePlatformQueryManager.h"
-#include "OgreVisibilityTerrainSceneManager.h"
-#include "VisibilityInfo.h"
-
-// output file for frame info
-const char* frames_out_filename = "frame.out";
-// output file for object positions / orientations
-const char* objects_out_filename = "objects.out";
-
-
-#define KEY_PRESSED(_key, _timeDelay, _macro) \
-{ \
-    if (mInputDevice->isKeyDown(_key) && mTimeDelay <= 0) \
-{ \
-    mTimeDelay = _timeDelay; \
-    _macro ; \
-} \
-}
-
-
-String mCurrentAlgorithmCaptions[GtpVisibility::VisibilityEnvironment::NUM_CULLING_MANAGERS] = 
-{
-    "View Frustum Culling", 
-	"Stop and Wait Culling", 
-	"Coherent Hierarchical Culling"
-};
-
-
-//-----------------------------------------------------------------------
-TerrainMouseQueryListener::TerrainMouseQueryListener(RenderWindow* win, Camera* cam, 
-									   SceneManager *sceneManager, 
-									   CEGUI::Renderer *renderer,
-									   TerrainContentGenerator *sceneGenerator,
-									   Camera *vizCamera,
-									   SceneNode *camNode,
-									   Light *sunLight): 
-mCamera(cam),
-mWindow(win),
-mNumScreenShots(0),
-mTimeDelay(0),
-mSceneDetailIndex(0),
-mMoveScale(0.0f),
-mRotScale(0.0f),
-mTranslateVector(Vector3::ZERO),
-mAniso(1),
-mFiltering(TFO_BILINEAR), 
-mGUIRenderer(renderer), 
-mSceneMgr(sceneManager),
-mCurrentObject(NULL),
-mTerrainContentGenerator(sceneGenerator),
-mVisibilityThreshold(0),
-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),
-mShowVisualization(false),
-mCullCamera(false),
-mRecord(false),
-mUseShadows(false),
-mShowHelp(false),
-mDisplayCameraDetails(false),
-mVisualizeCulledNodes(false),
-mSunLight(sunLight)
-{
-	//mInputDevice = PlatformManager::getSingleton().createInputReader();
-	
-	//mInputDevice->initialise(win, true, true);
-	mEventProcessor = new EventProcessor();
-	
-	mEventProcessor->initialise(win);
-	mEventProcessor->startProcessingEvents();
-	mEventProcessor->addMouseListener(this);
-	mEventProcessor->addMouseMotionListener(this);
-
-	//mEventProcessor->addKeyListener(this);
-	mInputDevice = mEventProcessor->getInputReader();
-	
-
-	// create ray query executor, used to place objects in terrain
-	mRayQueryExecutor = new RayQueryExecutor(mSceneMgr);
-	
-	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");
-	
-	mFrustumCulledNodesInfo = OverlayManager::getSingleton().getOverlayElement("Example/Visibility/FrustumCulledNodesInfo");
-	mQueryCulledNodesInfo = OverlayManager::getSingleton().getOverlayElement("Example/Visibility/QueryCulledNodesInfo");
-    mTraversedNodesInfo = OverlayManager::getSingleton().getOverlayElement("Example/Visibility/TraversedNodesInfo");
-	mHierarchyNodesInfo = OverlayManager::getSingleton().getOverlayElement("Example/Visibility/HierarchyNodesInfo");
-	mRenderedNodesInfo = OverlayManager::getSingleton().getOverlayElement("Example/Visibility/RenderedNodesInfo");
-	mObjectsInfo = OverlayManager::getSingleton().getOverlayElement("Example/Visibility/ObjectsInfo");
-	mUseOptimizationInfo = OverlayManager::getSingleton().getOverlayElement("Example/Visibility/UseOptimizationInfo");
-	mUseDepthPassInfo = OverlayManager::getSingleton().getOverlayElement("Example/Visibility/UseDepthPassInfo");
-	mQueriesIssuedInfo = OverlayManager::getSingleton().getOverlayElement("Example/Visibility/QueriesIssuedInfo");
-	
-	mAlgorithmInfo->setCaption(": " + mCurrentAlgorithmCaptions[mCurrentAlgorithm]);
-	mThresholdInfo->setCaption(": 0");
-	mFrustumCulledNodesInfo->setCaption(": 0");
-	mQueryCulledNodesInfo->setCaption(": 0");
-	mTraversedNodesInfo->setCaption(": 0");
-	mHierarchyNodesInfo->setCaption(": 0");
-	mRenderedNodesInfo->setCaption(": 0");
-	mObjectsInfo->setCaption(": 0");
-	mUseOptimizationInfo->setCaption(": true");
-	mUseDepthPassInfo->setCaption(": false");
-	mQueriesIssuedInfo->setCaption(": 0");
-
-	// show stats overlays
-	showStats(true);
-	//mHelpOverlay->show();
-
-	// set culling algorithm type
-	setAlgorithm(mCurrentAlgorithm);
-
-	// set scene manager options
-	mSceneMgr->setOption("UseOptimization", &mUseOptimization);
-
-	// 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);
-	mSceneMgr->setOption("ShowVisualization", &mShowVisualization);
-
-	mVisibilityManager = 
-		dynamic_cast<VisibilityTerrainSceneManager *>(mSceneMgr)->GetVisibilityManager();
-
-	dynamic_cast<PlatformQueryManager *>(mVisibilityManager->GetQueryManager())->
-		SetViewport(mWindow->getViewport(0));
-} 
-//-----------------------------------------------------------------------
-TerrainMouseQueryListener::~TerrainMouseQueryListener()
-{
-	//PlatformManager::getSingleton().destroyInputReader(mInputDevice);
-    
-	delete mRayQueryExecutor;
-	delete mEventProcessor;
-}
-//-----------------------------------------------------------------------
-void TerrainMouseQueryListener::mouseMoved(MouseEvent *e)
-{
-	// Update CEGUI with the mouse motion
-    CEGUI::System::getSingleton().injectMouseMove(e->getRelX() * 
-		mGUIRenderer->getWidth(), e->getRelY() * mGUIRenderer->getHeight());
-}
-//-----------------------------------------------------------------------
-void TerrainMouseQueryListener::mousePressed(MouseEvent* e)
-{
-     // Left mouse button down
-     if (e->getButtonID() & InputEvent::BUTTON0_MASK)
-     {
-		 CEGUI::MouseCursor::getSingleton().hide();
-
-		 // Setup the ray scene query
-         Ray mouseRay = mCamera->getCameraToViewportRay(e->getX(), e->getY());
-		 
-		 //Vector3 queryResult; mRayQueryExecutor->executeRayQuery(&queryResult, mouseRay);
-		 
-		 // Get results, create a node/entity on the position
-		 mCurrentObject = mTerrainContentGenerator->GenerateSceneObject(
-			 mouseRay.getOrigin(), Vector3::ZERO, "robot", false);
-		
-         mLMouseDown = true; 
-     }
-     // Right mouse button down
-     else if (e->getButtonID() & InputEvent::BUTTON1_MASK)
-     {
-         CEGUI::MouseCursor::getSingleton().hide();
-         mRMouseDown = true;
-     }
-} // mousePressed
-//-----------------------------------------------------------------------
-void TerrainMouseQueryListener::mouseReleased(MouseEvent* e)
-{
-    // Left mouse button up
-    if (e->getButtonID() & InputEvent::BUTTON0_MASK)
-    {
-		CEGUI::MouseCursor::getSingleton().show();
-        mLMouseDown = false;
-    }
-    // Right mouse button up
-    else if (e->getButtonID() & InputEvent::BUTTON1_MASK)
-    {
-        CEGUI::MouseCursor::getSingleton().show();
-        mRMouseDown = false;
-    }
-} 
-//-----------------------------------------------------------------------
-void TerrainMouseQueryListener::mouseDragged(MouseEvent *e)
- {
-	 // If we are dragging the left mouse button.	 	 
-	 if (mLMouseDown)
-     {
-		 Vector3 queryResult;
-		 Ray mouseRay = mCamera->getCameraToViewportRay(e->getX(), e->getY());
-
-		 if (mRayQueryExecutor->executeRayQuery(&queryResult, mouseRay))
-		 {
-			 if (mCurrentObject)
-			 {
-				 mCurrentObject->setPosition(queryResult);
-			 }
-		 }
-     }
-	 // If we are dragging the right mouse button.
-	 if (mRMouseDown)
-	 {
-		 //mCamera->yaw(-e->getRelX() * mRotateSpeed);
-		 //mCamera->pitch(-e->getRelY() * mRotateSpeed);
-		 mCamNode->yaw(-e->getRelX() * mRotateSpeed);
-		 mCamNode->pitch(-e->getRelY() * mRotateSpeed);
-	 }
-}
-//-----------------------------------------------------------------------
-bool TerrainMouseQueryListener::frameStarted(const FrameEvent &evt)
-{
-	if (mWindow->isClosed())
-	{
-        return false;
-	}
-
-//	mInputDevice->capture();
-
-	//-- IMPORTANT: must be set, otherwise terrain is not rendered correctly
-	int terrainLevelIdx = 0;
-	mSceneMgr->setOption("TerrainLevelIdx", &terrainLevelIdx);
-
-	//-- setup what is needed for immediate mouse/key movement
-	if (mTimeDelay >= 0) 
-	{
-		mTimeDelay -= 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 (!processUnbufferedKeyInput(evt))
-	{
-		return false;
-	}
-/*	if (!processUnbufferedMouseInput(evt))
-	{
-		return false;
-	}*/
-	// --- set parameters for visualization
-	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));
-		
-		// move by a constant so view plane is on bottom of viewport
-		mVizCamera->moveRelative(Vector3(0, 800, 0));
-	}
-
-	//-- set application state
-	switch (mAppState)
-	{
-	case REPLAY:
-		setCurrentFrameInfo(evt.timeSinceLastFrame);
-		break;
-	case WALKTHROUGH:
-		//-- if we are recording camera status per frame
-		if (mRecord)
-		{
-			addFrameInfo(mCamNode, evt.timeSinceLastFrame);
-			// print recording message
-			mWindow->setDebugText("Recording frame " + 
-				StringConverter::toString(mFrameInfo.size() - 1));
-		}	
-
-		moveCamera();
-		Clamp2Terrain();
-
-		break;
-	default:
-		break;
-	};	
-
-	return true;
-}
-//-----------------------------------------------------------------------
-void TerrainMouseQueryListener::ApplyVisibilityQuery()
-{
-	InfoContainer<GtpVisibility::NodeInfo> visibleNodes;
-	InfoContainer<GtpVisibility::MeshInfo> visibleGeometry;
-
-    mVisibilityManager->GetQueryManager()->ComputeCameraVisibility(*mCamera,
-			    &visibleNodes, &visibleGeometry, false);
-
-	for (int i=0; i < visibleGeometry.size(); ++i)
-	{
-		std::stringstream d; d << "Geometry visibility: " << visibleGeometry[i].GetVisibiliy();
-		LogManager::getSingleton().logMessage(d.str());
-	}
-	for (int i=0; i < visibleNodes.size(); ++i)
-	{
-		std::stringstream d; d << "Node visibility: " << visibleNodes[i].GetVisibiliy();
-		LogManager::getSingleton().logMessage(d.str());
-	}
-
-}
-//-----------------------------------------------------------------------
-void TerrainMouseQueryListener::Clamp2Terrain()
-{
-	// clamp to terrain
-	Vector3 camPos = mCamNode->getPosition();
-	Vector3 queryResult;
-
-	if (mRayQueryExecutor->executeRayQuery(&queryResult, 
-			Vector3(camPos.x, 5000.0f, camPos.z), Vector3::NEGATIVE_UNIT_Y))
-	{
-		mCamNode->setPosition(camPos.x, queryResult.y + 10, camPos.z);
-	}
-}
-//-----------------------------------------------------------------------
-bool TerrainMouseQueryListener::frameEnded(const FrameEvent& evt)
-{
-	if (mShutdownRequested)
-		return false;
-
-    updateStats();
-
-	return true;
-}
-//-----------------------------------------------------------------------
-void TerrainMouseQueryListener::moveCamera()
-{
-	// move node rather than camera so orientation is right in the visualization
-	mCamNode->yaw(mRotX);
-	mCamNode->pitch(mRotY);
-	mCamNode->translate(mCamNode->getLocalAxes(), mTranslateVector);
-}
-//-----------------------------------------------------------------------
-void TerrainMouseQueryListener::writeFrames()
-{
-	std::ofstream ofstr(frames_out_filename);
-	
-	std::vector<frame_info>::const_iterator it, it_end;
-
-	it_end = mFrameInfo.end();
-	for(it = mFrameInfo.begin(); it < it_end; ++it)
-	{
-		ofstr << StringConverter::toString((*it).position) << " " 
-			  << StringConverter::toString((*it).orientation) << " "
-			  << StringConverter::toString((*it).timeElapsed) << "\n";
-	}
-	ofstr.close();
-}
-//-----------------------------------------------------------------------
-void TerrainMouseQueryListener::loadFrames()
-{
-	std::ifstream ifstr(frames_out_filename);
-	char line[256];
-	frame_info info;
-
-	// reset current values
-	mFrameInfo.clear();
-	mCurrentFrame = 0;
-	
-	while (!ifstr.eof()) 
-	{
-		ifstr.getline(line, 256);
-		sscanf(line, "%f %f %f %f %f %f %f %f", &info.position.x, &info.position.y, &info.position.z,
-				&info.orientation.w, &info.orientation.x, &info.orientation.y, &info.orientation.z,
-				&info.timeElapsed);
-		
-		mFrameInfo.push_back(info);
-		
-		/*	std::stringstream d;
-		d << StringConverter::toString(info.position) << " " << StringConverter::toString(info.orientation);
-		LogManager::getSingleton().logMessage(d.str());		*/
-	}
-	ifstr.close();
-}
-//-----------------------------------------------------------------------
-void TerrainMouseQueryListener::nextAppState()
-{
-	mCurrentFrame = 0;
-
-	// if last state was replay state
-	if (mAppState == REPLAY)
-	{
-		// reset debug text and write frame info to file
-		mWindow->setDebugText("");
-		writeFrames();
-		
-		//-- write out stats for recorded walkthrough
-		std::stringstream d;
-		d << "Algorithm: " << mCurrentAlgorithmCaptions[mCurrentAlgorithm] << "\n"
-		  << "avg. FPS: " << mWindow->getAverageFPS() << "\n"
-		  << "best FPS: " << mWindow->getBestFPS() << "\n"
-		  << "worst FPS: " << mWindow->getWorstFPS() << "\n"
-		  << "best frame time: " <<	mWindow->getBestFrameTime() << "\n"
-		  << "worst frame time: " << mWindow->getWorstFrameTime();
- 		
-		LogManager::getSingleton().logMessage(d.str());
-	}
-	
-	//-- set the next státe
-	mAppState = (mAppState + 1) % STATE_NUM;
-
-	// replay recorded walkthrough
-	if (mAppState == REPLAY)
-	{
-		// no recording during replay
-		mRecord = false;
-
-		// load recorded walkthrough
-		if (mFrameInfo.size() == 0)
-		{
-			loadFrames();
-		}
-
-		// if there are no recorded frames => set next state
-		if (mFrameInfo.size() == 0) 
-		{
-			nextAppState();
-		}
-		else
-		{
-			mWindow->setDebugText("Replay");
-			
-			// reset, because we measure fps stats during walkthrough
-			mWindow->resetStatistics();
-
-			//-- initialise frame data
-			mTimeElapsed = 0;
-
-			mCamNode->setPosition(mFrameInfo[0].position);
-			mCamNode->setOrientation(mFrameInfo[0].orientation);
-		}
-	}
-
-}
-//-----------------------------------------------------------------------
-void TerrainMouseQueryListener::toggleRecord()
-{
-	mRecord = !mRecord;
-
-	// clear previous camera path
-	if (mRecord)
-		mFrameInfo.clear();
-	else
-		mWindow->setDebugText("");
-}
-//-----------------------------------------------------------------------
-void TerrainMouseQueryListener::changeThreshold(int incr)
-{
-	mVisibilityThreshold += incr; 
-	if(mVisibilityThreshold < 0) mVisibilityThreshold = 0;
-	
-	char str[100]; sprintf(str,": %d", mVisibilityThreshold);
-
-	mSceneMgr->setOption("Threshold", &mVisibilityThreshold); 
-	mThresholdInfo->setCaption(str);
-}
-//-----------------------------------------------------------------------
-void TerrainMouseQueryListener::zoomVizCamera(int zoom)
-{
-	mVizCameraHeight += zoom; 
-	if(mVizCameraHeight < 0) mVizCameraHeight = 0;
-}
-//-----------------------------------------------------------------------
-void TerrainMouseQueryListener::nextAlgorithm()
-{
-	mCurrentAlgorithm = (mCurrentAlgorithm + 1) % 
-		GtpVisibility::VisibilityEnvironment::NUM_CULLING_MANAGERS,
-
-	setAlgorithm(mCurrentAlgorithm);
-}
-//-----------------------------------------------------------------------
-void TerrainMouseQueryListener::setAlgorithm(int algorithm)
-{
-	mAlgorithmInfo->setCaption(": " + mCurrentAlgorithmCaptions[mCurrentAlgorithm]);
-	mSceneMgr->setOption("Algorithm", &mCurrentAlgorithm);
-}
-//-----------------------------------------------------------------------
-void TerrainMouseQueryListener::updateStats()
-{
-	unsigned int opt = 0;
-	char str[100];
-	
-	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());
-
-		//-- culling stats
-		mSceneMgr->getOption("NumFrustumCulledNodes", &opt); sprintf(str,": %d", opt); 
-		mFrustumCulledNodesInfo->setCaption(str);
-	
-		mSceneMgr->getOption("NumQueriesIssued", &opt); sprintf(str,": %d", opt); 
-		mQueriesIssuedInfo->setCaption(str);
-
-		mSceneMgr->getOption("NumQueryCulledNodes", &opt); sprintf(str,": %d", opt); 
-		mQueryCulledNodesInfo->setCaption(str);
-	
-		mSceneMgr->getOption("NumTraversedNodes", &opt); sprintf(str,": %d", opt); 
-		mTraversedNodesInfo->setCaption(str);
-
-		mSceneMgr->getOption("NumHierarchyNodes", &opt); sprintf(str,": %d", opt); 
-		mHierarchyNodesInfo->setCaption(str);
-
-		mSceneMgr->getOption("NumRenderedNodes", &opt); sprintf(str,": %d", opt); 
-		mRenderedNodesInfo->setCaption(str);
-
-		sprintf(str,": %d", mTerrainContentGenerator->GetObjectCount()); 
-		mObjectsInfo->setCaption(str);
-	}
-	catch(...)
-	{
-            // ignore
-	}
-}
-//-----------------------------------------------------------------------
-void TerrainMouseQueryListener::toggleUseOptimization()
-{
-	mUseOptimization = !mUseOptimization;
-
-	mSceneMgr->setOption("UseOptimization", &mUseOptimization);
-	// delayed rendering (i.e., render transparents afterwards) allows 
-	// no optimization which tests geometry instead of aabb
-	bool delayedRendering = !mUseOptimization;
-	mSceneMgr->setOption("DelayRenderTransparents", &delayedRendering);
-
-	if (mUseOptimization)
-		mUseOptimizationInfo->setCaption(": true");
-	else
-		mUseOptimizationInfo->setCaption(": false");
-}
-//-----------------------------------------------------------------------
-void TerrainMouseQueryListener::toggleShowOctree()
-{
-	mShowOctree = !mShowOctree;
-
-	mSceneMgr->setOption("ShowOctree", &mShowOctree);
-}
-//-----------------------------------------------------------------------
-void TerrainMouseQueryListener::toggleUseDepthPass()
-{
-	mUseDepthPass = !mUseDepthPass;
-
-	mSceneMgr->setOption("UseDepthPass", &mUseDepthPass);
-	
-	if (mUseDepthPass)
-	{
-		mUseDepthPassInfo->setCaption(": true");
-	}
-	else
-	{
-		mUseDepthPassInfo->setCaption(": false");
-	}
-}
-//-----------------------------------------------------------------------
-void TerrainMouseQueryListener::toggleShowViz()
-{
-	mShowVisualization = !mShowVisualization;
-	mVisualizeCulledNodes = !mVisualizeCulledNodes;
-
-	// create viewport with priority VIZ_VIEWPORT_Z_ORDER: 
-	// will be rendered over standard viewport
-	if (mShowVisualization)
-	{	
-		Viewport *vizvp = mWindow->addViewport(mVizCamera, 
-			VIZ_VIEWPORT_Z_ORDER, 0.6, 0.6, 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()));
-		
-		mSceneMgr->setOption("VisualizeCulledNodes", &mVisualizeCulledNodes);
-		//vizvp->setClearEveryFrame(false);
-
-		// Create a skyplane (for visualization background)
-		/*
-		Plane plane;
-		plane.d = -1000;
-		plane.normal = Vector3::UNIT_Y;
-		mSceneMgr->setSkyPlane(true, plane, "Examples/TransparentTest", 4000, 75, false);
-		*/
-		
-	}
-	else
-	{
-		mWindow->removeViewport(VIZ_VIEWPORT_Z_ORDER);
-		// if octree was enabled for visualization purpose, reset now
-		mSceneMgr->setOption("ShowOctree", &mShowOctree);
-	}
-}
-//-----------------------------------------------------------------------
-void TerrainMouseQueryListener::toggleUseShadows()
-{
-	mUseShadows = !mUseShadows;
-
-	mSunLight->setCastShadows(mUseShadows);
-
-	if (mUseShadows)
-	{
-		mSceneMgr->setShadowTechnique(SHADOWTYPE_TEXTURE_MODULATIVE);
-	}
-	else
-	{
-		mSceneMgr->setShadowTechnique(SHADOWTYPE_NONE);
-	}
-
-}
-//-----------------------------------------------------------------------
-void TerrainMouseQueryListener::nextNodeVizMode()
-{
-	mNodeVizMode = (mNodeVizMode + 1) % NODEVIZ_MODES_NUM;
-
-	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;
-
-	mSceneMgr->setOption("RenderNodesForViz", &renderNodesForViz);
-	mSceneMgr->setOption("RenderNodesContentForViz", &renderNodesContentForViz);
-}
-//-----------------------------------------------------------------------
-void TerrainMouseQueryListener::keyPressed(KeyEvent* e)
-{
-	if(e->getKey() == KC_ESCAPE)
-    {
-		mShutdownRequested = true;
-		e->consume();
-		return;
-	}
-
-	CEGUI::System::getSingleton().injectKeyDown(e->getKey());
-	CEGUI::System::getSingleton().injectChar(e->getKeyChar());
-	e->consume();
-}
-//-----------------------------------------------------------------------
-void TerrainMouseQueryListener::keyReleased(KeyEvent* e)
-{
-	CEGUI::System::getSingleton().injectKeyUp(e->getKey());
-	e->consume();
-}
-//-----------------------------------------------------------------------
-void TerrainMouseQueryListener::keyClicked(KeyEvent* e) 
-{
-	// Do nothing
-	e->consume();
-}
-//-----------------------------------------------------------------------
-void TerrainMouseQueryListener::addFrameInfo(SceneNode *camNode, Real timeElapsed)
-{
-	frame_info info;
-	info.orientation = mCamNode->getOrientation();
-	info.position = mCamNode->getPosition();
-	info.timeElapsed = timeElapsed;
-
-	mFrameInfo.push_back(info);
-}
-//-----------------------------------------------------------------------
-void TerrainMouseQueryListener::setCurrentFrameInfo(Real timeElapsed)
-{
-	//-- find current frame relative to elapsed frame time		
-	mTimeElapsed -= timeElapsed;
-
-	while ((mTimeElapsed <= 0) && (mCurrentFrame < (int)mFrameInfo.size() - 1))
-	{
-		mTimeElapsed += mFrameInfo[mCurrentFrame ++].timeElapsed;
-	}
-
-	frame_info new_frame = mFrameInfo[mCurrentFrame];
-	frame_info old_frame = mFrameInfo[mCurrentFrame - 1];
-		
-	//-- interpolate frames
-	Real factor = 1;
-
-	if (old_frame.timeElapsed > 0)
-		factor = mTimeElapsed / old_frame.timeElapsed;
-
-	Vector3 camPos = old_frame.position + factor * (new_frame.position - old_frame.position);
-	Quaternion camOrienation = Quaternion::Slerp(factor, old_frame.orientation, 
-		new_frame.orientation, true);
-
-	mCamNode->setPosition(camPos);
-	mCamNode->setOrientation(camOrienation);
-	
-	// stop replay after a full walkthrough
-	if (mCurrentFrame == (int)mFrameInfo.size() - 1)
-	{
-		nextAppState();
-	}
-}
-//-----------------------------------------------------------------------    
-bool TerrainMouseQueryListener::processUnbufferedKeyInput(const FrameEvent& evt)
-{
-	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))
-    {
-		mTranslateVector.z = mMoveScale;
-    }
-
-    if (mInputDevice->isKeyDown(KC_RIGHT))
-    {
-        mCamNode->yaw(-mRotScale);
-    }
-	
-    if (mInputDevice->isKeyDown(KC_LEFT))
-    {
-        mCamNode->yaw(mRotScale);
-    }
-
-	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_F4, 0.3, toggleRecord());
-	KEY_PRESSED(KC_F5, 0.3, ApplyVisibilityQuery());
-
-	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
-        mWindow->setDebugText("P: " + StringConverter::toString(mCamera->getDerivedPosition()) + " " + 
-            "O: " + StringConverter::toString(mCamera->getDerivedOrientation()));
-    }
-
-    // Return true to continue rendering
-    return true;
-}
-//-----------------------------------------------------------------------
-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)
-{
-	/* 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;
-}
-//-----------------------------------------------------------------------
-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();
-	}
-}
-
-	
Index: trunk/VUT/work/TestCulling/TestCullingApplication.cpp
===================================================================
--- trunk/VUT/work/TestCulling/TestCullingApplication.cpp	(revision 130)
+++ trunk/VUT/work/TestCulling/TestCullingApplication.cpp	(revision 133)
@@ -81,5 +81,5 @@
 void TestCullingApplication::createFrameListener()
 {
-	mFrameListener= new TerrainMouseQueryListener(mWindow, mCamera, mSceneMgr, 
+	mFrameListener= new TerrainFrameListener(mWindow, mCamera, mSceneMgr, 
 		mGUIRenderer, mSceneContentGenerator);
 	mFrameListener->showDebugOverlay(true);
@@ -94,8 +94,8 @@
 
 /***********************************************/
-/* TerrainMouseQueryListener implementation           */
+/* TerrainFrameListener implementation           */
 /***********************************************/
 //-----------------------------------------------------------------------
-TerrainMouseQueryListener::TerrainMouseQueryListener(RenderWindow* win, Camera* cam, 
+TerrainFrameListener::TerrainFrameListener(RenderWindow* win, Camera* cam, 
 									   SceneManager *sceneManager, 
 									   CEGUI::Renderer *renderer,
@@ -161,9 +161,9 @@
 } 
 //-----------------------------------------------------------------------
-TerrainMouseQueryListener::~TerrainMouseQueryListener()
-{
-}
-//-----------------------------------------------------------------------
-void TerrainMouseQueryListener::mouseMoved(MouseEvent *e)
+TerrainFrameListener::~TerrainFrameListener()
+{
+}
+//-----------------------------------------------------------------------
+void TerrainFrameListener::mouseMoved(MouseEvent *e)
 {
 	// Update CEGUI with the mouse motion
@@ -172,5 +172,5 @@
 }
 //-----------------------------------------------------------------------
-void TerrainMouseQueryListener::mousePressed(MouseEvent* e)
+void TerrainFrameListener::mousePressed(MouseEvent* e)
 {
      // Left mouse button down
@@ -188,5 +188,5 @@
 
  //-----------------------------------------------------------------------
-void TerrainMouseQueryListener::mouseReleased(MouseEvent* e)
+void TerrainFrameListener::mouseReleased(MouseEvent* e)
 {
     // Left mouse button up
@@ -204,5 +204,5 @@
 } 
 //-----------------------------------------------------------------------
-void TerrainMouseQueryListener::mouseDragged (MouseEvent *e)
+void TerrainFrameListener::mouseDragged (MouseEvent *e)
  {
 	 // If we are dragging the left mouse button.	 	 
@@ -219,10 +219,10 @@
 }
 //-----------------------------------------------------------------------
-bool TerrainMouseQueryListener::frameStarted(const FrameEvent &evt)
+bool TerrainFrameListener::frameStarted(const FrameEvent &evt)
 {	 
 	return ExampleFrameListener::frameStarted(evt);
 }
 //-----------------------------------------------------------------------
-bool TerrainMouseQueryListener::frameEnded(const FrameEvent& evt)
+bool TerrainFrameListener::frameEnded(const FrameEvent& evt)
 {
 	if (mShutdownRequested)
@@ -245,5 +245,5 @@
 }
 //-----------------------------------------------------------------------
-void TerrainMouseQueryListener::changeThreshold(int incr)
+void TerrainFrameListener::changeThreshold(int incr)
 {
 	mVisibilityThreshold += incr; 
@@ -256,5 +256,5 @@
 }
 //-----------------------------------------------------------------------
-void TerrainMouseQueryListener::nextAlgorithm()
+void TerrainFrameListener::nextAlgorithm()
 {
 	mCurrentAlgorithm = ++mCurrentAlgorithm % 
@@ -264,5 +264,5 @@
 }
 //-----------------------------------------------------------------------
-void TerrainMouseQueryListener::toggleUseOptimization()
+void TerrainFrameListener::toggleUseOptimization()
 {
 	mUseOptimization = !mUseOptimization;
@@ -276,5 +276,5 @@
 }
 //-----------------------------------------------------------------------
-void TerrainMouseQueryListener::toggleShowOctree()
+void TerrainFrameListener::toggleShowOctree()
 {
 	mShowOctree = !mShowOctree;
@@ -283,5 +283,5 @@
 }
 //-----------------------------------------------------------------------
-void TerrainMouseQueryListener::toggleUseDepthPass()
+void TerrainFrameListener::toggleUseDepthPass()
 {
 	mUseDepthPass = !mUseDepthPass;
@@ -290,5 +290,5 @@
 }
 //-----------------------------------------------------------------------
-void TerrainMouseQueryListener::toggleShowViz()
+void TerrainFrameListener::toggleShowViz()
 {
 	mShowVisualization = !mShowVisualization;
@@ -298,5 +298,5 @@
 }
 //-----------------------------------------------------------------------
-void TerrainMouseQueryListener::setAlgorithm(int algorithm)
+void TerrainFrameListener::setAlgorithm(int algorithm)
 {
 	mAlgorithmInfo->setCaption(": " + mCurrentAlgorithmCaptions[mCurrentAlgorithm]);
@@ -304,5 +304,5 @@
 }
 //-----------------------------------------------------------------------
-void TerrainMouseQueryListener::updateStats()
+void TerrainFrameListener::updateStats()
 {
 	unsigned int opt = 0;
@@ -331,5 +331,5 @@
 }
 //-----------------------------------------------------------------------
-void TerrainMouseQueryListener::keyPressed(KeyEvent* e)
+void TerrainFrameListener::keyPressed(KeyEvent* e)
 {
 	if(e->getKey() == KC_ESCAPE)
@@ -345,5 +345,5 @@
 }
 //-----------------------------------------------------------------------
-void TerrainMouseQueryListener::keyReleased(KeyEvent* e)
+void TerrainFrameListener::keyReleased(KeyEvent* e)
 {
 	CEGUI::System::getSingleton().injectKeyUp(e->getKey());
@@ -351,5 +351,5 @@
 }
 //-----------------------------------------------------------------------
-void TerrainMouseQueryListener::keyClicked(KeyEvent* e) 
+void TerrainFrameListener::keyClicked(KeyEvent* e) 
 {
 	// Do nothing
Index: trunk/VUT/work/TestCulling/TestCullingApplication.h
===================================================================
--- trunk/VUT/work/TestCulling/TestCullingApplication.h	(revision 115)
+++ trunk/VUT/work/TestCulling/TestCullingApplication.h	(revision 133)
@@ -25,13 +25,13 @@
 };
 
-class TerrainMouseQueryListener : public ExampleFrameListener, public MouseListener, public MouseMotionListener
+class TerrainFrameListener : public ExampleFrameListener, public MouseListener, public MouseMotionListener
 {
 public:
 
-    TerrainMouseQueryListener(RenderWindow* win, Camera* cam, SceneManager *sceneManager, 
+    TerrainFrameListener(RenderWindow* win, Camera* cam, SceneManager *sceneManager, 
 			CEGUI::Renderer *renderer, SceneContentGenerator *sceneContentGenerator);
 
 
-    ~TerrainMouseQueryListener( );
+    ~TerrainFrameListener( );
 
 	bool frameStarted(const FrameEvent& evt);
