Index: /trunk/VUT/OcclusionCullingSceneManager/TestCullingDotScene/TestCullingDotScene.vcproj
===================================================================
--- /trunk/VUT/OcclusionCullingSceneManager/TestCullingDotScene/TestCullingDotScene.vcproj	(revision 36)
+++ /trunk/VUT/OcclusionCullingSceneManager/TestCullingDotScene/TestCullingDotScene.vcproj	(revision 36)
@@ -0,0 +1,138 @@
+<?xml version="1.0" encoding="Windows-1252"?>
+<VisualStudioProject
+	ProjectType="Visual C++"
+	Version="7.10"
+	Name="TestCullingDotScene"
+	ProjectGUID="{BE13944C-D05E-467F-B0AC-8A65A3B5FE60}"
+	Keyword="Win32Proj">
+	<Platforms>
+		<Platform
+			Name="Win32"/>
+	</Platforms>
+	<Configurations>
+		<Configuration
+			Name="Debug|Win32"
+			OutputDirectory="Debug"
+			IntermediateDirectory="Debug"
+			ConfigurationType="1"
+			CharacterSet="2">
+			<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="WIN32;_DEBUG;_WINDOWS"
+				MinimalRebuild="TRUE"
+				BasicRuntimeChecks="3"
+				RuntimeLibrary="5"
+				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="$(OutDir)/TestCullingDotScene.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)/TestCullingDotScene.pdb"
+				SubSystem="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>
+		<Configuration
+			Name="Release|Win32"
+			OutputDirectory="Release"
+			IntermediateDirectory="Release"
+			ConfigurationType="1"
+			CharacterSet="2">
+			<Tool
+				Name="VCCLCompilerTool"
+				PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS"
+				RuntimeLibrary="4"
+				UsePrecompiledHeader="0"
+				WarningLevel="3"
+				Detect64BitPortabilityProblems="TRUE"
+				DebugInformationFormat="3"/>
+			<Tool
+				Name="VCCustomBuildTool"/>
+			<Tool
+				Name="VCLinkerTool"
+				OutputFile="$(OutDir)/TestCullingDotScene.exe"
+				LinkIncremental="1"
+				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=".\TestCullingDotSceneApplication.cpp">
+			</File>
+		</Filter>
+		<Filter
+			Name="Header Files"
+			Filter="h;hpp;hxx;hm;inl;inc;xsd"
+			UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}">
+			<File
+				RelativePath=".\TestCullingDotSceneApplication.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/TestCullingDotScene/TestCullingDotSceneApplication.cpp
===================================================================
--- /trunk/VUT/OcclusionCullingSceneManager/TestCullingDotScene/TestCullingDotSceneApplication.cpp	(revision 36)
+++ /trunk/VUT/OcclusionCullingSceneManager/TestCullingDotScene/TestCullingDotSceneApplication.cpp	(revision 36)
@@ -0,0 +1,660 @@
+/**
+    \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* raySceneQuery = 0;
+
+/***********************************************/
+/* TestCullingApplication implementation       */
+/***********************************************/
+TestCullingApplication::~TestCullingApplication()
+{
+	delete raySceneQuery;
+}
+
+void TestCullingApplication::parseDotScene( const String &SceneName, const String& groupName )
+{
+	TiXmlDocument	*XMLDoc;
+	TiXmlElement	*XMLRoot, *XMLNodes, *XMLPathFind;
+	try
+	{
+		DataStreamPtr pStream = ResourceGroupManager::getSingleton().openResource( SceneName, groupName );
+
+		String data = pStream->getAsString();
+
+		// Open the .scene File
+		XMLDoc = new TiXmlDocument();
+		XMLDoc->Parse( data.c_str() );
+		pStream->close();
+		pStream.setNull();
+
+		if( XMLDoc->Error() )
+		{
+			//We'll just log, and continue on gracefully
+			LogManager::getSingleton().logMessage("Error in dotscene demo app!!!!!");
+			delete XMLDoc;
+			return;
+		}
+	}
+	catch(...)
+	{
+		//We'll just log, and continue on gracefully
+		LogManager::getSingleton().logMessage("Error in dotscene demo app!!!!!");
+		delete XMLDoc;
+		return;
+	}
+
+	// Validate the File
+	XMLRoot = XMLDoc->RootElement();
+	if( String( XMLRoot->Value()) != "scene"  ) {
+		LogManager::getSingleton().logMessage( "Error: Invalid .scene File. Missing <scene>" );
+		delete XMLDoc;		
+		return;
+	}
+		
+	XMLNodes = XMLRoot->FirstChildElement( "nodes" );
+	
+	// Read in the scene nodes
+	if( XMLNodes )
+	{
+		TiXmlElement *XMLNode, *XMLPosition, *XMLRotation, *XMLScale,  *XMLEntity, *XMLBillboardSet,  *XMLLight;
+
+		XMLNode = XMLNodes->FirstChildElement( "node" );
+		
+		while( XMLNode )
+		{
+			// Process the current node
+			// Grab the name of the node
+			String NodeName = XMLNode->Attribute("name");
+			// First create the new scene node
+			SceneNode* NewNode = static_cast<SceneNode*>( mSceneMgr->getRootSceneNode()->createChild( NodeName ) );
+
+			Vector3 TempVec;
+			String TempValue;
+				
+			// Now position it...
+			XMLPosition = XMLNode->FirstChildElement("position");
+			
+			if( XMLPosition )
+			{
+				TempValue = XMLPosition->Attribute("x");
+				TempVec.x = StringConverter::parseReal(TempValue);
+				TempValue = XMLPosition->Attribute("y");
+				TempVec.y = StringConverter::parseReal(TempValue);
+				TempValue = XMLPosition->Attribute("z");
+				TempVec.z = StringConverter::parseReal(TempValue);
+				NewNode->setPosition( TempVec );
+			}
+
+			// Rotate it...
+			XMLRotation = XMLNode->FirstChildElement("rotation");
+			if( XMLRotation )
+			{
+				Quaternion TempQuat;
+				TempValue = XMLRotation->Attribute("qx");
+				TempQuat.x = StringConverter::parseReal(TempValue);
+				TempValue = XMLRotation->Attribute("qy");
+				TempQuat.y = StringConverter::parseReal(TempValue);
+				TempValue = XMLRotation->Attribute("qz");
+				TempQuat.z = StringConverter::parseReal(TempValue);
+				TempValue = XMLRotation->Attribute("qw");
+				TempQuat.w = StringConverter::parseReal(TempValue);
+				NewNode->setOrientation( TempQuat );
+			}
+
+			// Scale it.
+			XMLScale = XMLNode->FirstChildElement("scale");
+			
+			if( XMLScale )
+			{
+				TempValue = XMLScale->Attribute("x");
+				TempVec.x = StringConverter::parseReal(TempValue);
+				TempValue = XMLScale->Attribute("y");
+				TempVec.y = StringConverter::parseReal(TempValue);
+				TempValue = XMLScale->Attribute("z");
+				TempVec.z = StringConverter::parseReal(TempValue);
+				NewNode->setScale( TempVec );
+			}
+
+			XMLLight = XMLNode->FirstChildElement( "light" );
+			
+			if( XMLLight )
+				NewNode->attachObject( LoadLight( XMLLight ) );
+
+			// Check for an Entity
+			XMLEntity = XMLNode->FirstChildElement("entity");
+			
+			if( XMLEntity )
+			{
+				if( XMLEntity->Attribute("static") )
+				{
+					if( strcmp( XMLEntity->Attribute("static"), "false" )==0 ){
+						String EntityName, EntityMeshFilename;
+						EntityName = XMLEntity->Attribute( "name" );
+						EntityMeshFilename = XMLEntity->Attribute( "meshFile" );
+
+						// Create entity
+						Entity* NewEntity = mSceneMgr->createEntity(EntityName, EntityMeshFilename);
+						NewNode->attachObject( NewEntity );
+					}
+				}
+			}
+
+			XMLBillboardSet = XMLNode->FirstChildElement( "billboardSet" );
+			if( XMLBillboardSet )
+			{
+				String TempValue;
+
+				BillboardSet* bSet = mSceneMgr->createBillboardSet( NewNode->getName() );
+
+				BillboardType Type;
+				TempValue = XMLBillboardSet->Attribute( "type" );
+				if( TempValue == "orientedCommon" ) 
+					Type = BBT_ORIENTED_COMMON;
+				else if( TempValue == "orientedSelf" )
+					Type = BBT_ORIENTED_SELF;
+				else Type = BBT_POINT;
+
+				BillboardOrigin Origin;
+				TempValue = XMLBillboardSet->Attribute( "type" );
+				if( TempValue == "bottom_left" )
+					Origin = BBO_BOTTOM_LEFT;
+				else if( TempValue == "bottom_center" )
+					Origin = BBO_BOTTOM_CENTER;
+				else if( TempValue == "bottomRight"  )
+					Origin = BBO_BOTTOM_RIGHT;
+				else if( TempValue == "left" )
+					Origin = BBO_CENTER_LEFT;
+				else if( TempValue == "right" )
+					Origin = BBO_CENTER_RIGHT;
+				else if( TempValue == "topLeft" )
+					Origin = BBO_TOP_LEFT;
+				else if( TempValue == "topCenter" )
+					Origin = BBO_TOP_CENTER;
+				else if( TempValue == "topRight" )
+					Origin = BBO_TOP_RIGHT;
+				else 
+					Origin = BBO_CENTER;
+
+				bSet->setBillboardType( Type );
+				bSet->setBillboardOrigin( Origin );
+
+				TempValue = XMLBillboardSet->Attribute( "name" );
+				bSet->setMaterialName( TempValue );
+
+				int width, height;
+				width = StringConverter::parseReal( XMLBillboardSet->Attribute( "width" ) );
+				height = StringConverter::parseReal( XMLBillboardSet->Attribute( "height" ) );
+				bSet->setDefaultDimensions( width, height );
+				bSet->setVisible( true );
+				NewNode->attachObject( bSet );
+
+				TiXmlElement *XMLBillboard;
+
+				XMLBillboard = XMLBillboardSet->FirstChildElement( "billboard" );
+
+				while( XMLBillboard )
+				{
+					Billboard *b;
+					TempValue;
+					TempVec = Vector3( 0, 0, 0 );
+					ColourValue TempColour(1,1,1,1);
+
+					XMLPosition = XMLBillboard->FirstChildElement( "position" );
+					if( XMLPosition ){
+						TempValue = XMLPosition->Attribute("x");
+						TempVec.x = StringConverter::parseReal(TempValue);
+						TempValue = XMLPosition->Attribute("y");
+						TempVec.y = StringConverter::parseReal(TempValue);
+						TempValue = XMLPosition->Attribute("z");
+						TempVec.z = StringConverter::parseReal(TempValue);
+					}
+
+					TiXmlElement* XMLColour = XMLBillboard->FirstChildElement( "colourDiffuse" );
+					if( XMLColour )
+					{
+						TempValue = XMLColour->Attribute("r");
+						TempColour.r = StringConverter::parseReal(TempValue);
+						TempValue = XMLColour->Attribute("g");
+						TempColour.g = StringConverter::parseReal(TempValue);
+						TempValue = XMLColour->Attribute("b");
+						TempColour.b = StringConverter::parseReal(TempValue);
+					}
+
+					b = bSet->createBillboard( TempVec, TempColour);
+
+					XMLBillboard = XMLBillboard->NextSiblingElement( "billboard" );
+				}
+			}
+
+			// Move to the next node
+			XMLNode = XMLNode->NextSiblingElement( "node" );
+		}
+	}
+
+	// Close the XML File
+	delete XMLDoc;
+}
+
+Light* LoadLight( TiXmlElement *XMLLight )
+{
+	TiXmlElement *XMLDiffuse, *XMLSpecular, *XMLAttentuation, *XMLPosition;
+
+	// Create a light (point | directional | spot | radPoint)
+	Light* l = mSceneMgr->createLight( XMLLight->Attribute("name") );
+	if( !XMLLight->Attribute("type") || String(XMLLight->Attribute("type")) == "point" )
+		l->setType( Light::LT_POINT );
+	else if( String(XMLLight->Attribute("type")) == "directional")
+		l->setType( Light::LT_DIRECTIONAL );
+	else if( String(XMLLight->Attribute("type")) == "spot")
+		l->setType( Light::LT_SPOTLIGHT );
+	else if( String(XMLLight->Attribute("type")) == "radPoint")
+		l->setType( Light::LT_POINT );
+
+	XMLDiffuse = XMLLight->FirstChildElement("colourDiffuse");
+	if( XMLDiffuse )
+	{
+		ColourValue Diffuse;
+		Diffuse.r = Ogre::StringConverter::parseReal( XMLDiffuse->Attribute("r") );
+		Diffuse.g = Ogre::StringConverter::parseReal( XMLDiffuse->Attribute("g") );
+		Diffuse.b = Ogre::StringConverter::parseReal( XMLDiffuse->Attribute("b") );
+		Diffuse.a = 1;
+		l->setDiffuseColour(Diffuse);
+	}
+	
+	XMLSpecular = XMLLight->FirstChildElement("colourSpecular");
+	
+	if( XMLSpecular )
+	{
+		ColourValue Specular;
+		Specular.r = Ogre::StringConverter::parseReal( XMLSpecular->Attribute("r") );
+		Specular.g = Ogre::StringConverter::parseReal( XMLSpecular->Attribute("g") );
+		Specular.b = Ogre::StringConverter::parseReal( XMLSpecular->Attribute("b") );
+		Specular.a = 1;
+		l->setSpecularColour(Specular);
+	}
+
+	XMLAttentuation = XMLLight->FirstChildElement("lightAttenuation");
+	if( XMLAttentuation )
+	{
+		//get defaults incase not all values specified
+		Real range, constant, linear, quadratic;
+		range = l->getAttenuationRange();
+		constant = l->getAttenuationConstant();
+		linear = l->getAttenuationLinear();
+		quadratic = l->getAttenuationQuadric();
+			
+		if( XMLAttentuation->Attribute("range") )
+			range = StringConverter::parseReal( XMLAttentuation->Attribute("range") );
+		if( XMLAttentuation->Attribute("constant") )
+			constant = StringConverter::parseReal( XMLAttentuation->Attribute("constant") );
+		if( XMLAttentuation->Attribute("linear") )
+			linear = StringConverter::parseReal( XMLAttentuation->Attribute("linear") );
+		if( XMLAttentuation->Attribute("quadratic") )
+			quadratic = StringConverter::parseReal( XMLAttentuation->Attribute("quadratic") );
+			l->setAttenuation( range, constant, linear, quadratic );
+	}
+
+	XMLPosition = XMLLight->FirstChildElement("position");
+	if( XMLPosition ) 
+	{
+		Vector3 p = Vector3(0,0,0);
+		if( XMLPosition->Attribute("x") )
+			p.x = StringConverter::parseReal( XMLPosition->Attribute("x") );
+		if( XMLPosition->Attribute("y") )
+			p.y = StringConverter::parseReal( XMLPosition->Attribute("y") );
+		if( XMLPosition->Attribute("z") )
+			p.z = StringConverter::parseReal( XMLPosition->Attribute("z") );
+            
+		l->setPosition( p );
+	}
+
+	//castShadows		(true | false) "true"
+	l->setCastShadows( true );
+	if( XMLLight->Attribute("visible") )
+		if( String(XMLLight->Attribute("visible")) == "false" )
+				l->setCastShadows( false );
+			
+	//visible			(true | false) "true"		
+	l->setVisible( true );
+	if( XMLLight->Attribute("visible") )
+		if( String(XMLLight->Attribute("visible")) == "false" )
+			l->setVisible( false );
+
+	return l;
+}
+//-----------------------------------------------------------------------
+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);
+	mWindow->getViewport(0)->setBackgroundColour(fadeColour);
+
+	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;
+
+	// Set a nice viewpoint
+	mCamera->setPosition(707,2500,528);
+	mCamera->setOrientation(Quaternion(-0.3486, 0.0122, 0.9365, 0.0329));
+
+	raySceneQuery = mSceneMgr->createRayQuery(
+	Ray(mCamera->getPosition(), Vector3::NEGATIVE_UNIT_Y));
+
+     // Create a skybox
+  //   mSceneMgr->setSkyBox(true, "Examples/SpaceSkyBox");
+
+	 // 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( );
+     
+	/* CEGUI::Window* sheet = 
+            CEGUI::WindowManager::getSingleton().loadWindowLayout(
+                (CEGUI::utf8*)"ogregui.layout"); 
+
+     mGUISystem->setGUISheet(sheet);*/
+}
+//-----------------------------------------------------------------------
+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);
+
+	// show overlay
+	Overlay* pOver = OverlayManager::getSingleton().getByName("Example/OcclusionDemoOverlay"); 
+
+	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");
+
+	mAlgorithmInfo->setCaption(": " + mCurrentAlgorithmCaptions[mCurrentAlgorithm]);
+	mThresholdInfo->setCaption(": 0");
+	mFrustumCulledNodesInfo->setCaption(": 0");
+	mQueryCulledNodesInfo->setCaption(": 0");
+	mTraversedNodesInfo->setCaption(": 0");
+
+    pOver->show();
+} // MouseQueryListener
+//-----------------------------------------------------------------------
+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( );
+		 mLMouseDown = true;
+     } // if
+     // 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 )
+	 {
+		mShipNode->translate(-e->getRelX() * 200, -e->getRelY() * 200, 0.0);
+     }
+	 */
+	 
+	 // 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
+	static Ray updateRay;
+	updateRay.setOrigin(mCamera->getPosition());
+	updateRay.setDirection(Vector3::NEGATIVE_UNIT_Y);
+	raySceneQuery->setRay(updateRay);
+	RaySceneQueryResult& qryResult = raySceneQuery->execute();
+	RaySceneQueryResult::iterator i = qryResult.begin();
+	 
+	if (i != qryResult.end() && i->worldFragment)
+	{
+		SceneQuery::WorldFragment* wf = i->worldFragment;
+		mCamera->setPosition(mCamera->getPosition().x, 
+			i->worldFragment->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.3, 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);
+}
+//-----------------------------------------------------------------------
+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/TestCullingDotScene/TestCullingDotSceneApplication.h
===================================================================
--- /trunk/VUT/OcclusionCullingSceneManager/TestCullingDotScene/TestCullingDotSceneApplication.h	(revision 36)
+++ /trunk/VUT/OcclusionCullingSceneManager/TestCullingDotScene/TestCullingDotSceneApplication.h	(revision 36)
@@ -0,0 +1,108 @@
+/**
+    \file 
+        TestCullingApplication.h
+*/
+#include "CEGUIForwardRefs.h"
+#include "ExampleApplication.h"
+//#include "OgreOcclusionCullingSceneManager.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;
+};
+
+
+class TestCullingApplication : public ExampleApplication
+{
+public:
+	~TestCullingApplication();
+
+protected:
+	void createScene(void);
+	void createFrameListener(void);
+	void setupGui(void);
+	void parseDotScene( const String &SceneName, const String& groupName );
+	void Light* LoadLight( TiXmlElement *XMLLight );
+
+	virtual void createCamera(void);
+
+	CEGUI::OgreCEGUIRenderer *mGUIRenderer;
+	CEGUI::System *mGUISystem;
+
+private:
+	void chooseSceneManager(void);
+
+	//Entity* mShip;
+	//SceneNode* mShipNode;
+};
+
Index: /trunk/VUT/OcclusionCullingSceneManager/include/OgreOcclusionCullingTerrainSceneTraverser.h
===================================================================
--- /trunk/VUT/OcclusionCullingSceneManager/include/OgreOcclusionCullingTerrainSceneTraverser.h	(revision 35)
+++ /trunk/VUT/OcclusionCullingSceneManager/include/OgreOcclusionCullingTerrainSceneTraverser.h	(revision 36)
@@ -1,158 +1,16 @@
-#ifndef _OcclusionCullingSceneTraverser_H__
-#define _OcclusionCullingSceneTraverser_H__
+#ifndef _OcclusionCullingTerrainSceneTraverser_H__
+#define _OcclusionCullingTerrainSceneTraverser_H__
 
-#include "OgreSceneNode.h"
-#include "OgreSceneManager.h"
-#include "OgrePrerequisites.h"
-#include "OgreSolidHalfBoundingBox.h"
-#include "OgreCamera.h"
-#include "OgreRenderSystem.h"
-#include <queue>
+#include "OgreOcclusionCullingSceneTraverser.h"
 
 using namespace std;
 
 namespace Ogre {
-	/**
-		This class implements the compare operator for the priority queue.
-		a lower distance has a higher value in the queue
-	*/
-	template <typename T> class myless
+
+	class OcclusionCullingTerrainSceneTraverser: OcclusionCullingSceneTraverser
 	{
-	public:
-		myless(Camera *cam) { mCamera = cam; }
-		//bool operator() (HierarchyNode *v1, HierarchyNode *v2) const
-		bool operator() (T v1, T v2) const
-		{
-			return v1->getSquaredViewDepth(mCamera) > v2->getSquaredViewDepth(mCamera);
-		}
-	private:
-		Camera *mCamera;
-	};
-
-	typedef pair<SceneNode *, HardwareOcclusionQuery *> query_pair;
-	typedef priority_queue<SceneNode *, vector<SceneNode *>, myless<vector<SceneNode *>::value_type> > PriorityQueue;
-	typedef queue<query_pair> QueryQueue;
-	/**
-		Class which implements a scene mangager which uses occlusion queries for culling occluded objects
-	*/
-	class OcclusionCullingSceneTraverser
-	{
-	public:
-		/** Construction taking the current scene manager and the current rendersystem as argument
-		@param sm current scene manager
-		@param rsys current render system 
-		*/
-		OcclusionCullingSceneTraverser(SceneManager *sm, RenderSystem *rsys);
-		~OcclusionCullingSceneTraverser();
-	
-		enum {RENDER_CULL_FRUSTUM, RENDER_STOP_AND_WAIT, RENDER_COHERENT, NUM_RENDERMODES};
-		
-		/** Renders the scene with the specified algorithm
-			@comment 
-			The algorithm type can be set with the parameter "Algorithm" and setOption.
-
-			The algorithm is one of:
-			RENDER_CULL_FRUSTUM: renders the scene with view frustum culling only
-			RENDER_STOP_AND_WAIT: renders the scene with the hierarchical stop and wait algorithm
-			RENDER_COHERENT: renders the scene with the coherent hierarchical algorithm
-			
-			@param cam current camera
-			@param root root of hierarchy 
-		*/
-		void renderScene( Camera *cam, SceneNode *root );
-	
-		
-		/** Sets the given option for the scene traverser.
-			       @remarks
-			Options are:
-			"Algorithm", int *;			
-		*/
-		bool setOption( const String &, const void * );
-		/** Gets the given option for the scene traverser.
-	        @remarks
-		    See setOption
-		*/
-		bool getOption( const String &, void * );
-		bool getOptionKeys( StringVector &refKeys );
-		
-		/** Sets pointer to the current scene manager.
-		@param the scene manager */
-		void setSceneManager( SceneManager *sm );
-		
-		/** Sets pointer to the current render system 
-		@param the rendersystem */
-		void setRenderSystem( RenderSystem *rsys );
-		
-		/** Doing some necessary preprocessing.
-		@comment e.g., initialises occlusion queries */
-		void preprocess( void );
-
-		/** Sets the current number of scene nodes in the scene.
-		@param num number of scene nodes
-		*/
-		void setNumSceneNodes(int num );
-
-	protected:
-		/** query mode (= without color) or RENDER_MODE */
-		enum {MODE_QUERY, MODE_RENDER};
-		/** returns true if node is leaf of the hierarchy */
-		bool isLeaf( SceneNode *node );
-		//HACK
-		//unsigned int countSceneNodes(SceneNode *node);
 		void traverseNode( Camera *cam, SceneNode *node );
-		/** Renders current scene node 
-		@param cam current camera
-		@param node current scene node to be rendered
-		*/
-		void renderSceneNode( Camera *cam, SceneNode *node);
-		/** Sets rendering mode, e.g. query mode or render mode*/
-		void setRenderingMode( int mode );
-		/** Renders the scene with view frustum culling only. */
-		void renderCullFrustum( Camera *cam );
-		/** Renders the scene with the hierarchical stop and wait algorithm. */
-		void renderStopAndWait( Camera *cam );
-		/** Renders the scene with the coherent hierarchical algorithm and the query queye. */
-		void renderCoherentWithQueue( Camera *cam );
-		/** Issue a occlusion query for this node. */
-		HardwareOcclusionQuery *issueOcclusionQuery( SceneNode *node, bool wasVisible );
-		/** Pulls up the visibility from the child nodes. */
-		void pullUpVisibility( SceneNode *node );
-		/** delete all previously defined occlusion queries */
-		void deleteQueries();
-		/** Renders bounding box of specified node.
-		@param the scene node contained in the bounding box to be rendered
-		*/
-		void renderBoundingBox( SceneNode *node );
-		/** Returns one half of the bounding box.
-		@param the half of the bouding box
-		*/
-		SolidHalfBoundingBox *getSolidHalfBoundingBox( int half );
-
-		// we use a priority queue rather than a renderstack
-		PriorityQueue *mDistanceQueue; 
-		
-		std::vector<HardwareOcclusionQuery *> mOcclusionQueries;
-		// two halfes of a aabb
-		SolidHalfBoundingBox *mHalfBoundingBox[2];	
-
-		int mCurrentAlgorithm;
-
-		unsigned int mFrameId;
-		unsigned int mVisibilityThreshold;
-		
-		SceneManager *mSceneManager;
-		RenderSystem *mRenderSystem;
-
-		int mCurrentTestIdx;
-		int mQueryMode;
-
-		//--- statistics
-		unsigned int mNumSceneNodes;
-		unsigned int mNumTraversedNodes;
-		unsigned int mNumQueryCulledNodes;
-		unsigned int mNumFrustumCulledNodes;
-		unsigned int mNumRenderedGeometry;
 	};
 
 }
-#endif // OCCLUSIONCULLINGSCENEMANAGER_H
+#endif // OcclusionCullingTerrainSceneTraverser_H
Index: /trunk/VUT/OcclusionCullingSceneManager/include/OgreOcclusionCullingSceneTraverser.h
===================================================================
--- /trunk/VUT/OcclusionCullingSceneManager/include/OgreOcclusionCullingSceneTraverser.h	(revision 33)
+++ /trunk/VUT/OcclusionCullingSceneManager/include/OgreOcclusionCullingSceneTraverser.h	(revision 36)
@@ -100,5 +100,5 @@
 		//HACK
 		//unsigned int countSceneNodes(SceneNode *node);
-		void traverseNode( Camera *cam, SceneNode *node );
+		virtual void traverseNode( Camera *cam, SceneNode *node );
 		/** Renders current scene node 
 		@param cam current camera
Index: /trunk/VUT/OcclusionCullingSceneManager/scripts/Plugin_OcclusionCullingSceneManager.vcproj
===================================================================
--- /trunk/VUT/OcclusionCullingSceneManager/scripts/Plugin_OcclusionCullingSceneManager.vcproj	(revision 33)
+++ /trunk/VUT/OcclusionCullingSceneManager/scripts/Plugin_OcclusionCullingSceneManager.vcproj	(revision 36)
@@ -163,4 +163,7 @@
 			</File>
 			<File
+				RelativePath="..\src\OgreOcclusionCullingTerrainSceneTraverser.cpp">
+			</File>
+			<File
 				RelativePath="..\src\OgreSolidHalfBoundingBox.cpp">
 			</File>
@@ -183,4 +186,7 @@
 			<File
 				RelativePath="..\include\OgreOcclusionCullingTerrainSceneManager.h">
+			</File>
+			<File
+				RelativePath="..\include\OgreOcclusionCullingTerrainSceneTraverser.h">
 			</File>
 			<File
Index: /trunk/VUT/OcclusionCullingSceneManager/scripts/Plugin_OcclusionCullingSceneManager.sln
===================================================================
--- /trunk/VUT/OcclusionCullingSceneManager/scripts/Plugin_OcclusionCullingSceneManager.sln	(revision 16)
+++ /trunk/VUT/OcclusionCullingSceneManager/scripts/Plugin_OcclusionCullingSceneManager.sln	(revision 36)
@@ -6,5 +6,8 @@
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TestCulling", "..\TestCulling\TestCulling.vcproj", "{248F19A6-2FE0-4F5D-8928-E0EA10609887}"
 	ProjectSection(ProjectDependencies) = postProject
-		{80DECC17-BDDD-4412-8CF8-F7C1C17A7436} = {80DECC17-BDDD-4412-8CF8-F7C1C17A7436}
+	EndProjectSection
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TestCullingDotScene", "..\TestCullingDotScene\TestCullingDotScene.vcproj", "{BE13944C-D05E-467F-B0AC-8A65A3B5FE60}"
+	ProjectSection(ProjectDependencies) = postProject
 	EndProjectSection
 EndProject
@@ -23,4 +26,8 @@
 		{248F19A6-2FE0-4F5D-8928-E0EA10609887}.Release.ActiveCfg = Release|Win32
 		{248F19A6-2FE0-4F5D-8928-E0EA10609887}.Release.Build.0 = Release|Win32
+		{BE13944C-D05E-467F-B0AC-8A65A3B5FE60}.Debug.ActiveCfg = Debug|Win32
+		{BE13944C-D05E-467F-B0AC-8A65A3B5FE60}.Debug.Build.0 = Debug|Win32
+		{BE13944C-D05E-467F-B0AC-8A65A3B5FE60}.Release.ActiveCfg = Release|Win32
+		{BE13944C-D05E-467F-B0AC-8A65A3B5FE60}.Release.Build.0 = Release|Win32
 	EndGlobalSection
 	GlobalSection(ExtensibilityGlobals) = postSolution
Index: /trunk/VUT/OcclusionCullingSceneManager/src/OgreOcclusionCullingTerrainSceneTraverser.cpp
===================================================================
--- /trunk/VUT/OcclusionCullingSceneManager/src/OgreOcclusionCullingTerrainSceneTraverser.cpp	(revision 35)
+++ /trunk/VUT/OcclusionCullingSceneManager/src/OgreOcclusionCullingTerrainSceneTraverser.cpp	(revision 36)
@@ -1,236 +1,8 @@
-#include "OgreOcclusionCullingSceneTraverser.h"
-#include "OgreMath.h"
-#include "OgreIteratorWrappers.h"
-#include "OgreCamera.h"
-#include "OgreHardwareOcclusionQuery.h"
-//#include "OgreWireBoundingBox.h"
-#include "OgreSolidHalfBoundingBox.h"
-
-
-#include <windows.h>
+#include "OgreOcclusionCullingTerrainSceneTraverser.h"
+//#include <windows.h>
 
 namespace Ogre {
-	
 	//-----------------------------------------------------------------------
-	OcclusionCullingSceneTraverser::OcclusionCullingSceneTraverser(SceneManager *sm, RenderSystem *rsys): 
-	mFrameId(1), mDistanceQueue(NULL), mVisibilityThreshold(0), mCurrentTestIdx(0),
-	mQueryMode(MODE_RENDER), mNumSceneNodes(0), mCurrentAlgorithm(RENDER_COHERENT),
-	mNumTraversedNodes(0), mNumQueryCulledNodes(0), mNumFrustumCulledNodes(0), 
-	mNumRenderedGeometry(0), mSceneManager(sm), mRenderSystem(rsys)
-	{		
-		mHalfBoundingBox[0] = mHalfBoundingBox[1] = 0;
-	}
-	//-----------------------------------------------------------------------
-	OcclusionCullingSceneTraverser::~OcclusionCullingSceneTraverser()
-	{		
-		if(mHalfBoundingBox[0]) delete mHalfBoundingBox[0];
-		if(mHalfBoundingBox[1]) delete mHalfBoundingBox[1];
-
-		deleteQueries();
-		//SceneManager::~SceneManager();
-	}
-	//-----------------------------------------------------------------------
-	void OcclusionCullingSceneTraverser::renderScene( Camera *cam, SceneNode *root )
-	{
-		mNumTraversedNodes = 0;
-		mNumQueryCulledNodes = 0;
-		mNumFrustumCulledNodes = 0;
-		mNumRenderedGeometry = 0;
-		
-		mDistanceQueue = new PriorityQueue(myless<SceneNode *>(cam));
-		mDistanceQueue->push(root);
-		mCurrentTestIdx = 0;
-
-		mCurrentAlgorithm = RENDER_CULL_FRUSTUM;
-		switch(mCurrentAlgorithm)
-		{
-			case RENDER_CULL_FRUSTUM:
-				renderCullFrustum(cam);
-		        break;
-			case RENDER_STOP_AND_WAIT:
-				renderStopAndWait(cam);
-				break;
-			case RENDER_COHERENT:
-				renderCoherentWithQueue(cam);
-				break;
-			default:
-				renderCullFrustum(cam);
-				break;
-		}	
-		
-		delete mDistanceQueue;
-
-		mFrameId ++;
-	}
-	//-----------------------------------------------------------------------
-	void OcclusionCullingSceneTraverser::renderCoherentWithQueue(Camera *cam)
-	{
-		QueryQueue queryQueue;
-
-		//-- PART 1: process finished occlusion queries
-		while(!mDistanceQueue->empty() || !queryQueue.empty())
-		{
-			while(!queryQueue.empty() && 
-				  ((queryQueue.front().second)->resultAvailable() || mDistanceQueue->empty()))
-			{
-				SceneNode *node = queryQueue.front().first;
-				HardwareOcclusionQuery *query = queryQueue.front().second;
-
-				queryQueue.pop();
-			
-				// wait until result available
-				unsigned int visiblePixels;
-				query->pullOcclusionQuery(&visiblePixels);
-
-				if(visiblePixels > mVisibilityThreshold)
-				{
-					pullUpVisibility(node);
-					traverseNode(cam, node);
-				}
-				else
-				{
-					mNumQueryCulledNodes ++;
-				}
-			}	
-
-			//-- PART 2: hierarchical traversal
-			if(!mDistanceQueue->empty())
-			{
-				SceneNode *node = mDistanceQueue->top();
-				mDistanceQueue->pop();
-	
-				if(cam->isVisible(node->_getWorldAABB()))
-				{
-					// identify previously visible nodes
-					bool wasVisible = node->isNodeVisible() && (node->lastVisited() == mFrameId - 1);
-					
-					// identify nodes that we cannot skip queries for
-					bool leafOrWasInvisible = !wasVisible || isLeaf(node);
-
-					// reset node's visibility classification 
-					node->setNodeVisible(false);
-
-					// update node's visited flag
-					node->setLastVisited(mFrameId);
-				
-					// skip testing previously visible interior nodes
-					if(leafOrWasInvisible)
-					{
-						HardwareOcclusionQuery *query = issueOcclusionQuery(node, wasVisible);
-						queryQueue.push(query_pair(node, query));
-					}
-					
-					// always traverse a node if it was visible
-					if(wasVisible)
-					{
-						traverseNode(cam, node);
-					}
-				}
-				else
-				{
-					mNumFrustumCulledNodes ++;
-				}
-			}
-		}
-	}
-	//-----------------------------------------------------------------------
-	void OcclusionCullingSceneTraverser::renderCullFrustum(Camera *cam)
-	{
-		while(!mDistanceQueue->empty())
-		{
-			SceneNode *node = mDistanceQueue->top();
-			mDistanceQueue->pop();
-	
-			// interesting for visualization purpose
-			node->setNodeVisible(false);
-				
-			if(!cam->isVisible(node->_getWorldAABB()))
-			{
-				// update node's visited flag 
-				node->setLastVisited(mFrameId);
-				node->setNodeVisible(true);
-				traverseNode(cam, node);
-			}
-			//else
-				if(cam->isVisible(node->_getWorldAABB()))
-				{
-					mNumQueryCulledNodes ++;
-				}else
-			{			
-				mNumFrustumCulledNodes ++;
-			}
-		}
-	}	
-	//-----------------------------------------------------------------------
-	void OcclusionCullingSceneTraverser::renderStopAndWait(Camera *cam)
-	{
-		while(!mDistanceQueue->empty())
-		{
-			SceneNode *node = mDistanceQueue->top();
-			mDistanceQueue->pop();
-		
-			// interesting for the visualization
-			node->setNodeVisible(false);
-			node->setLastVisited(mFrameId);
-
-			if(cam->isVisible(node->_getWorldAABB()))
-			{
-				HardwareOcclusionQuery *query = issueOcclusionQuery(node, false);
-				
-				unsigned int visiblePixels;
-				// wait if result not available
-				query->pullOcclusionQuery(&visiblePixels);
-				
-				// node visible
-				if(visiblePixels > mVisibilityThreshold)
-				{
-					traverseNode(cam, node);
-				}
-				else
-				{
-					mNumQueryCulledNodes ++;
-				}
-			}
-			else
-			{
-				mNumFrustumCulledNodes ++;
-			}
-		}
-	}
-	//-----------------------------------------------------------------------
-	HardwareOcclusionQuery *OcclusionCullingSceneTraverser::issueOcclusionQuery( SceneNode *node, bool wasVisible )
-	{
-		// change state so the bounding box gets not actually rendered on the screen
-		setRenderingMode(MODE_QUERY);
-
-		// get next available test id
-		HardwareOcclusionQuery *query = mOcclusionQueries[mCurrentTestIdx++];
-		
-		query->beginOcclusionQuery();
-				
-		renderBoundingBox(node);
-
-		query->endOcclusionQuery();
-
-		return query;
-	}
-	//-----------------------------------------------------------------------
-	void OcclusionCullingSceneTraverser::setRenderingMode( int mode )
-	{	
-		// avoid unnecessary state changes
-		if(mode != mQueryMode)
-		{
-			bool enabled = (mode == MODE_RENDER);
-			
-			mRenderSystem->_setColourBufferWriteEnabled(enabled, 
-				enabled, enabled, enabled);
-			mRenderSystem->_setDepthBufferWriteEnabled(enabled);
-			mRenderSystem->setLightingEnabled(enabled);
-
-			mQueryMode = mode;
-		}
-	}
-	//-----------------------------------------------------------------------
-	void OcclusionCullingSceneTraverser::traverseNode( Camera *cam, SceneNode *node )
+	void OcclusionCullingTerrainSceneTraverser::traverseNode( Camera *cam, SceneNode *node )
 	{
 		mNumTraversedNodes ++;
@@ -251,5 +23,5 @@
 	}
 	//-----------------------------------------------------------------------
-	void OcclusionCullingSceneTraverser::renderSceneNode( Camera *cam, SceneNode *node )
+	void OcclusionCullingTerrainSceneTraverser::renderSceneNode( Camera *cam, SceneNode *node )
 	{
 		setRenderingMode(MODE_RENDER);
@@ -258,25 +30,4 @@
 		mSceneManager->_renderSceneNode(cam, node);
 		//MessageBox( NULL, "myplugin registered", "this is my plugin", MB_OK | MB_ICONERROR | MB_TASKMODAL);
-	}
-	//-----------------------------------------------------------------------
-	void OcclusionCullingSceneTraverser::preprocess( void )
-	{
-		//-- initialise occlusion queries.
-		deleteQueries();
-		
-		for(unsigned int i=0; i < mNumSceneNodes; i++)
-		{
-			mOcclusionQueries.push_back(mRenderSystem->createHardwareOcclusionQuery());
-		}	
-	}
-	//-----------------------------------------------------------------------
-	void OcclusionCullingSceneTraverser::setSceneManager( SceneManager *sm )
-	{
-		mSceneManager = sm;
-	}
-	//-----------------------------------------------------------------------
-	void OcclusionCullingSceneTraverser::setRenderSystem( RenderSystem *rsys )
-	{
-		mRenderSystem = rsys;
 	}
 	//-----------------------------------------------------------------------
@@ -296,10 +47,10 @@
 	}*/
 	//-----------------------------------------------------------------------
-	bool OcclusionCullingSceneTraverser::isLeaf( SceneNode *node )
+	bool OcclusionCullingTerrainSceneTraverser::isLeaf( SceneNode *node )
 	{
 		return (node->numChildren() == 0);
 	}
 	//-----------------------------------------------------------------------
-	void OcclusionCullingSceneTraverser::pullUpVisibility( SceneNode *node )
+	void OcclusionCullingTerrainSceneTraverser::pullUpVisibility( SceneNode *node )
 	{
 		while(node && !node->isNodeVisible())
@@ -310,13 +61,5 @@
 	}
 	//-----------------------------------------------------------------------
-	void OcclusionCullingSceneTraverser::deleteQueries( void )
-	{
-		for(unsigned int i=0; i < mNumSceneNodes; i++)
-			delete mOcclusionQueries[i];
-
-		mOcclusionQueries.clear();
-	}
-	//-----------------------------------------------------------------------
-	void OcclusionCullingSceneTraverser::renderBoundingBox( SceneNode *node )
+	void OcclusionCullingTerrainSceneTraverser::renderBoundingBox( SceneNode *node )
 	{
 		// Render two halfes of the bounding box (using triangle fans)
@@ -337,80 +80,3 @@
 		}
 	}
-	//-----------------------------------------------------------------------
-	SolidHalfBoundingBox *OcclusionCullingSceneTraverser::getSolidHalfBoundingBox( int half )
-	{
-		if(!mHalfBoundingBox[half])
-			mHalfBoundingBox[half] = new SolidHalfBoundingBox(half == 1);
-
-		return mHalfBoundingBox[half];	
-	}
-	//-----------------------------------------------------------------------
-	bool OcclusionCullingSceneTraverser::setOption( const String & key, const void * val )
-	{
-		if ( key == "Algorithm" )
-		{
-			mCurrentAlgorithm = * static_cast < const int * > ( val );
-			return true;
-		}
-		if ( key == "Threshold" )
-		{
-			mVisibilityThreshold = * static_cast < const int * > ( val );
-			return true;
-		}
-
-		return false;
-	}
-	//-----------------------------------------------------------------------
-	bool OcclusionCullingSceneTraverser::getOption( const String & key, void *val )
-	{
-		if ( key == "Algorithm" )
-		{
-			* static_cast < int * > ( val ) = mCurrentAlgorithm;
-			return true;
-		}
-		if ( key == "Threshold" )
-		{
-			* static_cast < unsigned int * > ( val ) = mVisibilityThreshold;
-			return true;
-		}
-		if ( key == "NumSceneNodes" )
-		{
-			* static_cast < unsigned int * > ( val ) = mNumSceneNodes;
-			return true;
-		}
-		if ( key == "NumTraversedNodes" )
-		{
-			* static_cast < unsigned int * > ( val ) = mNumTraversedNodes;
-			return true;
-		}
-		if ( key == "NumQueryCulledNodes" )
-		{
-			* static_cast < unsigned int * > ( val ) = mNumQueryCulledNodes;
-			return true;
-		}
-		if ( key == "NumFrustumCulledNodes" )
-		{
-			* static_cast < unsigned int * > ( val ) = mNumFrustumCulledNodes;
-			return true;
-		}
-		return false;
-	}
-	//-----------------------------------------------------------------------
-	bool OcclusionCullingSceneTraverser::getOptionKeys( StringVector & refKeys )
-	{
-		refKeys.push_back( "Algorithm" );
-		refKeys.push_back( "Threshold" );
-		refKeys.push_back( "NumSceneNodes" );
-		refKeys.push_back( "NumTraversedNodes" );
-		refKeys.push_back( "NumQueryCulledNodes" );
-		refKeys.push_back( "NumFrustumCulledNodes" );
-		//refKeys.push_back( "mNumRenderedGeometry" );
-
-		return true;
-	}
-	//-----------------------------------------------------------------------
-	void OcclusionCullingSceneTraverser::setNumSceneNodes(int num)
-	{
-		mNumSceneNodes = num;
-	}
 }	
