Index: trunk/VUT/work/TestCulling/TestCulling.vcproj
===================================================================
--- trunk/VUT/work/TestCulling/TestCulling.vcproj	(revision 78)
+++ trunk/VUT/work/TestCulling/TestCulling.vcproj	(revision 79)
@@ -122,4 +122,7 @@
 			UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}">
 			<File
+				RelativePath="..\TestCullingTerrain\SceneContentGenerator.cpp">
+			</File>
+			<File
 				RelativePath=".\TestCullingApplication.cpp">
 			</File>
@@ -129,4 +132,7 @@
 			Filter="h;hpp;hxx;hm;inl;inc;xsd"
 			UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}">
+			<File
+				RelativePath="..\TestCullingTerrain\SceneContentGenerator.h">
+			</File>
 			<File
 				RelativePath=".\TestCullingApplication.h">
Index: trunk/VUT/work/TestCulling/SceneContentGenerator.cpp
===================================================================
--- trunk/VUT/work/TestCulling/SceneContentGenerator.cpp	(revision 79)
+++ trunk/VUT/work/TestCulling/SceneContentGenerator.cpp	(revision 79)
@@ -0,0 +1,106 @@
+/**
+    \file 
+        SceneContentGenerator.cpp
+    \brief
+        Creates content for a scene.
+*/
+#include "SceneContentGenerator.h"
+#include <windows.h>
+
+namespace Ogre {
+
+/*******************************************************/
+/*     SceneContentGenerator implementation            */
+/*******************************************************/
+
+//-----------------------------------------------------------------------
+SceneContentGenerator::SceneContentGenerator(SceneManager *sm):
+mSceneMgr(sm), mCount(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))
+{
+}
+//-----------------------------------------------------------------------
+void SceneContentGenerator::GenerateScene(int numObjects, const String &objName)
+{
+	// initialise random generator
+	srand (time(0));
+	
+	Vector3 rotationRatio;
+	Vector3 translationRatio;
+
+	int currentCount = mCount;
+	int limit = 0;
+
+	//-- create random values between zero and one
+	while ((mCount - 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", mCount++);
+		
+	Entity *ent = mSceneMgr->createEntity(name, objName);
+		
+	SceneNode *currentObject = mSceneMgr->getRootSceneNode()->
+		createChildSceneNode(String(name) + "Node", position);
+
+	currentObject->attachObject(ent);
+	currentObject->setScale(0.1f, 0.1f, 0.1f);
+		
+	currentObject->yaw(Degree(rotation.x));
+	currentObject->pitch(Degree(rotation.y));
+	currentObject->roll(Degree(rotation.z));
+
+	return currentObject;
+	
+	/*
+	char msg[100];
+	sprintf(msg, "pos: %3.3f %3.3f %3.3f, newpos: %3.3f %3.3f %3.3f\n", 
+		position.x, position.y, position.z, queryResult.x, queryResult.y, queryResult.z);
+
+	OutputDebugString(msg);
+	*/
+}
+//-----------------------------------------------------------------------
+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;
+}
+
+} // namespace Ogre
Index: trunk/VUT/work/TestCulling/TestCullingApplication.cpp
===================================================================
--- trunk/VUT/work/TestCulling/TestCullingApplication.cpp	(revision 74)
+++ trunk/VUT/work/TestCulling/TestCullingApplication.cpp	(revision 79)
@@ -12,7 +12,7 @@
 #include <../CEGUIRenderer/include/OgreCEGUITexture.h>
 #include <OgreMemoryMacros.h>
-
-#include "Ogre.h"
+#include <Ogre.h>
 #include "TestCullingApplication.h"
+#include "SceneContentGenerator.h"
 
 #define WIN32_LEAN_AND_MEAN
@@ -48,11 +48,6 @@
 	//l->setPosition(20,80,50);
 
-	mMinTranslation = Vector3(-70.0f, -70.0f, 0.0f);
-	mMaxTranslation = Vector3(70.0f, 70.0f, 600.0f);
-
-	mMinAngle = Vector3(0, 0, 0);
-	mMaxAngle = Vector3(360, 360, 360);
-
-	generateScene(330);
+	SceneContentGenerator contentGenerator();
+	contentGenerator.GenerateScene(330);
 
 	// Create a skybox
@@ -90,48 +85,6 @@
     mSceneMgr = mRoot->getSceneManager(ST_GENERIC);
 }
-//-----------------------------------------------------------------------
-void TestCullingApplication::generateSceneObject(const Vector3 &translationRatio, 
-												 const Vector3 &rotationRatio, 
-												 const int idx, 
-												 const String& entName)
-{
-	Vector3 rotation = mMinAngle + rotationRatio * (mMaxAngle - mMinAngle);
-	Vector3 translation = mMinTranslation + 
-		translationRatio * (mMaxTranslation - mMinTranslation);
-
-	char name[16];
-    sprintf( name, "object%d", idx );
-
-    Entity *ent = mSceneMgr->createEntity(name, entName);
-	SceneNode *node = mSceneMgr->getRootSceneNode()->
-		createChildSceneNode(String(name) + "Node", translation);
-	node->attachObject(ent);
-	node->scale(0.1,0.1,0.1);
-
-	node->yaw(Degree(rotation.x));
-    node->pitch(Degree(rotation.y));
-	node->roll(Degree(rotation.z));
-}
-//-----------------------------------------------------------------------
-void TestCullingApplication::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");
-	}
-}
+
+
 /***********************************************/
 /* MouseQueryListener implementation           */
Index: trunk/VUT/work/TestCulling/SceneContentGenerator.h
===================================================================
--- trunk/VUT/work/TestCulling/SceneContentGenerator.h	(revision 79)
+++ trunk/VUT/work/TestCulling/SceneContentGenerator.h	(revision 79)
@@ -0,0 +1,50 @@
+#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);
+	
+	/** 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 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
+	*/
+	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);
+	
+protected:
+
+	Vector3 mMinAngle;
+	Vector3 mMaxAngle;
+	Vector3 mMaxPos;
+	Vector3 mMinPos;
+	
+	SceneManager *mSceneMgr;
+	int mCount;		// The number of objects on the screen
+};
+
+} // namespace Ogre
+
+#endif // SCENECONTENTGENERATOR_H_
Index: trunk/VUT/work/TestCulling/TestCullingApplication.h
===================================================================
--- trunk/VUT/work/TestCulling/TestCullingApplication.h	(revision 74)
+++ trunk/VUT/work/TestCulling/TestCullingApplication.h	(revision 79)
@@ -93,5 +93,5 @@
 	@param number of objects to generate
 	*/
-	void generateScene(int numObjects);
+	void GenerateScene(int numObjects);
 
 	/** generates a new scene object 
Index: trunk/VUT/work/TestCulling/TerrainContentGenerator.cpp
===================================================================
--- trunk/VUT/work/TestCulling/TerrainContentGenerator.cpp	(revision 61)
+++ 	(revision )
@@ -1,14 +1,0 @@
-/**
-    \file 
-        TerrainContentGenerator.cpp
-    \brief
-        Creates content for the terrain,
-*/
-
-#include "TerrainContentGenerator.h"
-
-//-----------------------------------------------------------------------
-TerrainContentGenerator::TerrainContentGenerator( void )
-{
-}
-
Index: trunk/VUT/work/TestCulling/TerrainContentGenerator.h
===================================================================
--- trunk/VUT/work/TestCulling/TerrainContentGenerator.h	(revision 61)
+++ 	(revision )
@@ -1,14 +1,0 @@
-/**
-    \file 
-        TerrainContentGenerator.h
-*/
-
-class TerrainContentGenerator
-{
-public:
-	TerrainContentGenerator();
-
-protected:
-
-};
-
