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))
