Index: trunk/VUT/OcclusionCullingSceneManager/TestCullingTerrain/TestCullingTerrainApplication.dsw
===================================================================
--- trunk/VUT/OcclusionCullingSceneManager/TestCullingTerrain/TestCullingTerrainApplication.dsw	(revision 47)
+++ trunk/VUT/OcclusionCullingSceneManager/TestCullingTerrain/TestCullingTerrainApplication.dsw	(revision 47)
@@ -0,0 +1,29 @@
+Microsoft Developer Studio Workspace File, Format Version 6.00
+# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
+
+###############################################################################
+
+Project: "Demo_TestCullingTerrain"=.\TestCullingTerrainApplication.dsp - Package Owner=<4>
+
+Package=<5>
+{{{
+}}}
+
+Package=<4>
+{{{
+}}}
+
+###############################################################################
+
+Global:
+
+Package=<5>
+{{{
+}}}
+
+Package=<3>
+{{{
+}}}
+
+###############################################################################
+
Index: trunk/VUT/OcclusionCullingSceneManager/TestCullingTerrain/TestCullingTerrain.vcproj
===================================================================
--- trunk/VUT/OcclusionCullingSceneManager/TestCullingTerrain/TestCullingTerrain.vcproj	(revision 47)
+++ trunk/VUT/OcclusionCullingSceneManager/TestCullingTerrain/TestCullingTerrain.vcproj	(revision 47)
@@ -0,0 +1,143 @@
+<?xml version="1.0" encoding="Windows-1252"?>
+<VisualStudioProject
+	ProjectType="Visual C++"
+	Version="7.10"
+	Name="TestCullingTerrain"
+	ProjectGUID="{248F19A6-2FE0-4F5D-8928-E0EA10609887}"
+	Keyword="Win32Proj">
+	<Platforms>
+		<Platform
+			Name="Win32"/>
+	</Platforms>
+	<Configurations>
+		<Configuration
+			Name="Debug|Win32"
+			OutputDirectory="..\bin\$(ConfigurationName)"
+			IntermediateDirectory="..\obj\$(ConfigurationName)"
+			ConfigurationType="1"
+			CharacterSet="2"
+			ReferencesPath="">
+			<Tool
+				Name="VCCLCompilerTool"
+				Optimization="0"
+				AdditionalIncludeDirectories="&quot;$(OGRE_PATH)\Dependencies\include&quot;;&quot;$(OGRE_PATH)\OgreMain\include&quot;;&quot;$(OGRE_PATH)\Samples\Common\include&quot;;&quot;$(OGRE_PATH)\Dependencies\include\CEGUI&quot;;&quot;$(OGRE_PATH)\PlugIns\OctreeSceneManager\include&quot;;&quot;$(OGRE_ADDONS_PATH)\dotsceneoctree\PlugIns\DotSceneManager\include&quot;;&quot;$(OGRE_PATH)\Samples\Common\CEGUIRenderer\include&quot;;../include"
+				PreprocessorDefinitions="_WINDOWS;_STLP_USE_DYNAMIC_LIB;OGRE_LIBRARY_IMPORTS;_DEBUG;WIN32;_STLP_DEBUG;PLUGIN_TERRAIN_IMPORTS"
+				MinimalRebuild="TRUE"
+				BasicRuntimeChecks="3"
+				RuntimeLibrary="3"
+				UsePrecompiledHeader="0"
+				WarningLevel="3"
+				Detect64BitPortabilityProblems="TRUE"
+				DebugInformationFormat="4"/>
+			<Tool
+				Name="VCCustomBuildTool"/>
+			<Tool
+				Name="VCLinkerTool"
+				AdditionalDependencies="Plugin_OctreeSceneManager.lib OGREMain_d.LIB CEGUIBase_d.lib OgreGUIRenderer_d.lib Plugin_DotSceneManager.lib"
+				OutputFile="$(OGRE_PATH)/Samples/Common/bin/Debug/TestCullingTerrain.exe"
+				LinkIncremental="2"
+				AdditionalLibraryDirectories="&quot;$(OGRE_PATH)\Dependencies\Lib\Debug&quot;;&quot;$(OGRE_ADDONS_PATH)\dotsceneoctree\PlugIns\DotSceneManager\bin\debug&quot;;&quot;$(OGRE_PATH)\OgreMain\Lib\Debug&quot;;&quot;$(OGRE_PATH)\PlugIns\OctreeSceneManager\bin\debug&quot;;&quot;$(OGRE_PATH)\Samples\Common\CEGUIRenderer\lib&quot;"
+				GenerateDebugInformation="TRUE"
+				ProgramDatabaseFile="$(OutDir)/TestCullingTerrain.pdb"
+				SubSystem="2"
+				ImportLibrary=""
+				TargetMachine="1"/>
+			<Tool
+				Name="VCMIDLTool"/>
+			<Tool
+				Name="VCPostBuildEventTool"/>
+			<Tool
+				Name="VCPreBuildEventTool"/>
+			<Tool
+				Name="VCPreLinkEventTool"/>
+			<Tool
+				Name="VCResourceCompilerTool"/>
+			<Tool
+				Name="VCWebServiceProxyGeneratorTool"/>
+			<Tool
+				Name="VCXMLDataGeneratorTool"/>
+			<Tool
+				Name="VCWebDeploymentTool"/>
+			<Tool
+				Name="VCManagedWrapperGeneratorTool"/>
+			<Tool
+				Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
+		</Configuration>
+		<Configuration
+			Name="Release|Win32"
+			OutputDirectory="Release"
+			IntermediateDirectory="Release"
+			ConfigurationType="1"
+			CharacterSet="2">
+			<Tool
+				Name="VCCLCompilerTool"
+				AdditionalIncludeDirectories="..\..\..\Samples\Common\Include, ..\..\..\OgreMain\include"
+				PreprocessorDefinitions="_WINDOWS,_STLP_USE_DYNAMIC_LIB,OGRE_LIBRARY_IMPORTS,_RELEASE,WIN32,_STLP_RELEASE"
+				RuntimeLibrary="2"
+				UsePrecompiledHeader="0"
+				WarningLevel="3"
+				Detect64BitPortabilityProblems="TRUE"
+				DebugInformationFormat="3"/>
+			<Tool
+				Name="VCCustomBuildTool"/>
+			<Tool
+				Name="VCLinkerTool"
+				AdditionalDependencies="OGREMain.LIB"
+				OutputFile="..\..\..\Samples\Common\Bin\Release\TestCullingTerrain.exe"
+				LinkIncremental="1"
+				AdditionalLibraryDirectories="..\..\..\OgreMain\Lib\Release"
+				GenerateDebugInformation="TRUE"
+				SubSystem="2"
+				OptimizeReferences="2"
+				EnableCOMDATFolding="2"
+				TargetMachine="1"/>
+			<Tool
+				Name="VCMIDLTool"/>
+			<Tool
+				Name="VCPostBuildEventTool"/>
+			<Tool
+				Name="VCPreBuildEventTool"/>
+			<Tool
+				Name="VCPreLinkEventTool"/>
+			<Tool
+				Name="VCResourceCompilerTool"/>
+			<Tool
+				Name="VCWebServiceProxyGeneratorTool"/>
+			<Tool
+				Name="VCXMLDataGeneratorTool"/>
+			<Tool
+				Name="VCWebDeploymentTool"/>
+			<Tool
+				Name="VCManagedWrapperGeneratorTool"/>
+			<Tool
+				Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
+		</Configuration>
+	</Configurations>
+	<References>
+	</References>
+	<Files>
+		<Filter
+			Name="Source Files"
+			Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx"
+			UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}">
+			<File
+				RelativePath=".\TestCullingTerrainApplication.cpp">
+			</File>
+		</Filter>
+		<Filter
+			Name="Header Files"
+			Filter="h;hpp;hxx;hm;inl;inc;xsd"
+			UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}">
+			<File
+				RelativePath=".\TestCullingTerrainApplication.h">
+			</File>
+		</Filter>
+		<Filter
+			Name="Resource Files"
+			Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx"
+			UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}">
+		</Filter>
+	</Files>
+	<Globals>
+	</Globals>
+</VisualStudioProject>
Index: trunk/VUT/OcclusionCullingSceneManager/TestCullingTerrain/TerrainContentGenerator.cpp
===================================================================
--- trunk/VUT/OcclusionCullingSceneManager/TestCullingTerrain/TerrainContentGenerator.cpp	(revision 47)
+++ trunk/VUT/OcclusionCullingSceneManager/TestCullingTerrain/TerrainContentGenerator.cpp	(revision 47)
@@ -0,0 +1,14 @@
+/**
+    \file 
+        TerrainContentGenerator.cpp
+    \brief
+        Creates content for the terrain,
+*/
+
+#include "TerrainContentGenerator.h"
+
+//-----------------------------------------------------------------------
+TerrainContentGenerator::TerrainContentGenerator( void )
+{
+}
+
Index: trunk/VUT/OcclusionCullingSceneManager/TestCullingTerrain/TestCullingTerrainApplication.cpp
===================================================================
--- trunk/VUT/OcclusionCullingSceneManager/TestCullingTerrain/TestCullingTerrainApplication.cpp	(revision 47)
+++ trunk/VUT/OcclusionCullingSceneManager/TestCullingTerrain/TestCullingTerrainApplication.cpp	(revision 47)
@@ -0,0 +1,409 @@
+/**
+    \file 
+        TestCullingApplication.cpp
+    \brief
+        Tests the occlusion culling algorithm
+*/
+
+#include <OgreNoMemoryMacros.h>
+#include <CEGUI/CEGUI.h>
+#include <../CEGUIRenderer/include/OgreCEGUIRenderer.h>
+#include <../CEGUIRenderer/include/OgreCEGUIResourceProvider.h>
+#include <../CEGUIRenderer/include/OgreCEGUITexture.h>
+#include <OgreMemoryMacros.h>
+
+#include "Ogre.h"
+#include "TestCullingApplication.h"
+#include "OgreOcclusionCullingSceneTraverser.h"
+
+#define WIN32_LEAN_AND_MEAN
+#include "windows.h"
+
+//RaySceneQuery* mRaySceneQuery = 0;
+
+/***********************************************/
+/* TestCullingApplication implementation       */
+/***********************************************/
+/*TestCullingApplication::~TestCullingApplication()
+{
+	delete mRaySceneQuery;
+}*/
+//-----------------------------------------------------------------------
+void TestCullingApplication::createCamera( void )
+{
+	// Create the camera
+	mCamera = mSceneMgr->createCamera("PlayerCam");
+
+	// Position it at 500 in Z direction
+	mCamera->setPosition(Vector3(128,25,128));
+
+	// Look back along -Z
+    mCamera->lookAt(Vector3(0,0,-300));
+    mCamera->setNearClipDistance( 1 );
+    mCamera->setFarClipDistance( 1000 );
+}
+//-----------------------------------------------------------------------
+void TestCullingApplication::createScene(void)
+{
+	Plane waterPlane;
+	// Set ambient light
+	mSceneMgr->setAmbientLight(ColourValue(0.5, 0.5, 0.5));
+	
+	// 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 );
+
+	mWindow->getViewport(0)->setBackgroundColour(fadeColour);
+
+	// 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 ) );*/
+
+	// CEGUI setup
+	setupGui();
+}
+//-----------------------------------------------------------------------
+void TestCullingApplication::setupGui( void )
+{
+	 mGUIRenderer = new CEGUI::OgreCEGUIRenderer(mWindow, Ogre::RENDER_QUEUE_OVERLAY, false, 3000, ST_EXTERIOR_CLOSE);
+     mGUISystem = new CEGUI::System(mGUIRenderer);
+
+	 // Mouse
+     CEGUI::SchemeManager::getSingleton().loadScheme((CEGUI::utf8*)"TaharezLook.scheme");
+     CEGUI::MouseCursor::getSingleton().setImage("TaharezLook", "MouseArrow");
+	 mGUISystem->setDefaultMouseCursor(
+                (CEGUI::utf8*)"TaharezLook", (CEGUI::utf8*)"MouseArrow");
+
+	 CEGUI::MouseCursor::getSingleton().show( );
+}
+//-----------------------------------------------------------------------
+void TestCullingApplication::createFrameListener(void)
+{
+	mFrameListener= new MouseQueryListener(mWindow, mCamera, mSceneMgr, mGUIRenderer);
+	mFrameListener->showDebugOverlay(true);
+	mRoot->addFrameListener(mFrameListener);
+}
+//-----------------------------------------------------------------------
+void TestCullingApplication::chooseSceneManager(void)
+{
+    //mSceneMgr = mRoot->getSceneManager(ST_GENERIC);
+	mSceneMgr = mRoot->getSceneManager(ST_EXTERIOR_CLOSE);
+}
+
+/***********************************************/
+/* MouseQueryListener implementation           */
+/***********************************************/
+//-----------------------------------------------------------------------
+MouseQueryListener::MouseQueryListener(RenderWindow* win, Camera* cam, SceneManager *sceneManager, CEGUI::Renderer *renderer)
+        : ExampleFrameListener(win, cam, false, true), mGUIRenderer(renderer), 
+		mShutdownRequested(false)
+{
+
+	// Setup default variables
+	mCurrentObject = NULL;
+	mLMouseDown = false;
+	mRMouseDown = false;
+	mSceneMgr = sceneManager;
+
+    // Reduce move speed
+	mMoveSpeed = 50;
+	mRotateSpeed *= 2;
+
+	mCurrentAlgorithm = OcclusionCullingSceneTraverser::RENDER_COHERENT;
+	mThreshold = 0;
+    
+	// Register this so that we get mouse events.
+	mEventProcessor->addMouseListener(this);
+	mEventProcessor->addMouseMotionListener(this);
+	mEventProcessor->addKeyListener(this);
+
+	mRaySceneQuery = mSceneMgr->createRayQuery( Ray() );
+
+	// show overlay
+	Overlay* pOver = OverlayManager::getSingleton().getByName("Example/OcclusionCullingDemoOverlay"); 
+
+	mAlgorithmInfo = OverlayManager::getSingleton().getOverlayElement("Example/Occlusion/AlgorithmInfo");
+	mThresholdInfo = OverlayManager::getSingleton().getOverlayElement("Example/Occlusion/ThresholdInfo");
+	mFrustumCulledNodesInfo = OverlayManager::getSingleton().getOverlayElement("Example/Occlusion/FrustumCulledNodesInfo");
+	mQueryCulledNodesInfo = OverlayManager::getSingleton().getOverlayElement("Example/Occlusion/QueryCulledNodesInfo");
+    mTraversedNodesInfo = OverlayManager::getSingleton().getOverlayElement("Example/Occlusion/TraversedNodesInfo");
+	mSceneNodesInfo = OverlayManager::getSingleton().getOverlayElement("Example/Occlusion/SceneNodesInfo");
+	mHierarchyNodesInfo = OverlayManager::getSingleton().getOverlayElement("Example/Occlusion/HierarchyNodesInfo");
+
+	mAlgorithmInfo->setCaption(": " + mCurrentAlgorithmCaptions[mCurrentAlgorithm]);
+	mThresholdInfo->setCaption(": 0");
+	mFrustumCulledNodesInfo->setCaption(": 0");
+	mQueryCulledNodesInfo->setCaption(": 0");
+	mTraversedNodesInfo->setCaption(": 0");
+	mSceneNodesInfo->setCaption(": 0");
+	mHierarchyNodesInfo->setCaption(": 0");
+
+    pOver->show();
+} 
+//-----------------------------------------------------------------------
+MouseQueryListener::~MouseQueryListener( )
+{
+	delete mRaySceneQuery;
+}
+//-----------------------------------------------------------------------
+void MouseQueryListener::mouseMoved (MouseEvent *e)
+{
+	// Update CEGUI with the mouse motion
+    CEGUI::System::getSingleton().injectMouseMove(e->getRelX() * mGUIRenderer->getWidth(), e->getRelY() * mGUIRenderer->getHeight());
+}
+//-----------------------------------------------------------------------
+void MouseQueryListener::mousePressed(MouseEvent* e)
+{
+     // Left mouse button down
+     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; 
+     }
+     // Right mouse button down
+     else if (e->getButtonID() & InputEvent::BUTTON1_MASK)
+     {
+         CEGUI::MouseCursor::getSingleton().hide( );
+         mRMouseDown = true;
+     } // else if
+} // mousePressed
+
+ //-----------------------------------------------------------------------
+void MouseQueryListener::mouseReleased(MouseEvent* e)
+{
+    // Left mouse button up
+    if (e->getButtonID() & InputEvent::BUTTON0_MASK)
+    {
+		CEGUI::MouseCursor::getSingleton().show( );
+        mLMouseDown = false;
+    }
+    // Right mouse button up
+    else if (e->getButtonID() & InputEvent::BUTTON1_MASK)
+    {
+        CEGUI::MouseCursor::getSingleton().show( );
+        mRMouseDown = false;
+    }
+} 
+//-----------------------------------------------------------------------
+void MouseQueryListener::mouseDragged (MouseEvent *e)
+ {
+	 // If we are dragging the left mouse button.	 	 
+	 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.
+	 if ( mRMouseDown )
+	 {
+		 mCamera->yaw( -e->getRelX() * mRotateSpeed );
+		 mCamera->pitch( -e->getRelY() * mRotateSpeed );
+	 }
+}
+//-----------------------------------------------------------------------
+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);
+}
+//-----------------------------------------------------------------------
+bool MouseQueryListener::frameEnded(const FrameEvent& evt)
+{
+	if (mShutdownRequested)
+		return false;
+
+    if (timeDelay >= 0) 
+        timeDelay -= evt.timeSinceLastFrame;
+
+    KEY_PRESSED(KC_SPACE, 0.3, changeAlgorithm());
+
+	KEY_PRESSED(KC_SUBTRACT, 0, changeThreshold(-10));
+	KEY_PRESSED(KC_ADD, 0, changeThreshold(10));
+	//KEY_PRESSED(KC_T, 1, change);
+      
+	changeStats();
+
+    return ExampleFrameListener::frameStarted(evt) && ExampleFrameListener::frameEnded(evt);        
+}
+//-----------------------------------------------------------------------
+void MouseQueryListener::changeThreshold(int incr)
+{
+	mThreshold += incr; if(mThreshold < 0) mThreshold = 0;
+	
+	char str[100]; sprintf(str,": %d", mThreshold);
+
+	mSceneMgr->setOption("Threshold", &mThreshold); 
+	mThresholdInfo->setCaption(str);
+}
+//-----------------------------------------------------------------------
+void MouseQueryListener::changeAlgorithm()
+{
+    mCurrentAlgorithm = ++mCurrentAlgorithm % OcclusionCullingSceneTraverser::NUM_RENDERMODES;
+
+	mAlgorithmInfo->setCaption(": " + mCurrentAlgorithmCaptions[mCurrentAlgorithm]);
+	mSceneMgr->setOption("Algorithm", &mCurrentAlgorithm);
+}
+//-----------------------------------------------------------------------
+void MouseQueryListener::changeStats()
+{
+	unsigned int opt = 0;
+	char str[100];
+	
+	mSceneMgr->getOption("NumFrustumCulledNodes", &opt); sprintf(str,": %d", opt); 
+	mFrustumCulledNodesInfo->setCaption(str);
+	
+	mSceneMgr->getOption("NumQueryCulledNodes", &opt); sprintf(str,": %d", opt); 
+	mQueryCulledNodesInfo->setCaption(str);
+	
+	mSceneMgr->getOption("NumTraversedNodes", &opt); sprintf(str,": %d", opt); 
+	mTraversedNodesInfo->setCaption(str);
+
+	mSceneMgr->getOption("NumSceneNodes", &opt); sprintf(str,": %d", opt); 
+	mSceneNodesInfo->setCaption(str);
+
+	mSceneMgr->getOption("NumOctreeNodes", &opt); sprintf(str,": %d", opt); 
+	mHierarchyNodesInfo->setCaption(str);
+}
+//-----------------------------------------------------------------------
+void MouseQueryListener::keyPressed(KeyEvent* e)
+{
+	if(e->getKey() == KC_ESCAPE)
+    {
+		mShutdownRequested = true;
+		e->consume();
+		return;
+	}
+
+	CEGUI::System::getSingleton().injectKeyDown(e->getKey());
+	CEGUI::System::getSingleton().injectChar(e->getKeyChar());
+	e->consume();
+}
+//-----------------------------------------------------------------------
+void MouseQueryListener::keyReleased(KeyEvent* e)
+{
+	CEGUI::System::getSingleton().injectKeyUp(e->getKey());
+	e->consume();
+}
+//-----------------------------------------------------------------------
+void MouseQueryListener::keyClicked(KeyEvent* e) 
+{
+	// Do nothing
+	e->consume();
+}
+//-----------------------------------------------------------------------
+INT WINAPI WinMain( HINSTANCE hInst, HINSTANCE, LPSTR strCmdLine, INT )
+{
+    // Create application object
+    TestCullingApplication app;
+
+	try 
+	{
+        app.go();
+    } 
+	catch( Ogre::Exception& e ) 
+	{
+        MessageBox( NULL, e.getFullDescription().c_str(), "An exception has occured!", MB_OK | MB_ICONERROR | MB_TASKMODAL);
+    }	
+
+    return 0;
+}
Index: trunk/VUT/OcclusionCullingSceneManager/TestCullingTerrain/TestCullingTerrainApplication.dsp
===================================================================
--- trunk/VUT/OcclusionCullingSceneManager/TestCullingTerrain/TestCullingTerrainApplication.dsp	(revision 47)
+++ trunk/VUT/OcclusionCullingSceneManager/TestCullingTerrain/TestCullingTerrainApplication.dsp	(revision 47)
@@ -0,0 +1,109 @@
+# Microsoft Developer Studio Project File - Name="Demo_TestCullingTerrainApplication" - Package Owner=<4>
+# Microsoft Developer Studio Generated Build File, Format Version 6.00
+# ** DO NOT EDIT **
+
+# TARGTYPE "Win32 (x86) Application" 0x0101
+
+CFG=Demo_TestCullingTerrainApplication - Win32 Debug
+!MESSAGE This is not a valid makefile. To build this project using NMAKE,
+!MESSAGE use the Export Makefile command and run
+!MESSAGE 
+!MESSAGE NMAKE /f "TestCullingTerrainApplication.mak".
+!MESSAGE 
+!MESSAGE You can specify a configuration when running NMAKE
+!MESSAGE by defining the macro CFG on the command line. For example:
+!MESSAGE 
+!MESSAGE NMAKE /f "TestCullingTerrainApplication.mak" CFG="Demo_TestCullingTerrainApplication - Win32 Debug"
+!MESSAGE 
+!MESSAGE Possible choices for configuration are:
+!MESSAGE 
+!MESSAGE "Demo_TestCullingTerrainApplication - Win32 Release" (based on "Win32 (x86) Application")
+!MESSAGE "Demo_TestCullingTerrainApplication - Win32 Debug" (based on "Win32 (x86) Application")
+!MESSAGE 
+
+# Begin Project
+# PROP AllowPerConfigDependencies 0
+# PROP Scc_ProjName ""
+# PROP Scc_LocalPath ""
+CPP=cl.exe
+MTL=midl.exe
+RSC=rc.exe
+
+!IF  "$(CFG)" == "Demo_TestCullingTerrainApplication - Win32 Release"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "..\bin\Release"
+# PROP BASE Intermediate_Dir "..\obj\Release"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir "..\bin\Release"
+# PROP Intermediate_Dir "..\obj\Release"
+# PROP Ignore_Export_Lib 1
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /YX /FD /c
+# ADD CPP /nologo /MD /W3 /GX /Zi /Od /I "." /I "$(OGRE_PATH)\OgreMain\include" /I "$(OGRE_PATH)\Samples/Common/include" /D "NDEBUG" /D "_MBCS" /D "_WINDOWS" /D "WIN32" /YX /FD /Zm1000 /c
+# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
+# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
+# ADD BASE RSC /l 0x809 /d "NDEBUG"
+# ADD RSC /l 0x809 /d "NDEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /machine:I386
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib OgreMain.lib /nologo /subsystem:windows /machine:I386 /out:"$(OGRE_PATH)\Samples\Common\Bin\Release\Demo_TestCullingTerrainApplication.exe" /libpath:"$(OGRE_PATH)\OgreMain\lib\release" 
+# SUBTRACT LINK32 /profile /debug
+
+!ELSEIF  "$(CFG)" == "Demo_TestCullingTerrainApplication - Win32 Debug"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 1
+# PROP BASE Output_Dir "..\bin\Debug"
+# PROP BASE Intermediate_Dir "..\obj\Debug"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 1
+# PROP Output_Dir "..\bin\Debug"
+# PROP Intermediate_Dir "..\obj\Debug"
+# PROP Ignore_Export_Lib 1
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /YX /FD /GZ /c
+# ADD CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /I "." /I "$(OGRE_PATH)\OgreMain\include" /I "$(OGRE_PATH)\Samples/Common/include" /D "_MBCS" /D "_WINDOWS" /D "_DEBUG" /D "WIN32" /FD /GZ /Zm1000 /c
+# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
+# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
+# ADD BASE RSC /l 0x809 /d "_DEBUG"
+# ADD RSC /l 0x809 /d "_DEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /debug /machine:I386 /pdbtype:sept
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib OgreMain_d.lib /nologo /subsystem:windows /debug /machine:I386 /nodefaultlib:"LIBCMT" /out:"$(OGRE_PATH)\Samples\Common\Bin\Debug\Demo_TestCullingTerrainApplication.exe" /pdbtype:sept /libpath:"$(OGRE_PATH)\OgreMain\lib\debug" 
+# SUBTRACT LINK32 /verbose
+
+!ENDIF 
+
+# Begin Target
+
+# Name "Demo_TestCullingTerrainApplication - Win32 Release"
+# Name "Demo_TestCullingTerrainApplication - Win32 Debug"
+# Begin Group "Source Files"
+
+# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
+# End Group
+# Begin Group "Header Files"
+
+# PROP Default_Filter "h;hpp;hxx;hm;inl"
+# Begin Source File
+
+SOURCE=TestCullingTerrainApplication.cpp
+# End Source File
+# End Group
+# Begin Group "Resource Files"
+
+# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
+# End Group
+# End Target
+# End Project
Index: trunk/VUT/OcclusionCullingSceneManager/TestCullingTerrain/TerrainContentGenerator.h
===================================================================
--- trunk/VUT/OcclusionCullingSceneManager/TestCullingTerrain/TerrainContentGenerator.h	(revision 47)
+++ trunk/VUT/OcclusionCullingSceneManager/TestCullingTerrain/TerrainContentGenerator.h	(revision 47)
@@ -0,0 +1,14 @@
+/**
+    \file 
+        TerrainContentGenerator.h
+*/
+
+class TerrainContentGenerator
+{
+public:
+	TerrainContentGenerator();
+
+protected:
+
+};
+
Index: trunk/VUT/OcclusionCullingSceneManager/TestCullingTerrain/TestCullingTerrainApplication.h
===================================================================
--- trunk/VUT/OcclusionCullingSceneManager/TestCullingTerrain/TestCullingTerrainApplication.h	(revision 47)
+++ trunk/VUT/OcclusionCullingSceneManager/TestCullingTerrain/TestCullingTerrainApplication.h	(revision 47)
@@ -0,0 +1,105 @@
+/**
+    \file 
+        TestCullingApplication.h
+*/
+#include "CEGUIForwardRefs.h"
+#include "ExampleApplication.h"
+#include "OgreOcclusionCullingSceneTraverser.h"
+
+Real timeDelay = 0;
+#define KEY_PRESSED(_key,_timeDelay, _macro) \
+{ \
+    if (mInputDevice->isKeyDown(_key) && timeDelay <= 0) \
+{ \
+    timeDelay = _timeDelay; \
+    _macro ; \
+} \
+}
+
+String mCurrentAlgorithmCaptions[OcclusionCullingSceneTraverser::NUM_RENDERMODES] = 
+{
+    "Cull Frustum", 
+	"Stop and Wait", 
+	"Coherent Occlusion Culling"
+};
+
+class MouseQueryListener : public ExampleFrameListener, public MouseListener, public MouseMotionListener
+{
+public:
+
+    MouseQueryListener(RenderWindow* win, Camera* cam, SceneManager *sceneManager, CEGUI::Renderer *renderer);
+
+
+    ~MouseQueryListener( );
+
+	bool frameStarted(const FrameEvent& evt);
+	bool frameEnded(const FrameEvent& evt);
+
+    /* MouseListener callbacks. */
+    virtual void mouseClicked(MouseEvent* e) { }
+    virtual void mouseEntered(MouseEvent* e) { }
+    virtual void mouseExited(MouseEvent* e)  { }
+
+    // This is when the mouse button goes DOWN.
+    virtual void mousePressed(MouseEvent* e);
+
+    // This is when the mouse button is let UP.
+    virtual void mouseReleased(MouseEvent* e);
+
+    /* MouseMotionListener callbacks */
+    virtual void mouseMoved (MouseEvent *e);
+   
+    // This is when the mouse is clicked, held and dragged.
+    virtual void mouseDragged (MouseEvent *e);
+
+    void keyPressed(KeyEvent* e);
+
+	void keyReleased(KeyEvent* e);
+	void keyClicked(KeyEvent* e);
+
+	void changeAlgorithm();
+	void changeThreshold(int incr);
+	void changeStats();
+
+protected:
+    bool mLMouseDown, mRMouseDown;     // True if the mouse buttons are down
+    SceneManager *mSceneMgr;           // A pointer to the scene manager
+    
+	CEGUI::Renderer *mGUIRenderer;     // cegui renderer
+	
+	bool mShutdownRequested;
+	int mCurrentAlgorithm;
+	int mThreshold;
+
+	OverlayElement *mAlgorithmInfo;
+	OverlayElement *mThresholdInfo;
+	OverlayElement *mFrustumCulledNodesInfo;
+	OverlayElement *mQueryCulledNodesInfo;
+    OverlayElement *mTraversedNodesInfo;
+	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
+};
+
+
+class TestCullingApplication : public ExampleApplication
+{
+public:
+	//~TestCullingApplication();
+
+protected:
+	void createScene(void);
+	void createFrameListener(void);
+	void setupGui(void);
+	virtual void createCamera(void);
+
+	CEGUI::OgreCEGUIRenderer *mGUIRenderer;
+	CEGUI::System *mGUISystem;
+
+private:
+	void chooseSceneManager(void);
+};
+
