Index: /trunk/VUT/OcclusionCullingSceneManager/TestCullingTerrain/TestCullingTerrainApplication.cpp
===================================================================
--- /trunk/VUT/OcclusionCullingSceneManager/TestCullingTerrain/TestCullingTerrainApplication.cpp	(revision 48)
+++ /trunk/VUT/OcclusionCullingSceneManager/TestCullingTerrain/TestCullingTerrainApplication.cpp	(revision 51)
@@ -46,5 +46,4 @@
 void TestCullingTerrainApplication::createScene(void)
 {
-	Plane waterPlane;
 	// Set ambient light
 	mSceneMgr->setAmbientLight(ColourValue(0.5, 0.5, 0.5));
@@ -61,12 +60,22 @@
 	// because the vertex program picked will be different
 	ColourValue fadeColour(0.93, 0.86, 0.76);
+	mWindow->getViewport(0)->setBackgroundColour(fadeColour);
 	//mSceneMgr->setFog( FOG_LINEAR, fadeColour, .001, 500, 1000);
     //mSceneMgr->setFog( FOG_EXP, fadeColour, 0.005 );
 
-	mWindow->getViewport(0)->setBackgroundColour(fadeColour);
+	
 
 	// Create a skybox
     //mSceneMgr->setSkyBox(true, "Examples/SpaceSkyBox", 500, false);
 	//mSceneMgr->setSkyDome( true, "Examples/CloudySky", 5, 8, 500, false );
+
+	/*	// Define the required skyplane
+	Plane plane;
+	// 5000 world units from the camera
+	plane.d = 5000;
+	// Above the camera, facing down
+	plane.normal = -Vector3::UNIT_Y;
+	// Create the plane 10000 units wide, tile the texture 3 times
+    mSceneMgr->setSkyPlane(true, plane, "Examples/SpaceSkyPlane",10000,3);*/
 
 	std::string terrain_cfg("terrain.cfg");
@@ -81,21 +90,10 @@
 	}
 
-/*	// Define the required skyplane
-	Plane plane;
-	// 5000 world units from the camera
-	plane.d = 5000;
-	// Above the camera, facing down
-	plane.normal = -Vector3::UNIT_Y;
-	// Create the plane 10000 units wide, tile the texture 3 times
-    mSceneMgr->setSkyPlane(true, plane, "Examples/SpaceSkyPlane",10000,3);*/
-
 	// Set a nice viewpoint
 	mCamera->setPosition(707,2500,528);
 	mCamera->setOrientation(Quaternion(-0.3486, 0.0122, 0.9365, 0.0329));
 
-	//mRaySceneQuery = mSceneMgr->createRayQuery(
-	//	Ray(mCamera->getPosition(), Vector3::NEGATIVE_UNIT_Y));
-
-	/*Entity *robotEnt = mSceneMgr->createEntity( "Robot", "robot.mesh" );
+	/*
+	Entity *robotEnt = mSceneMgr->createEntity( "Robot", "robot.mesh" );
 	SceneNode *robotNode = mSceneMgr->getRootSceneNode()->createChildSceneNode( "RobotNode", Vector3( 750, 25, 600 ));
 	robotNode->attachObject( robotEnt );
Index: /trunk/VUT/OcclusionCullingSceneManager/include/OgreSolidHalfBoundingBox.h
===================================================================
--- /trunk/VUT/OcclusionCullingSceneManager/include/OgreSolidHalfBoundingBox.h	(revision 26)
+++ /trunk/VUT/OcclusionCullingSceneManager/include/OgreSolidHalfBoundingBox.h	(revision 51)
@@ -15,15 +15,21 @@
 	class SolidHalfBoundingBox : public WireBoundingBox
 	{
+	public:
+
+		SolidHalfBoundingBox(bool isFirstHalf);
+		void setupBoundingBox(const AxisAlignedBox& aabb);
+		/** Override this method to prevent parent transforms (rotation,translation,scale)
+		and to make it public.
+        */
+		void getWorldTransforms( Matrix4* xform ) const;
+
     protected:
        
         /** Builds the wireframe line list.
+		@param the axis aligned bounding box for setting up the list.
         */
 		void setupBoundingBoxVertices(const AxisAlignedBox& aab);
-		
-	public:
-		
-		bool mIsFirstHalf;
-		void setupBoundingBox(const AxisAlignedBox& aabb);
-		SolidHalfBoundingBox(bool isFirstHalf);
+
+		bool mIsFirstHalf;	
 	};
 
Index: /trunk/VUT/OcclusionCullingSceneManager/include/OgreOcclusionCullingOctreeSceneManager.h
===================================================================
--- /trunk/VUT/OcclusionCullingSceneManager/include/OgreOcclusionCullingOctreeSceneManager.h	(revision 48)
+++ /trunk/VUT/OcclusionCullingSceneManager/include/OgreOcclusionCullingOctreeSceneManager.h	(revision 51)
@@ -42,13 +42,4 @@
 		bool getOptionKeys( StringVector &refKeys );
 
-		/** Renders one octant of an octree, i.e., renders current octant
-			node and does not traverse deeper into the tree.
-			@remark Note that OctreeNode instances are NOT part of the octree 
-			hierarchy, instead one octant of an Octree contains many OctreeNode instances.
-			@param octree the octree to be rendered
-			@param cam current camera
-		*/
-		void _renderOctant(Camera* cam, Octree *octree);
-
 	protected:
 		/** Recursively counts octree size (i.e., number of octree instances)
Index: /trunk/VUT/OcclusionCullingSceneManager/include/OgreOcclusionCullingSceneTraverser.h
===================================================================
--- /trunk/VUT/OcclusionCullingSceneManager/include/OgreOcclusionCullingSceneTraverser.h	(revision 42)
+++ /trunk/VUT/OcclusionCullingSceneManager/include/OgreOcclusionCullingSceneTraverser.h	(revision 51)
@@ -170,4 +170,5 @@
 		unsigned int mNumFrustumCulledNodes;
 		unsigned int mNumRenderedGeometry;
+		unsigned int mNumRenderedNodes;
 
 	private:
Index: /trunk/VUT/OcclusionCullingSceneManager/include/OgreOcclusionCullingTerrainSceneManager.h
===================================================================
--- /trunk/VUT/OcclusionCullingSceneManager/include/OgreOcclusionCullingTerrainSceneManager.h	(revision 48)
+++ /trunk/VUT/OcclusionCullingSceneManager/include/OgreOcclusionCullingTerrainSceneManager.h	(revision 51)
@@ -44,13 +44,4 @@
 		bool getOptionKeys( StringVector &refKeys );
 
-		/** Renders one octant of an octree, i.e., renders current octant
-			node and does not traverse deeper into the tree.
-			@remark Note that OctreeNode instances are NOT part of the octree 
-			hierarchy, instead one octant of an Octree contains many OctreeNode instances.
-			@param octree the octree to be rendered
-			@param cam current camera
-		*/
-		void _renderOctant(Camera* cam, Octree *octree);
-
 	protected:
 
Index: /trunk/VUT/OcclusionCullingSceneManager/src/OgreOcclusionCullingSceneManagerDll.cpp
===================================================================
--- /trunk/VUT/OcclusionCullingSceneManager/src/OgreOcclusionCullingSceneManagerDll.cpp	(revision 48)
+++ /trunk/VUT/OcclusionCullingSceneManager/src/OgreOcclusionCullingSceneManagerDll.cpp	(revision 51)
@@ -34,5 +34,5 @@
 namespace Ogre {
 
-   // OcclusionCullingDotSceneManager *occlusionDotPlugin;
+	// OcclusionCullingDotSceneManager *occlusionDotPlugin;
 	OcclusionCullingOctreeSceneManager *occlusionOctreePlugin;
 	OcclusionCullingTerrainSceneManager *occlusionTerrainPlugin;
@@ -54,6 +54,4 @@
 		Root::getSingleton().setSceneManager( ST_GENERIC, occlusionOctreePlugin );
 		Root::getSingleton().setSceneManager( ST_EXTERIOR_CLOSE, occlusionTerrainPlugin );
-		
-		// MessageBox( NULL, "myplugin registered", "this is my plugin", MB_OK | MB_ICONERROR | MB_TASKMODAL);
     }
     extern "C" void dllStopPlugin(void)
Index: /trunk/VUT/OcclusionCullingSceneManager/src/OgreSolidHalfBoundingBox.cpp
===================================================================
--- /trunk/VUT/OcclusionCullingSceneManager/src/OgreSolidHalfBoundingBox.cpp	(revision 26)
+++ /trunk/VUT/OcclusionCullingSceneManager/src/OgreSolidHalfBoundingBox.cpp	(revision 51)
@@ -89,4 +89,10 @@
 		setBoundingBox(aabb);
 	}
+	// Override this method to prevent parent transforms (rotation,translation,scale)
+    void SolidHalfBoundingBox::getWorldTransforms( Matrix4* xform ) const
+    {
+		// return identity matrix to prevent parent transforms
+        *xform = Matrix4::IDENTITY;
+    }
 }
 
Index: /trunk/VUT/OcclusionCullingSceneManager/src/OgreOcclusionCullingOctreeSceneManager.cpp
===================================================================
--- /trunk/VUT/OcclusionCullingSceneManager/src/OgreOcclusionCullingOctreeSceneManager.cpp	(revision 45)
+++ /trunk/VUT/OcclusionCullingSceneManager/src/OgreOcclusionCullingOctreeSceneManager.cpp	(revision 51)
@@ -16,5 +16,5 @@
 		//mDisplayNodes = true;
 		//mShowBoundingBoxes = true;
-		//mShowBoxes = true;
+		mShowBoxes = true;
 		mMaxDepth = 20;
 	}
@@ -57,5 +57,4 @@
 		// must be empty because objects are found and rendered in an interleaved fashion
 		// in _renderVisibibleObjects 
-		//char *msg = "now finding visible objects\n"; OutputDebugString(msg);
 	}
 	//-----------------------------------------------------------------------
@@ -92,40 +91,3 @@
 		return mOcclusionCullingOctreeSceneTraverser->getOptionKeys ( refKeys ) || OctreeSceneManager::getOptionKeys( refKeys );
 	}
-	//-----------------------------------------------------------------------
-	void OcclusionCullingOctreeSceneManager::_renderOctant(Camera *cam, Octree *octant)
-	{
-		//Add stuff to be rendered;
-        NodeList::iterator it = octant->mNodes.begin();
-         
-        while(it != octant->mNodes.end())
-        {
-            OctreeNode *sn = *it;
-
-            mNumObjects++;
-
-			// check bounding box visibility of scene nodes
-			if (cam->isVisible(sn->_getWorldAABB()))
-			{
-				sn->_addToRenderQueue(cam, getRenderQueue(), false);
-				//node->_findVisibleObjects(cam, getRenderQueue(), false, mDisplayNodes, false);
-				mVisible.push_back(sn);
-
-				if (mDisplayNodes)
-					getRenderQueue()->addRenderable(sn);
-
-				// check if the scene manager or this node wants the bounding box shown.
-				if (sn->getShowBoundingBox() || mShowBoundingBoxes)
-					sn->_addBoundingBoxToQueue(getRenderQueue());
-
-				if (mShowBoxes)
-					getRenderQueue()->addRenderable(octant->getWireBoundingBox());
-			}
-            ++it;
-        }
-
-		SceneManager::_renderVisibleObjects();
-	
-		// delete all rendered objects from renderqueue
-		_deleteRenderedQueueGroups();
-	}
 }	
Index: /trunk/VUT/OcclusionCullingSceneManager/src/OgreOcclusionCullingSceneTraverser.cpp
===================================================================
--- /trunk/VUT/OcclusionCullingSceneManager/src/OgreOcclusionCullingSceneTraverser.cpp	(revision 44)
+++ /trunk/VUT/OcclusionCullingSceneManager/src/OgreOcclusionCullingSceneTraverser.cpp	(revision 51)
@@ -16,5 +16,5 @@
 	mQueryMode(MODE_RENDER), mNumSceneNodes(0), mCurrentAlgorithm(RENDER_COHERENT),
 	mNumQueries(0), mNumTraversedNodes(0), mNumQueryCulledNodes(0), mNumFrustumCulledNodes(0), 
-	mNumRenderedGeometry(0), mSceneManager(sm), mRenderSystem(rsys), mSceneRoot(NULL)
+	mNumRenderedNodes(0),mNumRenderedGeometry(0), mSceneManager(sm), mRenderSystem(rsys), mSceneRoot(NULL)
 	{		
 		mHalfBoundingBox[0] = mHalfBoundingBox[1] = 0;
@@ -39,10 +39,16 @@
 		mNumFrustumCulledNodes = 0;
 		mNumRenderedGeometry = 0;
-		
+		mNumRenderedNodes = 0;
+
 		mCurrentTestIdx = 0;
 
 		initDistanceQueue(cam);
 
-//mCurrentAlgorithm = RENDER_CULL_FRUSTUM;
+		//deleteQueries();
+		//char *msg = "deleting queries\n"; OutputDebugString(msg);
+        //for(unsigned int i=0; i < 1000; i++)
+		//mOcclusionQueries.push_back(mRenderSystem->createHardwareOcclusionQuery());
+	    //mCurrentAlgorithm = RENDER_CULL_FRUSTUM;
+
 		switch(mCurrentAlgorithm)
 		{
@@ -54,6 +60,5 @@
 				break;
 			case RENDER_COHERENT:
-				//renderCoherentWithQueue(cam);
-renderStopAndWait(cam);
+				renderCoherentWithQueue(cam);
 				break;
 			default:
@@ -209,5 +214,5 @@
 			// wait if result not available
 			query->pullOcclusionQuery(&visiblePixels);
-				
+	
 			// node visible
 			if(visiblePixels > mVisibilityThreshold)
@@ -229,6 +234,6 @@
 		// TODO: in rendervisibleobjects, the rendermode is changed by ogre itself => change this!!
 		
-		//setRenderingMode(MODE_QUERY);
-		setRenderingMode(MODE_RENDER);
+		setRenderingMode(MODE_QUERY);
+		//setRenderingMode(MODE_RENDER);
 
 		// get next available test id
@@ -251,10 +256,10 @@
 		//{
 			bool enabled = (mode == MODE_RENDER);
-			
+//if(mode == MODE_QUERY){
 			mRenderSystem->_setColourBufferWriteEnabled(enabled, 
 				enabled, enabled, enabled);
 			mRenderSystem->_setDepthBufferWriteEnabled(enabled);
 			mRenderSystem->setLightingEnabled(enabled);
-
+//}
 			mQueryMode = mode;
 		//}
@@ -346,5 +351,5 @@
 	void OcclusionCullingSceneTraverser::deleteQueries( void )
 	{
-		for(unsigned int i=0; i < (unsigned int)mOcclusionQueries.size(); i++)
+		for(unsigned int i=0; i < (unsigned int)mOcclusionQueries.size(); ++i)
 			delete mOcclusionQueries[i];
 
@@ -357,11 +362,24 @@
 		for(int half = 0; half < 2; half ++)
 		{
-			//static Matrix4 xform[256];
-			//TODO: this should be full boudning box
+			static Matrix4 xform[256];
+			//TODO: this should be full bounding box
 			SolidHalfBoundingBox *halfbox = getSolidHalfBoundingBox(half);
 			halfbox->setupBoundingBox(*box);
-
-			mRenderSystem->_setWorldMatrix(Matrix4::IDENTITY);
 			
+			//mRenderSystem->_setWorldMatrix(Matrix4::IDENTITY);
+			// Set world transformation
+			/*halfbox->getWorldTransforms(xform);
+
+			int numMatrices = halfbox->getNumWorldTransforms();
+			if (numMatrices > 1)
+			{
+				mRenderSystem->_setWorldMatrices(xform, numMatrices);
+			}
+			else
+			{
+				mRenderSystem->_setWorldMatrix(*xform);
+			}
+			mRenderSystem->setClipPlanes(halfbox->getClipPlanes());
+
 			static RenderOperation ro;
 
@@ -369,8 +387,8 @@
 			halfbox->getRenderOperation(ro);
 			ro.srcRenderable = halfbox; 
-			mRenderSystem->_render(ro);
-
-			//mSceneManager->renderSingleObject(getSolidHalfBoundingBox(half), 
-			//	getSolidHalfBoundingBox(half)->getTechnique()->getPass(0), false);
+			mRenderSystem->_render(ro);*/
+
+			mSceneManager->myrenderSingleObject(getSolidHalfBoundingBox(half), 
+				getSolidHalfBoundingBox(half)->getTechnique()->getPass(0), false);
 		}
 	}
@@ -410,4 +428,5 @@
 		{
 			mOcclusionQueries.push_back(mRenderSystem->createHardwareOcclusionQuery());
+			//char *msg = "creating query!!\n"; OutputDebugString(msg);
 		}
 		
Index: /trunk/VUT/OcclusionCullingSceneManager/src/OgreOcclusionCullingOctreeSceneTraverser.cpp
===================================================================
--- /trunk/VUT/OcclusionCullingSceneManager/src/OgreOcclusionCullingOctreeSceneTraverser.cpp	(revision 48)
+++ /trunk/VUT/OcclusionCullingSceneManager/src/OgreOcclusionCullingOctreeSceneTraverser.cpp	(revision 51)
@@ -28,5 +28,9 @@
 		{
 			Octree *nextChild = octant->mChildren[(i & 4) >> 2][(i & 2) >> 1][i & 1];
-		
+
+			/*char msg[100];
+			sprintf(msg, "node number: %d %d %d\n", (i & 4) >> 2, (i & 2) >> 1, i & 1);
+			OutputDebugString(msg);*/
+
 			if(nextChild)
 				mOctreeDistanceQueue->push(nextChild);
@@ -44,5 +48,5 @@
 	
 			// interesting for visualization purpose
-			//TODO: octree->setNodeVisible(false);
+			octant->setOctreeVisible(false);
 			octant->_getCullBounds(&box);
 			
@@ -81,5 +85,4 @@
 			bool intersects = false;
 
-			//if(vis == OctreeCamera::NONE)
 			if(!cam->isVisible(box, intersects))
 			{
@@ -100,5 +103,5 @@
 			// wait if result not available
 			query->pullOcclusionQuery(&visiblePixels);
-			
+//visiblePixels = 1;
 			// node visible
 			if(visiblePixels > mVisibilityThreshold)
@@ -108,4 +111,11 @@
 			else
 			{
+				char msg[100];
+				Vector3 min = box.getMinimum();
+				Vector3 max = box.getMaximum();
+
+				sprintf(msg, "culling box: %3.3f %3.3f %3.3f %3.3f %3.3f %3.3f\n", min.x, min.y, min.z, max.x, max.y, max.z);
+				OutputDebugString(msg);
+
 				mNumQueryCulledNodes ++;
 			}
@@ -133,5 +143,5 @@
 				unsigned int visiblePixels;
 				query->pullOcclusionQuery(&visiblePixels);
-
+//visiblePixels = 1;
 				if(visiblePixels > mVisibilityThreshold)
 				{
@@ -164,5 +174,5 @@
 				if(intersects)
 				{
-					// update node's visited flag
+					// update octant's visited flag
 					octant->setLastVisited(mFrameId);
 					pullUpVisibility(cam, octant);			
@@ -174,5 +184,10 @@
 				// identify previously visible nodes
 				bool wasVisible = octant->isOctreeVisible() && (octant->lastVisited() == mFrameId - 1);
-					
+				
+				/* char msg[100];
+				if(wasVisible) sprintf(msg, "yes, was visible, %d\n", mFrameId);
+				else sprintf(msg, "no was invisible, %d\n", mFrameId);
+				OutputDebugString(msg);*/
+
 				// identify nodes that we cannot skip queries for
 				bool leafOrWasInvisible = !wasVisible || isLeaf(octant);
@@ -196,8 +211,4 @@
 					traverseOctant(cam, octant);
 				}
-				else
-				{
-					mNumFrustumCulledNodes ++;
-				}
 			}
 		}
@@ -218,13 +229,15 @@
 	void OcclusionCullingOctreeSceneTraverser::renderOctant( Camera *cam, Octree *octant )
 	{
-		//if(octant->numNodes() > 0)
+		if(octant->numNodes() == 0) return;
 		if(octant->lastVisited() != octant->lastRendered())
 		{
-			//setRenderingMode(MODE_RENDER);
+			//TODO: does nothing useful
+			setRenderingMode(MODE_RENDER);
+			mNumRenderedNodes ++;
 
 			octant->setLastRendered(octant->lastVisited());
-			((OcclusionCullingOctreeSceneManager *)mSceneManager)->_renderOctant(cam, octant);
-		}
-		else OutputDebugString("already rendered");
+			((OctreeSceneManager *)mSceneManager)->_renderOctant(cam, octant);
+		}
+		//else OutputDebugString("already rendered");
 	}
 	//-----------------------------------------------------------------------
Index: /trunk/VUT/OcclusionCullingSceneManager/src/OgreOcclusionCullingTerrainSceneManager.cpp
===================================================================
--- /trunk/VUT/OcclusionCullingSceneManager/src/OgreOcclusionCullingTerrainSceneManager.cpp	(revision 48)
+++ /trunk/VUT/OcclusionCullingSceneManager/src/OgreOcclusionCullingTerrainSceneManager.cpp	(revision 51)
@@ -18,5 +18,5 @@
 		//mDisplayNodes = true;
 		//mShowBoundingBoxes = true;
-		//mShowBoxes = true;
+		mShowBoxes = true;
 		mMaxDepth = 20;
 	}
@@ -95,41 +95,4 @@
 	}
 	//-----------------------------------------------------------------------
-	void OcclusionCullingTerrainSceneManager::_renderOctant(Camera *cam, Octree *octant)
-	{
-		//Add stuff to be rendered;
-        NodeList::iterator it = octant->mNodes.begin();
-         
-        while(it != octant->mNodes.end())
-        {
-            OctreeNode *sn = *it;
-
-            mNumObjects++;
-
-			// check bounding box visibility of scene nodes
-			if (cam->isVisible(sn->_getWorldAABB()))
-			{
-				sn->_addToRenderQueue(cam, getRenderQueue(), false);
-				//node->_findVisibleObjects(cam, getRenderQueue(), false, mDisplayNodes, false);
-				mVisible.push_back(sn);
-
-				if (mDisplayNodes)
-					getRenderQueue()->addRenderable(sn);
-
-				// check if the scene manager or this node wants the bounding box shown.
-				if (sn->getShowBoundingBox() || mShowBoundingBoxes)
-					sn->_addBoundingBoxToQueue(getRenderQueue());
-
-				if (mShowBoxes)
-					getRenderQueue()->addRenderable(octant->getWireBoundingBox());
-			}
-            ++it;
-        }
-
-		SceneManager::_renderVisibleObjects();
-	
-		// delete all rendered objects from renderqueue
-		_deleteRenderedQueueGroups();
-	}
-	//-----------------------------------------------------------------------
 	/*unsigned int OcclusionCullingTerrainSceneManager::countNumOctrees(Octree *root)
 	{
Index: /trunk/VUT/OcclusionCullingSceneManager/TestCulling/TestCullingApplication.cpp
===================================================================
--- /trunk/VUT/OcclusionCullingSceneManager/TestCulling/TestCullingApplication.cpp	(revision 44)
+++ /trunk/VUT/OcclusionCullingSceneManager/TestCulling/TestCullingApplication.cpp	(revision 51)
@@ -20,15 +20,13 @@
 #include "windows.h"
 
-//RaySceneQuery* mRaySceneQuery = 0;
 
 /***********************************************/
 /* TestCullingApplication implementation       */
 /***********************************************/
-/*TestCullingApplication::~TestCullingApplication()
-{
-	delete mRaySceneQuery;
-}*/
-//-----------------------------------------------------------------------
-void TestCullingApplication::createCamera( void )
+TestCullingApplication::~TestCullingApplication()
+{
+}
+//-----------------------------------------------------------------------
+/*void TestCullingApplication::createCamera( void )
 {
 	// Create the camera
@@ -42,9 +40,8 @@
     mCamera->setNearClipDistance( 1 );
     mCamera->setFarClipDistance( 1000 );
-}
+}*/
 //-----------------------------------------------------------------------
 void TestCullingApplication::createScene(void)
 {
-	Plane waterPlane;
 	// Set ambient light
 	mSceneMgr->setAmbientLight(ColourValue(0.5, 0.5, 0.5));
@@ -52,66 +49,24 @@
 	// Create a light
 	Light* l = mSceneMgr->createLight("MainLight");
-	// Accept default settings: point light, white diffuse, just set position
-	// NB I could attach the light to a SceneNode if I wanted it to move automatically with
-	//  other objects, but I don't
-	l->setPosition(20,80,50);
-
-	// --Fog
-	// NB it's VERY important to set this before calling setWorldGeometry 
-	// because the vertex program picked will be different
-	ColourValue fadeColour(0.93, 0.86, 0.76);
-	//mSceneMgr->setFog( FOG_LINEAR, fadeColour, .001, 500, 1000);
-    //mSceneMgr->setFog( FOG_EXP, fadeColour, 0.005 );
-
+	//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);
+
+	/*
 	mWindow->getViewport(0)->setBackgroundColour(fadeColour);
 
+	Entity *ogreHeadEnt = mSceneMgr->createEntity("head", "ogrehead.mesh");
+	mOgreHead = mSceneMgr->getRootSceneNode()->createChildSceneNode( "OgreHeadNode" );
+	mOgreHead->attachObject(ogreHeadEnt);
+	*/
+	generateScene(4);
 	// Create a skybox
-    //mSceneMgr->setSkyBox(true, "Examples/SpaceSkyBox", 500, false);
-	//mSceneMgr->setSkyDome( true, "Examples/CloudySky", 5, 8, 500, false );
-
-	std::string terrain_cfg("terrain.cfg");
-#if OGRE_PLATFORM == OGRE_PLATFORM_APPLE
-	terrain_cfg = mResourcePath + terrain_cfg;
-#endif
-	mSceneMgr -> setWorldGeometry( terrain_cfg );
-	// Infinite far plane?
-	if (mRoot->getRenderSystem()->getCapabilities()->hasCapability(RSC_INFINITE_FAR_PLANE))
-	{
-		mCamera->setFarClipDistance(0);
-	}
-
-/*	// Define the required skyplane
-	Plane plane;
-	// 5000 world units from the camera
-	plane.d = 5000;
-	// Above the camera, facing down
-	plane.normal = -Vector3::UNIT_Y;
-	// Create the plane 10000 units wide, tile the texture 3 times
-    mSceneMgr->setSkyPlane(true, plane, "Examples/SpaceSkyPlane",10000,3);*/
-
-	// Set a nice viewpoint
-	mCamera->setPosition(707,2500,528);
-	mCamera->setOrientation(Quaternion(-0.3486, 0.0122, 0.9365, 0.0329));
-
-	//mRaySceneQuery = mSceneMgr->createRayQuery(
-	//	Ray(mCamera->getPosition(), Vector3::NEGATIVE_UNIT_Y));
-
-	/*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 ) );*/
+    //mSceneMgr->setSkyBox(true, "Examples/CloudyNoonSkyBox", 1000, false);
+    ColourValue fadeColour(0.3, 0.9, 0.5);
+	mWindow->getViewport(0)->setBackgroundColour(fadeColour);
 
 	// CEGUI setup
@@ -142,8 +97,46 @@
 void TestCullingApplication::chooseSceneManager(void)
 {
-    //mSceneMgr = mRoot->getSceneManager(ST_GENERIC);
-	mSceneMgr = mRoot->getSceneManager(ST_EXTERIOR_CLOSE);
-}
-
+    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           */
@@ -156,5 +149,5 @@
 
 	// Setup default variables
-	mCurrentObject = NULL;
+	//mOgreHead = NULL;
 	mLMouseDown = false;
 	mRMouseDown = false;
@@ -173,6 +166,4 @@
 	mEventProcessor->addKeyListener(this);
 
-	mRaySceneQuery = mSceneMgr->createRayQuery( Ray() );
-
 	// show overlay
 	Overlay* pOver = OverlayManager::getSingleton().getByName("Example/OcclusionCullingDemoOverlay"); 
@@ -199,5 +190,4 @@
 MouseQueryListener::~MouseQueryListener( )
 {
-	delete mRaySceneQuery;
 }
 //-----------------------------------------------------------------------
@@ -213,27 +203,5 @@
      if (e->getButtonID() & InputEvent::BUTTON0_MASK)
      {
-		 CEGUI::MouseCursor::getSingleton().hide( );
-
-		 // Setup the ray scene query
-         Ray mouseRay = mCamera->getCameraToViewportRay( e->getX(), e->getY() );
-         mRaySceneQuery->setRay( mouseRay );
-
-         // 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, "Robot%d", mCount++ );
-
-             Entity *ent = mSceneMgr->createEntity( name, "robot.mesh" );
-             mCurrentObject = mSceneMgr->getRootSceneNode( )->createChildSceneNode( String(name) + "Node", itr->worldFragment->singleIntersection );
-             mCurrentObject->attachObject( ent );
-             mCurrentObject->setScale( 0.1f, 0.1f, 0.1f );
-         }
-
-         mLMouseDown = true; 
+		mLMouseDown = true; 
      }
      // Right mouse button down
@@ -267,14 +235,5 @@
 	 if ( mLMouseDown )
      {
-		 Ray mouseRay = mCamera->getCameraToViewportRay( e->getX(), e->getY() );
-		 mRaySceneQuery->setRay( mouseRay );
-
-		 RaySceneQueryResult &result = mRaySceneQuery->execute();
-		 RaySceneQueryResult::iterator itr = result.begin( );
-
-		 if ( itr != result.end() && itr->worldFragment )
-		 {
-			 mCurrentObject->setPosition( itr->worldFragment->singleIntersection );
-		 } 
+		
      }
 	 // If we are dragging the right mouse button.
@@ -287,22 +246,5 @@
 //-----------------------------------------------------------------------
 bool MouseQueryListener::frameStarted(const FrameEvent &evt)
-{
-	// clamp to terrain
-	Vector3 camPos = mCamera->getPosition( );
-    Ray cameraRay( Vector3(camPos.x, 5000.0f, camPos.z), Vector3::NEGATIVE_UNIT_Y );
-    mRaySceneQuery->setRay( cameraRay );
-
-    // Perform the scene query
-    RaySceneQueryResult &queryResult = mRaySceneQuery->execute();
-    RaySceneQueryResult::iterator it = queryResult.begin( );
-
-	if (it != queryResult.end() && it->worldFragment)
-	{
-		SceneQuery::WorldFragment* wf = it->worldFragment;
-
-		mCamera->setPosition(mCamera->getPosition().x, wf->singleIntersection.y + 10, 
-			mCamera->getPosition().z);
-	}
-	 
+{	 
 	return ExampleFrameListener::frameStarted(evt);
 }
Index: /trunk/VUT/OcclusionCullingSceneManager/TestCulling/TestCullingApplication.h
===================================================================
--- /trunk/VUT/OcclusionCullingSceneManager/TestCulling/TestCullingApplication.h	(revision 44)
+++ /trunk/VUT/OcclusionCullingSceneManager/TestCulling/TestCullingApplication.h	(revision 51)
@@ -79,8 +79,4 @@
 	OverlayElement *mHierarchyNodesInfo;
 	OverlayElement *mSceneNodesInfo;
-
-	SceneNode *mCurrentObject;         // The newly created object
-	int mCount;                        // The number of robots on the screen
-	RaySceneQuery *mRaySceneQuery;     // The ray scene query pointer
 };
 
@@ -95,8 +91,28 @@
 	void createFrameListener(void);
 	void setupGui(void);
-	virtual void createCamera(void);
+	/** 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);
+
+	//virtual void createCamera(void);
 
 	CEGUI::OgreCEGUIRenderer *mGUIRenderer;
 	CEGUI::System *mGUISystem;
+
+	Vector3 mMinTranslation;
+	Vector3 mMaxTranslation;
+
+	Vector3 mMinAngle;
+	Vector3 mMaxAngle;
 
 private:
