Index: trunk/VUT/work/TestCullingTerrain/TerrainContentGenerator.cpp
===================================================================
--- trunk/VUT/work/TestCullingTerrain/TerrainContentGenerator.cpp	(revision 81)
+++ trunk/VUT/work/TestCullingTerrain/TerrainContentGenerator.cpp	(revision 81)
@@ -0,0 +1,89 @@
+#include "TerrainContentGenerator.h"
+#include <windows.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(100)
+{
+	mMinPos = Vector3(0.0f, 5000.0f, 0.0f);
+	mMaxPos =Vector3(1000.0f, 5000.0f, 1000.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;
+	
+	if (mRayQueryExecutor->executeRayQuery(&queryResult, position, Vector3::NEGATIVE_UNIT_Y))
+	{
+		// reject if height too big
+		if(queryResult.y < mMaxHeight)
+		{
+			return SceneContentGenerator::GenerateSceneObject(queryResult, rotation, objName);
+		}
+	}
+	
+	return NULL;
+}
+//-----------------------------------------------------------------------
+void TerrainContentGenerator::SetMaxHeight(Real maxHeight)
+{
+	mMaxHeight = maxHeight;
+}
+
+} // namespace Ogre
Index: trunk/VUT/work/TestCullingTerrain/TerrainContentGenerator.h
===================================================================
--- trunk/VUT/work/TestCullingTerrain/TerrainContentGenerator.h	(revision 81)
+++ trunk/VUT/work/TestCullingTerrain/TerrainContentGenerator.h	(revision 81)
@@ -0,0 +1,43 @@
+#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 fills a terrain with content in a random fashion 
+*/
+class TerrainContentGenerator: public SceneContentGenerator
+{
+public:
+	TerrainContentGenerator(SceneManager *sm);
+	~TerrainContentGenerator();
+
+	SceneNode *GenerateSceneObject(const Vector3 &position, 
+		const Vector3 &rotation, const String &objName);
+
+	void SetMaxHeight(Real maxHeight);
+
+protected:
+	RayQueryExecutor *mRayQueryExecutor;
+	Real mMaxHeight;
+};
+
+} // namespace Ogre
+#endif // _TERRAINCONTENTGENERATOR_H
Index: trunk/VUT/work/TestCullingTerrain/SceneContentGenerator.cpp
===================================================================
--- trunk/VUT/work/TestCullingTerrain/SceneContentGenerator.cpp	(revision 80)
+++ 	(revision )
@@ -1,106 +1,0 @@
-/**
-    \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/TestCullingTerrain/SceneContentGenerator.h
===================================================================
--- trunk/VUT/work/TestCullingTerrain/SceneContentGenerator.h	(revision 80)
+++ 	(revision )
@@ -1,50 +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);
-	
-	/** 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_
