Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/BvhLoader.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/BvhLoader.cpp	(revision 3021)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/BvhLoader.cpp	(revision 3052)
@@ -76,30 +76,47 @@
 	BvhNode *root = LoadNextNode(stream, NULL);
 
-#if 1
+#if 0
 
 	bvh->mRoot = root;
 
 #else
-	// copy root and set new one for dynamic objects
+	// we are setting a new root node
+	// which adds one level of indirection to the bvh but 
+	// allows us to use dynamic objects
+	// the new bvh has two main branches
+	// one is the static branch (the old root),
+	// one is the dynamic branch 
+	// we create a 'dynamic' leaf which basically is a container
+	// for all dynamic objects underneath
+	// the bounding boxes of the dynamic tree must be updated
+	// once each frame in order to be able to incorporate
+	// the movements of the objects within
+
 	BvhInterior *newRoot = new BvhInterior(NULL);
-	
+	bvh->mRoot = newRoot;
+
+	BvhLeaf *dynamicLeaf = new BvhLeaf(newRoot);
+
+	newRoot->mFront = root;
+	newRoot->mBack = dynamicLeaf;
+	root->mParent = newRoot;
+
+	// the separation is a purely logical one
+	// the bounding boxes of the child nodes is the
+	// same as for the root node
 	newRoot->mBox = root->mBox;
+	dynamicLeaf->mBox = root->mBox;
+
+	newRoot->mArea = newRoot->mBox.SurfaceArea();
+	dynamicLeaf->mArea = dynamicLeaf->mBox.SurfaceArea();
+
 	newRoot->mFirst = root->mFirst;
 	newRoot->mLast = root->mLast;
 
-	// create 'dynamic' leaf which basically is a container
-	// for all dynamic objects
-	BvhLeaf *dynamicLeaf = new BvhLeaf(newRoot);
-	dynamicLeaf->mBox = root->mBox;
-
-	newRoot->mFront = root;
-	root->mParent = newRoot;
-
-	newRoot->mBack = dynamicLeaf;
-
-	bvh->mRoot = newRoot;
+	dynamicLeaf->mFirst = 0;
+	dynamicLeaf->mLast = 0;
 #endif
 
-	tQueue.push(bvh->mRoot);
+	tQueue.push(root);
 	bvh->mNumNodes = 1;
 
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ResourceManager.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ResourceManager.cpp	(revision 3050)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ResourceManager.cpp	(revision 3052)
@@ -91,4 +91,10 @@
 
 
+void ResourceManager::DelSingleton()
+{
+	DEL_PTR(sResourceManager);
+}
+
+
 SceneEntity *ResourceManager::LoadSceneEntity(igzstream &str)
 {	
@@ -431,5 +437,4 @@
 
 
-
 ShaderProgram *ResourceManager::CreateFragmentProgram(const std::string &filename, 
 													  const std::string &funcName)
@@ -438,5 +443,4 @@
 
 	ShaderProgram *p = new ShaderProgram(sCgContext, fullName, sCgFragmentProfile, funcName);
-
 	mShaders.push_back(p);
 
@@ -465,6 +469,6 @@
 		cerr << "Program " << funcName << " in " << fullName << " failed to load" << endl;
 	}
-	
-	cout << "Program " << funcName << " in " << fullName << " loaded" << endl;
+	else
+		cout << "Program " << funcName << " in " << fullName << " loaded" << endl;
 
 	return p;
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Bvh.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Bvh.cpp	(revision 3042)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Bvh.cpp	(revision 3052)
@@ -402,4 +402,10 @@
 void Bvh::UpdateDistance(BvhNode *node) const
 {
+	// use distance to center rather than the distance to the near plane because
+	// otherwise problems with big object penetrating the near plane 
+	// (e.g., big objects in the distance which are then always visible)
+	// especially annoying is this problem when using the frustum 
+	// fitting on the visible objects for shadow mapping
+
 	//node->mDistance = node->GetBox()GetMinDistance(sNearPlane);
 	node->mDistance = sNearPlane.Distance(node->GetBox().Center());
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderState.h
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderState.h	(revision 3050)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderState.h	(revision 3052)
@@ -36,6 +36,4 @@
 	*/
 	RenderState();
-	
-	~RenderState() { Reset(); };
 	/** This must be called each time before and after an occlusion test.
 		Mode is one of render mode or query mode. Returns true if a state
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ResourceManager.h
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ResourceManager.h	(revision 3045)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ResourceManager.h	(revision 3052)
@@ -32,29 +32,10 @@
 public:
 
-	/** Returns the resource manager as a singleton.
-	*/
-	static ResourceManager *GetSingleton()
-	{
-		if (!sResourceManager)
-		{
-			sResourceManager = new ResourceManager();
-		}
-
-		return sResourceManager;
-	}
-
-	/** We also want full control over the delete.
-	*/
-	static void DelSingleton()
-	{
-		DEL_PTR(sResourceManager);
-	}
-
 	/** Loads a model
 	*/
 	bool Load(const std::string &filename, SceneEntityContainer &geometry);
-
+	/** Returns number of scene entities loaded with this manager.
+	*/
 	int GetNumEntities() const { return (int)mSceneEntities.size(); }
-
 	/** Creates new gpu program parameters.
 	*/
@@ -71,4 +52,10 @@
 	void DisableVertexProfile();
 
+	/** Returns the resource manager as a singleton.
+	*/
+	inline static ResourceManager *GetSingleton();
+	/** We also want full control over the delete.
+	*/
+	static void DelSingleton();
 
 protected:
@@ -111,8 +98,5 @@
 	LODContainer mLODs;
 
-	////////
-
 	/// the scene entities
-
 	SceneEntityContainer mSceneEntities;
 
@@ -132,4 +116,13 @@
 
 
+ResourceManager *ResourceManager::GetSingleton()
+{
+	if (!sResourceManager)
+		sResourceManager = new ResourceManager();
+	
+	return sResourceManager;
+}
+
+
 }
 #endif
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp	(revision 3051)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp	(revision 3052)
@@ -95,12 +95,8 @@
 
 int assumedVisibleFrames = 10;
-
 int maxBatchSize = 50;
-
 int trianglesPerVirtualLeaf = INITIAL_TRIANGLES_PER_VIRTUAL_LEAVES;
-
 SceneQuery *sceneQuery = NULL;
 RenderQueue *renderQueue = NULL;
-
 // traverses and renders the hierarchy
 RenderTraverser *shadowTraverser = NULL;
@@ -291,5 +287,4 @@
 int main(int argc, char* argv[])
 {
-/*
 #ifdef _CRT_SET
 
@@ -304,5 +299,5 @@
 	_CrtSetReportFile(_CRT_ASSERT,_CRTDBG_FILE_STDERR); 
 #endif
-*/
+
 	cout << "=== reading environment file ===" << endl << endl;
 
@@ -470,5 +465,4 @@
 	{
 		cerr << "loading file " << skyDomeStr << " failed" << endl;
-
 		CleanUp();
 		exit(0);
@@ -1094,5 +1088,4 @@
 		CleanUp();
 		exit(0);
-		break;
 	case 32: // space
 		renderMode = (renderMode + 1) % RenderTraverser::NUM_TRAVERSAL_TYPES;
@@ -1649,5 +1642,5 @@
 	DEL_PTR(shadowMap);
 	DEL_PTR(shadowTraverser);
-	
+
 	ResourceManager::DelSingleton();
 	loader = NULL;
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/FriendlyCulling.vcproj
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/FriendlyCulling.vcproj	(revision 3040)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/FriendlyCulling.vcproj	(revision 3052)
@@ -112,5 +112,5 @@
 				EnableFiberSafeOptimizations="true"
 				AdditionalIncludeDirectories="libs;libs/GL;libs/Devil/include;src;libs/Zlib/include;&quot;$(CG_INC_PATH)&quot;"
-				PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS"
+				PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;_CRT_SET"
 				StringPooling="true"
 				RuntimeLibrary="2"
