Index: trunk/VUT/GtpVisibility/include/HierarchyInterface.h
===================================================================
--- trunk/VUT/GtpVisibility/include/HierarchyInterface.h	(revision 112)
+++ trunk/VUT/GtpVisibility/include/HierarchyInterface.h	(revision 130)
@@ -3,8 +3,14 @@
 
 #include "DistanceQueue.h"
+#include "VisibilityMesh.h"
 
 namespace GtpVisibility {
 
 enum  CullingType {QUERY_CULLED, FRUSTUM_CULLED};
+
+typedef std::vector<HierarchyNode *> HierarchyNodeList;
+typedef std::vector<GtpVisibility::Mesh *> GeometryList;
+typedef std::pair<HierarchyNode *, OcclusionQuery *> QueryPair;
+typedef std::queue<QueryPair> QueryQueue;
 
 /**	Class which implements a hierarchy interface for a scene hierarchy.
@@ -26,6 +32,6 @@
 	*/
 	virtual void TraverseNode(HierarchyNode *node) = 0;
-	/** Renders current scene node .
-		@param node current scene node to be rendered
+	/** Renders current hierarchy node.
+		@param node current hierarchy node to be rendered
 	*/
 	virtual void RenderNode(HierarchyNode *node) = 0;
@@ -119,4 +125,27 @@
 		CullingType type) = NULL;
 
+	/** Returns vector of previously rendered hierarchy nodes.
+	*/
+	std::vector<HierarchyNode *> *GetRenderedNodes();
+	/** Returns vector of previoulsy rendered geometry.
+	*/
+	
+	/** Issue a occlusion query for this mesh.
+		@param node the current mesh
+		@returns occlusion query for this node
+	*/
+	virtual GtpVisibility::OcclusionQuery *IssueOcclusionQuery(GtpVisibility::Mesh *mesh) = 0;
+
+	/** Returns geometry of hierarchy node. 
+	*/
+	virtual void GetGeometry(GtpVisibility::HierarchyNode *node,	
+					 		 GeometryList *geometryList, 
+							 bool includeChildren) = 0;
+
+
+	/** Renders geometry.
+	*/
+	virtual void RenderGeometry(GtpVisibility::Mesh *geom) = 0;
+
 protected:
 	
@@ -128,5 +157,4 @@
 	//--- statistics
 	unsigned int mNumTraversedNodes;
-	unsigned int mNumRenderedNodes;
 
 	DistanceQueue *mDistanceQueue;
@@ -134,5 +162,5 @@
 	HierarchyNode *mPreviousNode;
 
-	
+	std::vector<HierarchyNode *> mRenderedNodes;
 };
 } // namespace GtpVisibility
Index: trunk/VUT/GtpVisibility/include/QueryManager.h
===================================================================
--- trunk/VUT/GtpVisibility/include/QueryManager.h	(revision 113)
+++ trunk/VUT/GtpVisibility/include/QueryManager.h	(revision 130)
@@ -11,4 +11,6 @@
 namespace GtpVisibility {
   
+typedef std::vector<OcclusionQuery *> QueryList;
+
 /** This abstract class defines interface for a specific visibility query
     algorithm. The interface supports two from point visibility queries and
@@ -23,5 +25,5 @@
 public:
     /** Constructor taking a hierarchy interface as an argument. This allows to operate
-	onm different hierarchy types, while reusing the implementation of the query methods.
+	on different hierarchy types, while reusing the implementation of the query methods.
      */
     QueryManager(HierarchyInterface *hierarchyInterface);
@@ -81,8 +83,8 @@
 	     );
   
-	/** Sets the scene traverser.
-      @remark the scene traverser depends on the type of hierarchyInterface the scene consists of.
+	/** Sets the hierarchy interface.
+      @remark the traversal depends on the type of hierarchyInterface the scene consists of.
 	*/
-	void SetSceneTraverser(HierarchyInterface *hierarchyInterface);
+	void SetHierarchyInterface(HierarchyInterface *hierarchyInterface);
 
 protected:
Index: trunk/VUT/GtpVisibility/include/VisibilityInfo.h
===================================================================
--- trunk/VUT/GtpVisibility/include/VisibilityInfo.h	(revision 71)
+++ trunk/VUT/GtpVisibility/include/VisibilityInfo.h	(revision 130)
@@ -16,4 +16,6 @@
     NodeInfo(HierarchyNode *node,const float v): mNode(node), mVisibility(v) {}
 
+	float GetVisibiliy() const {return mVisibility;}
+
 protected:
     /** pointer to the scene node */
@@ -31,4 +33,6 @@
 public:
 	MeshInfo(Mesh *mesh, const float v): mMesh(mesh), mVisibility(v) {}
+
+	float GetVisibiliy() const {return mVisibility;}
 
 protected:
Index: trunk/VUT/GtpVisibility/include/VisibilityMesh.h
===================================================================
--- trunk/VUT/GtpVisibility/include/VisibilityMesh.h	(revision 71)
+++ trunk/VUT/GtpVisibility/include/VisibilityMesh.h	(revision 130)
@@ -2,8 +2,9 @@
 #define _VisibilityMesh_H__
 
-#include "OgreMesh.h"
+//#include <OgreMesh.h>
+#include <OgreEntity.h>
 
 namespace GtpVisibility {
-  typedef Ogre::Mesh Mesh;
+  typedef Ogre::Entity Mesh;
 }
 
Index: trunk/VUT/GtpVisibility/include/CoherentHierarchicalCullingManager.h
===================================================================
--- trunk/VUT/GtpVisibility/include/CoherentHierarchicalCullingManager.h	(revision 74)
+++ trunk/VUT/GtpVisibility/include/CoherentHierarchicalCullingManager.h	(revision 130)
@@ -8,7 +8,4 @@
 namespace GtpVisibility
 {
-
-typedef std::pair<HierarchyNode *, OcclusionQuery *> QueryPair;
-typedef std::queue<QueryPair> QueryQueue;
 
 /** Renders the scene with the coherent hierarchical culling algorithm. 
Index: trunk/VUT/GtpVisibility/include/VisibilityManager.h
===================================================================
--- trunk/VUT/GtpVisibility/include/VisibilityManager.h	(revision 114)
+++ trunk/VUT/GtpVisibility/include/VisibilityManager.h	(revision 130)
@@ -55,4 +55,10 @@
 	*/
 	void SetUseChcOptimization(bool useOptimization);
+	/** Sets pointer to a query manager. 
+	*/
+	void SetQueryManager(QueryManager *queryManager);
+	/** see set 
+	*/
+	QueryManager *GetQueryManager();
 
 protected:
Index: trunk/VUT/GtpVisibility/scripts/GtpVisibility.vcproj
===================================================================
--- trunk/VUT/GtpVisibility/scripts/GtpVisibility.vcproj	(revision 120)
+++ trunk/VUT/GtpVisibility/scripts/GtpVisibility.vcproj	(revision 130)
@@ -64,4 +64,5 @@
 				PreprocessorDefinitions="WIN32;NDEBUG;_LIB"
 				RuntimeLibrary="2"
+				RuntimeTypeInfo="TRUE"
 				UsePrecompiledHeader="0"
 				WarningLevel="3"
@@ -107,7 +108,4 @@
 			</File>
 			<File
-				RelativePath="..\include\DistanceQueue.h">
-			</File>
-			<File
 				RelativePath="..\src\DummyPreprocessingManager.cpp">
 			</File>
@@ -148,4 +146,10 @@
 			</File>
 			<File
+				RelativePath="..\include\DistanceQueue.h">
+			</File>
+			<File
+				RelativePath="..\include\DummyQueryManager.h">
+			</File>
+			<File
 				RelativePath="..\include\FrustumCullingManager.h">
 			</File>
Index: trunk/VUT/GtpVisibility/src/CoherentHierarchicalCullingManager.cpp
===================================================================
--- trunk/VUT/GtpVisibility/src/CoherentHierarchicalCullingManager.cpp	(revision 119)
+++ trunk/VUT/GtpVisibility/src/CoherentHierarchicalCullingManager.cpp	(revision 130)
@@ -48,5 +48,5 @@
 
 			if (!mHierarchyInterface->CheckFrustumVisible(node, intersects))
-			{//if (mHierarchyInterface->mIsShadowPass)
+			{
 				mNumFrustumCulledNodes ++;
 				
Index: trunk/VUT/GtpVisibility/src/HierarchyInterface.cpp
===================================================================
--- trunk/VUT/GtpVisibility/src/HierarchyInterface.cpp	(revision 120)
+++ trunk/VUT/GtpVisibility/src/HierarchyInterface.cpp	(revision 130)
@@ -7,6 +7,6 @@
 //-----------------------------------------------------------------------
 HierarchyInterface::HierarchyInterface(): 
-mFrameId(0), mNumTraversedNodes(0), mNumRenderedNodes(0), 
-mSceneRoot(0), mPreviousNode(0), mCurrentTestIdx(0), mUseOptimization(false)
+mFrameId(0), mNumTraversedNodes(0), mSceneRoot(0), 
+mPreviousNode(0), mCurrentTestIdx(0), mUseOptimization(false)
 //, mIsShadowPass(false)
 {	
@@ -26,8 +26,8 @@
 void HierarchyInterface::InitFrame(HierarchyNode *root)
 {
-	mFrameId ++;
+	++ mFrameId;
 	mCurrentTestIdx = 0;
 	mNumTraversedNodes = 0;
-	mNumRenderedNodes = 0;
+	mRenderedNodes.clear();
 
 	SetSceneRoot(root);
@@ -63,11 +63,16 @@
 unsigned int HierarchyInterface::GetNumRenderedNodes()
 {
-	return mNumRenderedNodes;
+	return (unsigned int)mRenderedNodes.size();
 }
-
+//-----------------------------------------------------------------------
 void HierarchyInterface::SetUseOptimization(bool useOptimization)
 {
 	mUseOptimization = useOptimization;
 }
+//-----------------------------------------------------------------------
+std::vector<HierarchyNode *> *HierarchyInterface::GetRenderedNodes()
+{
+	return &mRenderedNodes;
+}
 
 } // namespace GtpVisibility
Index: trunk/VUT/GtpVisibility/src/QueryManager.cpp
===================================================================
--- trunk/VUT/GtpVisibility/src/QueryManager.cpp	(revision 71)
+++ trunk/VUT/GtpVisibility/src/QueryManager.cpp	(revision 130)
@@ -5,4 +5,5 @@
  
 QueryManager::QueryManager(HierarchyInterface *hierarchyInterface)
+:mHierarchyInterface(hierarchyInterface)
 {
 }
Index: trunk/VUT/GtpVisibility/src/VisibilityManager.cpp
===================================================================
--- trunk/VUT/GtpVisibility/src/VisibilityManager.cpp	(revision 114)
+++ trunk/VUT/GtpVisibility/src/VisibilityManager.cpp	(revision 130)
@@ -83,4 +83,13 @@
 	return mCullingManagerType;
 }
-
+//-----------------------------------------------------------------------
+void VisibilityManager::SetQueryManager(QueryManager *queryManager)
+{
+	mQueryManager = queryManager;
+}
+//-----------------------------------------------------------------------
+QueryManager *VisibilityManager::GetQueryManager()
+{
+	return mQueryManager;
+}
 } // namespace GtpVisibility
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());
 }
 //-----------------------------------------------------------------------
Index: trunk/VUT/Ogre/include/OgreVisibilityOptionsManager.h
===================================================================
--- trunk/VUT/Ogre/include/OgreVisibilityOptionsManager.h	(revision 114)
+++ trunk/VUT/Ogre/include/OgreVisibilityOptionsManager.h	(revision 130)
@@ -2,8 +2,10 @@
 #define _VisibilityOptionsManager_H__
 
+
+#include <OgreString.h>
+#include <OgreStringVector.h>
 #include "VisibilityManager.h"
 #include "HierarchyInterface.h"
-#include <OgreString.h>
-#include <OgreStringVector.h>
+
 
 namespace Ogre {
@@ -30,10 +32,10 @@
 		"Algorithm", "Threshold";			
 	*/
-	bool setOption( const String &, const void * );
+	bool setOption(const String &, const void *);
 	/** Gets the given option for the scene traverser.
 	    @remarks
 	    See setOption
 	*/
-	bool getOption( const String &, void * );
+	bool getOption(const String &, void *);
 	bool getOptionKeys( StringVector &refKeys );
 	
Index: trunk/VUT/Ogre/include/OgreSceneContentGenerator.h
===================================================================
--- trunk/VUT/Ogre/include/OgreSceneContentGenerator.h	(revision 107)
+++ trunk/VUT/Ogre/include/OgreSceneContentGenerator.h	(revision 130)
@@ -37,13 +37,18 @@
 	void SetScale(Vector3 scale);
 	
-	/** the number of created objects */
+	/** The number of created objects */
 	int GetObjectCount();
 
-	/** writes scene nodes to file */
+	/** Writes scene nodes to file */
 	bool WriteObjects(const std::string &filename);
 
-	/** loads scene nodes from file */
+	/** Loads scene nodes from file */
 	bool LoadObjects(const std::string &filename);
-
+	/** Generates a scene object with the specified parameters
+		@param position the position of the scene object
+		@param orientation the orientation of the scene object
+		@param objName the mesh name of the scene object
+		@returns the created scene object
+	*/
 	SceneNode *GenerateSceneObject(const Vector3 &position, 
 		const Quaternion &orientation, const String &objName);
Index: trunk/VUT/Ogre/include/OgreOctreeHierarchyInterface.h
===================================================================
--- trunk/VUT/Ogre/include/OgreOctreeHierarchyInterface.h	(revision 112)
+++ trunk/VUT/Ogre/include/OgreOctreeHierarchyInterface.h	(revision 130)
@@ -3,5 +3,6 @@
 
 #include <OgreOctree.h>
-#include "OgrePlatformHierarchyInterface.h"
+#include <OgreOctreeSceneManager.h>
+#include "OgreSceneNodeHierarchyInterface.h"
 
 namespace Ogre {
@@ -9,8 +10,8 @@
 	This class implements the hierarchy interface for the Ogre octree hierarchy.
 */
-class OctreeHierarchyInterface : public PlatformHierarchyInterface
+class OctreeHierarchyInterface : public SceneNodeHierarchyInterface
 {
 public:
-	OctreeHierarchyInterface(SceneManager *sm, RenderSystem *rsys);
+	OctreeHierarchyInterface(OctreeSceneManager *sm, RenderSystem *rsys);
 	
 	/** Sets the number of nodes in this octree 
@@ -46,4 +47,11 @@
 							 GtpVisibility::CullingType type);
 
+	/*bool FindVisibleObjects(GtpVisibility::HierarchyNode *node,	
+							InfoContainer<GtpVisibility::MeshInfo> *visibleGeometry, 
+							bool includeChildren = false);*/
+	void GetGeometry(GtpVisibility::HierarchyNode *node,
+					 GtpVisibility::GeometryList *geometryList, 
+					 bool includeChildren);
+
 protected:
 	/** Returns pointer to the bounding box of the node.
@@ -57,4 +65,5 @@
 	*/
 	Real GetSquaredViewDepth(const Camera* cam, const AxisAlignedBox* box) const;
+	/** number of octree hierarchy nodes */
 	unsigned int mNumOctreeNodes;
 };
Index: trunk/VUT/Ogre/include/OgreVisibilityOctreeSceneManager.h
===================================================================
--- trunk/VUT/Ogre/include/OgreVisibilityOctreeSceneManager.h	(revision 122)
+++ trunk/VUT/Ogre/include/OgreVisibilityOctreeSceneManager.h	(revision 130)
@@ -65,4 +65,6 @@
 	/** Creates material for depth pass, e.g., a pass that only fills the depth buffer */
 	void InitDepthPass();
+	
+	/** Prepares visualization of hierarchical culling. */
 	void ShowVisualization(Camera *cam);
 	OctreeHierarchyInterface *mHierarchyInterface;
Index: trunk/VUT/Ogre/include/OgreSceneNodeHierarchyInterface.h
===================================================================
--- trunk/VUT/Ogre/include/OgreSceneNodeHierarchyInterface.h	(revision 112)
+++ trunk/VUT/Ogre/include/OgreSceneNodeHierarchyInterface.h	(revision 130)
@@ -3,4 +3,7 @@
 
 #include "OgrePlatformHierarchyInterface.h"
+#include "VisibilityInfo.h"
+#include "QueryManager.h"
+
 
 namespace Ogre {
@@ -38,4 +41,12 @@
 	void VisualizeCulledNode(GtpVisibility::HierarchyNode *node, 
 							GtpVisibility::CullingType type);
+
+	/*bool FindVisibleObjects(GtpVisibility::HierarchyNode *node,	
+							InfoContainer<GtpVisibility::MeshInfo> *visibleGeometry, 
+							bool includeChildren = false);*/
+	
+	void GetGeometry(GtpVisibility::HierarchyNode *node,	
+					 GtpVisibility::GeometryList *geometryList, 
+					 bool includeChildren);
 };
 
Index: trunk/VUT/Ogre/include/OgrePlatformHierarchyInterface.h
===================================================================
--- trunk/VUT/Ogre/include/OgrePlatformHierarchyInterface.h	(revision 121)
+++ trunk/VUT/Ogre/include/OgrePlatformHierarchyInterface.h	(revision 130)
@@ -10,4 +10,5 @@
 #include "OgreSolidBoundingBox.h"
 #include "HierarchyInterface.h"
+#include "VisibilityInfo.h"
 #include "OgrePlatformOcclusionQuery.h"
 
@@ -51,5 +52,6 @@
 		@remark If null, the actual camera is used for both viewing and culling		
 	*/
-	void InitFrame(GtpVisibility::HierarchyNode *root, Camera *cam, Camera *cullCam = NULL, bool leaveTransparentsInQueue = false);
+	void InitFrame(GtpVisibility::HierarchyNode *root, Camera *cam, Camera *cullCam = NULL, 
+		bool leaveTransparentsInQueue = false);
 	/** Checks if the node is visible from the current view frustum.
 		@param node the current node
@@ -78,19 +80,61 @@
 		GtpVisibility::HierarchyNode *node, const bool wasVisible);
 
+	/** Issue a occlusion query for this mesh.
+		@param node the current mesh
+		@returns occlusion query for this node
+	*/
+	GtpVisibility::OcclusionQuery *IssueOcclusionQuery(GtpVisibility::Mesh *mesh);
+
 	/** If true, the interface finds and renders only objects which are marked as shadow casters.
 		@remark This is important for the shadow texture pass
 	*/
 	void SetOnlyShadowCasters(bool onlyShadowCasters);
-	/** see set */
+	/** see set 
+	*/
 	bool GetOnlyShadowCasters();
-	/** see set */
+	/** see set 
+	*/
 	bool GetUseOptimization();
+	/** see set
+	*/
+	SceneManager *GetSceneManager();
 
-	/** true if bounding box query is currently active. */
+	/** see set 
+	*/
+	RenderSystem *GetRenderSystem();
+	
+	/** true if bounding box query is currently active. 
+	*/
     bool IsBoundingBoxQuery();
 
+	/** Finds visible objects of hierarchy node using occlusion queries
+	@param node the current scene node
+	@param objs the visible objects
+	@param includeChildren if the children of current scene nodes should also be traversed
+	*/
+	/*virtual bool FindVisibleObjects(GtpVisibility::HierarchyNode *node,	
+									InfoContainer<GtpVisibility::MeshInfo> *visibleGeometry, 
+									bool includeChildren = false) = 0;*/
 protected:
-	/** materials for visualizing frustum and query culled nodes */
+	/** Renders geometry 
+	*/
+	void RenderGeometry(GtpVisibility::Mesh *geom);
+
+	/** Materials for visualizing frustum and query culled nodes.
+	*/
 	void CreateNodeVizMaterials();
+
+	/** Deletes all occlusion queries.
+	*/
+	void DeleteQueries();
+	
+	/** Renders bounding box of specified node.
+		@param box the bounding box of the scene node to be rendered 
+	*/
+	void RenderBoundingBox(AxisAlignedBox *box);
+
+	/** Returns pointer to current renderable bounding box geometry.
+	*/
+	SolidBoundingBox *GetSolidBoundingBox();
 
 	/** A pass that prepares an occlusion query.
@@ -98,23 +142,10 @@
 		vertex and fragment program.
 	*/
-	void SetOcclusionPass();
+	//void SetOcclusionPass();
 
-	/** Deletes all occlusion queries.
-	*/
-	void DeleteQueries();
-	/** Renders bounding box of specified node.
-		@param box the bounding box of the scene node to be rendered 
-	*/
-	void RenderBoundingBox(AxisAlignedBox *box);
-
-	/** Returns pointer to current renderable bounding box geometry
-	*/
-	SolidBoundingBox *GetSolidBoundingBox();
-
-	/** Returns pointer to current renderable half bounding box geometry
-	*/
+	/** Returns pointer to current renderable half bounding box geometry.*/
 	//SolidHalfBoundingBox *GetSolidHalfBoundingBox();
 
-	/** Renderable of an aabb
+	/** Renderable of an aabb.
 	*/
 	SolidBoundingBox *mSolidBoundingBox;
Index: trunk/VUT/Ogre/include/OgreVisibilityTerrainSceneManager.h
===================================================================
--- trunk/VUT/Ogre/include/OgreVisibilityTerrainSceneManager.h	(revision 129)
+++ trunk/VUT/Ogre/include/OgreVisibilityTerrainSceneManager.h	(revision 130)
@@ -9,4 +9,5 @@
 
 #include "OgreOctreeHierarchyInterface.h"
+#include "OgrePlatformQueryManager.h"
 #include "VisibilityManager.h"
 
@@ -17,5 +18,5 @@
 	using occlusion queries for visibility culling.
 */
-class VisibilityTerrainSceneManager: public TerrainSceneManager
+class __declspec(dllexport) VisibilityTerrainSceneManager: public TerrainSceneManager
 {
 public:
@@ -74,4 +75,7 @@
 	Entity* createEntity(const String& entityName, const String& meshName);
 
+	/** Returns pointer to visibility manager */
+	GtpVisibility::VisibilityManager *GetVisibilityManager();
+
 protected:
 	
@@ -101,4 +105,6 @@
 
 	int mCurrentEntityId;
+
+	PlatformQueryManager *mQueryManager;
 };
 
Index: trunk/VUT/Ogre/include/OgreTerrainContentGenerator.h
===================================================================
--- trunk/VUT/Ogre/include/OgreTerrainContentGenerator.h	(revision 110)
+++ trunk/VUT/Ogre/include/OgreTerrainContentGenerator.h	(revision 130)
@@ -35,5 +35,5 @@
 	*/
 	SceneNode *GenerateSceneObject(const Vector3 &position, 
-		const Vector3 &rotation, const String &objName);
+		const Vector3 &rotation, const String &objName, const bool clampToTerrain = true);
 	
 	/** offset which is added to objects when put into the terrain */
Index: trunk/VUT/Ogre/scripts/Plugin_VisibilitySceneManager.vcproj
===================================================================
--- trunk/VUT/Ogre/scripts/Plugin_VisibilitySceneManager.vcproj	(revision 115)
+++ trunk/VUT/Ogre/scripts/Plugin_VisibilitySceneManager.vcproj	(revision 130)
@@ -93,4 +93,5 @@
 				BufferSecurityCheck="FALSE"
 				EnableFunctionLevelLinking="TRUE"
+				RuntimeTypeInfo="TRUE"
 				UsePrecompiledHeader="0"
 				WarningLevel="3"
@@ -196,4 +197,7 @@
 				</File>
 				<File
+					RelativePath="..\include\OgrePlatformQueryManager.h">
+				</File>
+				<File
 					RelativePath="..\include\OgreSceneContentGenerator.h">
 				</File>
@@ -222,4 +226,7 @@
 				<File
 					RelativePath="..\src\OgrePlatformOcclusionQuery.cpp">
+				</File>
+				<File
+					RelativePath="..\src\OgrePlatformQueryManager.cpp">
 				</File>
 				<File
Index: trunk/VUT/Ogre/src/OgreSceneNodeHierarchyInterface.cpp
===================================================================
--- trunk/VUT/Ogre/src/OgreSceneNodeHierarchyInterface.cpp	(revision 115)
+++ trunk/VUT/Ogre/src/OgreSceneNodeHierarchyInterface.cpp	(revision 130)
@@ -1,6 +1,11 @@
-#include "OgreSceneNodeHierarchyInterface.h"
 #include <OgreIteratorWrappers.h>
 #include <OgreCamera.h>
 #include <OgreSceneNode.h>
+#include <OgreEntity.h>
+#include <OgreSubEntity.h>
+#include <OgreLogManager.h>
+#include "OgreSceneNodeHierarchyInterface.h"
+#include "OgrePlatformOcclusionQuery.h"
+
 
 namespace Ogre {
@@ -40,5 +45,5 @@
 	{
 		sceneNode->setLastRendered(sceneNode->lastVisited());
-		mNumRenderedNodes ++;
+		mRenderedNodes.push_back(node);
 
 		mSceneManager->_renderSceneNode(mCamera, sceneNode, mLeaveTransparentsInQueue);
@@ -130,3 +135,25 @@
 	// TODO
 }
+//-----------------------------------------------------------------------
+void SceneNodeHierarchyInterface::GetGeometry(GtpVisibility::HierarchyNode *node,	
+											  GtpVisibility::GeometryList *geometryList, 
+											  bool includeChildren)
+{
+	SceneNode::ObjectIterator objIt = 
+		static_cast<SceneNode *>(node)->getAttachedObjectIterator();
+
+	while (objIt.hasMoreElements())
+    {
+		MovableObject *movable = objIt.getNext();
+		
+		// we are interested only in the entities, i.e., intances of geometry
+		if (movable->getMovableType() == "Entity")
+		{
+			Entity *ent = static_cast<Entity *>(movable);
+			//std::stringstream d; d << "ent " << ent->getName(); 
+			//LogManager::getSingleton().logMessage(d.str());
+			geometryList->push_back(ent);
+		}
+    }
+}
 } // namespace Ogre	
Index: trunk/VUT/Ogre/src/OgreVisibilityTerrainSceneManager.cpp
===================================================================
--- trunk/VUT/Ogre/src/OgreVisibilityTerrainSceneManager.cpp	(revision 129)
+++ trunk/VUT/Ogre/src/OgreVisibilityTerrainSceneManager.cpp	(revision 130)
@@ -24,9 +24,11 @@
 mDelayRenderTransparents(true),
 mUseDepthPass(false),
-mRenderItemBuffer(true),
+mRenderItemBuffer(false),
 mCurrentEntityId(0)
 {
 	mHierarchyInterface = new OctreeHierarchyInterface(this, mDestRenderSystem);
-
+	mQueryManager = new PlatformQueryManager(mHierarchyInterface, mCurrentViewport);
+
+	mVisibilityManager->SetQueryManager(mQueryManager);
 	//mDisplayNodes = true;
 	//mShowBoundingBoxes = true;
@@ -87,9 +89,13 @@
 		mHierarchyInterface = NULL;
 	}
+	if (mQueryManager)
+	{
+		delete mQueryManager;
+		mQueryManager = NULL;
+	}
 }
 //-----------------------------------------------------------------------
 void VisibilityTerrainSceneManager::ShowVisualization(Camera *cam)
 {
-	LogManager::getSingleton().logMessage("***********VISUALIZATION************");
 	// add player camera for visualization purpose
 	try 
@@ -189,7 +195,5 @@
 		setAmbientLight(ColourValue(1,1,1,1));
 	}
-
-	LogManager::getSingleton().logMessage("***********FIND OBJECTS************");
-	getRenderQueue()->clear();
+	//getRenderQueue()->clear();
 
 	//-- show visible scene nodes and octree bounding boxes from last frame
@@ -221,9 +225,4 @@
 void VisibilityTerrainSceneManager::_renderVisibleObjects()
 {
-	/*
-	std::stringstream d;
-	d << "Terrain render level: " << TerrainRenderable::getCurrentRenderLevelIndex();
-	LogManager::getSingleton().logMessage(d.str());
-
 	// increase terrain renderlevel
 	int renderLevel = TerrainRenderable::getCurrentRenderLevelIndex() + 1;
@@ -233,14 +232,12 @@
 		renderLevel = 0;
 	}
-*/
+
 	// visualization: apply standard rendering
 	if (mShowVisualization)
 	{	
 		TerrainSceneManager::_renderVisibleObjects();
-	//	TerrainRenderable::setCurrentRenderLevelIndex(renderLevel);
+		TerrainRenderable::setCurrentRenderLevelIndex(renderLevel);
 		return;
 	}
-
-	LogManager::getSingleton().logMessage("***********RENDER OBJECTS************");
 
 	InitDepthPass(); 	// create material for depth pass
@@ -309,5 +306,5 @@
 	TerrainSceneManager::_renderVisibleObjects();
 
-	//TerrainRenderable::setCurrentRenderLevelIndex(renderLevel);
+	TerrainRenderable::setCurrentRenderLevelIndex(renderLevel);
 	//WriteLog(); // write out stats
 }
@@ -374,9 +371,9 @@
 	// notifiy that frame has ended so terrain render level can be reset for correct
 	// terrain rendering
-/*	if (key == "TerrainLevelIdx")
+	if (key == "TerrainLevelIdx")
 	{
 		TerrainRenderable::setCurrentRenderLevelIndex((*static_cast<const int *>(val)));
 		return true;
-	}*/
+	}
 	return VisibilityOptionsManager(mVisibilityManager, mHierarchyInterface).
 		setOption(key, val) || TerrainSceneManager::setOption(key, val);
@@ -507,5 +504,5 @@
 				//<< ", renderable name: " << irend->
 				RenderSingleObjectForItemBuffer(*irend, ipass->first);
-				RenderSingleObjectForOcclusionQuery(
+				//RenderSingleObjectForOcclusionQuery(
 		}
 	}
@@ -562,5 +559,5 @@
 	//LogManager::getSingleton().logMessage("has vertex program");
 	Pass *usedPass = setPass(mItemBufferPass); 
-//Pass *usedPass = setPass(pass);
+	//Pass *usedPass = setPass(pass);
 	std::stringstream d;
 	d << "item buffer id: " << rend->getId() << ", col: " << col;
@@ -571,9 +568,15 @@
 }
 //-----------------------------------------------------------------------
-Entity* VisibilityTerrainSceneManager::createEntity(const String& entityName, const String& meshName)
+GtpVisibility::VisibilityManager *VisibilityTerrainSceneManager::GetVisibilityManager()
+{
+	return mVisibilityManager;
+}
+//-----------------------------------------------------------------------
+Entity* VisibilityTerrainSceneManager::createEntity(const String& entityName, 
+													const String& meshName)
 {
 	Entity *ent = SceneManager::createEntity(entityName, meshName);
 
-	for (int i = 0; i < ent->getNumSubEntities(); ++i)
+	for (int i = 0; i < (int)ent->getNumSubEntities(); ++i)
 	{
 		ent->getSubEntity(i)->setId(mCurrentEntityId ++);
Index: trunk/VUT/Ogre/src/OgreSceneContentGenerator.cpp
===================================================================
--- trunk/VUT/Ogre/src/OgreSceneContentGenerator.cpp	(revision 121)
+++ trunk/VUT/Ogre/src/OgreSceneContentGenerator.cpp	(revision 130)
@@ -186,3 +186,4 @@
 	return true;
 }
+
 } // namespace Ogre
Index: trunk/VUT/Ogre/src/OgreOctreeHierarchyInterface.cpp
===================================================================
--- trunk/VUT/Ogre/src/OgreOctreeHierarchyInterface.cpp	(revision 115)
+++ trunk/VUT/Ogre/src/OgreOctreeHierarchyInterface.cpp	(revision 130)
@@ -9,6 +9,6 @@
 
 //-----------------------------------------------------------------------
-OctreeHierarchyInterface::OctreeHierarchyInterface(SceneManager *sm, RenderSystem *rsys): 
-PlatformHierarchyInterface(sm, rsys)
+OctreeHierarchyInterface::OctreeHierarchyInterface(OctreeSceneManager *sm, RenderSystem *rsys): 
+SceneNodeHierarchyInterface(sm, rsys)
 {
 }
@@ -106,8 +106,8 @@
 		octant->setLastRendered(mFrameId);
 
-		static_cast<OctreeSceneManager *>(mSceneManager)->_renderOctant(mCamera, 
+		dynamic_cast<OctreeSceneManager *>(mSceneManager)->_renderOctant(mCamera, 
 			octant, mOnlyShadowCasters, mLeaveTransparentsInQueue);
 
-		mNumRenderedNodes ++;
+		mRenderedNodes.push_back(node);
 	}
 #endif
@@ -157,5 +157,46 @@
 	}
 
-	static_cast<OctreeSceneManager *>(mSceneManager)->getBoxes()->push_back(box);
-}
+	dynamic_cast<OctreeSceneManager *>(mSceneManager)->getBoxes()->push_back(box);
+}
+//-----------------------------------------------------------------------
+void OctreeHierarchyInterface::GetGeometry(GtpVisibility::HierarchyNode *node,	
+										   GtpVisibility::GeometryList *geometryList, 
+										   bool includeChildren)
+{
+	NodeList::const_iterator nodeIt, nodeIt_end;
+	nodeIt_end = static_cast<Octree *>(node)->mNodes.end();
+
+	for (nodeIt = static_cast<Octree *>(node)->mNodes.begin(); nodeIt != nodeIt_end; ++nodeIt)
+	{
+		SceneNodeHierarchyInterface::GetGeometry(*nodeIt, geometryList, includeChildren);
+	}
+}
+//-----------------------------------------------------------------------
+/*bool OctreeHierarchyInterface::FindVisibleObjects(GtpVisibility::HierarchyNode *node,	
+									InfoContainer<GtpVisibility::MeshInfo> *visibleGeometry, 
+									bool includeChildren)
+{
+	bool foundVisible = false;
+
+	PlatformOcclusionQuery query(mRenderSystem);
+
+	NodeList *nodes = &static_cast<Octree *>(node)->mNodes;
+	
+	NodeList::const_iterator nodeIt = nodes->begin(), nodeIt_end;
+	
+	nodeIt_end = nodes->end();
+
+	while (nodeIt != nodeIt_end)
+	{
+		OctreeNode *octreeNode = (*nodeIt);
+		if (SceneNodeHierarchyInterface::FindVisibleObjects(octreeNode, visibleGeometry, includeChildren))
+		{
+			foundVisible = true;
+		}
+		++nodeIt;
+	}
+
+	return foundVisible;
+}*/
+
 } // namespace Ogre
Index: trunk/VUT/Ogre/src/OgrePlatformHierarchyInterface.cpp
===================================================================
--- trunk/VUT/Ogre/src/OgrePlatformHierarchyInterface.cpp	(revision 122)
+++ trunk/VUT/Ogre/src/OgrePlatformHierarchyInterface.cpp	(revision 130)
@@ -1,4 +1,7 @@
 #include <OgreCamera.h>
 #include <OgreLogManager.h>
+#include <OgreSubEntity.h>
+#include <OgreEntity.h>
+#include <OgreMovableObject.h>
 #include "OgreSolidBoundingBox.h"
 #include "OgrePlatformHierarchyInterface.h"
@@ -138,6 +141,6 @@
 	mCullCamera = cullCam ? cullCam : cam;
 
-	if (mCullCamera != mCamera)
-		LogManager::getSingleton().logMessage("cullcamera is not camera!");
+	//if (mCullCamera != mCamera)
+	//	LogManager::getSingleton().logMessage("cullcamera is not camera");
 
 	// create materials for node visualization
@@ -186,4 +189,5 @@
 	{
 		mIsBoundingBoxQuery = true;
+
 		//LogManager::getSingleton().logMessage("render box\n");
 		RenderBoundingBox(GetBoundingBox(node));
@@ -197,5 +201,20 @@
 }
 //-----------------------------------------------------------------------
-void PlatformHierarchyInterface::SetOcclusionPass()
+GtpVisibility::OcclusionQuery *PlatformHierarchyInterface::IssueOcclusionQuery(GtpVisibility::Mesh *mesh)
+{
+	// get next available test id
+	GtpVisibility::OcclusionQuery *query = GetNextOcclusionQuery();
+
+	//-- the actual query test
+	query->BeginQuery();
+	
+	RenderGeometry(mesh);
+
+	query->EndQuery();
+
+	return query;
+}
+//-----------------------------------------------------------------------
+/*void PlatformHierarchyInterface::SetOcclusionPass()
 {
     // disable vertex and fragment program
@@ -215,5 +234,5 @@
 	// Set colour write mode off
 	mRenderSystem->_setColourBufferWriteEnabled(false, false, false, false);
-}
+}*/
 //-----------------------------------------------------------------------
 SolidBoundingBox *PlatformHierarchyInterface::GetSolidBoundingBox()
@@ -228,5 +247,4 @@
 {
 	mOnlyShadowCasters = onlyShadowCasters;
-	//mIsShadowPass = mOnlyShadowCasters ;
 }
 //-----------------------------------------------------------------------
@@ -245,3 +263,18 @@
 	return mIsBoundingBoxQuery;
 }
+//-----------------------------------------------------------------------
+void PlatformHierarchyInterface::RenderGeometry(GtpVisibility::Mesh *geom)
+{
+	mSceneManager->_renderMovableObject(geom, mLeaveTransparentsInQueue);
+}
+//-----------------------------------------------------------------------
+SceneManager *PlatformHierarchyInterface::GetSceneManager()
+{
+	return mSceneManager;
+}
+//-----------------------------------------------------------------------
+RenderSystem *PlatformHierarchyInterface::GetRenderSystem()
+{
+	return mRenderSystem;
+}
 } // namespace Ogre
Index: trunk/VUT/Ogre/src/OgreTerrainContentGenerator.cpp
===================================================================
--- trunk/VUT/Ogre/src/OgreTerrainContentGenerator.cpp	(revision 111)
+++ trunk/VUT/Ogre/src/OgreTerrainContentGenerator.cpp	(revision 130)
@@ -68,9 +68,14 @@
 //-----------------------------------------------------------------------
 SceneNode *TerrainContentGenerator::GenerateSceneObject(const Vector3 &position, 
-					 const Vector3 &rotation, const String& objName)
+					 const Vector3 &rotation, const String& objName, const bool clampToTerrain)
 {
 	Vector3 queryResult;
 	// set y to max height so we are sure to be over terrain
 	Vector3 pos(position.x, MAX_HEIGHT, position.z);
+
+	if (!clampToTerrain)
+	{
+		return SceneContentGenerator::GenerateSceneObject(queryResult, rotation, objName);
+	}
 
 	if (mRayQueryExecutor->executeRayQuery(&queryResult, position, Vector3::NEGATIVE_UNIT_Y))
