Index: /GTP/trunk/App/Demos/Vis/KdTreeDemo/OGRE/include/TestKdTreeAppListener.h
===================================================================
--- /GTP/trunk/App/Demos/Vis/KdTreeDemo/OGRE/include/TestKdTreeAppListener.h	(revision 1163)
+++ /GTP/trunk/App/Demos/Vis/KdTreeDemo/OGRE/include/TestKdTreeAppListener.h	(revision 1165)
@@ -666,4 +666,22 @@
         mCamera->moveRelative(mTranslateVector);
 		mTopCam->moveRelative(mCullTransVec);
+
+		Vector3 pos = mCamera->getPosition();
+		RaySceneQuery * rsquery = mSceneMgr->createRayQuery(Ray(pos, Vector3::NEGATIVE_UNIT_Y));
+		RaySceneQueryResult& rsresult = rsquery->execute();
+
+		RaySceneQueryResult::iterator it = rsresult.begin();
+		RaySceneQueryResult::iterator end = rsresult.end();
+
+		while (it != end && it->movable)
+		{
+			if (it->movable->getName() != "PlayerCam")
+			{
+				mCamera->setPosition(pos.x, it->movable->getWorldBoundingBox().getCenter().y + 3, pos.z);
+				break;
+			}
+			it++;
+		}
+		OGRE_DELETE(rsquery);
 	}
 
Index: /GTP/trunk/App/Demos/Vis/KdTreeDemo/OGRE/src/TestKdTree.cpp
===================================================================
--- /GTP/trunk/App/Demos/Vis/KdTreeDemo/OGRE/src/TestKdTree.cpp	(revision 1163)
+++ /GTP/trunk/App/Demos/Vis/KdTreeDemo/OGRE/src/TestKdTree.cpp	(revision 1165)
@@ -117,7 +117,11 @@
 		//mCamera->setPosition(Vector3(830, 300, -540));
 		//mCamera->setOrientation(Quaternion(-0.3486, 0.0122, 0.9365, 0.0329));
-		mCamera->setPosition(Vector3(688, 866, 944));
-		mCamera->setOrientation(Quaternion(-0.979419, 0.201128, 0.0165594, 0.00340038));
+		// total view
+		//mCamera->setPosition(Vector3(688, 866, 944));
+		//mCamera->setOrientation(Quaternion(-0.979419, 0.201128, 0.0165594, 0.00340038));
 		mTopCam->setPosition(Vector3(1232, 3990, -1477));
+		// walkthrough view
+		mCamera->setPosition(Vector3(1102.56, 181.845, -350.305));
+		mCamera->setOrientation(Quaternion(-0.977321, -0.117497, -0.174903, 0.0210273));
 	}
 	else
Index: /GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/OgreKdTree.h
===================================================================
--- /GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/OgreKdTree.h	(revision 1163)
+++ /GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/OgreKdTree.h	(revision 1165)
@@ -19,4 +19,6 @@
 
 #include <stack>
+
+#include "OgreKdTreeHierarchyInterface.h"
 
 namespace Ogre
@@ -339,4 +341,6 @@
 
 	public:
+		friend class Ogre::KdTreeHierarchyInterface;
+
 		typedef KdTree::Leaf * LeafPtr;
 		typedef std::set<LeafPtr> LeafSet;
Index: /GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/OgreKdTreeSceneManager.h
===================================================================
--- /GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/OgreKdTreeSceneManager.h	(revision 1163)
+++ /GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/OgreKdTreeSceneManager.h	(revision 1165)
@@ -11,6 +11,10 @@
 #define _KdTreeSceneManager_H__
 
+#include <OgreKdTreeHierarchyInterface.h>
 #include <OgreSceneManager.h>
 #include "OgreKdTree.h"
+#include "VisibilityManager.h"
+
+#define KDTREE_MAX_DEPTH 20
 
 namespace Ogre
@@ -23,5 +27,5 @@
 	{
 	public:
-		KdTreeSceneManager(const String& name);
+		KdTreeSceneManager(const String& name, GtpVisibility::VisibilityManager *vm);
 		//KdTreeSceneManager(const String& name, int maxdepth);
 		~KdTreeSceneManager(void);
@@ -54,5 +58,9 @@
 			SceneManager::clearScene();
 		}
+
 	protected:
+		GtpVisibility::VisibilityManager *mVisibilityManager;
+
+		KdTreeHierarchyInterface *mHierarchyInterface;
 
 		int mMaxDepth;
@@ -76,6 +84,10 @@
 	protected:
 		void initMetaData(void) const;
+		GtpVisibility::VisibilityManager *visManager;
 	public:
-		KdTreeSceneManagerFactory(void) {};
+		KdTreeSceneManagerFactory(GtpVisibility::VisibilityManager * vm)
+		{
+			visManager = vm;
+		};
 		~KdTreeSceneManagerFactory(void) {};
 		/// Factory type name
Index: /GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/OgreKdTreeHierarchyInterface.h
===================================================================
--- /GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/OgreKdTreeHierarchyInterface.h	(revision 1165)
+++ /GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/OgreKdTreeHierarchyInterface.h	(revision 1165)
@@ -0,0 +1,31 @@
+/*
+-----------------------------------------------------------------------------
+This source file is part of the GameTools Project
+http://www.gametools.org
+
+Author: Martin Szydlowski
+-----------------------------------------------------------------------------
+*/
+
+#ifndef _OgreKdTreeHierarchyInterface_H_
+#define _OgreKdTreeHierarchyInterface_H_
+
+#include "OgreSceneNodeHierarchyInterface.h"
+
+namespace Ogre
+{
+
+class KdTreeSceneManager;
+
+class KdTreeHierarchyInterface : public SceneNodeHierarchyInterface
+{
+public:
+	KdTreeHierarchyInterface(KdTreeSceneManager *sm, RenderSystem *rsys);
+	virtual ~KdTreeHierarchyInterface() {};
+
+	bool IsLeaf(GtpVisibility::HierarchyNode *node) const;
+};
+
+} // namespace Ogre
+
+#endif // _OgreKdTreeHierarchyInterface_H_
Index: /GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/scripts/Plugin_VisibilitySceneManager.vcproj
===================================================================
--- /GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/scripts/Plugin_VisibilitySceneManager.vcproj	(revision 1163)
+++ /GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/scripts/Plugin_VisibilitySceneManager.vcproj	(revision 1165)
@@ -273,4 +273,7 @@
 				</File>
 				<File
+					RelativePath="..\include\OgreKdTreeHierarchyInterface.h">
+				</File>
+				<File
 					RelativePath="..\include\OgreKdTreeSceneManager.h">
 				</File>
@@ -284,4 +287,7 @@
 				<File
 					RelativePath="..\src\OgreKdTree.cpp">
+				</File>
+				<File
+					RelativePath="..\src\OgreKdTreeHierarchyInterface.cpp">
 				</File>
 				<File
Index: /GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreKdTreeSceneManager.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreKdTreeSceneManager.cpp	(revision 1163)
+++ /GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreKdTreeSceneManager.cpp	(revision 1165)
@@ -18,23 +18,6 @@
 namespace Ogre
 {
-	KdTreeSceneManager::KdTreeSceneManager(const String& name):
-		SceneManager(name)
-	{
-		int maxdepth = 20;
-		mKdTree = 0;
-		init(maxdepth);
-	}
-
-	KdTreeSceneManager::~KdTreeSceneManager(void)
-	{
-		delete mKdTree;
-	}
-
-	const String& KdTreeSceneManager::getTypeName(void) const
-	{
-		return KdTreeSceneManagerFactory::FACTORY_TYPE_NAME;
-	}
-
-	void KdTreeSceneManager::init(int maxdepth)
+	KdTreeSceneManager::KdTreeSceneManager(const String& name, GtpVisibility::VisibilityManager *vm):
+		SceneManager(name), mKdTree(0), mVisibilityManager(vm)
 	{
 		// Replace root node with my node
@@ -44,5 +27,5 @@
 		mSceneRoot->_notifyRootNode();
 
-		mMaxDepth = maxdepth;
+		mMaxDepth = KDTREE_MAX_DEPTH;
 		mShowBoxes = false;
 
@@ -50,10 +33,22 @@
 		OGRE_DELETE(mKdTree);
 
-		mBuildMethod = KdTree::KDBM_RECURSIVE;
-		//mBuildMethod = KdTree::KDBM_PRIORITYQUEUE;
+		//mBuildMethod = KdTree::KDBM_RECURSIVE;
+		mBuildMethod = KdTree::KDBM_PRIORITYQUEUE;
 #ifdef KDTREE_DEBUG
 		mHighlighLevel = 0;
 		mShowAllBoxes = false;
 #endif
+
+		mHierarchyInterface = new KdTreeHierarchyInterface(this, mDestRenderSystem);
+	}
+
+	KdTreeSceneManager::~KdTreeSceneManager(void)
+	{
+		delete mKdTree;
+	}
+
+	const String& KdTreeSceneManager::getTypeName(void) const
+	{
+		return KdTreeSceneManagerFactory::FACTORY_TYPE_NAME;
 	}
 
@@ -310,5 +305,5 @@
 		mMetaData.typeName = FACTORY_TYPE_NAME;
 		mMetaData.description = "Scene manager that organises the scene based on a kd-tree";
-		mMetaData.sceneTypeMask = ST_GENERIC; // support generic scenes (so far)
+		mMetaData.sceneTypeMask = 0xFFFF; // support all types of scenes (hopefully)
 		mMetaData.worldGeometrySupported = false;
 	}
@@ -317,5 +312,5 @@
 		const String& instanceName)
 	{
-		return new KdTreeSceneManager(instanceName);
+		return new KdTreeSceneManager(instanceName, visManager);
 	}
 	//-----------------------------------------------------------------------
Index: /GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreVisibilitySceneManagerDll.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreVisibilitySceneManagerDll.cpp	(revision 1163)
+++ /GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreVisibilitySceneManagerDll.cpp	(revision 1165)
@@ -54,5 +54,5 @@
 	//visibilityTerrainPlugin = new VisibilityTerrainSceneManagerFactory(visManager);
 	occlusionCullingPlugin = new OcclusionCullingSceneManagerFactory(visManager);
-	kdTreeFactory = new KdTreeSceneManagerFactory();
+	kdTreeFactory = new KdTreeSceneManagerFactory(visManager);
 	// Construct listener manager singleton
 	new TerrainPageSourceListenerManager();
Index: /GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreKdTreeHierarchyInterface.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreKdTreeHierarchyInterface.cpp	(revision 1165)
+++ /GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreKdTreeHierarchyInterface.cpp	(revision 1165)
@@ -0,0 +1,29 @@
+/*
+-----------------------------------------------------------------------------
+This source file is part of the GameTools Project
+http://www.gametools.org
+
+Author: Martin Szydlowski
+-----------------------------------------------------------------------------
+*/
+
+#include "OgreKdTreeSceneManager.h"
+#include "OgreKdTreeHierarchyInterface.h"
+
+namespace Ogre
+{
+
+KdTreeHierarchyInterface::KdTreeHierarchyInterface(KdTreeSceneManager *sm, RenderSystem *rsys):
+	SceneNodeHierarchyInterface(sm, rsys)
+{
+
+}
+
+bool KdTreeHierarchyInterface::IsLeaf(GtpVisibility::HierarchyNode *node) const
+{
+	KdTree::Node * kdnode = static_cast<KdTree::Node *>(node);
+	return kdnode->isLeaf();
+}
+
+
+}
Index: /GTP/trunk/Lib/Vis/shared/scripts/GtpVisibility.sln
===================================================================
--- /GTP/trunk/Lib/Vis/shared/scripts/GtpVisibility.sln	(revision 1163)
+++ /GTP/trunk/Lib/Vis/shared/scripts/GtpVisibility.sln	(revision 1165)
@@ -40,4 +40,6 @@
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TestKdTree", "..\..\..\..\App\Demos\Vis\KdTreeDemo\OGRE\scripts\TestKdTree.vcproj", "{17F2C6F9-6101-430E-ABF4-71383868EF24}"
 	ProjectSection(ProjectDependencies) = postProject
+		{80DECC17-BDDD-4412-8CF8-F7C1C17A7436} = {80DECC17-BDDD-4412-8CF8-F7C1C17A7436}
+		{7319E499-473D-4CE5-9983-725D6E68A55D} = {7319E499-473D-4CE5-9983-725D6E68A55D}
 	EndProjectSection
 EndProject
