Index: trunk/VUT/Ogre/include/OgreSceneContentGenerator.h
===================================================================
--- trunk/VUT/Ogre/include/OgreSceneContentGenerator.h	(revision 107)
+++ trunk/VUT/Ogre/include/OgreSceneContentGenerator.h	(revision 107)
@@ -0,0 +1,66 @@
+#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 __declspec(dllexport) 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
+		@remark internally stores pointer to object
+	*/
+	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);
+	void SetScale(Vector3 scale);
+	
+	/** the number of created objects */
+	int GetObjectCount();
+
+	/** writes scene nodes to file */
+	bool WriteObjects(const std::string &filename);
+
+	/** loads scene nodes from file */
+	bool LoadObjects(const std::string &filename);
+
+	SceneNode *GenerateSceneObject(const Vector3 &position, 
+		const Quaternion &orientation, const String &objName);
+
+protected:
+
+	Vector3 mMinAngle;
+	Vector3 mMaxAngle;
+	Vector3 mMaxPos;
+	Vector3 mMinPos;
+	Vector3 mScale;
+
+	SceneManager *mSceneMgr;
+	
+	std::vector<SceneNode *> mSceneObjects;
+};
+
+} // namespace Ogre
+
+#endif // SCENECONTENTGENERATOR_H_
Index: trunk/VUT/Ogre/include/OgreTerrainContentGenerator.h
===================================================================
--- trunk/VUT/Ogre/include/OgreTerrainContentGenerator.h	(revision 107)
+++ trunk/VUT/Ogre/include/OgreTerrainContentGenerator.h	(revision 107)
@@ -0,0 +1,50 @@
+#ifndef _TERRAINCONTENTGENERATOR_H__
+#define _TERRAINCONTENTGENERATOR_H__
+
+#include "OgreSceneContentGenerator.h"
+//#include <Ogre.h>
+
+namespace Ogre {
+
+/** Class which executes a simple ray query.
+*/
+class __declspec(dllexport) 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 __declspec(dllexport) 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/Ogre/scripts/Plugin_VisibilitySceneManager.vcproj
===================================================================
--- trunk/VUT/Ogre/scripts/Plugin_VisibilitySceneManager.vcproj	(revision 100)
+++ trunk/VUT/Ogre/scripts/Plugin_VisibilitySceneManager.vcproj	(revision 107)
@@ -71,5 +71,5 @@
 		<Configuration
 			Name="Release|Win32"
-			OutputDirectory="..\bin\$(ConfigurationName)"
+			OutputDirectory="..\lib\$(ConfigurationName)"
 			IntermediateDirectory="..\obj\$(ConfigurationName)"
 			ConfigurationType="2"
@@ -157,4 +157,7 @@
 				</File>
 				<File
+					RelativePath="..\include\OgreTerrainContentGenerator.h">
+				</File>
+				<File
 					RelativePath="..\include\OgreVisibilityOctreeSceneManager.h">
 				</File>
@@ -171,4 +174,7 @@
 				<File
 					RelativePath="..\src\OgreOctreeHierarchyInterface.cpp">
+				</File>
+				<File
+					RelativePath="..\src\OgreTerrainContentGenerator.cpp">
 				</File>
 				<File
@@ -193,4 +199,7 @@
 				</File>
 				<File
+					RelativePath="..\include\OgreSceneContentGenerator.h">
+				</File>
+				<File
 					RelativePath="..\include\OgreSceneNodeHierarchyInterface.h">
 				</File>
@@ -216,4 +225,7 @@
 				<File
 					RelativePath="..\src\OgrePlatformOcclusionQuery.cpp">
+				</File>
+				<File
+					RelativePath="..\src\OgreSceneContentGenerator.cpp">
 				</File>
 				<File
Index: trunk/VUT/Ogre/src/OgreVisibilityTerrainSceneManager.cpp
===================================================================
--- trunk/VUT/Ogre/src/OgreVisibilityTerrainSceneManager.cpp	(revision 104)
+++ trunk/VUT/Ogre/src/OgreVisibilityTerrainSceneManager.cpp	(revision 107)
@@ -52,10 +52,16 @@
     {
 		// add player camera for visualization purpose
-		Camera *c;
-		if ((c = getCamera("PlayerCam")) != NULL)
-		{
-			getRenderQueue()->addRenderable(c);
-		}
-		
+		try {
+			Camera *c;
+			if ((c = getCamera("PlayerCam")) != NULL)
+			{
+				getRenderQueue()->addRenderable(c);
+			}   
+        }
+        catch(...)
+        {
+            // ignore
+        }
+				
 		for (NodeList::iterator it = mVisible.begin(); it != mVisible.end(); ++it)
 		{
Index: trunk/VUT/Ogre/src/OgreSceneContentGenerator.cpp
===================================================================
--- trunk/VUT/Ogre/src/OgreSceneContentGenerator.cpp	(revision 107)
+++ trunk/VUT/Ogre/src/OgreSceneContentGenerator.cpp	(revision 107)
@@ -0,0 +1,189 @@
+/**
+    \file 
+        SceneContentGenerator.cpp
+    \brief
+        Creates content for a scene.
+*/
+#include "OgreSceneContentGenerator.h"
+
+// limit for failed attempts to create objects (to avoids infinite loop)
+#define MAX_FAILED_ATTEMPTS 500000
+
+namespace Ogre {
+
+/*******************************************************/
+/*     SceneContentGenerator implementation            */
+/*******************************************************/
+
+//-----------------------------------------------------------------------
+SceneContentGenerator::SceneContentGenerator(SceneManager *sm):
+mSceneMgr(sm),
+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)
+//, mObjectCount(0)
+{
+}
+//-----------------------------------------------------------------------
+void SceneContentGenerator::GenerateScene(int numObjects, const String &objName)
+{
+	// initialise random generator
+	srand (time(0));
+	
+	Vector3 rotationRatio;
+	Vector3 translationRatio;
+
+	int old_count = GetObjectCount();
+	int failed_attempts = 0; // counter used to avoid invinite loop
+
+	//-- create random values between zero and one
+	while ((GetObjectCount() < numObjects + old_count) && 
+		   (failed_attempts < MAX_FAILED_ATTEMPTS))
+	{
+		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);
+
+		// failed to generate new object
+		if (!GenerateSceneObject(position, rotation, objName))
+			++failed_attempts; 
+	}
+}
+//-----------------------------------------------------------------------
+SceneNode *SceneContentGenerator::GenerateSceneObject(const Vector3 &position, 
+					 const Quaternion &orientation, const String& objName)
+{
+	char name[25];
+	sprintf(name, "%s Entity%d", objName.c_str(), GetObjectCount());
+		
+	Entity *ent = mSceneMgr->createEntity(name, objName + ".mesh");
+		
+	SceneNode *currentObject = mSceneMgr->getRootSceneNode()->
+		createChildSceneNode(String(name) + "Node", position);
+
+	currentObject->attachObject(ent);
+	currentObject->setScale(mScale);
+	currentObject->setOrientation(orientation);
+
+	//-- store pointer to object
+	mSceneObjects.push_back(currentObject);
+
+	return currentObject;
+}
+//-----------------------------------------------------------------------
+SceneNode *SceneContentGenerator::GenerateSceneObject(const Vector3 &position, 
+					 const Vector3 &rotation, const String& objName)
+{
+	Matrix3 mat;
+	mat.FromEulerAnglesXYZ(Degree(rotation.x),//.valueRadians(), 
+						   Degree(rotation.y),//.valueRadians(), 
+						   Degree(rotation.z));//.valueRadians());
+
+	return GenerateSceneObject(position, Quaternion(mat), objName);
+}
+//-----------------------------------------------------------------------
+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 (int)mSceneObjects.size();
+}
+//-----------------------------------------------------------------------
+void SceneContentGenerator::SetScale(Vector3 scale)
+{
+	mScale = scale;
+}
+//-----------------------------------------------------------------------
+bool SceneContentGenerator::WriteObjects(const std::string &filename)
+{
+	std::ofstream ofstr(filename.c_str());
+	std::vector<SceneNode *>::const_iterator it, it_end;
+
+	it_end = mSceneObjects.end();
+
+	if(!ofstr.is_open())
+		return false;
+
+	char str[100];
+
+	for(it = mSceneObjects.begin(); it < it_end; ++it)
+	{
+		SceneNode *node = (*it);
+		sscanf(node->getName().c_str(), "%s ", str); // write name of mesh
+
+		ofstr << str << " "
+			  << StringConverter::toString(node->getPosition()) << " " 
+			  << StringConverter::toString(node->getOrientation()) << " "
+			  << StringConverter::toString(node->getScale()) << "\n";
+	}
+	ofstr.close();
+
+	return true;
+}
+//-----------------------------------------------------------------------
+bool SceneContentGenerator::LoadObjects(const std::string &filename)
+{
+	std::ifstream ifstr(filename.c_str());
+	
+	char line[256];
+
+	Vector3 position;
+	Quaternion orientation;
+	char objName[100];
+
+	if(!ifstr.is_open())
+		return false;
+
+	//mSceneObjects.clear(); // reset list of objects
+
+	while (!ifstr.eof()) 
+	{
+		ifstr.getline(line, 256);
+		sscanf(line, "%s %f %f %f %f %f %f %f %f %f %f", objName, 
+			&position.x, &position.y, &position.z,
+			&orientation.w, &orientation.x, &orientation.y, &orientation.z,
+			&mScale.x, &mScale.y, &mScale.z);
+		
+		/*Vector3 rot(orientation.getYaw().valueDegrees(), 
+					orientation.getPitch().valueDegrees(), 
+					orientation.getRoll().valueDegrees());*/
+
+		(void)GenerateSceneObject(position, orientation, objName);
+		
+		std::stringstream d;
+		d << StringConverter::toString(position) << " " << StringConverter::toString(orientation);
+		LogManager::getSingleton().logMessage(d.str());
+	}
+	ifstr.close();
+
+	return true;
+}
+} // namespace Ogre
Index: trunk/VUT/Ogre/src/OgreTerrainContentGenerator.cpp
===================================================================
--- trunk/VUT/Ogre/src/OgreTerrainContentGenerator.cpp	(revision 107)
+++ trunk/VUT/Ogre/src/OgreTerrainContentGenerator.cpp	(revision 107)
@@ -0,0 +1,98 @@
+#include "OgreTerrainContentGenerator.h"
+
+#define MAX_HEIGHT 5000 // maximal possible height
+
+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, MAX_HEIGHT, 0.0f);
+	mMaxPos = Vector3(3000.0f, MAX_HEIGHT, 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;
+	// set y to max height so we are sure to be over terrain
+	Vector3 pos(position.x, MAX_HEIGHT, position.z);
+
+	if (mRayQueryExecutor->executeRayQuery(&queryResult, position, Vector3::NEGATIVE_UNIT_Y))
+	{
+		// reject if height is too high
+		if (queryResult.y < mMaxPos.y)
+		{
+			return SceneContentGenerator::GenerateSceneObject(queryResult, rotation, objName);
+		}
+	}
+	
+	return NULL;
+}
+//-----------------------------------------------------------------------
+RayQueryExecutor *TerrainContentGenerator::GetRayQueryExecutor()
+{
+	return mRayQueryExecutor;
+}
+//-----------------------------------------------------------------------
+/*void TerrainContentGenerator::SetMaxHeight(Real maxHeight)
+{
+	mMaxHeight = maxHeight;
+}*/
+
+} // namespace Ogre
