Index: trunk/VUT/Ogre/include/OgrePlatformHierarchyInterface.h
===================================================================
--- trunk/VUT/Ogre/include/OgrePlatformHierarchyInterface.h	(revision 92)
+++ trunk/VUT/Ogre/include/OgrePlatformHierarchyInterface.h	(revision 94)
@@ -34,16 +34,21 @@
 	GtpVisibility::OcclusionQuery *GetNextOcclusionQuery();
 		
-	/** Sets the current camera.
+	/** Sets the current camera used for the rendering.
 		@param cam the current camera
 	*/
 	void SetCamera(Camera *cam);
-		
+	/** Sets the current camera used for culling.
+		@param cam the current camera
+		@remark the default is the camera used for rendering
+	*/
+	void SetCullCamera(Camera *cullCam);
 	/** Initialises this scene traverser for the current frame.
 	@param root root of the hierarchy
 		@param cam current camera
+		@param cullCam the camera used for culling. If null, the current camera is used
 		@remark convenience method wich calls VisibilitySceneTraverser::initFrame,
 		sets the current camera, and initialises the distance queue.
 	*/
-	void InitFrame(GtpVisibility::HierarchyNode *root, Ogre::Camera *cam);
+	void InitFrame(GtpVisibility::HierarchyNode *root, Camera *cam, Camera *cullCam = NULL);
 	/** Checks if the node is visible from the current view frustum.
 		@param node the current node
@@ -95,4 +100,6 @@
 
 	Camera *mCamera;
+	Camera *mCullCamera;
+
 	AxisAlignedBox mBox;
 	
Index: trunk/VUT/Ogre/src/OgreOctreeHierarchyInterface.cpp
===================================================================
--- trunk/VUT/Ogre/src/OgreOctreeHierarchyInterface.cpp	(revision 93)
+++ trunk/VUT/Ogre/src/OgreOctreeHierarchyInterface.cpp	(revision 94)
@@ -2,8 +2,10 @@
 #include "OgreVisibilityOctreeSceneManager.h"
 #include <OgreOctree.h>
+#include <OgreLogManager.h>
+
 #include <windows.h>
 
 namespace Ogre {
-//namespace GtpVisibility {
+
 //-----------------------------------------------------------------------
 OctreeHierarchyInterface::OctreeHierarchyInterface(SceneManager *sm, RenderSystem *rsys): 
@@ -25,5 +27,6 @@
 	
 	// if not all subtrees are empty
-	if (octree->numNodes() > (int)octree->mNodes.size())
+	//if (octree->numNodes() > (int)octree->mNodes.size())
+	if (!IsLeaf(node))
 	{
 		for(int i=0; i<8; ++i)
@@ -42,13 +45,7 @@
 bool OctreeHierarchyInterface::IsLeaf(GtpVisibility::HierarchyNode *node) const
 {
-	Octree *octant = static_cast<Octree *>(node);
-
-	for(int i=0; i<8; i++)
-	{
-		if (octant->mChildren[(i & 4) >> 2][(i & 2) >> 1][i & 1])
-			return false;
-	}
-
-	return true;
+	Octree *octree = static_cast<Octree *>(node);
+	// HACK: if there are subtrees, they are empty => we are not interested in them
+	return octree->numNodes() == (int)octree->mNodes.size();
 }
 //-----------------------------------------------------------------------
@@ -68,5 +65,5 @@
 	Vector3 mid = ((box->getMinimum() - box->getMaximum()) * 0.5) + box->getMinimum();
 
-	return (mCamera->getDerivedPosition() - mid).squaredLength();
+	return (mCullCamera->getDerivedPosition() - mid).squaredLength();
 }
 //-----------------------------------------------------------------------
Index: trunk/VUT/Ogre/src/OgreVisibilityOctreeSceneManager.cpp
===================================================================
--- trunk/VUT/Ogre/src/OgreVisibilityOctreeSceneManager.cpp	(revision 93)
+++ trunk/VUT/Ogre/src/OgreVisibilityOctreeSceneManager.cpp	(revision 94)
@@ -6,6 +6,4 @@
 #include <OgreCamera.h>
 #include <OgreLogManager.h>
-
-#include <windows.h>
 
 namespace Ogre {
@@ -18,6 +16,5 @@
 	mHierarchyInterface = 
 		new OctreeHierarchyInterface(this, mDestRenderSystem);
-	//visManager->SetCullingManager(GtpVisibility::VisibilityEnvironment::STOP_AND_WAIT_CULLING);
-	
+		
 	//mDisplayNodes = true;
 	//mShowBoundingBoxes = true;
@@ -34,5 +31,9 @@
 void VisibilityOctreeSceneManager::_renderVisibleObjects()
 {
-	mHierarchyInterface->InitFrame(mOctree, mCameraInProgress);
+	Camera *cullCam = NULL;
+
+	if(mCullCamera) cullCam = getCamera("CullCamera");
+	
+	mHierarchyInterface->InitFrame(mOctree, mCameraInProgress, cullCam);
 	mVisibilityManager->GetCullingManager()->InitFrame();
 
Index: trunk/VUT/Ogre/src/OgreSceneNodeHierarchyInterface.cpp
===================================================================
--- trunk/VUT/Ogre/src/OgreSceneNodeHierarchyInterface.cpp	(revision 87)
+++ trunk/VUT/Ogre/src/OgreSceneNodeHierarchyInterface.cpp	(revision 94)
@@ -3,6 +3,4 @@
 #include <OgreCamera.h>
 #include <OgreSceneNode.h>
-
-//#include <windows.h>
 
 namespace Ogre {
Index: trunk/VUT/Ogre/src/OgrePlatformHierarchyInterface.cpp
===================================================================
--- trunk/VUT/Ogre/src/OgrePlatformHierarchyInterface.cpp	(revision 93)
+++ trunk/VUT/Ogre/src/OgrePlatformHierarchyInterface.cpp	(revision 94)
@@ -1,4 +1,4 @@
 #include <OgreCamera.h>
-
+#include <OgreLogManager.h>
 //#include "OgreSolidHalfBoundingBox.h"
 #include "OgreSolidBoundingBox.h"
@@ -11,5 +11,6 @@
 //-----------------------------------------------------------------------
 PlatformHierarchyInterface::PlatformHierarchyInterface(SceneManager *sm, RenderSystem *rsys):
-mSceneManager(sm), mRenderSystem(rsys), mSolidBoundingBox(NULL)/*, mSolidHalfBoundingBox(NULL)*/
+mSceneManager(sm), mRenderSystem(rsys), mSolidBoundingBox(NULL),
+mCamera(NULL), mCullCamera(NULL)
 {
 }
@@ -64,4 +65,9 @@
 }
 //-----------------------------------------------------------------------
+void PlatformHierarchyInterface::SetCullCamera(Ogre::Camera *cullCam)
+{
+	mCullCamera = cullCam;
+}
+//-----------------------------------------------------------------------
 GtpVisibility::OcclusionQuery *PlatformHierarchyInterface::GetNextOcclusionQuery()
 {
@@ -74,5 +80,5 @@
 }
 //-----------------------------------------------------------------------
-void PlatformHierarchyInterface::InitFrame(GtpVisibility::HierarchyNode *root, Camera *cam)
+void PlatformHierarchyInterface::InitFrame(GtpVisibility::HierarchyNode *root, Camera *cam, Camera *cullCam)
 {
 	GtpVisibility::HierarchyInterface::InitFrame(root);
@@ -80,4 +86,9 @@
 
 	SetCamera(cam);
+
+	if(cullCam)
+		SetCullCamera(cullCam);
+	else
+		SetCullCamera(cam);
 }
 //-----------------------------------------------------------------------
@@ -96,5 +107,5 @@
 {
 #ifdef GTP_VISIBILITY_MODIFIED_OGRE
-	return mCamera->isVisible(*GetBoundingBox(node), intersects);
+	return mCullCamera->isVisible(*GetBoundingBox(node), intersects);
 #else
 	return true;
@@ -113,10 +124,13 @@
 	// if node is leaf and was visible => will be rendered anyway.
 	// In this case we can also test with the real geometry.
-	if(mUseOptimization && wasVisible && IsLeaf(node))
+	// if camera for culling is different from camera for rendering => cannot optimize
+	if (mUseOptimization && wasVisible && IsLeaf(node) && (mCamera == mCullCamera))
 	{
+		//LogManager::getSingleton().logMessage("render node\n");
 		RenderNode(node);
 	}
 	else
 	{
+		//LogManager::getSingleton().logMessage("render box\n");
 		RenderBoundingBox(GetBoundingBox(node));
 	}
Index: trunk/VUT/Ogre/src/OgreVisibilityTerrainSceneManager.cpp
===================================================================
--- trunk/VUT/Ogre/src/OgreVisibilityTerrainSceneManager.cpp	(revision 93)
+++ trunk/VUT/Ogre/src/OgreVisibilityTerrainSceneManager.cpp	(revision 94)
@@ -32,5 +32,16 @@
 void VisibilityTerrainSceneManager::_renderVisibleObjects()
 {
-	mHierarchyInterface->InitFrame(mOctree, mCameraInProgress);
+	Camera *cullCam = NULL;
+
+	// if two cameras (one for culling, one for visualization)
+	if(mCullCamera)
+		cullCam = getCamera("CullCamera");
+	
+	if(cullCam && (mCameraInProgress != cullCam))
+		OutputDebugString("using cullcam\n");
+	else
+		OutputDebugString("not using cullcam\n");
+
+	mHierarchyInterface->InitFrame(mOctree, mCameraInProgress, cullCam);
 	mVisibilityManager->GetCullingManager()->InitFrame();
 
Index: trunk/VUT/Ogre/src/OgreSolidBoundingBox.cpp
===================================================================
--- trunk/VUT/Ogre/src/OgreSolidBoundingBox.cpp	(revision 92)
+++ trunk/VUT/Ogre/src/OgreSolidBoundingBox.cpp	(revision 94)
@@ -6,5 +6,5 @@
 #include "OgreCamera.h"
 #include "OgreMaterialManager.h"
-//#include <windows.h>
+
 
 namespace Ogre {
Index: trunk/VUT/Ogre/src/OgreVisibilitySceneManagerDll.cpp
===================================================================
--- trunk/VUT/Ogre/src/OgreVisibilitySceneManagerDll.cpp	(revision 74)
+++ trunk/VUT/Ogre/src/OgreVisibilitySceneManagerDll.cpp	(revision 94)
@@ -34,5 +34,4 @@
 #include <OgreRoot.h>
 
-//#include <windows.h>
 GtpVisibility::VisibilityEnvironment *visEnv;
 GtpVisibility::VisibilityManager *visManager;
Index: trunk/VUT/Ogre/src/OgreVisibilitySceneManager.cpp
===================================================================
--- trunk/VUT/Ogre/src/OgreVisibilitySceneManager.cpp	(revision 87)
+++ trunk/VUT/Ogre/src/OgreVisibilitySceneManager.cpp	(revision 94)
@@ -7,5 +7,4 @@
 #include "OgreVisibilityOptionsManager.h"
 
-//#include <windows.h>
 
 namespace Ogre {
