Index: trunk/VUT/work/TestCullingTerrain/TestCullingTerrain.vcproj
===================================================================
--- trunk/VUT/work/TestCullingTerrain/TestCullingTerrain.vcproj	(revision 105)
+++ trunk/VUT/work/TestCullingTerrain/TestCullingTerrain.vcproj	(revision 107)
@@ -21,5 +21,5 @@
 				Name="VCCLCompilerTool"
 				Optimization="0"
-				AdditionalIncludeDirectories="&quot;$(OGRE_PATH)\Dependencies\include&quot;;&quot;$(OGRE_PATH)\OgreMain\include&quot;;&quot;$(OGRE_PATH)\Samples\Common\include&quot;;&quot;$(OGRE_PATH)\Dependencies\include\CEGUI&quot;;&quot;$(OGRE_PATH)\PlugIns\OctreeSceneManager\include&quot;;&quot;$(OGRE_ADDONS_PATH)\dotsceneoctree\PlugIns\DotSceneManager\include&quot;;&quot;$(OGRE_PATH)\Samples\Common\CEGUIRenderer\include&quot;;..\..\GtpVisibility\include;..\include;..\TestCulling"
+				AdditionalIncludeDirectories="&quot;$(OGRE_PATH)\Dependencies\include&quot;;&quot;$(OGRE_PATH)\OgreMain\include&quot;;&quot;$(OGRE_PATH)\Samples\Common\include&quot;;&quot;$(OGRE_PATH)\Dependencies\include\CEGUI&quot;;&quot;$(OGRE_PATH)\PlugIns\OctreeSceneManager\include&quot;;&quot;$(OGRE_ADDONS_PATH)\dotsceneoctree\PlugIns\DotSceneManager\include&quot;;&quot;$(OGRE_PATH)\Samples\Common\CEGUIRenderer\include&quot;;..\..\GtpVisibility\include;..\..\Ogre\include;..\include;..\TestCulling"
 				PreprocessorDefinitions="_WINDOWS;_STLP_USE_DYNAMIC_LIB;OGRE_LIBRARY_IMPORTS;_DEBUG;WIN32;_STLP_DEBUG;PLUGIN_TERRAIN_IMPORTS;GTP_VISIBILITY_MODIFIED_OGRE"
 				MinimalRebuild="TRUE"
@@ -72,5 +72,5 @@
 			<Tool
 				Name="VCCLCompilerTool"
-				AdditionalIncludeDirectories="&quot;$(OGRE_PATH)\Dependencies\include&quot;;&quot;$(OGRE_PATH)\OgreMain\include&quot;;&quot;$(OGRE_PATH)\Samples\Common\include&quot;;&quot;$(OGRE_PATH)\Dependencies\include\CEGUI&quot;;&quot;$(OGRE_PATH)\ReferenceApplication\ReferenceAppLayer\include&quot;;&quot;$(OGRE_PATH)\PlugIns\OctreeSceneManager\include&quot;;&quot;$(OGRE_ADDONS_PATH)\dotsceneoctree\PlugIns\DotSceneManager\include&quot;;&quot;$(OGRE_PATH)\Samples\Common\CEGUIRenderer\include&quot;;..\..\GtpVisibility\include;..\include;..\TestCulling"
+				AdditionalIncludeDirectories="&quot;$(OGRE_PATH)\Dependencies\include&quot;;&quot;$(OGRE_PATH)\OgreMain\include&quot;;&quot;$(OGRE_PATH)\Samples\Common\include&quot;;&quot;$(OGRE_PATH)\Dependencies\include\CEGUI&quot;;&quot;$(OGRE_PATH)\ReferenceApplication\ReferenceAppLayer\include&quot;;&quot;$(OGRE_PATH)\PlugIns\OctreeSceneManager\include&quot;;&quot;$(OGRE_ADDONS_PATH)\dotsceneoctree\PlugIns\DotSceneManager\include&quot;;&quot;$(OGRE_PATH)\Samples\Common\CEGUIRenderer\include&quot;;..\..\Ogre\include;..\..\GtpVisibility\include;..\include;..\TestCulling"
 				PreprocessorDefinitions="_WINDOWS;_STLP_USE_DYNAMIC_LIB;OGRE_LIBRARY_IMPORTS;_RELEASE;WIN32;_STLP_RELEASE;GTP_VISIBILITY_MODIFIED_OGRE"
 				RuntimeLibrary="2"
@@ -83,8 +83,8 @@
 			<Tool
 				Name="VCLinkerTool"
-				AdditionalDependencies="OGREMain.LIB Plugin_OctreeSceneManager.lib CEGUIBase.lib OgreGUIRenderer.lib"
+				AdditionalDependencies="OGREMain.LIB CEGUIBase.lib OgreGUIRenderer.lib Plugin_OctreeSceneManager.lib Plugin_VisibilitySceneManager.lib"
 				OutputFile="$(OGRE_PATH)/Samples/Common/bin/Release/TestCullingTerrain.exe"
 				LinkIncremental="1"
-				AdditionalLibraryDirectories="&quot;$(OGRE_PATH)\Dependencies\Lib\$(ConfigurationName)&quot;;&quot;$(OGRE_ADDONS_PATH)\dotsceneoctree\PlugIns\DotSceneManager\bin\$(ConfigurationName)&quot;;&quot;$(OGRE_PATH)\OgreMain\Lib\$(ConfigurationName)&quot;;&quot;$(OGRE_PATH)\PlugIns\OctreeSceneManager\bin\$(ConfigurationName)&quot;;&quot;$(OGRE_PATH)\Samples\Common\CEGUIRenderer\lib&quot;"
+				AdditionalLibraryDirectories="&quot;$(OGRE_PATH)\Dependencies\Lib\$(ConfigurationName)&quot;;&quot;$(OGRE_ADDONS_PATH)\dotsceneoctree\PlugIns\DotSceneManager\bin\$(ConfigurationName)&quot;;&quot;$(OGRE_PATH)\OgreMain\Lib\$(ConfigurationName)&quot;;&quot;$(OGRE_PATH)\PlugIns\OctreeSceneManager\bin\$(ConfigurationName)&quot;;&quot;$(OGRE_PATH)\Samples\Common\CEGUIRenderer\lib&quot;;&quot;$(GAMETOOLS_PATH)\trunk\VUT\Ogre\lib\$(ConfigurationName)&quot;"
 				GenerateDebugInformation="TRUE"
 				SubSystem="2"
@@ -122,10 +122,4 @@
 			UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}">
 			<File
-				RelativePath="..\TestCulling\SceneContentGenerator.cpp">
-			</File>
-			<File
-				RelativePath=".\TerrainContentGenerator.cpp">
-			</File>
-			<File
 				RelativePath=".\TestCullingTerrainApplication.cpp">
 			</File>
@@ -136,10 +130,4 @@
 			UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}">
 			<File
-				RelativePath="..\TestCulling\SceneContentGenerator.h">
-			</File>
-			<File
-				RelativePath=".\TerrainContentGenerator.h">
-			</File>
-			<File
 				RelativePath=".\TestCullingTerrainApplication.h">
 			</File>
Index: trunk/VUT/work/TestCullingTerrain/TestCullingTerrainApplication.cpp
===================================================================
--- trunk/VUT/work/TestCullingTerrain/TestCullingTerrainApplication.cpp	(revision 106)
+++ trunk/VUT/work/TestCullingTerrain/TestCullingTerrainApplication.cpp	(revision 107)
@@ -23,4 +23,7 @@
 #define VIZ_VIEWPORT_Z_ORDER 10
 
+const char* frame_outfile = "frame.out";
+const char* objects_outfile = "objects.out";
+
 /*******************************************************/
 /*     TestCullingTerrainApplication implementation    */
@@ -45,5 +48,4 @@
 	*	because then the camera is displayed correctly in the visualization
 	*/
-	
 	mCamNode = mSceneMgr->getRootSceneNode()->createChildSceneNode(
 		"CamNode1", Vector3(707, 5000, 528));
@@ -126,12 +128,19 @@
 
 	mTerrainContentGenerator = new TerrainContentGenerator(mSceneMgr);
-	mTerrainContentGenerator->SetMaxPos(Vector3(3000.0f, 5000.0f, 3000.0f));
-
-	mTerrainContentGenerator->GenerateScene(1500, "robot.mesh");
-//	mTerrainContentGenerator->GenerateScene(500, "ninja.mesh");
+
+	// if no objects file generate yourself
+	if (!mTerrainContentGenerator->LoadObjects("objects.out"))
+	{
+		// the objects are generated on the whole terrain
+		// height is restricted to 50, so no objects appear on peaks 
+		// => there is much occlusion
+		mTerrainContentGenerator->SetMaxPos(Vector3(3000.0f, 50.0f, 3000.0f));
+		mTerrainContentGenerator->GenerateScene(1500, "robot");
+		//	mTerrainContentGenerator->GenerateScene(500, "ninja");
+	}
 
 	// no limitations needed anymore: the user can set 
 	// objects also on peaks of terrain
-	mTerrainContentGenerator->SetMaxHeight(5000); 
+	mTerrainContentGenerator->SetMaxPos(Vector3(3000.0f, 5000.0f, 3000.0f));
 }
 //-----------------------------------------------------------------------
@@ -192,6 +201,8 @@
 mCamNode(camNode),
 mCullCamera(false),
-mState(WALKTHROUGH),
-mCurrentFrame(1)
+mAppState(WALKTHROUGH),
+mCurrentFrame(0),
+mRecord(false),
+mTimeElapsed(0)
 {
 	// Reduce move speed
@@ -270,5 +281,5 @@
 		 // Get results, create a node/entity on the position
 		 mCurrentObject = mTerrainContentGenerator->GenerateSceneObject(
-			 mouseRay.getOrigin(), mouseRay.getDirection(), "robot.mesh");
+			 mouseRay.getOrigin(), Vector3(0,0,0), "robot.mesh");
 		
          mLMouseDown = true; 
@@ -326,21 +337,23 @@
 bool MouseQueryListener::frameStarted(const FrameEvent &evt)
 {
-	switch (mState)
+	switch (mAppState)
 	{
 	case REPLAY:
-		SetCurrentCameraPath(mCamNode);
-		mCamNode->setPosition(mCameraPath[mCurrentFrame].position);
-		mCamNode->setOrientation(mCameraPath[mCurrentFrame].orientation);
-		(mCurrentFrame++) % mCameraPath.size();
+		setCurrentFrameInfo(evt.timeSinceLastFrame);
 		break;
 	case WALKTHROUGH:
+		if (mRecord)
+		{
+			addFrameInfo(mCamNode, evt.timeSinceLastFrame);
+			// print recording message
+			mWindow->setDebugText("Recording frame " + 
+				StringConverter::toString(mFrameInfo.size() - 1));
+		}	
+	
 		Clamp2Terrain();
-
-	case RECORD:
-		AddCameraPath(mCamNode);
 		break;
 	default:
 		break;
-	};
+	};	
 	
 	if (mShowVisualization)
@@ -358,11 +371,12 @@
 		mVizCamera->setPosition(camPos.x, mVizCameraHeight, camPos.z);
 
-		// Point down -Z axis
+		// point down -Z axis
 		mVizCamera->pitch(Radian(Degree(270.0)));
 	
-		// Rotation arounnd X axis
+		// rotation arounnd X axis
 		mVizCamera->yaw(Math::ATan2(-mCamera->getDerivedDirection().x, 
 			-mCamera->getDerivedDirection().z));
 		
+		// move by a constant so view plane is on bottom of viewport
 		mVizCamera->moveRelative(Vector3(0, 800, 0));
 	}
@@ -392,5 +406,5 @@
         timeDelay -= evt.timeSinceLastFrame;
 
-    KEY_PRESSED(KC_SPACE, 0.3, nextAlgorithm());
+	KEY_PRESSED(KC_SPACE, 0.3, nextAlgorithm());
 
 	KEY_PRESSED(KC_O, 0.3, toggleUseOptimization());
@@ -399,15 +413,23 @@
 	KEY_PRESSED(KC_1, 0.3, toggleShowViz());
 	KEY_PRESSED(KC_2, 0.3, toggleRenderNodesForViz());
+	
 	KEY_PRESSED(KC_SUBTRACT, 0, changeThreshold(-10));
 	KEY_PRESSED(KC_ADD, 0, changeThreshold(10));
+	
 	KEY_PRESSED(KC_3, 0, zoomVizCamera(50));
 	KEY_PRESSED(KC_4, 0, zoomVizCamera(-50));
-	KEY_PRESSED(KC_F1, 0, setState(RECORD));
-	KEY_PRESSED(KC_F2, 0, setState(REPLAY));
-	KEY_PRESSED(KC_F3, 0, setState(WALKTHROUGH));
+
+	KEY_PRESSED(KC_F1, 0.3, nextAppState());
+	KEY_PRESSED(KC_F2, 0.3, toggleRecord());
+	KEY_PRESSED(KC_F3, 0.3, mTerrainContentGenerator->WriteObjects(objects_outfile));
+	//KEY_PRESSED(KC_F3, 0.3, writeFrames());
+	//KEY_PRESSED(KC_F4, 0.3, loadFrames());
+
 	updateStats();
 
-	return ExampleFrameListener::frameStarted(evt) && ExampleFrameListener::frameEnded(evt);
-}
+	//return ExampleFrameListener::frameStarted(evt) && ExampleFrameListener::frameEnded(evt);
+	return ExampleFrameListener::frameEnded(evt);
+}
+//-----------------------------------------------------------------------
 void MouseQueryListener::moveCamera()
 {
@@ -417,4 +439,124 @@
 }
 //-----------------------------------------------------------------------
+void MouseQueryListener::writeFrames()
+{
+	std::ofstream ofstr(frame_outfile);
+	
+	std::vector<frame_info>::const_iterator it, it_end;
+
+	it_end = mFrameInfo.end();
+	for(it = mFrameInfo.begin(); it < it_end; ++it)
+	{
+		ofstr << StringConverter::toString((*it).position) << " " 
+			<< StringConverter::toString((*it).orientation) << " "
+			<< StringConverter::toString((*it).timeElapsed) << "\n";
+	}
+	ofstr.close();
+}
+//-----------------------------------------------------------------------
+void MouseQueryListener::loadFrames()
+{
+	std::ifstream ifstr(frame_outfile);
+	char line[256];
+	frame_info info;
+
+	// reset current values
+	mFrameInfo.clear();
+	mCurrentFrame = 0;
+	
+	while (!ifstr.eof()) 
+	{
+		ifstr.getline(line, 256);
+		sscanf(line, "%f %f %f %f %f %f %f %f", &info.position.x, &info.position.y, &info.position.z,
+				&info.orientation.w, &info.orientation.x, &info.orientation.y, &info.orientation.z,
+				&info.timeElapsed);
+		
+		mFrameInfo.push_back(info);
+		
+		/*
+		std::stringstream d;
+		d << StringConverter::toString(info.position) << " " << StringConverter::toString(info.orientation);
+		LogManager::getSingleton().logMessage(d.str());
+		*/
+	}
+	ifstr.close();
+}
+//-----------------------------------------------------------------------
+void MouseQueryListener::setAppState(int state)
+{
+	mAppState = state;
+}
+//-----------------------------------------------------------------------
+void MouseQueryListener::nextAppState()
+{
+	mCurrentFrame = 0;
+
+	// if last state was replay state
+	if (mAppState == REPLAY)
+	{
+		// reset debug text and write frame info to file
+		mWindow->setDebugText("");
+		writeFrames();
+		
+		//-- write out stats
+		std::stringstream d;
+		d << "Algorithm: " << mCurrentAlgorithmCaptions[mCurrentAlgorithm] << "\n"
+		  << "avg. FPS: " << mWindow->getAverageFPS() << "\n"
+		  << "best FPS: " << mWindow->getBestFPS() << "\n"
+		  << "worst FPS: " << mWindow->getWorstFPS() << "\n"
+		  << "best frame time: " <<	mWindow->getBestFrameTime() << "\n"
+		  << "worst frame time: " << mWindow->getWorstFrameTime();
+ 		
+		LogManager::getSingleton().logMessage(d.str());
+	}
+	
+	//-- set the next státe
+	mAppState = (mAppState + 1) % STATE_NUM;
+
+	// replay recorded walkthrough
+	if (mAppState == REPLAY)
+	{
+		// no recording during replay
+		mRecord = false;
+
+		// load recorded walkthrough
+		if (mFrameInfo.size() == 0)
+		{
+			loadFrames();
+		}
+
+		// if there are no recorded frames => set next state
+		if (mFrameInfo.size() == 0) 
+		{
+			nextAppState();
+		}
+		else
+		{
+			mWindow->setDebugText("Replay");
+			
+			// reset, because we measure fps stats during walkthrough
+			mWindow->resetStatistics();
+
+			//-- initialise frame data
+			mTimeElapsed = 0;
+
+			mCamNode->setPosition(mFrameInfo[0].position);
+			mCamNode->setOrientation(mFrameInfo[0].orientation);
+		}
+	}
+
+}
+//-----------------------------------------------------------------------
+void MouseQueryListener::toggleRecord()
+{
+	mRecord = !mRecord;
+
+	// clear previous camera path
+	if (mRecord)
+		mFrameInfo.clear();
+	else
+		mWindow->setDebugText("");
+}
+//-----------------------------------------------------------------------
 void MouseQueryListener::changeThreshold(int incr)
 {
@@ -452,5 +594,5 @@
 void MouseQueryListener::nextAlgorithm()
 {
-	mCurrentAlgorithm = ++mCurrentAlgorithm % 
+	mCurrentAlgorithm = (mCurrentAlgorithm + 1) % 
 		GtpVisibility::VisibilityEnvironment::NUM_CULLING_MANAGERS,
 
@@ -586,17 +728,57 @@
 }
 //-----------------------------------------------------------------------
-void MouseQueryListener::AddCameraPath(SceneNode *camNode)
+void MouseQueryListener::addFrameInfo(SceneNode *camNode, Real timeElapsed)
 {
 	frame_info info;
 	info.orientation = mCamNode->getOrientation();
 	info.position = mCamNode->getPosition();
-	mCameraPath.push_back(info);
-}
-//-----------------------------------------------------------------------
-void MouseQueryListener::SetCurrentCameraPath(SceneNode *camNode)
-{
-	mCamNode->setPosition(mCameraPath[mCurrentFrame].position);
-	mCamNode->setOrientation(mCameraPath[mCurrentFrame].orientation);
-	(mCurrentFrame++) % mCameraPath.size();
+	info.timeElapsed = timeElapsed;
+
+	mFrameInfo.push_back(info);
+}
+//-----------------------------------------------------------------------
+void MouseQueryListener::setCurrentFrameInfo(Real timeElapsed)
+{
+	//-- find right frame relative to elapsed frame time		
+	mTimeElapsed -= timeElapsed;
+
+	while ((mTimeElapsed <= 0) && (mCurrentFrame < (int)mFrameInfo.size() - 1))
+	{
+		mTimeElapsed += mFrameInfo[mCurrentFrame ++].timeElapsed;
+		/*std::stringstream d;
+		d << StringConverter::toString(mTimeElapsed) << " " 
+			<< StringConverter::toString(timeElapsed)  << " " 
+			<< StringConverter::toString(mFrameInfo[mCurrentFrame - 1].timeElapsed) 
+			<< " " << mCurrentFrame;
+		LogManager::getSingleton().logMessage(d.str());*/
+	}
+
+	frame_info new_frame = mFrameInfo[mCurrentFrame];
+	frame_info old_frame = mFrameInfo[mCurrentFrame - 1];
+		
+	//-- interpolate frames
+	Real factor = 1;
+
+	if (old_frame.timeElapsed > 0)
+		factor = mTimeElapsed / old_frame.timeElapsed;
+
+	Vector3 camPos = old_frame.position + factor * (new_frame.position - old_frame.position);
+	Quaternion camOrienation = Quaternion::Slerp(factor, old_frame.orientation, 
+		new_frame.orientation, true);
+
+	mCamNode->setPosition(camPos);
+	mCamNode->setOrientation(camOrienation);
+	/*
+	std::stringstream d;
+	d << "old pos: " << StringConverter::toString(old_frame.position) << "\n"
+	  << "interp pos: " << StringConverter::toString(camPos) << "\n"
+	  << " new pos: " << StringConverter::toString(new_frame.position);
+	LogManager::getSingleton().logMessage(d.str());*/
+
+	// stop replay after a full walkthrough
+	if (mCurrentFrame == (int)mFrameInfo.size() - 1)
+	{
+		nextAppState();
+	}
 }
 
@@ -604,5 +786,5 @@
 /*      VisualizationRenderTargetListener implementation      */
 /**************************************************************/
-
+//-----------------------------------------------------------------------
 VisualizationRenderTargetListener::VisualizationRenderTargetListener(SceneManager *sceneMgr)
 :RenderTargetListener(), mSceneMgr(sceneMgr)
Index: trunk/VUT/work/TestCullingTerrain/TestCullingTerrainApplication.h
===================================================================
--- trunk/VUT/work/TestCullingTerrain/TestCullingTerrainApplication.h	(revision 106)
+++ trunk/VUT/work/TestCullingTerrain/TestCullingTerrainApplication.h	(revision 107)
@@ -5,5 +5,5 @@
 #include "CEGUIForwardRefs.h"
 #include "ExampleApplication.h"
-#include "TerrainContentGenerator.h"
+#include "OgreTerrainContentGenerator.h"
 #include "VisibilityEnvironment.h"
 #include <OgreRenderTargetListener.h>
@@ -32,4 +32,5 @@
 	Vector3 position;
 	Quaternion orientation;
+	Real timeElapsed;
 } frame_info;
 
@@ -84,8 +85,10 @@
 	void keyClicked(KeyEvent* e);
 
+	enum  {WALKTHROUGH, REPLAY, STATE_NUM};
+
 	void nextAlgorithm();
-	void setAlgorithm(int algorithm);
 	void changeThreshold(int incr);
 	void updateStats();
+
 	void toggleUseOptimization();
 	void toggleShowOctree();
@@ -93,11 +96,20 @@
 	void toggleShowViz();
 	void toggleRenderNodesForViz();
+	void toggleRecord();
+
 	void zoomVizCamera(int zoom);
+	
+	void addFrameInfo(SceneNode *camNode, Real timeElapsed);
+	void setCurrentFrameInfo(Real timeElapsed);
+
+	void setAppState(int state);
+	void nextAppState();
+
+	void setAlgorithm(int algorithm);
+
 	void moveCamera();
-	void AddCameraPath(SceneNode *camNode);
-	void SetCurrentCameraPath(SceneNode *camNode);
-
-	enum {WALKTHROUGH, REPLAY} State;
-
+	
+	void writeFrames();
+	void loadFrames();
 
 protected:
@@ -124,6 +136,6 @@
 	OverlayElement *mQueriesIssuedInfo;
 
-	SceneNode *mCurrentObject;         // The newly created object
-	int mObjectCount;                 // The number of robots on the screen
+	SceneNode *mCurrentObject;    // the newly created object
+	int mObjectCount;             // The number of objects on the screen
 
 	RayQueryExecutor *mRayQueryExecutor;
@@ -143,9 +155,11 @@
 	
 	//std::deque<Vector3> mWalkList;   // The list of points we are walking to
-	std::vector<frame_info> mCameraPath;
+	std::vector<frame_info> mFrameInfo;
 		
 	int mCurrentFrame;
 	// the current application state
-	int mState;
+	int mAppState;
+	bool mRecord;
+	Real mTimeElapsed;
 };
 
Index: trunk/VUT/work/TestCullingTerrain/TerrainContentGenerator.cpp
===================================================================
--- trunk/VUT/work/TestCullingTerrain/TerrainContentGenerator.cpp	(revision 106)
+++ 	(revision )
@@ -1,94 +1,0 @@
-#include "TerrainContentGenerator.h"
-
-namespace Ogre {
-
-/*************************************************/
-/*         RayQueryExecutor implementation       */
-/*************************************************/
-
-//-----------------------------------------------------------------------
-RayQueryExecutor::RayQueryExecutor(SceneManager *sm)
-{
-	mRaySceneQuery = sm->createRayQuery(Ray());
-}
-//-----------------------------------------------------------------------
-RayQueryExecutor::~RayQueryExecutor()
-{
-	delete mRaySceneQuery;
-}
-//-----------------------------------------------------------------------
-bool RayQueryExecutor::executeRayQuery(Vector3 *result, const Vector3 &pos, 
-									   const Vector3 &dir)
-{
-	return executeRayQuery(result, Ray(pos, dir));
-}
-//-----------------------------------------------------------------------
-bool RayQueryExecutor::executeRayQuery(Vector3 *result, const Ray &ray)
-{
-    mRaySceneQuery->setRay(ray);
-
-    // Perform the scene query
-    RaySceneQueryResult &queryResult = mRaySceneQuery->execute();
-    RaySceneQueryResult::iterator it = queryResult.begin();
-
-	if (it != queryResult.end() && it->worldFragment)
-	{
-		SceneQuery::WorldFragment* wf = it->worldFragment;
-
-		*result = wf->singleIntersection; 
-		return true;
-	}
-
-	return false;
-}
-
-/*******************************************************/
-/*     TerrainContentGenerator implementation          */
-/*******************************************************/
-
-//-----------------------------------------------------------------------
-TerrainContentGenerator::TerrainContentGenerator(SceneManager *sm):
-SceneContentGenerator(sm), mMaxHeight(50)
-{
-	mMinPos = Vector3(0.0f, 5000.0f, 0.0f);
-	mMaxPos = Vector3(3000.0f, 5000.0f, 3000.0f);
-
-	mMinAngle = Vector3(0.0f, 0.0f, 0.0f);
-	mMaxAngle = Vector3(360.0f, 0.0f, 0.0f);
-
-	mRayQueryExecutor = new RayQueryExecutor(sm);
-}
-//-----------------------------------------------------------------------
-TerrainContentGenerator::~TerrainContentGenerator()
-{
-	delete mRayQueryExecutor;
-}
-//-----------------------------------------------------------------------
-SceneNode *TerrainContentGenerator::GenerateSceneObject(const Vector3 &position, 
-					 const Vector3 &rotation, const String& objName)
-{
-	Vector3 queryResult;
-	Vector3 pos(position.x, 5000, position.z);
-	if (mRayQueryExecutor->executeRayQuery(&queryResult, position, Vector3::NEGATIVE_UNIT_Y))
-	{
-		// reject if height is too high
-		if(queryResult.y < mMaxHeight)
-		{
-			return SceneContentGenerator::GenerateSceneObject(queryResult, rotation, objName);
-		}
-	}
-	
-	return NULL;
-}
-//-----------------------------------------------------------------------
-RayQueryExecutor *TerrainContentGenerator::GetRayQueryExecutor()
-{
-	return mRayQueryExecutor;
-}
-//-----------------------------------------------------------------------
-void TerrainContentGenerator::SetMaxHeight(Real maxHeight)
-{
-	mMaxHeight = maxHeight;
-}
-
-} // namespace Ogre
Index: trunk/VUT/work/TestCullingTerrain/TerrainContentGenerator.h
===================================================================
--- trunk/VUT/work/TestCullingTerrain/TerrainContentGenerator.h	(revision 106)
+++ 	(revision )
@@ -1,50 +1,0 @@
-#ifndef _TERRAINCONTENTGENERATOR_H__
-#define _TERRAINCONTENTGENERATOR_H__
-
-#include "SceneContentGenerator.h"
-#include <Ogre.h>
-
-namespace Ogre {
-
-/** Class which executes a simple ray query.
-*/
-class RayQueryExecutor
-{
-public:
-	RayQueryExecutor(SceneManager *sm);
-	~RayQueryExecutor();
-	
-	bool executeRayQuery(Vector3 *result, const Vector3 &pos, const Vector3 &dir);
-	bool RayQueryExecutor::executeRayQuery( Vector3 *result, const Ray &ray);
-
-protected:
-	RaySceneQuery *mRaySceneQuery;
-};
-
-/** 
-	Class which randomly fills a terrain with objects.
-*/
-class TerrainContentGenerator: public SceneContentGenerator
-{
-public:
-	TerrainContentGenerator(SceneManager *sm);
-	~TerrainContentGenerator();
-
-	/** 
-		Generates objects and places it on the terrain
-	*/
-	SceneNode *GenerateSceneObject(const Vector3 &position, 
-		const Vector3 &rotation, const String &objName);
-	
-	/** maximum height where objects can be put into the terrain */
-	void SetMaxHeight(Real maxHeight);
-	
-	RayQueryExecutor *GetRayQueryExecutor();
-
-protected:
-	RayQueryExecutor *mRayQueryExecutor;
-	Real mMaxHeight;
-};
-
-} // namespace Ogre
-#endif // _TERRAINCONTENTGENERATOR_H
Index: trunk/VUT/work/TestCulling/TestCulling.vcproj
===================================================================
--- trunk/VUT/work/TestCulling/TestCulling.vcproj	(revision 82)
+++ trunk/VUT/work/TestCulling/TestCulling.vcproj	(revision 107)
@@ -72,5 +72,5 @@
 			<Tool
 				Name="VCCLCompilerTool"
-				AdditionalIncludeDirectories="&quot;$(OGRE_PATH)\Dependencies\include&quot;;&quot;$(OGRE_PATH)\OgreMain\include&quot;;&quot;$(OGRE_PATH)\Samples\Common\include&quot;;&quot;$(OGRE_PATH)\Dependencies\include\CEGUI&quot;;&quot;$(OGRE_PATH)\PlugIns\OctreeSceneManager\include&quot;;&quot;$(OGRE_ADDONS_PATH)\dotsceneoctree\PlugIns\DotSceneManager\include&quot;;&quot;$(OGRE_PATH)\Samples\Common\CEGUIRenderer\include&quot;;../include;../../GtpVisibility/include"
+				AdditionalIncludeDirectories="&quot;$(OGRE_PATH)\Dependencies\include&quot;;&quot;$(OGRE_PATH)\OgreMain\include&quot;;&quot;$(OGRE_PATH)\Samples\Common\include&quot;;&quot;$(OGRE_PATH)\Dependencies\include\CEGUI&quot;;&quot;$(OGRE_PATH)\PlugIns\OctreeSceneManager\include&quot;;&quot;$(OGRE_ADDONS_PATH)\dotsceneoctree\PlugIns\DotSceneManager\include&quot;;&quot;$(OGRE_PATH)\Samples\Common\CEGUIRenderer\include&quot;;../include;../../Ogre/include;../../GtpVisibility/include"
 				PreprocessorDefinitions="_WINDOWS;_STLP_USE_DYNAMIC_LIB;OGRE_LIBRARY_IMPORTS;_RELEASE;WIN32;_STLP_RELEASE;GTP_VISIBILITY_MODIFIED_OGRE"
 				RuntimeLibrary="2"
@@ -83,8 +83,8 @@
 			<Tool
 				Name="VCLinkerTool"
-				AdditionalDependencies="OGREMain.LIB Plugin_OctreeSceneManager.lib CEGUIBase.lib OgreGUIRenderer.lib"
+				AdditionalDependencies="OGREMain.LIB Plugin_OctreeSceneManager.lib CEGUIBase.lib OgreGUIRenderer.lib Plugin_VisibilitySceneManager.lib"
 				OutputFile="$(OGRE_PATH)/Samples/Common/bin/Release/TestCulling.exe"
 				LinkIncremental="1"
-				AdditionalLibraryDirectories="&quot;$(OGRE_PATH)\Dependencies\Lib\$(ConfigurationName)&quot;;&quot;$(OGRE_ADDONS_PATH)\dotsceneoctree\PlugIns\DotSceneManager\bin\$(ConfigurationName)&quot;;&quot;$(OGRE_PATH)\OgreMain\Lib\$(ConfigurationName)&quot;;&quot;$(OGRE_PATH)\PlugIns\OctreeSceneManager\bin\$(ConfigurationName)&quot;;&quot;$(OGRE_PATH)\Samples\Common\CEGUIRenderer\lib&quot;"
+				AdditionalLibraryDirectories="&quot;$(OGRE_PATH)\Dependencies\Lib\$(ConfigurationName)&quot;;&quot;$(OGRE_ADDONS_PATH)\dotsceneoctree\PlugIns\DotSceneManager\bin\$(ConfigurationName)&quot;;&quot;$(OGRE_PATH)\OgreMain\Lib\$(ConfigurationName)&quot;;&quot;$(OGRE_PATH)\PlugIns\OctreeSceneManager\bin\$(ConfigurationName)&quot;;&quot;$(GAMETOOLS_PATH)\trunk\VUT\Ogre\lib\$(ConfigurationName)&quot;;&quot;$(OGRE_PATH)\Samples\Common\CEGUIRenderer\lib&quot;"
 				GenerateDebugInformation="TRUE"
 				SubSystem="2"
@@ -122,7 +122,4 @@
 			UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}">
 			<File
-				RelativePath=".\SceneContentGenerator.cpp">
-			</File>
-			<File
 				RelativePath=".\TestCullingApplication.cpp">
 			</File>
@@ -132,7 +129,4 @@
 			Filter="h;hpp;hxx;hm;inl;inc;xsd"
 			UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}">
-			<File
-				RelativePath=".\SceneContentGenerator.h">
-			</File>
 			<File
 				RelativePath=".\TestCullingApplication.h">
Index: trunk/VUT/work/TestCulling/TestCullingApplication.cpp
===================================================================
--- trunk/VUT/work/TestCulling/TestCullingApplication.cpp	(revision 103)
+++ trunk/VUT/work/TestCulling/TestCullingApplication.cpp	(revision 107)
@@ -14,5 +14,5 @@
 #include <Ogre.h>
 #include "TestCullingApplication.h"
-#include "SceneContentGenerator.h"
+#include "OgreSceneContentGenerator.h"
 
 #define WIN32_LEAN_AND_MEAN
@@ -212,6 +212,6 @@
 	 if ( mRMouseDown )
 	 {
-		 mCamera->yaw( -e->getRelX() * mRotateSpeed );
-		 mCamera->pitch( -e->getRelY() * mRotateSpeed );
+		 mCamera->yaw(-e->getRelX() * mRotateSpeed);
+		 mCamera->pitch(-e->getRelY() * mRotateSpeed);
 	 }
 }
Index: trunk/VUT/work/TestCulling/TestCullingApplication.h
===================================================================
--- trunk/VUT/work/TestCulling/TestCullingApplication.h	(revision 100)
+++ trunk/VUT/work/TestCulling/TestCullingApplication.h	(revision 107)
@@ -6,5 +6,5 @@
 #include "ExampleApplication.h"
 #include "VisibilityEnvironment.h"
-#include "SceneContentGenerator.h"
+#include "OgreSceneContentGenerator.h"
 
 Real timeDelay = 0;
Index: trunk/VUT/work/TestCulling/SceneContentGenerator.cpp
===================================================================
--- trunk/VUT/work/TestCulling/SceneContentGenerator.cpp	(revision 106)
+++ 	(revision )
@@ -1,107 +1,0 @@
-/**
-    \file 
-        SceneContentGenerator.cpp
-    \brief
-        Creates content for a scene.
-*/
-#include "SceneContentGenerator.h"
-
-namespace Ogre {
-
-/*******************************************************/
-/*     SceneContentGenerator implementation            */
-/*******************************************************/
-
-//-----------------------------------------------------------------------
-SceneContentGenerator::SceneContentGenerator(SceneManager *sm):
-mSceneMgr(sm), mObjectCount(0),
-mMinPos(Vector3(-70.0f, -70.0f, 0.0f)),
-mMaxPos(Vector3(70.0f, 70.0f, 600.0f)), 
-mMinAngle(Vector3(0.0f, 0.0f, 0.0f)),
-mMaxAngle(Vector3(360, 360, 360)),
-mScale(0.1, 0.1, 0.1)
-{
-}
-//-----------------------------------------------------------------------
-void SceneContentGenerator::GenerateScene(int numObjects, const String &objName)
-{
-	// initialise random generator
-	srand (time(0));
-	
-	Vector3 rotationRatio;
-	Vector3 translationRatio;
-
-	int currentCount = mObjectCount;
-	int limit = 0;
-
-	//-- create random values between zero and one
-	while ((mObjectCount - currentCount < numObjects) && (limit < 50000))
-	{
-		rotationRatio.x = rand() / (float) RAND_MAX;
-		rotationRatio.y = rand() / (float) RAND_MAX;
-		rotationRatio.z = rand() / (float) RAND_MAX;
-
-		translationRatio.x = rand() / (float) RAND_MAX;
-		translationRatio.y = rand() / (float) RAND_MAX;
-		translationRatio.z = rand() / (float) RAND_MAX;
-
-		// Setup the ray scene query
-		Vector3 rotation = mMinAngle + rotationRatio * (mMaxAngle - mMinAngle);
-		Vector3 position = mMinPos + translationRatio * (mMaxPos - mMinPos);
-
-		(void)GenerateSceneObject(position, rotation, objName);
-		++limit; // just in case: to avoid endless loop
-	}
-}
-//-----------------------------------------------------------------------
-SceneNode *SceneContentGenerator::GenerateSceneObject(const Vector3 &position, 
-					 const Vector3 &rotation, const String& objName)
-{
-	char name[25];
-	sprintf(name, "Entity%d", mObjectCount++);
-		
-	Entity *ent = mSceneMgr->createEntity(name, objName);
-		
-	SceneNode *currentObject = mSceneMgr->getRootSceneNode()->
-		createChildSceneNode(String(name) + "Node", position);
-
-	currentObject->attachObject(ent);
-	currentObject->setScale(mScale);
-		
-	currentObject->yaw(Degree(rotation.x));
-	currentObject->pitch(Degree(rotation.y));
-	currentObject->roll(Degree(rotation.z));
-
-	return currentObject;
-}
-//-----------------------------------------------------------------------
-void SceneContentGenerator::SetMinAngle(Vector3 minAngle)
-{
-	mMinAngle = minAngle;
-}
-//-----------------------------------------------------------------------
-void SceneContentGenerator::SetMaxAngle(Vector3 maxAngle)
-{
-	mMaxAngle = maxAngle;
-}
-//-----------------------------------------------------------------------
-void SceneContentGenerator::SetMinPos(Vector3 minPos)
-{
-	mMinPos = minPos;
-}
-//-----------------------------------------------------------------------
-void SceneContentGenerator::SetMaxPos(Vector3 maxPos)
-{
-	mMaxPos = maxPos;
-}
-//-----------------------------------------------------------------------
-int SceneContentGenerator::GetObjectCount()
-{
-	return mObjectCount;
-}
-//-----------------------------------------------------------------------
-void SceneContentGenerator::SetScale(Vector3 scale)
-{
-	mScale = scale;
-}
-} // namespace Ogre
Index: trunk/VUT/work/TestCulling/SceneContentGenerator.h
===================================================================
--- trunk/VUT/work/TestCulling/SceneContentGenerator.h	(revision 106)
+++ 	(revision )
@@ -1,53 +1,0 @@
-#ifndef _SCENECONTENTGENERATOR_H__
-#define _SCENECONTENTGENERATOR_H__
-
-#include <OgrePrerequisites.h>
-#include <OgreMath.h>
-#include <Ogre.h>
-
-namespace Ogre {
-
-/** Class which fills a scene with content in a random fashion.
-*/
-class SceneContentGenerator
-{
-public:
-	SceneContentGenerator(SceneManager *sm);
-	virtual ~SceneContentGenerator() {};
-	/** Generates scene object in a random fashion.
-		@param number of objects to generate
-		@param objName the name of the mesh to be generated
-	*/
-	void GenerateScene(int numObjects, const String &objName);
-	/** Generates a new object in the scene using ray scene queries 
-		and inserts it into thr scene hierarchy.
-		@param position position where the object is created
-		@param rotation rotation angle applied locally to object
-		@objName the name of the object entity
-		@returns scene object if it was successfully created, NULL otherwise
-	*/
-	virtual SceneNode *GenerateSceneObject(const Vector3 &position, 
-		const Vector3 &rotation, const String &objName);
-
-	void SetMinAngle(Vector3 minAngle);
-	void SetMaxAngle(Vector3 maxAngle);
-	void SetMinPos(Vector3 minPos);
-	void SetMaxPos(Vector3 maxPos);
-	int GetObjectCount();
-	void SetScale(Vector3 scale);
-
-protected:
-
-	Vector3 mMinAngle;
-	Vector3 mMaxAngle;
-	Vector3 mMaxPos;
-	Vector3 mMinPos;
-	Vector3 mScale;
-
-	SceneManager *mSceneMgr;
-	int mObjectCount;		// The number of objects on the screen
-};
-
-} // namespace Ogre
-
-#endif // SCENECONTENTGENERATOR_H_
