Index: trunk/VUT/OcclusionCullingSceneManager/TestCullingTerrain/TerrainContentGenerator.cpp
===================================================================
--- trunk/VUT/OcclusionCullingSceneManager/TestCullingTerrain/TerrainContentGenerator.cpp	(revision 47)
+++ trunk/VUT/OcclusionCullingSceneManager/TestCullingTerrain/TerrainContentGenerator.cpp	(revision 55)
@@ -5,10 +5,92 @@
         Creates content for the terrain,
 */
-
 #include "TerrainContentGenerator.h"
 
 //-----------------------------------------------------------------------
-TerrainContentGenerator::TerrainContentGenerator( void )
+TerrainContentGenerator::TerrainContentGenerator( SceneManager *sm, RayQueryExecutor *rayQueryEx )
 {
+	mSceneMgr = sm;
+	mRayQueryExecutor = rayQueryEx;
+
+	mMinTranslation = Vector3(-70.0f, -70.0f, 0.0f);
+	mMaxTranslation = Vector3(70.0f, 70.0f, 600.0f);
+
+	mMinAngle = 0;
+	mMaxAngle = 360;
+
+	mCount = 0;
 }
+//-----------------------------------------------------------------------
+void TerrainContentGenerator::generateScene( int numObjects )
+{
+	srand (time (0));
+	
+	Vector3 rotationRatio;
+	Vector3 translationRatio;
 
+	for(int i=0; i < numObjects; i++)
+	{
+		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;
+
+		generateSceneObject(translationRatio, rotationRatio, i, "sphere.mesh");
+	}
+}
+//-----------------------------------------------------------------------
+void TerrainContentGenerator::generateSceneObject(const Vector3 &translationRatio, 
+					 const Vector3 &rotationRatio, const int idx, const String& entName)
+{
+	// Setup the ray scene query
+	Real rotation = mMinAngle + rotationRatio.x * (mMaxAngle - mMinAngle);
+	Vector3 translation = mMinTranslation + translationRatio * (mMaxTranslation - mMinTranslation);
+
+	translation.y = 5000;
+    
+	Vector3 queryResult;
+
+	if(mRayQueryExecutor->executeRayQuery(&queryResult, translation, Vector3::NEGATIVE_UNIT_Y))
+	{
+		char name[16];
+		sprintf( name, "%s%d", entName.c_str(), mCount++);
+
+		Entity *ent = mSceneMgr->createEntity(name, entName);
+		SceneNode *currentObject = mSceneMgr->getRootSceneNode( )->createChildSceneNode( String(name) + "Node", queryResult);
+		currentObject->attachObject(ent);
+		currentObject->setScale(0.1f, 0.1f, 0.1f);
+	}
+}
+//-----------------------------------------------------------------------
+RayQueryExecutor::RayQueryExecutor( SceneManager *sm )
+{
+	mRaySceneQuery = sm->createRayQuery(Ray());
+}
+//-----------------------------------------------------------------------
+RayQueryExecutor::~RayQueryExecutor()
+{
+	delete mRaySceneQuery;
+}
+//-----------------------------------------------------------------------
+bool RayQueryExecutor::executeRayQuery( Vector3 *result, const Vector3 &pos, const Vector3 &dir )
+{
+	Ray ray(pos, dir);
+    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;
+}
Index: trunk/VUT/OcclusionCullingSceneManager/TestCullingTerrain/TestCullingTerrainApplication.cpp
===================================================================
--- trunk/VUT/OcclusionCullingSceneManager/TestCullingTerrain/TestCullingTerrainApplication.cpp	(revision 52)
+++ trunk/VUT/OcclusionCullingSceneManager/TestCullingTerrain/TestCullingTerrainApplication.cpp	(revision 55)
@@ -20,13 +20,14 @@
 #include "windows.h"
 
-//RaySceneQuery* mRaySceneQuery = 0;
-
-/***********************************************/
-/* TestCullingTerrainApplication implementation       */
-/***********************************************/
-/*TestCullingTerrainApplication::~TestCullingTerrainApplication()
-{
-	delete mRaySceneQuery;
-}*/
+
+/************************************************/
+/* TestCullingTerrainApplication implementation */
+/************************************************/
+TestCullingTerrainApplication::~TestCullingTerrainApplication()
+{
+	delete mRayQueryExecutor;
+	delete mTerrainContentGenerator;
+}
+
 //-----------------------------------------------------------------------
 void TestCullingTerrainApplication::createCamera( void )
@@ -40,10 +41,41 @@
 	// Look back along -Z
     mCamera->lookAt(Vector3(0,0,-300));
-    mCamera->setNearClipDistance( 1 );
-    mCamera->setFarClipDistance( 1000 );
-}
-//-----------------------------------------------------------------------
-void TestCullingTerrainApplication::createScene(void)
-{
+    mCamera->setNearClipDistance(1);
+    mCamera->setFarClipDistance(1000);
+}
+//-----------------------------------------------------------------------
+void TestCullingTerrainApplication::generateSceneObject(const Vector3 &translationRatio, 
+					 const Vector3 &rotationRatio, const int idx, const String& entName)
+{
+	// Setup the ray scene query
+	/*Vector3 rotation = mMinAngle + rotationRatio * (mMaxAngle - mMinAngle);
+	Vector3 translation = mMinTranslation + translationRatio * (mMaxTranslation - mMinTranslation);
+
+	translation.y = 5000;
+    Ray ray(translation, Vector3::NEGATIVE_UNIT_Y);
+    mRaySceneQuery->setRay(ray);
+
+    // Execute query
+	RaySceneQueryResult &result = mRaySceneQuery->execute();
+	RaySceneQueryResult::iterator itr = result.begin( );
+
+	// Get results, create a node/entity on the position
+	if ( itr != result.end() && itr->worldFragment )
+	{
+		char name[16];
+		sprintf( name, "%s%d", entName.c_str(), mCount++ );
+
+		Entity *ent = mSceneMgr->createEntity( name, entName );
+		SceneNode currentObject = mSceneMgr->getRootSceneNode( )->createChildSceneNode( String(name) + "Node", itr->worldFragment->singleIntersection );
+		currentObject->attachObject( ent );
+		currentObject->setScale( 0.1f, 0.1f, 0.1f );
+	}*/
+}
+
+//-----------------------------------------------------------------------
+void TestCullingTerrainApplication::createScene( void )
+{
+	mRayQueryExecutor = new RayQueryExecutor(mSceneMgr);
+	mTerrainContentGenerator = new TerrainContentGenerator(mSceneMgr, mRayQueryExecutor);
 	// Set ambient light
 	mSceneMgr->setAmbientLight(ColourValue(0.5, 0.5, 0.5));
@@ -62,7 +94,4 @@
 	mWindow->getViewport(0)->setBackgroundColour(fadeColour);
 	//mSceneMgr->setFog( FOG_LINEAR, fadeColour, .001, 500, 1000);
-    //mSceneMgr->setFog( FOG_EXP, fadeColour, 0.005 );
-
-	
 
 	// Create a skybox
@@ -94,23 +123,4 @@
 	mCamera->setOrientation(Quaternion(-0.3486, 0.0122, 0.9365, 0.0329));
 
-	/*
-	Entity *robotEnt = mSceneMgr->createEntity( "Robot", "robot.mesh" );
-	SceneNode *robotNode = mSceneMgr->getRootSceneNode()->createChildSceneNode( "RobotNode", Vector3( 750, 25, 600 ));
-	robotNode->attachObject( robotEnt );
-	robotNode->scale( .3, .3, .3 );
-	robotNode->yaw( Degree( 160 ) );
-
-	Entity *ogreEnt = mSceneMgr->createEntity( "Ogre", "ogrehead.mesh" );
-    SceneNode *ogreNode = mSceneMgr->getRootSceneNode()->createChildSceneNode( "Ogre", Vector3( 800, 50, 830 ) );
-    ogreNode->attachObject( ogreEnt );
-	ogreNode->scale(.2,.2,.2);
-	ogreNode->yaw( Degree( 20 ) );
-
-	Entity *ogreEnt2 = mSceneMgr->createEntity( "Ogre2", "ogrehead.mesh" );
-    SceneNode *ogreNode2 = mSceneMgr->getRootSceneNode()->createChildSceneNode( "Ogre2", Vector3( 700, 50, 730 ) );
-    ogreNode2->attachObject( ogreEnt2 );
-	ogreNode2->scale(.05,.05,.05);
-	ogreNode->yaw( Degree( 40 ) );*/
-
 	// CEGUI setup
 	setupGui();
@@ -133,5 +143,5 @@
 void TestCullingTerrainApplication::createFrameListener(void)
 {
-	mFrameListener= new MouseQueryListener(mWindow, mCamera, mSceneMgr, mGUIRenderer);
+	mFrameListener= new MouseQueryListener(mWindow, mCamera, mSceneMgr, mGUIRenderer, mRayQueryExecutor);
 	mFrameListener->showDebugOverlay(true);
 	mRoot->addFrameListener(mFrameListener);
@@ -148,7 +158,6 @@
 /***********************************************/
 //-----------------------------------------------------------------------
-MouseQueryListener::MouseQueryListener(RenderWindow* win, Camera* cam, SceneManager *sceneManager, CEGUI::Renderer *renderer)
-        : ExampleFrameListener(win, cam, false, true), mGUIRenderer(renderer), 
-		mShutdownRequested(false)
+MouseQueryListener::MouseQueryListener(RenderWindow* win, Camera* cam, SceneManager *sceneManager, CEGUI::Renderer *renderer, RayQueryExecutor *rqe)
+        : ExampleFrameListener(win, cam, false, true), mGUIRenderer(renderer), mShutdownRequested(false), mRayQueryExecutor(rqe)
 {
 
@@ -171,5 +180,5 @@
 	mEventProcessor->addKeyListener(this);
 
-	mRaySceneQuery = mSceneMgr->createRayQuery( Ray() );
+	mRaySceneQuery = mSceneMgr->createRayQuery(Ray());
 
 	// show overlay
Index: trunk/VUT/OcclusionCullingSceneManager/TestCullingTerrain/TerrainContentGenerator.h
===================================================================
--- trunk/VUT/OcclusionCullingSceneManager/TestCullingTerrain/TerrainContentGenerator.h	(revision 47)
+++ trunk/VUT/OcclusionCullingSceneManager/TestCullingTerrain/TerrainContentGenerator.h	(revision 55)
@@ -3,12 +3,44 @@
         TerrainContentGenerator.h
 */
+#include "ExampleApplication.h"
+
+class RayQueryExecutor
+{
+public:
+	RayQueryExecutor( SceneManager *sm );
+	~RayQueryExecutor( );
+	bool executeRayQuery( Vector3 *result, const Vector3 &pos, const Vector3 &dir );
+protected:
+	RaySceneQuery *mRaySceneQuery;
+};
 
 class TerrainContentGenerator
 {
 public:
-	TerrainContentGenerator();
+	TerrainContentGenerator(  SceneManager *sm, RayQueryExecutor *rayQueryEx );
+	/** generates a the scene hierarchy with random values 
+	@param number of objects to generate
+	*/
+	void generateScene( int numObjects );
+	/** 
+		generates a new scene object 
+		@param tranlationRatio ratio between minimal and maximal possible translation
+		@param rotationRatio ratio between minimal and maximal possible rotation
+		@idx the index of the new object
+		@entName the name of the object entity
+	*/
+	void generateSceneObject( const Vector3 &translationRatio, const Vector3 &rotationRatio, 
+							  const int idx, const String &entName );
 
 protected:
 
+	Real mMinAngle;
+	Real mMaxAngle;
+	Vector3 mMaxTranslation;
+	Vector3 mMinTranslation;
+
+	RayQueryExecutor *mRayQueryExecutor;
+	SceneManager *mSceneMgr;
+	int mCount;		// The number of objects on the screen
 };
 
Index: trunk/VUT/OcclusionCullingSceneManager/TestCullingTerrain/TestCullingTerrainApplication.h
===================================================================
--- trunk/VUT/OcclusionCullingSceneManager/TestCullingTerrain/TestCullingTerrainApplication.h	(revision 52)
+++ trunk/VUT/OcclusionCullingSceneManager/TestCullingTerrain/TestCullingTerrainApplication.h	(revision 55)
@@ -6,4 +6,5 @@
 #include "ExampleApplication.h"
 #include "OgreOcclusionCullingSceneTraverser.h"
+#include "TerrainContentGenerator.h"
 
 Real timeDelay = 0;
@@ -28,5 +29,6 @@
 public:
 
-    MouseQueryListener(RenderWindow* win, Camera* cam, SceneManager *sceneManager, CEGUI::Renderer *renderer);
+    MouseQueryListener(RenderWindow* win, Camera* cam, SceneManager *sceneManager, 
+		CEGUI::Renderer *renderer, RayQueryExecutor *rqe);
 
 
@@ -82,6 +84,8 @@
 
 	SceneNode *mCurrentObject;         // The newly created object
+	RaySceneQuery *mRaySceneQuery;     // The ray scene query pointer
 	int mCount;                        // The number of robots on the screen
-	RaySceneQuery *mRaySceneQuery;     // The ray scene query pointer
+
+	RayQueryExecutor *mRayQueryExecutor;
 };
 
@@ -90,5 +94,5 @@
 {
 public:
-	//~TestCullingTerrainApplication();
+	~TestCullingTerrainApplication();
 
 protected:
@@ -98,6 +102,24 @@
 	virtual void createCamera(void);
 
+	/** 
+		generates a new scene object 
+		@param tranlationRatio ratio between minimal and maximal possible translation
+		@param rotationRatio ratio between minimal and maximal possible rotation
+		@idx the index of the new object
+		@entName the name of the object entity
+	*/
+	void generateSceneObject(const Vector3 &translationRatio, const Vector3 &rotationRatio, 
+							 const int idx, const String &entName);
+
 	CEGUI::OgreCEGUIRenderer *mGUIRenderer;
 	CEGUI::System *mGUISystem;
+	RayQueryExecutor *mRayQueryExecutor;
+	TerrainContentGenerator *mTerrainContentGenerator;
+
+	Vector3 mMinTranslation;
+	Vector3 mMaxTranslation;
+
+	Vector3 mMinAngle;
+	Vector3 mMaxAngle;
 
 private:
