Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderTraverser.cpp
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderTraverser.cpp	(revision 3072)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderTraverser.cpp	(revision 3074)
@@ -150,5 +150,5 @@
 	++ mFrameId;
 
-	mBvh->InitFrame(mCamera);
+	mBvh->InitFrame(mCamera, mRenderState);
 
 	mStats.Reset();
Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Shape.cpp
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Shape.cpp	(revision 3073)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Shape.cpp	(revision 3074)
@@ -26,8 +26,6 @@
 void Shape::Render(RenderState *state)
 {
-	//if (mMaterial) mMaterial->Render(state);
-	//mDepthWriteEnabled = true;
-glDepthMask(GL_TRUE);	glDepthFunc(GL_LESS);
-glEnable(GL_DEPTH_TEST);
+	if (mMaterial) mMaterial->Render(state);
+	
 	mGeometry->Render(state);
 }
Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/BvhLoader.cpp
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/BvhLoader.cpp	(revision 3072)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/BvhLoader.cpp	(revision 3074)
@@ -78,4 +78,5 @@
 
 	bvh->mStaticRoot = root;
+	// we have at least the root, the static and the dynamic branch
 	bvh->mNumNodes = 3;
 
@@ -107,17 +108,13 @@
 	}
 
-
-	////////////
+	///////////
 	//-- create dynamic part of the hierarchy
 
 	bvh->CreateDynamicBranch();
 
-	
 	///////////
 	//-- post process nodes
 
-	/// this function must be called once after creation
 	bvh->PostProcess();
-
 
 	cout << "... finished loading " << bvh->mNumNodes << " nodes" << endl;
Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderState.cpp
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderState.cpp	(revision 3073)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderState.cpp	(revision 3074)
@@ -311,7 +311,4 @@
 		}
 	}
-			ShaderManager::GetSingleton()->DisableFragmentProfile();
-			ShaderManager::GetSingleton()->DisableVertexProfile();
-
 }
 
@@ -341,3 +338,4 @@
 
 
-}
+
+}
Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Bvh.h
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Bvh.h	(revision 3073)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Bvh.h	(revision 3074)
@@ -586,5 +586,5 @@
 	/** Sets frame dependent values
 	*/
-	void InitFrame(Camera *camera);
+	void InitFrame(Camera *camera, RenderState *state);
 	/** Stores the orthogonal distance from the viewpoint to a point on the node.
 		We choose the the nearest bounding box vertex . 
@@ -738,4 +738,6 @@
 
 	void CreateRoot();
+
+	void UpdateDynamicBounds(RenderState *state);
 
 
Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Bvh.cpp
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Bvh.cpp	(revision 3073)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Bvh.cpp	(revision 3074)
@@ -207,8 +207,8 @@
 Bvh::~Bvh() 
 {
-	if (mVertices) delete [] mVertices; 
-	if (mIndices) delete [] mIndices;
-	if (mTestIndices) delete [] mTestIndices;
-	if (mGeometry) delete [] mGeometry;
+	DEL_ARRAY_PTR(mVertices);
+	DEL_ARRAY_PTR(mIndices);
+	DEL_ARRAY_PTR(mTestIndices);
+	DEL_ARRAY_PTR(mGeometry);
 
 	if (mRoot) delete mRoot;
@@ -220,5 +220,5 @@
 void Bvh::Init()
 {
-	//mStaticRoot = NULL;
+	mStaticRoot = NULL;
 	mDynamicRoot = NULL;
 	mRoot = NULL;
@@ -435,5 +435,5 @@
 
 
-void Bvh::InitFrame(Camera *cam)
+void Bvh::InitFrame(Camera *cam, RenderState *state)
 {
 	// = 0011 1111 which means that at the beginning, all six planes have to frustum culled
@@ -452,4 +452,5 @@
 	{
 		UpdateDynamicBranch(mDynamicRoot);
+		UpdateDynamicBounds(state);
 	}
 }
@@ -532,5 +533,5 @@
 	///////////////////
 	//-- for the first time we come here => create vbo and indices
-/*
+
 	if (!mIndices)
 	{	
@@ -544,9 +545,9 @@
 		PrepareVertices();
 	}
-*/
+
 	///////////////
 
 	int numNodes = 0;
-/*
+
 	BvhNodeContainer::const_iterator nit, nit_end = nodes.end();
 
@@ -563,5 +564,5 @@
 		numNodes += node->mNumTestNodes;
 	}
-*/
+
 	return numNodes;
 }
@@ -660,7 +661,13 @@
 	// collect all nodes
 	BvhNodeContainer nodes;
-	CollectNodes(mRoot, nodes);
-
-	// assign ids to all nodes of the "regular" hierarchy
+	//CollectNodes(mRoot, nodes);
+	// first collect dynamic nodes so we make sure that they are in the beginning
+	CollectNodes(mDynamicRoot, nodes);
+	// then collect static nodes
+	CollectNodes(mStaticRoot, nodes);
+	// also add root
+	nodes.push_back(mRoot);
+
+	// assign ids to all nodes of the hierarchy
 	int i = 0;
 	BvhNodeContainer::const_iterator lit, lit_end = nodes.end();
@@ -679,5 +686,10 @@
 
 	nodes.reserve(GetNumNodes());
-	CollectNodes(mRoot, nodes);
+	// first collect dynamic nodes so we make sure that they are in the beginning
+	CollectNodes(mDynamicRoot, nodes);
+	// then collect static nodes
+	CollectNodes(mStaticRoot, nodes);
+	// also add root
+	nodes.push_back(mRoot);
 
 	const unsigned int bufferSize = 8 * (int)nodes.size();
@@ -704,12 +716,58 @@
 		            bufferSize * sizeof(Vector3), 
 		            mVertices, 
-					GL_STATIC_DRAW_ARB);
+					//GL_STATIC_DRAW_ARB);
+					GL_DYNAMIC_DRAW_ARB);
 
 	glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);
 
 	// data handled by graphics driver from now on
-	DEL_PTR(mVertices);
+	DEL_ARRAY_PTR(mVertices);
 
 	cout << "******** created vbos for tighter bounds *********" << endl;
+}
+
+
+void Bvh::UpdateDynamicBounds(RenderState *state)
+{
+	// vbos not created yet
+	if (mVboId == -1) return;
+
+	// collect all nodes
+	static BvhNodeContainer nodes;
+	nodes.clear();
+	//nodes.reserve(GetNumNodes());
+	CollectNodes(mDynamicRoot, nodes);
+
+	const unsigned int bufferSize = 8 * (int)nodes.size();
+	
+	if (!mVertices)	mVertices = new Vector3[bufferSize];
+	
+	int i = 0;
+	
+	// store bounding box vertices
+	BvhNodeContainer::const_iterator lit, lit_end = nodes.end();
+
+	for (lit = nodes.begin(); lit != lit_end; ++ lit, i += 8)
+	{
+		BvhNode *node = *lit;
+
+		for (int j = 0; j < 8; ++ j)
+			(static_cast<Vector3 *>(mVertices))[node->GetId() * 8 + j] = node->GetBox().GetVertex(j);
+	}
+	
+	if (state->GetCurrentVboId() != mVboId)
+	{
+		glBindBufferARB(GL_ARRAY_BUFFER_ARB, mVboId);
+		// set the vertex pointer to the vertex buffer
+		glVertexPointer(3, GL_FLOAT, 0, (char *)NULL);	
+
+		state->SetCurrentVboId(mVboId);
+	}
+
+	glBufferSubDataARB(GL_ARRAY_BUFFER_ARB, 0,
+					   bufferSize * sizeof(Vector3), 
+					   mVertices);
+
+	glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);
 }
 
@@ -1061,5 +1119,4 @@
 	CreateRoot();
 
-	ComputeIds();
 	ComputeMaxDepthForVirtualLeaves();
 	// set virtual leaves for specified number of triangles
@@ -1067,6 +1124,10 @@
 	/// for each node compute the number of leaves under this node
 	UpdateNumLeaves(mRoot);
+	// compute new ids
+	ComputeIds();
 	// specify bounds for occlusion tests
 	RecomputeBounds();
+
+	mBox = mRoot->GetBox();
 
 	// compute and print stats
@@ -1267,6 +1328,4 @@
 	if (TerminationCriteriaMet(leaf))
 	{
-		leaf->mIsVirtualLeaf = true;
-		leaf->mIsMaxDepthForVirtualLeaf = true;
 		//cout << "leaf constructed:" << leaf->mBox << " " << leaf->mFirst << " " << leaf->mLast << endl;
 		return leaf;
@@ -1412,5 +1471,5 @@
 	// create new root
 	mRoot = new BvhInterior(NULL);
-	
+
 	// the separation is a purely logical one
 	// the bounding boxes of the child nodes are 
Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Transform3.cpp
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Transform3.cpp	(revision 3071)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Transform3.cpp	(revision 3074)
@@ -40,4 +40,5 @@
 	mIsIdentity = false;
 	mMatrix = mMatrix * trafo;
+	//mMatrix = trafo * mMatrix;
 }
 
Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp	(revision 3072)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp	(revision 3074)
@@ -53,5 +53,4 @@
 #include "SkyPreetham.h"
 #include "Texture.h"
-//#include "EntityMerger.h"
 #include "ShaderManager.h"
 
@@ -184,6 +183,5 @@
 
 bool useOptimization = false;
-//bool useTightBounds = true;
-bool useTightBounds = false;
+bool useTightBounds = true;
 bool useRenderQueue = true;
 bool useMultiQueries = true;
@@ -453,5 +451,5 @@
 	LoadModel("city.dem", sceneEntities);
 
-/*
+
 	//////////
 	//-- load some dynamic stuff
@@ -464,5 +462,5 @@
 	buddha->GetTransform()->SetMatrix(transl);
 
-	for (int i = 0; i < 10; ++ i)
+	/*for (int i = 0; i < 10; ++ i)
 	{
 		SceneEntity *ent = new SceneEntity(*buddha);
@@ -471,6 +469,6 @@
 		Vector3 offs = Vector3::ZERO();
 
-		offs.x = RandomValue(.0f, 150.0f);
-		offs.y = RandomValue(.0f, 150.0f);
+		offs.x = RandomValue(.0f, 50.0f);
+		offs.y = RandomValue(.0f, 50.0f);
 
 		transl = TranslationMatrix(sceneCenter + offs);
@@ -479,7 +477,7 @@
 		ent->SetTransform(transform);
 		dynamicObjects.push_back(ent);
-	}
-
-*/
+	}*/
+
+
 	///////////
 	//-- load the associated static bvh
@@ -870,4 +868,14 @@
 void MainLoop() 
 {	
+	Vector3 offs = Vector3::ZERO();
+	//offs.x = RandomValue(-.1f, .1f);
+	//offs.y = RandomValue(-.1f, .1f);
+	offs.x = RandomValue(.0f, .01f);
+	offs.y = RandomValue(.0f, .01f);
+
+	Matrix4x4 mat = TranslationMatrix(offs);
+		
+	buddha->GetTransform()->MultMatrix(mat);
+
 	Vector3 oldPos = camera->GetPosition();
 
