Index: trunk/VUT/work/TestCullingTerrain/TerrainMouseQueryListener.h
===================================================================
--- trunk/VUT/work/TestCullingTerrain/TerrainMouseQueryListener.h	(revision 121)
+++ trunk/VUT/work/TestCullingTerrain/TerrainMouseQueryListener.h	(revision 130)
@@ -9,4 +9,5 @@
 #include <OgreException.h>
 #include "VisibilityEnvironment.h"
+#include "VisibilityManager.h"
 #include "OgreTerrainContentGenerator.h"
 
@@ -113,4 +114,11 @@
 	void toggleRecord();
 
+	void ApplyVisibilityQuery();
+
+	void switchMouseMode() 
+	{
+        mUseBufferedInputMouse = !mUseBufferedInputMouse;
+		mInputDevice->setBufferedInput(mUseBufferedInputKeys, mUseBufferedInputMouse);
+	}
 protected:
 
@@ -201,4 +209,9 @@
 
 	Light *mSunLight;
+	GtpVisibility::VisibilityManager *mVisibilityManager;
+	EventProcessor* mEventProcessor;
+	
+	bool mUseBufferedInputKeys, mUseBufferedInputMouse, mInputTypeSwitchingOn;
+	
 };
 
Index: trunk/VUT/work/TestCullingTerrain/TestCullingTerrain.vcproj
===================================================================
--- trunk/VUT/work/TestCullingTerrain/TestCullingTerrain.vcproj	(revision 115)
+++ trunk/VUT/work/TestCullingTerrain/TestCullingTerrain.vcproj	(revision 130)
@@ -75,4 +75,5 @@
 				PreprocessorDefinitions="_WINDOWS;_STLP_USE_DYNAMIC_LIB;OGRE_LIBRARY_IMPORTS;_RELEASE;WIN32;_STLP_RELEASE;GTP_VISIBILITY_MODIFIED_OGRE"
 				RuntimeLibrary="2"
+				RuntimeTypeInfo="TRUE"
 				UsePrecompiledHeader="0"
 				WarningLevel="3"
Index: trunk/VUT/work/TestCullingTerrain/TerrainMouseQueryListener.cpp
===================================================================
--- trunk/VUT/work/TestCullingTerrain/TerrainMouseQueryListener.cpp	(revision 122)
+++ trunk/VUT/work/TestCullingTerrain/TerrainMouseQueryListener.cpp	(revision 130)
@@ -6,4 +6,7 @@
 #include <OgreMemoryMacros.h>
 #include "TerrainMouseQueryListener.h"
+#include "OgrePlatformQueryManager.h"
+#include "OgreVisibilityTerrainSceneManager.h"
+#include "VisibilityInfo.h"
 
 // output file for frame info
@@ -54,6 +57,6 @@
 mTerrainContentGenerator(sceneGenerator),
 mVisibilityThreshold(0),
-//mCurrentAlgorithm(GtpVisibility::VisibilityEnvironment::COHERENT_HIERARCHICAL_CULLING),
-mCurrentAlgorithm(GtpVisibility::VisibilityEnvironment::FRUSTUM_CULLING),
+mCurrentAlgorithm(GtpVisibility::VisibilityEnvironment::COHERENT_HIERARCHICAL_CULLING),
+//mCurrentAlgorithm(GtpVisibility::VisibilityEnvironment::FRUSTUM_CULLING),
 mNodeVizMode(NODEVIZ_NONE),
 mVizCameraHeight(Real(2500.0)),
@@ -81,12 +84,17 @@
 mSunLight(sunLight)
 {
-	mInputDevice = PlatformManager::getSingleton().createInputReader();
-	mInputDevice->initialise(win, true, true);
-
-	/*
+	//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);
-	*/
+
+	//mEventProcessor->addKeyListener(this);
+	mInputDevice = mEventProcessor->getInputReader();
+	
 
 	// create ray query executor, used to place objects in terrain
@@ -145,11 +153,18 @@
 	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);
+	//PlatformManager::getSingleton().destroyInputReader(mInputDevice);
     
 	delete mRayQueryExecutor;
+	delete mEventProcessor;
 }
 //-----------------------------------------------------------------------
@@ -170,10 +185,10 @@
 		 // Setup the ray scene query
          Ray mouseRay = mCamera->getCameraToViewportRay(e->getX(), e->getY());
-   
-		 Vector3 queryResult;
+		 
+		 //Vector3 queryResult; mRayQueryExecutor->executeRayQuery(&queryResult, mouseRay);
 		 
 		 // Get results, create a node/entity on the position
 		 mCurrentObject = mTerrainContentGenerator->GenerateSceneObject(
-			 mouseRay.getOrigin(), Vector3(0,0,0), "robot");
+			 mouseRay.getOrigin(), Vector3::ZERO, "robot", false);
 		
          mLMouseDown = true; 
@@ -231,54 +246,56 @@
 bool TerrainMouseQueryListener::frameStarted(const FrameEvent &evt)
 {
-	LogManager::getSingleton().logMessage("frame started");
 	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;
-	 }
-
-	 if (mShowVisualization)
-	 {
+	}
+
+//	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);
-		// also render nodew content?
-		//mSceneMgr->setOption("RenderNodesForViz", &mRenderNodesForViz);
-
-		// -- setup visualization camera
+		
+		// ---- setup visualization camera
+
 		mVizCamera->setPosition(0, 0, 0);
 		mVizCamera->setOrientation(Quaternion::IDENTITY);
@@ -289,5 +306,5 @@
 		// point down -Z axis
 		mVizCamera->pitch(Radian(Degree(270.0)));
-	
+
 		// rotation arounnd X axis
 		mVizCamera->yaw(Math::ATan2(-mCamera->getDerivedDirection().x, 
@@ -298,4 +315,5 @@
 	}
 
+	//-- set application state
 	switch (mAppState)
 	{
@@ -312,14 +330,35 @@
 				StringConverter::toString(mFrameInfo.size() - 1));
 		}	
-	
-		 moveCamera();
-		 Clamp2Terrain();
-
-		 break;
+
+		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());
+	}
+
 }
 //-----------------------------------------------------------------------
@@ -365,6 +404,6 @@
 	{
 		ofstr << StringConverter::toString((*it).position) << " " 
-			<< StringConverter::toString((*it).orientation) << " "
-			<< StringConverter::toString((*it).timeElapsed) << "\n";
+			  << StringConverter::toString((*it).orientation) << " "
+			  << StringConverter::toString((*it).timeElapsed) << "\n";
 	}
 	ofstr.close();
@@ -390,9 +429,7 @@
 		mFrameInfo.push_back(info);
 		
-		/*
-		std::stringstream d;
+		/*	std::stringstream d;
 		d << StringConverter::toString(info.position) << " " << StringConverter::toString(info.orientation);
-		LogManager::getSingleton().logMessage(d.str());
-		*/
+		LogManager::getSingleton().logMessage(d.str());		*/
 	}
 	ifstr.close();
@@ -791,4 +828,5 @@
 	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());
Index: trunk/VUT/work/TestCullingTerrain/TestCullingTerrainApplication.h
===================================================================
--- trunk/VUT/work/TestCullingTerrain/TestCullingTerrainApplication.h	(revision 115)
+++ trunk/VUT/work/TestCullingTerrain/TestCullingTerrainApplication.h	(revision 130)
@@ -57,5 +57,5 @@
 
 	TerrainMouseQueryListener *mTerrainFrameListener;
-
+	
 private:
 	void chooseSceneManager(void);
Index: trunk/VUT/work/TestCulling/TestCullingApplication.cpp
===================================================================
--- trunk/VUT/work/TestCulling/TestCullingApplication.cpp	(revision 115)
+++ trunk/VUT/work/TestCulling/TestCullingApplication.cpp	(revision 130)
@@ -161,12 +161,13 @@
 } 
 //-----------------------------------------------------------------------
-TerrainMouseQueryListener::~TerrainMouseQueryListener( )
-{
-}
-//-----------------------------------------------------------------------
-void TerrainMouseQueryListener::mouseMoved (MouseEvent *e)
+TerrainMouseQueryListener::~TerrainMouseQueryListener()
+{
+}
+//-----------------------------------------------------------------------
+void TerrainMouseQueryListener::mouseMoved(MouseEvent *e)
 {
 	// Update CEGUI with the mouse motion
-    CEGUI::System::getSingleton().injectMouseMove(e->getRelX() * mGUIRenderer->getWidth(), e->getRelY() * mGUIRenderer->getHeight());
+    CEGUI::System::getSingleton().injectMouseMove(e->getRelX() * 
+		mGUIRenderer->getWidth(), e->getRelY() * mGUIRenderer->getHeight());
 }
 //-----------------------------------------------------------------------
