Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SceneEntity.h
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SceneEntity.h	(revision 2841)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SceneEntity.h	(revision 2842)
@@ -51,5 +51,5 @@
 	/** Returns the transformed bounding box.
 	*/
-	AxisAlignedBox3 GetBoundingBox() const;
+	//AxisAlignedBox3 GetBoundingBox() const;
 	/** set frame where we last rendered this node
 	*/
@@ -62,6 +62,8 @@
 	inline Transform3 *GetTransform() const  { return mTransform; }
 
+	void GetCurrentLODLevel(ShapeContainer &shapes);
 
-	void GetCurrentLODLevel(ShapeContainer &shapes);
+	int CountNumTriangles();
+
 
 protected:
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Geometry.h
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Geometry.h	(revision 2840)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Geometry.h	(revision 2842)
@@ -35,4 +35,5 @@
 
 	inline bool HasTexture() const { return mHasTexture; }
+	
 	const AxisAlignedBox3& GetBoundingBox() const;
 
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderTraverser.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderTraverser.cpp	(revision 2839)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderTraverser.cpp	(revision 2842)
@@ -109,7 +109,7 @@
 		{
 			SceneEntity *ent = entities[i];
-#ifdef TODO
-			mStats.mNumRenderedTriangles += ent->GetGeometry()->GetNumTriangles();
-#endif
+			
+			mStats.mNumRenderedTriangles += ent->CountNumTriangles();
+
 			if (mUseRenderQueue)
 				mRenderQueue->Enqueue(ent);
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Shape.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Shape.cpp	(revision 2840)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Shape.cpp	(revision 2842)
@@ -4,8 +4,5 @@
 #include "Geometry.h"
 #include "SceneEntity.h"
-
-#include "glInterface.h"
-#include <Cg/cg.h>
-#include <Cg/cgGL.h>
+#include "Transform3.h"
 
 
@@ -30,5 +27,8 @@
 	if (mMaterial) mMaterial->Render(state);
 
+	mParent->GetTransform()->Load(state);
 	mGeometry->Render(state);
+	mParent->GetTransform()->Unload(state);
+
 }
 
@@ -46,3 +46,20 @@
 
 
+
+AxisAlignedBox3 Shape::GetBoundingBox() const
+{
+	return mGeometry->GetBoundingBox();
 }
+
+
+AxisAlignedBox3 Shape::GetTransformedBoundingBox() const
+{
+	AxisAlignedBox3 box = mGeometry->GetBoundingBox();
+	Matrix4x4 *mat = mParent->GetTransform()->GetMatrix();
+
+	if (mat) Transform(box, *mat);
+
+	return box;
+}
+
+}
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ResourceManager.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ResourceManager.cpp	(revision 2840)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ResourceManager.cpp	(revision 2842)
@@ -9,4 +9,5 @@
 #include "Vector3.h"
 #include "Transform3.h"
+#include "Shape.h"
 
 
@@ -26,4 +27,5 @@
 	CLEAR_CONTAINER(mTextures);
 	CLEAR_CONTAINER(mTrafos);
+	CLEAR_CONTAINER(mShapes);
 }
 
@@ -62,4 +64,10 @@
 	sceneGeom = new SceneEntity(trafo);
 
+	// create shape
+	Shape *shape = new Shape(geom, mat, sceneGeom);
+	mShapes.push_back(shape);
+
+	sceneGeom->AddShape(shape);
+
 	return sceneGeom;
 }
@@ -104,5 +112,5 @@
 
 		mGeometryTable[i] = geom;
-		mMaterialTable[i] = mat;
+		mMaterialTable[i] = mat;		
 
 		mGeometry.push_back(geom);
@@ -199,4 +207,5 @@
 		SceneEntity *ent = LoadSceneEntity(str);
 		entities[i] = ent;
+
 		mSceneEntities.push_back(ent);
 	}
@@ -232,4 +241,5 @@
 	mGeometryTable.clear();
 	mMaterialTable.clear();
+	//mShapesTable.clear();
 
 	return true;
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderQueue.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderQueue.cpp	(revision 2841)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderQueue.cpp	(revision 2842)
@@ -14,14 +14,4 @@
 {
 
-static Camera *sCam = NULL;
-
-
-inline static bool CompDist(SceneEntity *e1, SceneEntity *e2)
-{
-	return 
-		(SqrMagnitude(e1->GetBoundingBox().Center() - sCam->GetPosition()) <
-		 SqrMagnitude(e2->GetBoundingBox().Center() - sCam->GetPosition()));
-}
-
 
 inline static bool CompDist2(RenderQueueBucket *b1, RenderQueueBucket *b2)
@@ -29,4 +19,5 @@
 	return (b1->mMinDistance < b2->mMinDistance);
 }
+
 
 
@@ -46,5 +37,4 @@
 mSize(0)
 {
-	sCam = cam;
 }
 
@@ -91,5 +81,5 @@
 	shapes.clear();
 
-	entity->GetCurrentLODLevel(shapes)
+	entity->GetCurrentLODLevel(shapes);
 
 	ShapeContainer::const_iterator sit, sit_end = shapes.end();
@@ -107,7 +97,7 @@
 	++ mSize;
 	
-	if (entity->mRenderQueueBucket)
-	{
-		bucket = entity->mRenderQueueBucket;
+	if (shape->mRenderQueueBucket)
+	{
+		bucket = shape->mRenderQueueBucket;
 	}
 	else
@@ -119,5 +109,5 @@
 		for (; i < mBuckets.size(); ++ i)
 		{
-			if (bucketFound = FitsInBucket(entity, i))
+			if (bucketFound = FitsInBucket(shape, i))
 				break;
 		}
@@ -128,5 +118,5 @@
 			RenderQueueBucket *bucket = new RenderQueueBucket();
 
-			Material *mat = entity->GetMaterial();
+			Material *mat = shape->GetMaterial();
 
 			bucket->mAlphaTestEnabled = mat->IsAlphaTestEnabled();
@@ -143,5 +133,6 @@
 			// assume that the incoming nodes are ordered by distance => set min dist
 			// on first incoming node
-			float dist = SqrMagnitude(entity->GetBoundingBox().Center() - mCamera->GetPosition());
+			Vector3 v = shape->GetTransformedBoundingBox().Center() - mCamera->GetPosition();
+			const float dist = SqrMagnitude(v);
 			mBuckets[i]->mMinDistance = dist;
 
@@ -150,8 +141,8 @@
 
 		bucket = mBuckets[i];
-		entity->mRenderQueueBucket = bucket;
-	}
-
-	bucket->mEntities.push_back(entity);
+		shape->mRenderQueueBucket = bucket;
+	}
+
+	bucket->mShapes.push_back(shape);
 }
 
@@ -174,6 +165,7 @@
 void RenderQueue::Render()
 {
+	// sort the buckets
 	Sort();
-	
+
 	// render all buckets
 	for (size_t i = 0; i < mBuckets.size(); ++ i)
@@ -215,4 +207,11 @@
 
 
+void RenderQueue::Sort()
+{
+	// sort buckets itself
+	sort(mBuckets.begin(), mBuckets.end(), CompDist2);
+}
+
+
 void RenderQueue::Apply()
 {
@@ -222,10 +221,3 @@
 
 
-void RenderQueue::Sort()
-{
-	// sort buckets itself
-	sort(mBuckets.begin(), mBuckets.end(), CompDist2);
-}
-
-
-}
+}
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Shape.h
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Shape.h	(revision 2840)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Shape.h	(revision 2842)
@@ -12,9 +12,11 @@
 
 
-
 class Material;
 class Geometry;
 class RenderState;
+class AxisAlignedBox3;
+
 struct RenderQueueBucket;
+
 
 /** Class representing a shape.
@@ -43,5 +45,11 @@
 	*/
 	void SetMaterial(Material *mat);
-	
+	/** Returns the transformed bounding box.
+	*/
+	AxisAlignedBox3 GetBoundingBox() const;
+	/** Returns bounding box transformed with the parent transform.
+	*/
+	AxisAlignedBox3 GetTransformedBoundingBox() const;
+
 	inline Material *GetMaterial() const  { return mMaterial; }
 
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Bvh.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Bvh.cpp	(revision 2839)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Bvh.cpp	(revision 2842)
@@ -152,5 +152,5 @@
 	{
 		mGeometry[i] = (*it);
-		mBox.Include((*it)->GetBoundingBox());
+		//mBox.Include((*it)->GetBoundingBox());
 	}
 
@@ -799,7 +799,5 @@
 	for (int i = node->mFirst; i <= node->mLast; ++ i)
 	{
-#ifdef TODO
-		numTriangles += mGeometry[i]->GetGeometry()->GetNumTriangles();
-#endif
+		numTriangles += mGeometry[i]->CountNumTriangles();
 	}
 
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ResourceManager.h
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ResourceManager.h	(revision 2840)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ResourceManager.h	(revision 2842)
@@ -48,4 +48,5 @@
 	std::map<int, Material *> mMaterialTable;
 	std::map<int, Geometry *> mGeometryTable;
+	//std::map<int, Shape *> mShapesTable;
 
 	// these are kept to be able to delete these resources afterwards
@@ -53,6 +54,8 @@
 	std::vector<Material *> mMaterials;
 	std::vector<Geometry *> mGeometry;
-	std::vector<SceneEntity *> mSceneEntities;
 	std::vector<Transform3 *> mTrafos;
+	
+	SceneEntityContainer mSceneEntities;
+	ShapeContainer mShapes;
 };
 
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderQueue.h
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderQueue.h	(revision 2841)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderQueue.h	(revision 2842)
@@ -70,11 +70,9 @@
 protected:
 
+	void Sort();
+
 	void Enqueue(Shape *shape);
 
 	inline bool FitsInBucket(Shape *shape, size_t idx) const;
-
-	/** Sorts the render queue by materials / textures.
-	*/
-	void Sort();
 	/** Clears the render queue
 	*/
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SceneEntity.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SceneEntity.cpp	(revision 2841)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SceneEntity.cpp	(revision 2842)
@@ -9,6 +9,10 @@
 
 
+using namespace std;
+
+
 namespace CHCDemoEngine 
 {
+
 
 SceneEntity::SceneEntity(Transform3 *trafo): mTransform(trafo)
@@ -26,5 +30,5 @@
 	ShapeContainer::const_iterator sit, sit_end;
 
-	if (mLODInfos->empty())
+	if (mLODInfos.empty())
 	{
 		sit = mShapes.begin(); sit_end = mShapes.end();
@@ -35,16 +39,14 @@
 	int i = 0;
 
-	LODInfo *info;
-
 	LODInfoContainer::const_iterator lid, lid_end = mLODInfos.end();
 
 	for (lid = mLODInfos.begin(); lid != lid_end; ++ lid)
 	{
-		info = *lid;
+		LODInfo *lodInfo = *lid;
 
-		if (info->mDistance > mDistance)
+		if (lodInfo->mSquaredDistance > mDistance)
 		{
-			sit = info->mShapes.begin(); 
-			sit_end = info->mShapes.end();
+			sit = lodInfo->mShapes.begin(); 
+			sit_end = lodInfo->mShapes.end();
 			break;
 		}
@@ -70,5 +72,5 @@
 	ShapeContainer::const_iterator sit, sit_end = shapes.end();
 
-	for (; sit != sit_end; ++ sit)
+	for (sit = shapes.begin(); sit != sit_end; ++ sit)
 	{
 		(*sit)->Render(state);
@@ -101,15 +103,20 @@
 
 
-AxisAlignedBox3 SceneEntity::GetBoundingBox() const
+int SceneEntity::CountNumTriangles()
 {
-#ifdef TODO
-	AxisAlignedBox3 box = mGeometry->GetBoundingBox();
-	if (mTransform) Transform(box, *mTransform);
-#else
-	AxisAlignedBox3 box;
-#endif
-	
+	int numTriangles = 0;
+	static ShapeContainer shapes;
+	shapes.clear();
 
-	return box;
+	GetCurrentLODLevel(shapes);
+
+	ShapeContainer::const_iterator sit, sit_end = shapes.end();
+
+	for (sit = shapes.begin(); sit != sit_end; ++ sit)
+	{
+		numTriangles += (*sit)->GetGeometry()->GetNumTriangles();
+	}
+
+	return numTriangles;
 }
 
