Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/LODInfo.h
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/LODInfo.h	(revision 2847)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/LODInfo.h	(revision 2848)
@@ -13,8 +13,40 @@
 struct LODLevel
 {
+	//friend class SceneEntity;
+
 public:
 	
 	LODLevel(float squaredDist): mSquaredDistance(squaredDist) {}
 
+	inline float GetSquaredDistance() { return mSquaredDistance; }
+
+	inline int GetNumShapes() { return (int)mShapes.size(); }
+	
+	inline int GetNumTriangles() { return mNumTriangles; }
+
+	inline Shape *GetShape(size_t i) { return mShapes[i]; }
+
+	inline ShapeContainer &GetShapes() { return mShapes; }
+
+	void AddShape(Shape *shape);
+
+
+	////////////////
+
+	/** Has to be called each frame in order to use proper LOD level.
+	*/
+	static void InitFrame(const Vector3 &viewPoint);
+
+
+	static int sFrameId;
+	static Vector3 sViewPoint;
+
+
+
+protected:
+
+	/////////////////////
+
+	float mNumTriangles;
 
 	/// distance of this LOD level
@@ -22,12 +54,4 @@
 	/// shapes belonging to this LOD level
 	ShapeContainer mShapes;
-
-
-	/** Has to be called each frame in order to use proper LOD level.
-	*/
-	static void InitFrame(const Vector3 &viewPoint);
-
-	static int sFrameId;
-	static Vector3 sViewPoint;
 };
 
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SceneEntity.h
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SceneEntity.h	(revision 2847)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SceneEntity.h	(revision 2848)
@@ -62,5 +62,5 @@
 		with 0 being the highest or the current lod level (if the argument is -1).
 	*/
-	int CountNumTriangles(int lodLevel = 0);
+	int CountNumTriangles(int lodLevel = -1);
 	/** Returns the bounding box.
 	*/
@@ -87,8 +87,9 @@
 	*/
 	int GetNumLODLevels() const { return (int)mLODLevels.size(); }
-
 	/** Returns transformed center point of this shape.
 	*/
 	Vector3 GetCenter() const;
+
+
 
 protected:
@@ -97,5 +98,7 @@
 	*/
 	void UpdateLODs(const Vector3 &viewPoint);
-
+	/** Returns updated index of current lod level.
+	*/
+	int GetCurrentLODLevel();
 
 
@@ -112,8 +115,7 @@
 
 	int mCurrentLODLevel;
-
 	/// which frame the lod info was last updated
 	int mLODLastUpdated;
-
+	/// the center of gravity of this scene entity
 	Vector3 mCenter;
 };
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderTraverser.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderTraverser.cpp	(revision 2847)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderTraverser.cpp	(revision 2848)
@@ -270,9 +270,10 @@
 		 
 	if (mRenderQueue->GetSize() > 0)
+	{
 		++ mStats.mNumBatches;
-
-	mRenderQueue->Apply();
-}
-
-
-}
+		mRenderQueue->Apply();
+	}
+}
+
+
+}
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SceneQuery.h
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SceneQuery.h	(revision 2843)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SceneQuery.h	(revision 2848)
@@ -21,5 +21,4 @@
 
 	~SceneQuery() { DEL_ARRAY_PTR(mDepth); }
-
 	/** Calculates intersection of vertical ray at position pt.x, pt.y and 
 	    stores the intersection point if valid. returns true if the intersection 
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ResourceManager.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ResourceManager.cpp	(revision 2846)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ResourceManager.cpp	(revision 2848)
@@ -91,5 +91,5 @@
 
 			sceneGeom->AddShape(shape);
-			lodLevel->mShapes.push_back(shape);
+			lodLevel->AddShape(shape);
 		}
 
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SceneQuery.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SceneQuery.cpp	(revision 2838)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SceneQuery.cpp	(revision 2848)
@@ -7,11 +7,11 @@
 #include <IL/il.h>
 #include <assert.h>
-#include "RenderTexture.h"
+//#include "RenderTexture.h"
 
 
 using namespace std;
 
-static int texWidth = 2048;
-static int texHeight = 2048;
+const static int texWidth = 2048;
+const static int texHeight = 2048;
 
 
@@ -107,5 +107,5 @@
 	{
 		// temporal smoothing of depth values
-		const float x = 0.5f;
+		const float x = .5f;
 		depth = d * x + depth * (1.0f - x);
 
@@ -131,5 +131,5 @@
 
 	orthoCam->SetNear(0.0f);
-	orthoCam->Yaw(-M_PI * 0.5f);
+	orthoCam->Yaw(M_PI * 0.5f);
 
 	Vector3 pos = Vector3(mSceneBox.Center().x, mSceneBox.Center().y, mSceneBox.Max().z);
@@ -165,5 +165,5 @@
 		glPushMatrix();
 
-		glOrtho(-xlen, xlen, -ylen, ylen, 0.0f, mSceneBox.Size().z); 
+		glOrtho(+xlen, -xlen, ylen, -ylen, 0.0f, mSceneBox.Size().z); 
 
 		glMatrixMode(GL_MODELVIEW);
@@ -185,6 +185,6 @@
 
 	GrabDepthBuffer(mDepth, depthTexture);
-	//ExportDepthBuffer(mDepth);
-	//PrintGLerror("grab");
+	ExportDepthBuffer(mDepth);
+	PrintGLerror("grab");
 
 	DEL_PTR(depthTexture);
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderQueue.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderQueue.cpp	(revision 2847)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderQueue.cpp	(revision 2848)
@@ -188,5 +188,4 @@
 		}
 	}
-
 	//Print();
 }
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Shape.h
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Shape.h	(revision 2847)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Shape.h	(revision 2848)
@@ -53,5 +53,6 @@
 	*/
 	AxisAlignedBox3 GetTransformedBoundingBox() const;
-
+	/** Returns material of this shape.
+	*/
 	inline Material *GetMaterial() const  { return mMaterial; }
 	/** Returns transformed center point of this shape.
@@ -67,5 +68,4 @@
 	Material *mMaterial;
 	SceneEntity *mParent;
-
 	/// pointer to the renderqueue bucket this entity belongs to
 	RenderQueueBucket *mRenderQueueBucket;
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Bvh.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Bvh.cpp	(revision 2842)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Bvh.cpp	(revision 2848)
@@ -144,6 +144,4 @@
 	mGeometry = new SceneEntity*[mGeometrySize];
 
-	mBox.Initialize();
-
 	SceneEntityContainer::const_iterator it, it_end = entities.end();
 
@@ -152,8 +150,5 @@
 	{
 		mGeometry[i] = (*it);
-		//mBox.Include((*it)->GetBoundingBox());
-	}
-
-	cout << "scene box: " << mBox << endl;
+	}
 }
 
@@ -799,5 +794,5 @@
 	for (int i = node->mFirst; i <= node->mLast; ++ i)
 	{
-		numTriangles += mGeometry[i]->CountNumTriangles();
+		numTriangles += mGeometry[i]->CountNumTriangles(0);
 	}
 
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderQueue.h
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderQueue.h	(revision 2844)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderQueue.h	(revision 2848)
@@ -86,7 +86,9 @@
 	void Print();
 
+
 	///////////
 
 	RenderState *mState;
+	
 	Camera *mCamera;
 	//SceneEntityContainer mEntities;
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/LODInfo.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/LODInfo.cpp	(revision 2847)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/LODInfo.cpp	(revision 2848)
@@ -1,4 +1,7 @@
 #include "LODInfo.h"
 #include "Vector3.h"
+#include "Shape.h"
+#include "Geometry.h"
+
 
 
@@ -17,3 +20,10 @@
 
 
+void LODLevel::AddShape(Shape *shape)
+{
+	mShapes.push_back(shape);
+	mNumTriangles += shape->GetGeometry()->GetNumTriangles();
 }
+
+
+}
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SceneEntity.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SceneEntity.cpp	(revision 2847)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SceneEntity.cpp	(revision 2848)
@@ -45,15 +45,23 @@
 		LODLevel *lod = mLODLevels[i];
 
-		if (lod->mSquaredDistance > distance)
+		if (lod->GetSquaredDistance() > distance)
 			break;
 
 		mCurrentLODLevel = i;
 	}
+}
 
-	/*if (mLODLevels.size() > 1)
+
+int SceneEntity::GetCurrentLODLevel()
+{
+	if (mLODLastUpdated != LODLevel::sFrameId)
 	{
-		Debug << "dist: " << distance << " numshapes: " << mLODLevels[mCurrentLODLevel]->mShapes.size() << " lod: " << mCurrentLODLevel << " of " << mLODLevels.size() << endl;
-	}*/
+		mLODLastUpdated = LODLevel::sFrameId;
+		UpdateLODs(LODLevel::sViewPoint);
+	}
+
+	return mCurrentLODLevel;
 }
+
 
 void SceneEntity::GetCurrentLODLevel(ShapeContainer::iterator &start, 
@@ -66,6 +74,6 @@
 	}
 
-	start = mLODLevels[mCurrentLODLevel]->mShapes.begin(); 
-	end = mLODLevels[mCurrentLODLevel]->mShapes.end();
+	start = mLODLevels[mCurrentLODLevel]->GetShapes().begin(); 
+	end   = mLODLevels[mCurrentLODLevel]->GetShapes().end();
 }
 
@@ -77,6 +85,6 @@
 	LODLevel *lod = mLODLevels[level];
 
-	start = lod->mShapes.begin();
-	end = lod->mShapes.end();
+	start = lod->GetShapes().begin();
+	end = lod->GetShapes().end();
 }
 
@@ -130,18 +138,8 @@
 	if (lodLevel == -1)
 	{
-		GetCurrentLODLevel(sit, sit_end);
-	}
-	else
-	{
-		GetLODLevel(lodLevel, sit, sit_end);
+		lodLevel = GetCurrentLODLevel();
 	}
 
-
-	for (; sit != sit_end; ++ sit)
-	{
-		numTriangles += (*sit)->GetGeometry()->GetNumTriangles();
-	}
-
-	return numTriangles;
+	return mLODLevels[lodLevel]->GetNumTriangles();
 }
 
@@ -168,6 +166,5 @@
 	Matrix4x4 *mat = mTransform->GetMatrix();
 
-	if (!mat)
-		return mCenter;
+	if (!mat) return mCenter;
 
 	return (*mat) * mCenter;
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp	(revision 2847)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp	(revision 2848)
@@ -2022,6 +2022,6 @@
 	bool validIntersect = sceneQuery->CalcIntersection(playerPos);
 
-	if (validIntersect &&
-		(( playerPos.z - oldPos.z) < bvh->GetBox().Size(2) * 1e-1f))
+	if (validIntersect ) 
+		// && ((playerPos.z - oldPos.z) < bvh->GetBox().Size(2) * 1e-1f))
 	{
 		camera->SetPosition(playerPos);
