Index: trunk/VUT/Ogre/include/OgreTerrainContentGenerator.h
===================================================================
--- trunk/VUT/Ogre/include/OgreTerrainContentGenerator.h	(revision 130)
+++ trunk/VUT/Ogre/include/OgreTerrainContentGenerator.h	(revision 135)
@@ -32,8 +32,14 @@
 
 	/** 
-		Generates objects and places it on the terrain
+		Generates objects and places it on the terrain.
 	*/
 	SceneNode *GenerateSceneObject(const Vector3 &position, 
-		const Vector3 &rotation, const String &objName, const bool clampToTerrain = true);
+		const Vector3 &rotation, const String &objName);
+	/** 
+		Generates objects and optionally places it on the terrain.
+		@param clampToTerrain if true, scene object is clamped to the terrain
+	*/
+	SceneNode *GenerateSceneObject(const Vector3 &position, 
+		const Vector3 &rotation, const String &objName, const bool clampToTerrain);
 	
 	/** offset which is added to objects when put into the terrain */
Index: trunk/VUT/Ogre/src/OgreVisibilityTerrainSceneManager.cpp
===================================================================
--- trunk/VUT/Ogre/src/OgreVisibilityTerrainSceneManager.cpp	(revision 134)
+++ trunk/VUT/Ogre/src/OgreVisibilityTerrainSceneManager.cpp	(revision 135)
@@ -274,5 +274,4 @@
 	TerrainSceneManager::_renderVisibleObjects();
 
-
 #ifdef GTP_VISIBILITY_MODIFIED_OGRE
 	_deleteRenderedQueueGroups(false);
@@ -300,4 +299,8 @@
 	mVisibilityManager->ApplyVisibilityCulling();
 
+	// delete remaining renderables from queue (or all but transparents)
+#ifdef GTP_VISIBILITY_MODIFIED_OGRE
+	_deleteRenderedQueueGroups(mSkipTransparents);
+#endif
 
 	// for depth pass: add visible nodes found with the visibility culling
@@ -320,4 +323,5 @@
 
 	TerrainRenderable::setCurrentRenderLevelIndex(renderLevel);
+	getRenderQueue()->clear();
 	//WriteLog(); // write out stats
 }
Index: trunk/VUT/Ogre/src/OgreOctreeHierarchyInterface.cpp
===================================================================
--- trunk/VUT/Ogre/src/OgreOctreeHierarchyInterface.cpp	(revision 130)
+++ trunk/VUT/Ogre/src/OgreOctreeHierarchyInterface.cpp	(revision 135)
@@ -137,5 +137,6 @@
 	{
 		mPreviousNode = node;
-		static_cast<Octree *>(node)->_getCullBounds(&mBox);
+	//	static_cast<Octree *>(node)->_getCullBounds(&mBox);
+		mBox = static_cast<Octree *>(node)->_getWorldAABB();
 	}
 
Index: trunk/VUT/Ogre/src/OgrePlatformHierarchyInterface.cpp
===================================================================
--- trunk/VUT/Ogre/src/OgrePlatformHierarchyInterface.cpp	(revision 133)
+++ trunk/VUT/Ogre/src/OgrePlatformHierarchyInterface.cpp	(revision 135)
@@ -188,6 +188,6 @@
 	else
 	{
-		// used by the scene manager, because bounding box rendering must be handled
-		// differently
+		// this information is used e.g., by the scene graph, because the bounding box
+		// must be treated differently to the scene geometry during rendering
 		mIsBoundingBoxQuery = true;
 
Index: trunk/VUT/Ogre/src/OgrePlatformQueryManager.cpp
===================================================================
--- trunk/VUT/Ogre/src/OgrePlatformQueryManager.cpp	(revision 134)
+++ trunk/VUT/Ogre/src/OgrePlatformQueryManager.cpp	(revision 135)
@@ -25,9 +25,4 @@
 			    bool relativeVisibility)
 {
-	if (relativeVisibility)
-		LogManager::getSingleton().logMessage("relative");
-	else
-		LogManager::getSingleton().logMessage("absolute");
-
 	// we need access to the scene manager and the rendersystem
 	PlatformHierarchyInterface *pfHierarchyInterface = 
@@ -39,4 +34,6 @@
 	Camera *pCam = const_cast<Camera *>(&camera); 
 
+	bool overlayEnabled = mViewport->getOverlaysEnabled();
+	mViewport->setOverlaysEnabled(false);
 	pfHierarchyInterface->GetSceneManager()->_renderScene(pCam, mViewport, false);
 
@@ -53,8 +50,21 @@
 	GtpVisibility::GeometryList geometryList;
 	
-	GtpVisibility::HierarchyNodeList::const_iterator nodeIt, nodeIt_end = nodeList->end();
+	GtpVisibility::HierarchyNodeList::iterator nodeIt, nodeIt_end = nodeList->end();
 	// geometry list has still do be built
 	GtpVisibility::GeometryList::iterator geometryIt, geometryIt_end;
 
+	// to obtain the correct number of projected pixels, depth write must be disabled
+
+	bool enableDepthWrite = false;
+	// this option must be provided by the scene manager
+	pfHierarchyInterface->GetSceneManager()->setOption("DepthWrite", &enableDepthWrite);
+
+	/* relative visiblity:
+		1) get visible pixels count of objects
+		2) clear frame buffer
+		3) get projected visible pixels count:
+		   test all objects again without depth write (set as option in scene manager)
+		4) calculate ratio between visible vs. projected pixels
+	*/
 	// for relative visibility we need 2 rendering passes
 	int n = relativeVisibility ? 2 : 1;
@@ -63,5 +73,5 @@
 	{
 		//-- queries for hierarchy nodes
-		for (nodeIt = nodeList->begin(); nodeIt != nodeIt_end; ++nodeIt)
+		for (nodeIt = nodeList->begin(); nodeIt != nodeIt_end; ++nodeIt)		
 		{
 			// TODO: DELETE QUERIES FROM PREVIOUS RENDER
@@ -69,5 +79,5 @@
 			
 			// store geometry of the hierarchy node in a geometry list (only once!)
-			if (i == n - 2)
+			if (i == 0)
 			{
 				mHierarchyInterface->GetGeometry(*nodeIt, &geometryList, false);
@@ -83,27 +93,16 @@
 		}
 
-		// --- relative visiblity
-		/* 
-			1) get visible pixels count of objects
-			2) clear frame buffer
-			3) get projected visible pixels count:
-			   test all objects again without depth write (set as option in scene manager)
-			4) calculate ratio between visible vs. projected pixels
-		*/
-		if (i == n - 2) // if relativeVisibility, between first and second loop
-		{
-			pfHierarchyInterface->GetRenderSystem()->clearFrameBuffer(FBT_COLOUR | FBT_DEPTH);
-		}
-
-		// to obtain the correct number of projected pixels, depth write must be disabled
-		bool enableDepthWrite = (i != n - 2);
-
-		// this option must be provided by the scene manager
-		pfHierarchyInterface->GetSceneManager()->setOption("DepthWrite", &enableDepthWrite);
+	
+		pfHierarchyInterface->GetRenderSystem()->clearFrameBuffer(FBT_DEPTH);
 	}
 
+	enableDepthWrite = true;
+	// this option must be provided by the scene manager
+	pfHierarchyInterface->GetSceneManager()->setOption("DepthWrite", &enableDepthWrite);
+	
+	mViewport->setOverlaysEnabled(overlayEnabled);
 
 	//---- collect results
-	unsigned int visiblePixels;
+	unsigned int visiblePixels = 0;
 
 	GtpVisibility::QueryList::iterator visQueryIt, projQueryIt;
@@ -111,9 +110,11 @@
 	visQueryIt = queryList[0].begin();
 	projQueryIt = queryList[1].begin();
+
 	
 	for (nodeIt = nodeList->begin(); nodeIt != nodeIt_end; ++nodeIt)
 	{
 		(*visQueryIt)->GetQueryResult(visiblePixels, true);
-
+	
+		
 		float vis = (float)visiblePixels;
 
@@ -121,7 +122,5 @@
 		{
 			(*projQueryIt)->GetQueryResult(visiblePixels, true);
-			std::stringstream d; d << "relativ " << visiblePixels;
-			LogManager::getSingleton().logMessage(d.str());
-
+	
 			if (visiblePixels > 0)
 			{				
@@ -132,5 +131,5 @@
 
 		++visQueryIt;
-
+		
 		// leave nodes with visibilty 0 in queue: 
 		// happens if node is intersected by near plane
@@ -141,7 +140,8 @@
 	geometryIt_end = geometryList.end();
 	
-	/*for (geometryIt = geometryList.begin(); geometryIt != geometryIt_end; ++geometryIt)
+	for (geometryIt = geometryList.begin(); geometryIt != geometryIt_end; ++geometryIt)
 	{
-		(*absQueryIt)->GetQueryResult(visiblePixels, true);
+		(*visQueryIt)->GetQueryResult(visiblePixels, true);
+		
 
 		float vis = (float)visiblePixels;
@@ -150,5 +150,5 @@
 		if (relativeVisibility)
 		{
-			(*relQueryIt)->GetQueryResult(visiblePixels, true);
+			(*projQueryIt)->GetQueryResult(visiblePixels, true);
 
 			if (visiblePixels)
@@ -156,8 +156,8 @@
 				vis /= (float) visiblePixels;
 			}
-			++relQueryIt;
+			++projQueryIt;
 		}
 
-		++absQueryIt;
+		++visQueryIt;
 
 		// approximate depth ordering during rendering => 
@@ -167,5 +167,5 @@
 			visibleGeometry->push_back(GtpVisibility::MeshInfo(*geometryIt, vis));
 		}
-	}*/
+	}
 
 }
@@ -176,5 +176,5 @@
 			       bool relativeVisibility)
 {
-	 visibleNodes->push_back(GtpVisibility::NodeInfo(mHierarchyInterface->GetSceneRoot(), 1.0f));
+	
 }
 //-----------------------------------------------------------------------
Index: trunk/VUT/Ogre/src/OgreTerrainContentGenerator.cpp
===================================================================
--- trunk/VUT/Ogre/src/OgreTerrainContentGenerator.cpp	(revision 130)
+++ trunk/VUT/Ogre/src/OgreTerrainContentGenerator.cpp	(revision 135)
@@ -70,12 +70,21 @@
 					 const Vector3 &rotation, const String& objName, const bool clampToTerrain)
 {
+	
+	if (clampToTerrain)
+	{
+		return GenerateSceneObject(position, rotation, objName);
+	}
+	else
+	{
+		return SceneContentGenerator::GenerateSceneObject(position, rotation, objName);
+	}
+}
+//-----------------------------------------------------------------------
+SceneNode *TerrainContentGenerator::GenerateSceneObject(const Vector3 &position, 
+					 const Vector3 &rotation, const String& objName)
+{
 	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))
Index: trunk/VUT/Ogre/resources/VisibilityDemo.overlay
===================================================================
--- trunk/VUT/Ogre/resources/VisibilityDemo.overlay	(revision 121)
+++ trunk/VUT/Ogre/resources/VisibilityDemo.overlay	(revision 135)
@@ -240,9 +240,10 @@
 }
 
+
 Example/Visibility/HelpOverlay
 {
 	zorder 600
 	// Stats block
-	container BorderPanel(Example/Visibility/HelpPanel)
+	container BorderPanel(Example/Visibility/Help/HelpPanel)
 	{
 		metrics_mode pixels
@@ -250,5 +251,5 @@
 		vert_align top
 		width 600
-		height 315
+		height 300
 		left 200
 		top 200
@@ -276,5 +277,5 @@
 		}
 
-		element TextArea(Example/Visibility/Help/Help)
+		element TextArea(Example/Visibility/Help/HelpOptions)
 		{
 			metrics_mode pixels
@@ -293,5 +294,5 @@
 		{
 			left 5
-			top 40
+			top 30
 			width 180
 			height 30
@@ -301,5 +302,5 @@
 		{
 			left 5
-			top 55
+			top 45
 			width 180
 			height 30
@@ -309,5 +310,5 @@
 		{
 			left 5
-			top 85
+			top 75
 			width 180
 			height 30
@@ -317,5 +318,5 @@
 		{
 			left 5
-			top 70
+			top 60
 			width 180
 			height 30
@@ -325,5 +326,5 @@
 		{
 			left 5
-			top 115
+			top 105
 			width 180
 			height 30
@@ -333,5 +334,5 @@
 		{
 			left 5
-			top 130
+			top 120
 			width 180
 			height 30
@@ -342,5 +343,5 @@
 		{
 			left 5
-			top 160
+			top 150
 			width 180
 			height 30
@@ -350,5 +351,5 @@
 		{
 			left 5
-			top 175
+			top 165
 			width 175
 			height 30
@@ -358,5 +359,5 @@
 		{
 			left 5
-			top 190
+			top 180
 			width 190
 			height 30
@@ -366,5 +367,5 @@
 		{
 			left 5
-			top 220
+			top 210
 			width 180
 			height 30
@@ -374,5 +375,5 @@
 		{
 			left 5
-			top 235
+			top 225
 			width 180
 			height 30
@@ -382,5 +383,5 @@
 		{
 			left 5
-			top 250
+			top 240
 			width 180
 			height 30
@@ -390,5 +391,5 @@
 		{
 			left 5
-			top 265
+			top 255
 			width 180
 			height 30
@@ -398,5 +399,5 @@
 		{
 			left 5
-			top 280
+			top 270
 			width 180
 			height 30
@@ -405,2 +406,144 @@
 	}
 }
+
+Example/Visibility/QueryOverlay
+{
+	zorder 650
+	// Stats block
+	container BorderPanel(Example/Visibility/Query/QueryPanel)
+	{
+		metrics_mode pixels
+		horz_align left
+		vert_align top
+		width 600
+		height 120
+		left 200
+		top 300
+		material Core/StatsBlockCenter
+		
+        	border_size 1 1 1 1
+        	border_material Core/StatsBlockBorder
+        	border_topleft_uv     0.0000 1.0000 0.0039 0.9961
+	    	border_top_uv         0.0039 1.0000 0.9961 0.9961
+	    	border_topright_uv    0.9961 1.0000 1.0000 0.9961
+	    	border_left_uv        0.0000 0.9961 0.0039 0.0039
+	    	border_right_uv       0.9961 0.9961 1.0000 0.0039
+	    	border_bottomleft_uv  0.0000 0.0039 0.0039 0.0000
+        	border_bottom_uv      0.0039 0.0039 0.9961 0.0000
+	    	border_bottomright_uv 0.9961 0.0039 1.0000 0.0000
+
+		container Panel(Example/Visibility/Query/BreakPanel)
+		{
+			metrics_mode pixels
+			left 5 
+			top 22
+			width 590
+			height 1
+			material Core/StatsBreak
+		}
+
+		element TextArea(Example/Visibility/Query/Headline)
+		{
+			metrics_mode pixels
+			left 5
+			top 5
+			width 90
+			height 30
+			font_name TrebuchetMSBold
+			char_height 19
+			caption Exact Visibility Query
+			colour_top 1 1 0.7
+			colour_bottom 1 1 0.7
+		}
+
+		element TextArea(Example/Visibility/Query/QueryType): Example/Visibility/Templates/BasicText
+		{
+			left 5
+			top 30
+			width 90
+			height 30
+			caption Type
+		}
+		
+		
+		element TextArea(Example/Visibility/Query/QueryTypeInfo): Example/Visibility/Templates/BasicText
+		{
+			left 180
+			top 30
+			width 90
+			height 30
+			caption :
+		}
+
+		element TextArea(Example/Visibility/Query/VisibleNodes): Example/Visibility/Templates/BasicText
+		{
+			left 5
+			top 45
+			width 90
+			height 30
+			caption Visible nodes
+		}
+		element TextArea(Example/Visibility/Query/VisibleNodesInfo): Example/Visibility/Templates/BasicText
+		{
+			left 180
+			top 45
+			width 90
+			height 30
+			caption :
+		}
+
+		element TextArea(Example/Visibility/Query/VisibleGeometry): Example/Visibility/Templates/BasicText
+		{
+			left 5
+			top 60
+			width 90
+			height 30
+			caption Visible geometry
+		}
+		element TextArea(Example/Visibility/Query/VisibleGeometryInfo): Example/Visibility/Templates/BasicText
+		{
+			left 180
+			top 60
+			width 90
+			height 30
+			caption :
+		}
+
+		element TextArea(Example/Visibility/Query/NodeVisibility): Example/Visibility/Templates/BasicText
+		{
+			left 5
+			top 75
+			width 90
+			height 30
+			caption Avg. node visibility
+		}
+
+		element TextArea(Example/Visibility/Query/NodeVisibilityInfo): Example/Visibility/Templates/BasicText
+		{
+			left 180
+			top 75
+			width 90
+			height 30
+			caption:
+		}
+
+		element TextArea(Example/Visibility/Query/GeometryVisibility): Example/Visibility/Templates/BasicText
+		{
+			left 5
+			top 90
+			width 90
+			height 30
+			caption Avg. geometry visibility
+		}
+
+		element TextArea(Example/Visibility/Query/GeometryVisibilityInfo): Example/Visibility/Templates/BasicText
+		{
+			left 180
+			top 90
+			width 90
+			height 30
+			caption:
+		}
+
+	}
+}
