Index: trunk/VUT/work/TestCullingTerrain/TerrainFrameListener.cpp
===================================================================
--- trunk/VUT/work/TestCullingTerrain/TerrainFrameListener.cpp	(revision 159)
+++ trunk/VUT/work/TestCullingTerrain/TerrainFrameListener.cpp	(revision 160)
@@ -11,7 +11,5 @@
 #include "OgreItemBufferQueryManager.h"
 #include "OgreOcclusionQueriesQueryManager.h"
-
-
-
+#include "TestCullingTerrainApplication.h"
 
 // output file for frame info
@@ -48,4 +46,16 @@
 };
 
+Real currentObjectTerrainOffsets[] = 
+{
+	0,
+	7,
+	0
+};
+Real currentObjectScales[] = 
+{
+	0.1,
+	0.1,
+	0.07
+};
 //-----------------------------------------------------------------------
 TerrainFrameListener::TerrainFrameListener(RenderWindow* win, Camera* cam, 
@@ -55,5 +65,6 @@
 									   Camera *vizCamera,
 									   SceneNode *camNode,
-									   Light *sunLight): 
+									   Light *sunLight,
+									   TestCullingTerrainApplication *app): 
 mCamera(cam),
 mWindow(win),
@@ -79,5 +90,5 @@
 mAppState(WALKTHROUGH),
 mCurrentFrame(0),
-mTimeElapsed(0),
+mReplayTimeElapsed(0),
 mRotateSpeed(72),
 mMoveSpeed(50),
@@ -105,5 +116,7 @@
 mDelayedTraversedNodes(0.0),
 mUseItemBuffer(false),
-mRenderPatchesForItemBuffer(false)
+mRenderPatchesForItemBuffer(false),
+mCurrentObjectType(0),
+mApplication(app)
 {
 	//mInputDevice = PlatformManager::getSingleton().createInputReader();
@@ -118,63 +131,22 @@
 	mEventProcessor->addKeyListener(this);
 
-	mInputDevice = mEventProcessor->getInputReader();
-	
+	mInputDevice = mEventProcessor->getInputReader();	
 
 	// create ray query executor, used to place objects in terrain
 	mRayQueryExecutor = new RayQueryExecutor(mSceneMgr);
 	
+	//-- overlays
+	mDebugOverlay = OverlayManager::getSingleton().getByName("Core/DebugOverlay");
 	mHelpOverlay = OverlayManager::getSingleton().getByName("Example/Visibility/HelpOverlay"); 
-	mDebugOverlay = OverlayManager::getSingleton().getByName("Core/DebugOverlay");
 	mQueryOverlay = OverlayManager::getSingleton().getByName("Example/Visibility/QueryOverlay"); 
-
-	//-- 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");
-	mTestGeometryForVisibleLeavesInfo = OverlayManager::getSingleton().getOverlayElement("Example/Visibility/TestGeometryForVisibleLeavesInfo");
-	mUseDepthPassInfo = OverlayManager::getSingleton().getOverlayElement("Example/Visibility/UseDepthPassInfo");
-	mAssumedVisibilityInfo = OverlayManager::getSingleton().getOverlayElement("Example/Visibility/AssumedVisibilityInfo");
-
-	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");
-	mQueriesIssuedInfo = OverlayManager::getSingleton().getOverlayElement("Example/Visibility/QueriesIssuedInfo");
-	mDelayedQueriesIssuedInfo = OverlayManager::getSingleton().getOverlayElement("Example/Visibility/DelayedQueriesIssuedInfo");
-	mDelayedTraversedNodesInfo = OverlayManager::getSingleton().getOverlayElement("Example/Visibility/DelayedTraversedNodesInfo");
-
-	mAlgorithmInfo->setCaption(": " + currentAlgorithmCaptions[mCurrentAlgorithm]);
-	mThresholdInfo->setCaption(": 0");
-	mFrustumCulledNodesInfo->setCaption(": 0");
-	mQueryCulledNodesInfo->setCaption(": 0");
-	mTraversedNodesInfo->setCaption(": 0");
-	mHierarchyNodesInfo->setCaption(": 0");
-	mRenderedNodesInfo->setCaption(": 0");
-	mObjectsInfo->setCaption(": 0");
-	mTestGeometryForVisibleLeavesInfo->setCaption(": true");
-	mUseDepthPassInfo->setCaption(": false");
-	mQueriesIssuedInfo->setCaption(": 0");
-	mAssumedVisibilityInfo->setCaption(": 0");
-	mDelayedQueriesIssuedInfo->setCaption(": 0");
-	mDelayedTraversedNodesInfo->setCaption(": 0");
-
-	//-- visibility query stats overlay
-	mQueryTypeInfo = OverlayManager::getSingleton().getOverlayElement("Example/Visibility/Query/QueryTypeInfo");
-	
-	mQueryVisibleNodesInfo = OverlayManager::getSingleton().getOverlayElement("Example/Visibility/Query/VisibleNodesInfo");
-    mQueryVisibleGeometryInfo = OverlayManager::getSingleton().getOverlayElement("Example/Visibility/Query/VisibleGeometryInfo");
-	mQueryVisiblePatchInfo = OverlayManager::getSingleton().getOverlayElement("Example/Visibility/Query/VisiblePatchInfo");
-	
-	mQueryNodeVisibilityInfo = OverlayManager::getSingleton().getOverlayElement("Example/Visibility/Query/NodeVisibilityInfo");
-	mQueryGeometryVisibilityInfo = OverlayManager::getSingleton().getOverlayElement("Example/Visibility/Query/GeometryVisibilityInfo");
-	mQueryPatchVisibilityInfo = OverlayManager::getSingleton().getOverlayElement("Example/Visibility/Query/PatchVisibilityInfo");
+	mCullStatsOverlay = OverlayManager::getSingleton().getByName("Example/Visibility/CullStatsOverlay"); 
+
+	initVisStatsOverlay(); // visibility stats overlay
+	initHelpOverlay(); // help overlay
+	initQueryOverlay(); // visibility query stats overlay
 
 	// show stats overlays
 	showStats(true);
-	//mHelpOverlay->show();
-
+	
 	// set culling algorithm type
 	setAlgorithm(mCurrentAlgorithm);
@@ -193,4 +165,6 @@
 	mSceneMgr->setOption("CullCamera", &mCullCamera);
 	mSceneMgr->setOption("PrepareVisualization", &mShowVisualization);
+
+	setObjectType(mCurrentObjectType);
 
 	// reset statistics
@@ -229,8 +203,21 @@
 		 //Vector3 queryResult; mRayQueryExecutor->executeRayQuery(&queryResult, mouseRay);
 		 
-		 // Get results, create a node/entity on the position
+		 // get results, create a node/entity on the position
 		 mCurrentObject = mTerrainContentGenerator->GenerateSceneObject(
-			 mouseRay.getOrigin()/*queryResult*/, Vector3::ZERO, "robot");
+			 mouseRay.getOrigin()/*queryResult*/, Vector3::ZERO, 
+			 mApplication->getCurrentObjectCaption(mCurrentObjectType));
 		
+		 if (mCurrentObjectType == 0) // only robot has animation phases
+		 {
+			 Entity *ent = mTerrainContentGenerator->GetGeneratedEntities()->back();
+			 AnimationState *st = ent->getAnimationState("Walk");
+
+			 st->setLoop(true);
+			 st->setEnabled(true);
+					
+			 mApplication->getAnimationStates().push_back(st);
+			 mApplication->getAnimationSpeed().push_back(Math::RangeRandom(0.5, 1.5));
+		 }
+
          mLMouseDown = true; 
      }
@@ -271,4 +258,7 @@
 			 if (mCurrentObject)
 			 {
+				 // apply offset so object is ON terrain
+				 queryResult.y += currentObjectTerrainOffsets[mCurrentObjectType];
+
 				 mCurrentObject->setPosition(queryResult);
 			 }
@@ -292,4 +282,10 @@
 	}
 
+	for (int i = 0; i < (int)mApplication->getAnimationStates().size(); ++i)
+    {
+		mApplication->getAnimationStates()[i]->addTime(evt.timeSinceLastFrame * 
+			 mApplication->getAnimationSpeed()[i]);
+    }
+
 	if (mDisplayCameraDetails)
     {
@@ -299,7 +295,4 @@
     }
 
-	//-- IMPORTANT: must be set, otherwise terrain is not rendered correctly
-	mSceneMgr->endFrame();
-
 	//-- setup what is needed for immediate mouse/key movement
 	if (mTimeDelay >= 0) 
@@ -307,5 +300,5 @@
 		mTimeDelay -= evt.timeSinceLastFrame;
 	}
-
+	
 	// If this is the first frame, pick a speed
 	if (evt.timeSinceLastFrame == 0)
@@ -387,5 +380,5 @@
 }
 //-----------------------------------------------------------------------
-void TerrainFrameListener::ApplyVisibilityQuery(bool fromPoint, bool relativeVisibility, 
+void TerrainFrameListener::applyVisibilityQuery(bool fromPoint, bool relativeVisibility, 
 												bool useItemBuffer)
 {
@@ -523,5 +516,5 @@
 
 	// show the results
-	if (!mShowQueryStats)
+	if (!mShowQueryStats && !mShowHelp)
 	{
 		mQueryOverlay->show();
@@ -552,4 +545,10 @@
 
     updateStats();
+
+	//-- IMPORTANT: must be set, otherwise terrain is not rendered correctly
+	mSceneMgr->endFrame();
+
+	if (mTimeDelay <= 0) // approx. one second
+		mTimeDelay = 1.0;
 
 	return true;
@@ -660,5 +659,5 @@
 
 			//-- initialise frame data
-			mTimeElapsed = 0;
+			mReplayTimeElapsed = 0;
 
 			mCamNode->setPosition(mFrameInfo[0].position);
@@ -716,4 +715,18 @@
 }
 //-----------------------------------------------------------------------
+void TerrainFrameListener::setObjectType(int objectType)
+{
+	if (mCurrentObjectType >= 3)
+		mCurrentObjectType = 0;
+
+	// parameters for new object
+	mTerrainContentGenerator->SetOffset(currentObjectTerrainOffsets[mCurrentObjectType]);
+	Real scale = currentObjectScales[mCurrentObjectType];
+	mTerrainContentGenerator->SetScale(Vector3(scale, scale, scale));
+
+	mCurrentObjectTypeInfo->setCaption(": " + 
+		mApplication->getCurrentObjectCaption(mCurrentObjectType));
+}
+//-----------------------------------------------------------------------
 void TerrainFrameListener::setAlgorithm(int algorithm)
 {
@@ -739,4 +752,6 @@
 	static String trisString = "Triangle Count: ";
 
+	// HACK: compute average fps ourselfs, because ogre avg. fps is wrong
+	// TODO: update only once per second
 	mAvgFps += mWindow->getStatistics().lastFPS;
 	++ mFrameCount;
@@ -755,10 +770,11 @@
 
 		//guiAvg->setCaption(avgFps + StringConverter::toString(stats.avgFPS));
-		guiAvg->setCaption(avgFpsString + StringConverter::toString(avgFps));
+		if (mTimeDelay < 0) // only update once per second
+			guiAvg->setCaption(avgFpsString + StringConverter::toString(avgFps) + " ms");
 		guiCurr->setCaption(currFpsString + StringConverter::toString(stats.lastFPS));
 		guiBest->setCaption(bestFpsString + StringConverter::toString(stats.bestFPS)
-			+" "+StringConverter::toString(stats.bestFrameTime)+" ms");
+			+" "+StringConverter::toString(stats.bestFrameTime) + " ms");
 		guiWorst->setCaption(worstFpsString + StringConverter::toString(stats.worstFPS)
-			+" "+StringConverter::toString(stats.worstFrameTime)+" ms");
+			+" "+StringConverter::toString(stats.worstFrameTime) + " ms");
 
 		OverlayElement* guiTris = OverlayManager::getSingleton().getOverlayElement("Core/NumTris");
@@ -772,15 +788,7 @@
 		mFrustumCulledNodesInfo->setCaption(str);
 
-		// delay so there is no jump
-		mSceneMgr->getOption("NumQueriesIssued", &opt); 
-		sprintf(str,": %d", (int)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);
@@ -790,16 +798,16 @@
 
 		sprintf(str,": %d", mTerrainContentGenerator->GetObjectCount()); 
-		mObjectsInfo->setCaption(str);
-
-		// delay so there is no jump
+		mObjectsCountInfo->setCaption(str);
+
+		// take old value into account in order to create no sudden changes
 		mSceneMgr->getOption("NumQueriesIssued", &opt); 
 		mDelayedQueriesIssued = mDelayedQueriesIssued * 0.8 + (float)opt * 0.2;
 		sprintf(str,": %d", (int)mDelayedQueriesIssued); 
-		mDelayedQueriesIssuedInfo->setCaption(str);
+		mQueriesIssuedInfo->setCaption(str);
 
 		mSceneMgr->getOption("NumTraversedNodes", &opt); 
 		mDelayedTraversedNodes = mDelayedTraversedNodes * 0.8 + (float)opt * 0.2;
 		sprintf(str,": %d", (int)mDelayedTraversedNodes); 
-		mDelayedTraversedNodesInfo->setCaption(str);
+		mTraversedNodesInfo->setCaption(str);
 
 	}
@@ -815,7 +823,8 @@
 	mSceneMgr->setOption("TestGeometryForVisibleLeaves", &mTestGeometryForVisibleLeaves);
 	
-	// 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
+	/* disable optimization which tests geometry instead of aabb
+	 * for "delayed" rendering of transparents (i.e., render transparents after all the solids)
+	 * because otherwise visible transparents could be skipped
+	 */
 	bool delayedRendering = !mTestGeometryForVisibleLeaves;
 
@@ -928,4 +937,11 @@
 void TerrainFrameListener::keyPressed(KeyEvent* e)
 {
+	// hide exact visibility query overlay
+	if (mShowQueryStats)
+	{
+		mQueryOverlay->hide();
+		mShowQueryStats = false;
+	}
+
 	switch(e->getKey())
 	{
@@ -997,8 +1013,15 @@
 		break;
 	case KC_F5:
-		ApplyVisibilityQuery(false, mShiftPressed, mUseItemBuffer);
+		applyVisibilityQuery(false, mShiftPressed, mUseItemBuffer);
 		break;
 	case KC_F6:
-		ApplyVisibilityQuery(true, mShiftPressed, mUseItemBuffer);
+		applyVisibilityQuery(true, mShiftPressed, mUseItemBuffer);
+		break;
+	
+	case KC_F7:
+		setObjectType(++mCurrentObjectType);
+		break;
+	case KC_F8:
+		mApplication->generateScene(500, mCurrentObjectType);
 		break;
 	
@@ -1018,4 +1041,9 @@
 	case KC_LSHIFT:
 		mShiftPressed = true;
+		break;
+	case KC_DELETE:
+		mTerrainContentGenerator->RemoveGeneratedObjects();
+		mApplication->getAnimationStates().clear();
+		mApplication->getAnimationSpeed().clear();
 		break;
 	//KEY_PRESSED(KC_F3, 0.3, writeFrames());
@@ -1060,9 +1088,9 @@
 {
 	//-- find current frame relative to elapsed frame time		
-	mTimeElapsed -= timeElapsed;
-
-	while ((mTimeElapsed <= 0) && (mCurrentFrame < (int)mFrameInfo.size() - 1))
-	{
-		mTimeElapsed += mFrameInfo[mCurrentFrame ++].timeElapsed;
+	mReplayTimeElapsed -= timeElapsed;
+
+	while ((mReplayTimeElapsed <= 0) && (mCurrentFrame < (int)mFrameInfo.size() - 1))
+	{
+		mReplayTimeElapsed += mFrameInfo[mCurrentFrame ++].timeElapsed;
 	}
 
@@ -1075,5 +1103,5 @@
 	if (old_frame.timeElapsed > 0)
 	{
-		factor = mTimeElapsed / old_frame.timeElapsed;
+		factor = mReplayTimeElapsed / old_frame.timeElapsed;
 	}
 
@@ -1241,2 +1269,137 @@
 	}
 }
+//-----------------------------------------------------------------------
+void TerrainFrameListener::initOverlayElement(OverlayElement **elInfo, String ext, 
+											  String name, int top, String caption)
+{
+	OverlayElement *el = 
+		OverlayManager::getSingleton().getOverlayElement(ext + name);
+
+	(*elInfo) = OverlayManager::getSingleton().getOverlayElement(ext + name + "Info");
+	(*elInfo)->setCaption(caption);
+
+	el->setTop(top);
+	(*elInfo)->setTop(top);
+}
+//-----------------------------------------------------------------------
+void TerrainFrameListener::initHelpOverlayElement(String name, int top)
+{
+	OverlayElement *el = OverlayManager::getSingleton().getOverlayElement(
+		"Example/Visibility/Help/" + name);
+
+	el->setTop(top);
+}
+//-----------------------------------------------------------------------
+void TerrainFrameListener::initHelpOverlay()
+{
+	const int vert_space = 15;
+	int top = 30;
+
+	initHelpOverlayElement("ShowHelp", top); top += vert_space;
+	initHelpOverlayElement("Stats", top); top += vert_space;
+	initHelpOverlayElement("AppState", top); top += vert_space;
+	initHelpOverlayElement("Recorded", top); top += vert_space;
+	initHelpOverlayElement("Screenshots", top); top += vert_space;
+	initHelpOverlayElement("WriteOut", top); top += vert_space;
+
+	top +=vert_space;
+	initHelpOverlayElement("SceneDetail", top); top += vert_space;
+	initHelpOverlayElement("DisplayCameraDetails", top); top += vert_space;
+	initHelpOverlayElement("DisplayOctree", top); top += vert_space;
+	initHelpOverlayElement("UseShadows", top); top += vert_space;
+	initHelpOverlayElement("Filter", top); top += vert_space;
+
+	//-- visualization
+	top += vert_space;
+	initHelpOverlayElement("VizSection", top); top += vert_space;
+	initHelpOverlayElement("Viz", top); top += vert_space;
+	initHelpOverlayElement("NextVizMode", top); top += vert_space;
+	initHelpOverlayElement("ZoomViz", top); top += vert_space;
+
+
+	//-- visibility queries
+	top += vert_space;
+	initHelpOverlayElement("VisQuery", top); top += vert_space;
+	initHelpOverlayElement("FromCameraQuery", top); top += vert_space;
+	initHelpOverlayElement("FromPointQuery", top); top += vert_space;
+	initHelpOverlayElement("QueryType", top); top += vert_space;
+	initHelpOverlayElement("QueryTarget", top); top += vert_space;
+
+	//-- object generation
+	top += vert_space;
+	initHelpOverlayElement("SceneObjects", top); top += vert_space;
+	initHelpOverlayElement("GenerateObjects", top); top += vert_space;
+	initHelpOverlayElement("RemoveObjects", top); top += vert_space;
+	initHelpOverlayElement("DropObject", top); top += vert_space;
+
+	OverlayElement *helpPanel = OverlayManager::getSingleton().getOverlayElement(
+		"Example/Visibility/Help/HelpPanel");
+
+	helpPanel->setHeight(top + 10);
+}
+//-----------------------------------------------------------------------
+void TerrainFrameListener::initVisStatsOverlay()
+{
+	const int border_height = 10;
+	const int vert_space = 15;
+
+	//-- visibility culling stats overlay
+	int top = border_height;
+
+	String ext = "Example/Visibility/";
+	
+	initOverlayElement(&mAlgorithmInfo, ext, "Algorithm", top,
+		": " + currentAlgorithmCaptions[mCurrentAlgorithm]); top += vert_space;
+
+	initOverlayElement(&mThresholdInfo, ext, "Threshold", top, ": 0"); top += vert_space;
+	initOverlayElement(&mTestGeometryForVisibleLeavesInfo, ext, 
+		"TestGeometryForVisibleLeaves", top, ": true"); top += vert_space;
+	initOverlayElement(&mUseDepthPassInfo, ext, "UseDepthPass", top, ": false"); top += vert_space;
+	initOverlayElement(&mAssumedVisibilityInfo, ext, "AssumedVisibility", top, ": 0"); top += vert_space;
+	initOverlayElement(&mCurrentObjectTypeInfo, ext, "CurrentObjectType", top, ": "); top += vert_space;
+
+	OverlayElement *optionsPanel = OverlayManager::getSingleton().
+		getOverlayElement("Example/Visibility/VisibilityPanel");
+
+	optionsPanel->setHeight(top + border_height);
+
+	top = border_height;
+	//ext = "Example/Visibility/";
+	initOverlayElement(&mFrustumCulledNodesInfo, ext, "FrustumCulledNodes", top, ": 0"); top += vert_space;
+	initOverlayElement(&mQueryCulledNodesInfo, ext, "QueryCulledNodes", top, ": 0"); top += vert_space;
+	initOverlayElement(&mTraversedNodesInfo, ext, "TraversedNodes", top, ": 0"); top += vert_space;
+	initOverlayElement(&mHierarchyNodesInfo, ext, "HierarchyNodes", top, ": 0"); top += vert_space;
+	initOverlayElement(&mRenderedNodesInfo, ext, "RenderedNodes", top, ": 0"); top += vert_space;
+	initOverlayElement(&mObjectsCountInfo, ext, "ObjectsCount", top, ": 0"); top += vert_space;
+	initOverlayElement(&mQueriesIssuedInfo, ext, "QueriesIssued", top, ": 0"); top += vert_space;
+
+	OverlayElement *visPanel = OverlayManager::getSingleton().
+		getOverlayElement("Example/Visibility/VisibilityStatsPanel");
+
+	visPanel->setHeight(top + border_height);
+}
+//-----------------------------------------------------------------------
+void TerrainFrameListener::initQueryOverlay()
+{
+	const int border_height = 10;
+	const int vert_space = 15;
+
+	//-- visibility culling stats overlay
+	int top = border_height + 25;
+
+	String ext = "Example/Visibility/Query/";
+	    
+	initOverlayElement(&mQueryTypeInfo , ext, "QueryType", top,	": 0"); top += vert_space;
+	initOverlayElement(&mQueryVisibleGeometryInfo , ext, "VisibleGeometry", top,	": 0"); top += vert_space;
+	initOverlayElement(&mQueryVisibleNodesInfo , ext, "VisibleNodes", top,	": 0"); top += vert_space;
+	initOverlayElement(&mQueryVisiblePatchInfo , ext, "VisiblePatches", top,	": 0"); top += vert_space;
+	initOverlayElement(&mQueryNodeVisibilityInfo , ext, "NodeVisibility", top,	": 0"); top += vert_space;
+	initOverlayElement(&mQueryGeometryVisibilityInfo , ext, "GeometryVisibility", top,	": 0"); top += vert_space;
+	initOverlayElement(&mQueryPatchVisibilityInfo , ext, "PatchVisibility", top,	": 0"); top += vert_space;
+
+
+	OverlayElement *queryPanel = OverlayManager::getSingleton().
+		getOverlayElement("Example/Visibility/Query/QueryPanel");
+
+	queryPanel->setHeight(top + border_height);
+}
Index: trunk/VUT/work/TestCullingTerrain/TestCullingTerrainApplication.cpp
===================================================================
--- trunk/VUT/work/TestCullingTerrain/TestCullingTerrainApplication.cpp	(revision 159)
+++ trunk/VUT/work/TestCullingTerrain/TestCullingTerrainApplication.cpp	(revision 160)
@@ -15,7 +15,17 @@
 #include <windows.h>
 
-/*******************************************************/
-/*     TestCullingTerrainApplication implementation    */
-/*******************************************************/
+String currentObjectCaptions[] =
+{
+	"robot",
+	"athene",
+	"ninja"
+	//"ogrehead"
+};
+
+/*********************************************************/
+/*      TestCullingTerrainApplication implementation     */
+/*********************************************************/
+
+
 TestCullingTerrainApplication::TestCullingTerrainApplication():
 mTerrainContentGenerator(NULL)
@@ -30,5 +40,4 @@
 		mTerrainContentGenerator = NULL;
 	}
-	//if(mRenderTargetListener)	delete mRenderTargetListener;
 }
 //-----------------------------------------------------------------------
@@ -127,9 +136,6 @@
 	setupGui();
 
-	
 	/* // occluder plane to test visibility
-	Plane plane;
-	plane.normal = Vector3::UNIT_Y;
-	plane.d = -60;
+	Plane plane; plane.normal = Vector3::UNIT_Y;	plane.d = -60;
 	MeshManager::getSingleton().createPlane("Myplane",
 		ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, plane,
@@ -152,16 +158,14 @@
 	mTerrainContentGenerator = new TerrainContentGenerator(mSceneMgr);
 	
-	// if no objects file generate yourself
+	// if no objects in file, we generate new objects
 	if (!mTerrainContentGenerator->LoadObjects("objects.out"))
 	{
 		// to provide much occlusion,
-		// height is restricted to 50, so no objects appear on peaks
+		// height is restricted to 50 => no objects appear on peaks
 		mTerrainContentGenerator->SetMaxPos(Vector3(3000.0f, 50.0f, 3000.0f));
 		mTerrainContentGenerator->SetOffset(0);
 
-		// the objects are generated on the whole terrain
-		//mTerrainContentGenerator->GenerateScene(1500, "robot");
-		mTerrainContentGenerator->GenerateScene(1500, "athene");
-		//mTerrainContentGenerator->GenerateScene(500, "ninja");
+		// the objects are generated randomly distributed over the terrain
+		generateScene(1500, 0);
 	}
 
@@ -169,4 +173,36 @@
 	// objects also on peaks of terrain
 	mTerrainContentGenerator->SetMaxPos(Vector3(3000.0f, 5000.0f, 3000.0f));
+}
+//-----------------------------------------------------------------------
+void  TestCullingTerrainApplication::generateScene(int num, int objectType)
+{
+	mTerrainContentGenerator->GenerateScene(num, currentObjectCaptions[objectType]);
+
+	if (objectType != 0) // from our objects, only robot has animation phases
+		return;
+
+	EntityList *entList = mTerrainContentGenerator->GetGeneratedEntities();
+
+	//-- add animation state for new robots (located at the end of the list)
+	for (int i = entList->size() - num; i < entList->size(); ++i)
+	{
+		Entity *ent = (*entList)[i];
+		AnimationState *st = ent->getAnimationState("Idle");
+		st->setEnabled(true);
+		st->setLoop(true);
+
+		mAnimationStates.push_back(st);
+		mAnimationSpeed.push_back(Math::RangeRandom(0.5, 1.5));
+	}
+}
+//-----------------------------------------------------------------------
+std::vector<AnimationState *> &TestCullingTerrainApplication::getAnimationStates()
+{
+	return mAnimationStates;
+}
+//-----------------------------------------------------------------------
+std::vector<Real> &TestCullingTerrainApplication::getAnimationSpeed()
+{
+	return mAnimationSpeed;
 }
 //-----------------------------------------------------------------------
@@ -189,15 +225,18 @@
 {
 	mTerrainFrameListener = new TerrainFrameListener(mWindow, mCamera, mSceneMgr, 
-		mGUIRenderer, mTerrainContentGenerator, mVizCamera, mCamNode, mSunLight);
+		mGUIRenderer, mTerrainContentGenerator, mVizCamera, mCamNode, mSunLight, this);
 	
 	mRoot->addFrameListener(mTerrainFrameListener);
 }
 //-----------------------------------------------------------------------
+String TestCullingTerrainApplication::getCurrentObjectCaption(int id)
+{
+	return currentObjectCaptions[id];
+}
+//-----------------------------------------------------------------------
 void TestCullingTerrainApplication::chooseSceneManager()
 {
 	mSceneMgr = mRoot->getSceneManager(ST_EXTERIOR_CLOSE);
 }
-
-
 /**************************************************************/
 /*      VisualizationRenderTargetListener implementation      */
Index: trunk/VUT/work/TestCullingTerrain/TerrainFrameListener.h
===================================================================
--- trunk/VUT/work/TestCullingTerrain/TerrainFrameListener.h	(revision 159)
+++ trunk/VUT/work/TestCullingTerrain/TerrainFrameListener.h	(revision 160)
@@ -13,4 +13,7 @@
 #include "OgrePlatformQueryManager.h"
 
+class TestCullingTerrainApplication;
+
+
 using namespace Ogre;
 
@@ -25,7 +28,13 @@
 public:
 	
-   TerrainFrameListener(RenderWindow* win, Camera* cam, SceneManager *sceneManager, 
-		CEGUI::Renderer *renderer, TerrainContentGenerator *contentGenerator, Camera *vizCamera,
-		SceneNode *camNode, Light *sunLight);
+   TerrainFrameListener(RenderWindow* win, 
+						Camera* cam, 
+						SceneManager *sceneManager, 
+						CEGUI::Renderer *renderer, 
+						TerrainContentGenerator *contentGenerator, 
+						Camera *vizCamera,
+						SceneNode *camNode, 
+						Light *sunLight,
+						TestCullingTerrainApplication *app);
 
    ~TerrainFrameListener();
@@ -122,9 +131,21 @@
 		@param useItemBuffer if item buffer should be used or occlusion queries
 	*/
-	void ApplyVisibilityQuery(bool fromPoint, bool relativeVisibility, bool useItemBuffer);
+	void applyVisibilityQuery(bool fromPoint, bool relativeVisibility, bool useItemBuffer);
 
 	void toggleShowQueryStats();
 
+	/** Sets the type of the objects generated in the scene.
+	*/
+	void setObjectType(int objectType);
+
 protected:
+
+	void initHelpOverlayElement(String name, int top);
+	void initOverlayElement(OverlayElement **elInfo, String ext, String name, int top, String caption);
+
+	//-- initialise overlays
+	void initHelpOverlay();
+	void initVisStatsOverlay();
+	void initQueryOverlay();
 
 	void resetStats();
@@ -162,8 +183,9 @@
 	OverlayElement *mUseDepthPassInfo;
 	OverlayElement *mRenderedNodesInfo;
-	OverlayElement *mObjectsInfo;
+	OverlayElement *mObjectsCountInfo;
 	OverlayElement *mQueriesIssuedInfo;
 	OverlayElement *mDelayedQueriesIssuedInfo;
 	OverlayElement *mDelayedTraversedNodesInfo;
+	OverlayElement *mCurrentObjectTypeInfo;
 
 	OverlayElement *mQueryTypeInfo;
@@ -203,5 +225,5 @@
 	std::vector<frame_info> mFrameInfo;
 		
-	Real mTimeElapsed;
+	Real mReplayTimeElapsed;
 	//EventProcessor* mEventProcessor;
     InputReader* mInputDevice;
@@ -211,5 +233,4 @@
     RenderWindow* mWindow;
    
-    //bool mUseBufferedInputKeys, mUseBufferedInputMouse, mInputTypeSwitchingOn;
 	unsigned int mNumScreenShots;
     int mSceneDetailIndex;
@@ -248,4 +269,8 @@
 
 	bool mRenderPatchesForItemBuffer;
+
+	int mCurrentObjectType;
+
+	TestCullingTerrainApplication *mApplication;
 };
 
Index: trunk/VUT/work/TestCullingTerrain/TestCullingTerrainApplication.h
===================================================================
--- trunk/VUT/work/TestCullingTerrain/TestCullingTerrainApplication.h	(revision 145)
+++ trunk/VUT/work/TestCullingTerrain/TestCullingTerrainApplication.h	(revision 160)
@@ -25,5 +25,5 @@
 
 
-class TestCullingTerrainApplication : public ExampleApplication
+class TestCullingTerrainApplication: public ExampleApplication
 {
 public:
@@ -31,5 +31,13 @@
 	~TestCullingTerrainApplication();
 
+	void generateScene(int num, int objectType);
+
+	String getCurrentObjectCaption(int id);
+
+	std::vector<AnimationState *> &getAnimationStates();
+	std::vector<Real> &getAnimationSpeed();
+
 protected:
+
 	//-- inherited from ExampleApplication
 	bool setup();
@@ -40,4 +48,7 @@
 	
 	virtual void createRenderTargetListener();
+
+	std::vector<AnimationState *> mAnimationStates;
+	std::vector<Real> mAnimationSpeed;
 
 	/** cegui setup */
@@ -61,5 +72,4 @@
 	TerrainFrameListener *mTerrainFrameListener;
 	ColourValue mAmbientLight;
-	//VisualizationRenderTargetListener *mVizRenderTargetListener;
 	
 private:
Index: trunk/VUT/work/ogre_changes/Plugins/OctreeSceneManager/src/OgreOctree.cpp
===================================================================
--- trunk/VUT/work/ogre_changes/Plugins/OctreeSceneManager/src/OgreOctree.cpp	(revision 158)
+++ trunk/VUT/work/ogre_changes/Plugins/OctreeSceneManager/src/OgreOctree.cpp	(revision 160)
@@ -262,7 +262,4 @@
 	mWorldAABB = mWorldAABB.intersection(box); 
 	
-	//std::stringstream d; d << "updating box: " << mWorldAABB << ", depth: " << mDepth << "null: " << mBox.isNull();
-	//LogManager::getSingleton().logMessage(d.str());
-
 	// recursively update parent bounds
 	if (mParent)
Index: trunk/VUT/work/TestCulling/TestCullingApplication.cpp
===================================================================
--- trunk/VUT/work/TestCulling/TestCullingApplication.cpp	(revision 155)
+++ trunk/VUT/work/TestCulling/TestCullingApplication.cpp	(revision 160)
@@ -31,10 +31,10 @@
 
 	// Position it at 500 in Z direction
-	mCamera->setPosition(Vector3(128,25,128));
+	mCamera->setPosition(Vector3(128, 25, 128));
 
 	// Look back along -Z
-    mCamera->lookAt(Vector3(0,0,-300));
-    mCamera->setNearClipDistance( 1 );
-    mCamera->setFarClipDistance( 1000 );
+    mCamera->lookAt(Vector3(0, 0, -300));
+    mCamera->setNearClipDistance(1);
+    mCamera->setFarClipDistance(1000);
 }*/
 //-----------------------------------------------------------------------
@@ -67,5 +67,6 @@
 void TestCullingApplication::setupGui()
 {
-	 mGUIRenderer = new CEGUI::OgreCEGUIRenderer(mWindow, Ogre::RENDER_QUEUE_OVERLAY, false, 3000, ST_EXTERIOR_CLOSE);
+	 mGUIRenderer = new CEGUI::OgreCEGUIRenderer(mWindow, 
+		 Ogre::RENDER_QUEUE_OVERLAY, false, 3000, ST_EXTERIOR_CLOSE);
      mGUISystem = new CEGUI::System(mGUIRenderer);
 
@@ -93,13 +94,13 @@
 
 
-/***********************************************/
-/* TerrainFrameListener implementation         */
-/***********************************************/
+/*****************************************************/
+/*       TerrainFrameListener implementation         */
+/*****************************************************/
 //-----------------------------------------------------------------------
 TerrainFrameListener::TerrainFrameListener(RenderWindow* win, Camera* cam, 
 									   SceneManager *sceneManager, 
 									   CEGUI::Renderer *renderer,
-									   SceneContentGenerator *sceneContentGenerator)
-: ExampleFrameListener(win, cam, false, true),
+									   SceneContentGenerator *sceneContentGenerator):
+ExampleFrameListener(win, cam, false, true),
 mSceneMgr(sceneManager),
 mGUIRenderer(renderer), 
@@ -136,5 +137,5 @@
 	mHierarchyNodesInfo = OverlayManager::getSingleton().getOverlayElement("Example/Visibility/HierarchyNodesInfo");
 	mRenderedNodesInfo = OverlayManager::getSingleton().getOverlayElement("Example/Visibility/RenderedNodesInfo");
-	mObjectsInfo = OverlayManager::getSingleton().getOverlayElement("Example/Visibility/ObjectsInfo");
+	mObjectsCountInfo = OverlayManager::getSingleton().getOverlayElement("Example/Visibility/ObjectsInfo");
 	mTestGeometryForVisibleLeavesInfo = OverlayManager::getSingleton().getOverlayElement("Example/Visibility/TestGeometryForVisibleLeavesInfo");
 	mQueriesIssuedInfo = OverlayManager::getSingleton().getOverlayElement("Example/Visibility/QueriesIssuedInfo");
@@ -148,5 +149,5 @@
 	mHierarchyNodesInfo->setCaption(": 0");
 	mRenderedNodesInfo->setCaption(": 0");
-	mObjectsInfo->setCaption(": 0");
+	mObjectsCountInfo->setCaption(": 0");
 	mTestGeometryForVisibleLeavesInfo->setCaption(": true");
 	mQueriesIssuedInfo->setCaption(": 0");
@@ -330,5 +331,5 @@
 
 	sprintf(str,": %d", mSceneContentGenerator->GetObjectCount()); 
-	mObjectsInfo->setCaption(str);
+	mObjectsCountInfo->setCaption(str);
 }
 //-----------------------------------------------------------------------
Index: trunk/VUT/work/TestCulling/TestCullingApplication.h
===================================================================
--- trunk/VUT/work/TestCulling/TestCullingApplication.h	(revision 155)
+++ trunk/VUT/work/TestCulling/TestCullingApplication.h	(revision 160)
@@ -1,6 +1,5 @@
-/**
-    \file 
-        TestCullingApplication.h
-*/
+#ifndef _TerrainFrameListener_H__
+#define _TerrainFrameListener_H__
+
 #include "CEGUIForwardRefs.h"
 #include "ExampleApplication.h"
@@ -29,9 +28,12 @@
 public:
 
-    TerrainFrameListener(RenderWindow* win, Camera* cam, SceneManager *sceneManager, 
-			CEGUI::Renderer *renderer, SceneContentGenerator *sceneContentGenerator);
+    TerrainFrameListener(RenderWindow* win, 
+						 Camera* cam, 
+						 SceneManager *sceneManager, 
+						 CEGUI::Renderer *renderer, 
+						 SceneContentGenerator *sceneContentGenerator);
 
 
-    ~TerrainFrameListener( );
+    ~TerrainFrameListener();
 
 	bool frameStarted(const FrameEvent& evt);
@@ -86,5 +88,5 @@
 	OverlayElement *mHierarchyNodesInfo;
 	OverlayElement *mRenderedNodesInfo;
-	OverlayElement *mObjectsInfo;
+	OverlayElement *mObjectsCountInfo;
 	OverlayElement *mTestGeometryForVisibleLeavesInfo;
 	OverlayElement *mQueriesIssuedInfo;
@@ -130,2 +132,3 @@
 };
 
+#endif // _TerrainFrameListener_H__
