Index: GTP/trunk/App/Demos/Vis/CHC_revisited/RenderTraverser.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/CHC_revisited/RenderTraverser.cpp	(revision 2761)
+++ GTP/trunk/App/Demos/Vis/CHC_revisited/RenderTraverser.cpp	(revision 2762)
@@ -2,4 +2,5 @@
 #include "glInterface.h"
 #include "Timers.h"
+#include "Camera.h"
 
 
@@ -66,6 +67,9 @@
 void RenderTraverser::TraverseNode(BvhNode *node)
 {
-	if (node->IsVirtualLeaf()||node->IsLeaf())
-	{
+
+	if (node->IsVirtualLeaf())
+	{
+		//RenderBox(node->GetBox());
+
 		//mNumRenderedGeometry +=
 		mBvh->Render(node, mRenderState);
@@ -74,5 +78,4 @@
 	{
 		// for non leafs this renders only the bounding volume (if the flag is set)
-		//node->Render();
 		BvhInterior *interior = static_cast<BvhInterior *>(node);
 
@@ -394,3 +397,109 @@
 }
 
-}
+
+void RenderTraverser::RenderBox(const AxisAlignedBox3 &box)
+{
+	glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
+	glDisable(GL_CULL_FACE);
+	glColor3f(1.0f, 0.0f, 0.0f);
+
+	glBegin(GL_QUADS);
+	glVertex3f(box.Min().x, box.Max().y, box.Min().z);
+	glVertex3f(box.Max().x, box.Max().y, box.Min().z);
+	glVertex3f(box.Max().x, box.Min().y, box.Min().z);
+	glVertex3f(box.Min().x, box.Min().y, box.Min().z);
+	glEnd();
+
+	glBegin(GL_QUADS);
+	glVertex3f(box.Min().x, box.Min().y, box.Max().z);
+	glVertex3f(box.Max().x, box.Min().y, box.Max().z);
+	glVertex3f(box.Max().x, box.Max().y, box.Max().z);
+	glVertex3f(box.Min().x, box.Max().y, box.Max().z);
+	glEnd();
+
+	glBegin(GL_QUADS);
+	glVertex3f(box.Max().x, box.Min().y, box.Min().z);
+	glVertex3f(box.Max().x, box.Min().y, box.Max().z);
+	glVertex3f(box.Max().x, box.Max().y, box.Max().z);
+	glVertex3f(box.Max().x, box.Max().y, box.Min().z);
+	glEnd();
+
+	glBegin(GL_QUADS);
+	glVertex3f(box.Min().x, box.Min().y, box.Min().z);
+	glVertex3f(box.Min().x, box.Min().y, box.Max().z);
+	glVertex3f(box.Min().x, box.Max().y, box.Max().z);
+	glVertex3f(box.Min().x, box.Max().y, box.Min().z);
+	glEnd();
+
+	glBegin(GL_QUADS);
+	glVertex3f(box.Min().x, box.Min().y, box.Min().z);
+	glVertex3f(box.Max().x, box.Min().y, box.Min().z);
+	glVertex3f(box.Max().x, box.Min().y, box.Max().z);
+	glVertex3f(box.Min().x, box.Min().y, box.Max().z);
+	glEnd();
+
+	glBegin(GL_QUADS);
+	glVertex3f(box.Min().x, box.Max().y, box.Min().z);
+	glVertex3f(box.Max().x, box.Max().y, box.Min().z);
+	glVertex3f(box.Max().x, box.Max().y, box.Max().z);
+	glVertex3f(box.Min().x, box.Max().y, box.Max().z);
+	glEnd();
+
+	glEnable(GL_CULL_FACE);
+
+	glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
+}
+
+
+void RenderTraverser::RenderFrustum()
+{
+	Vector3 ftl, ftr, fbl, fbr, ntl, ntr, nbl, nbr;
+	mCamera->ComputePoints(ftl, ftr, fbl, fbr, ntl, ntr, nbl, nbr);
+
+	glLineWidth(2);
+
+	glBegin(GL_LINE_LOOP);
+	glVertex3d(fbl.x, fbl.y, fbl.z);
+	glVertex3d(fbr.x, fbr.y, fbr.z);
+	glVertex3d(ftr.x, ftr.y, ftr.z);
+	glVertex3d(ftl.x, ftl.y, ftl.z);
+	glEnd();
+
+	glBegin(GL_LINE_LOOP);
+	glVertex3d(nbl.x, nbl.y, nbl.z);
+	glVertex3d(nbr.x, nbr.y, nbr.z);
+	glVertex3d(ntr.x, ntr.y, ntr.z);
+	glVertex3d(ntl.x, ntl.y, ntl.z);
+	glEnd();
+
+	glBegin(GL_LINE_LOOP);
+	glVertex3d(fbl.x, fbl.y, fbl.z);
+	glVertex3d(ftl.x, ftl.y, ftl.z);
+	glVertex3d(ntl.x, ntl.y, ntl.z);
+	glVertex3d(nbl.x, nbl.y, nbl.z);
+	glEnd();
+
+	glBegin(GL_LINE_LOOP);
+	glVertex3d(fbr.x, fbr.y, fbr.z);
+	glVertex3d(ftr.x, ftr.y, ftr.z);
+	glVertex3d(ntr.x, ntr.y, ntr.z);
+	glVertex3d(nbr.x, nbr.y, nbr.z);
+	glEnd();
+
+	glBegin(GL_LINE_LOOP);
+	glVertex3d(fbr.x, fbr.y, fbr.z);
+	glVertex3d(fbl.x, fbl.y, fbl.z);
+	glVertex3d(nbl.x, nbl.y, nbl.z);
+	glVertex3d(nbr.x, nbr.y, nbr.z);
+	glEnd();
+
+	glBegin(GL_LINE_LOOP);
+	glVertex3d(ftr.x, ftr.y, ftr.z);
+	glVertex3d(ftl.x, ftl.y, ftl.z);
+	glVertex3d(ntl.x, ntl.y, ntl.z);
+	glVertex3d(ntr.x, ntr.y, ntr.z);
+	glEnd();
+}
+
+
+}
Index: GTP/trunk/App/Demos/Vis/CHC_revisited/Bvh.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/CHC_revisited/Bvh.cpp	(revision 2761)
+++ GTP/trunk/App/Demos/Vis/CHC_revisited/Bvh.cpp	(revision 2762)
@@ -292,4 +292,41 @@
 
 
+bool Bvh::TestPlane(BvhNode *node, int i, bool &bIntersect)
+{
+	// do the test only if necessary
+	if (1)//node->mPlaneMask & (1 << i))
+	{//cout<<"plane "<< i << endl;
+		bool outs = true;
+		//-- test the n-vertex
+		for (int j = 0; j < 8; ++ j)
+		{
+			if (sFrustum.mClipPlanes[i].Distance(node->mBox.GetVertex(j)) <= 0) outs = false;
+		}
+		if (outs) return 0;
+		//if ((node->mBox.GetDistance(sClipPlaneAABBVertexIndices[i * 2 + 0], sFrustum.mClipPlanes[i]) > 0.0f))
+			//&&	(node->mBox.GetDistance(sClipPlaneAABBVertexIndices[i * 2 + 1], sFrustum.mClipPlanes[i]) > 0.0f))
+		{
+			// outside
+		//	node->mPreferredPlane = i;
+			//cout<<"f " << node->mBox.GetDistance(sClipPlaneAABBVertexIndices[i * 2 + 0], sFrustum.mClipPlanes[i]) << " " << sFrustum.mClipPlanes[i] << endl;
+		//	return false;
+		}//else cout<<"ok " << node->mBox.GetDistance(sClipPlaneAABBVertexIndices[i * 2 + 0], sFrustum.mClipPlanes[i]) << " " << sFrustum.mClipPlanes[i] << endl;
+
+		//-- test the p-vertex
+		if (node->mBox.GetDistance(sClipPlaneAABBVertexIndices[i * 2 + 1], sFrustum.mClipPlanes[i]) <= 0.0f)
+		{
+			// completely inside: children don't need to check against this plane no more
+			node->mPlaneMask^= 1 << i;
+		}
+		else 
+		{
+			bIntersect = true;
+		}
+	}
+
+	return true;
+}
+
+
 int	Bvh::IsWithinViewFrustum(BvhNode *node)
 {
@@ -300,31 +337,15 @@
 
 
+	for (int i = 0; i < 6; ++ i)
+	{
+		if (!TestPlane(node, i, bIntersect)) return 0;
+	}
+
 	////////
-	//-- do the view frustum culling for the planes [mPreferredPlane - 5]
-
+	//-- apply frustum culling for the planes [mPreferredPlane - 5]
+/*
 	for (int i = node->mPreferredPlane; i < 6; ++ i)
 	{
-		//-- do the test only if necessary
-		if (node->mPlaneMask & (1 << i))
-		{
-			//-- test the n-vertex
-			if (node->mBox.GetDistance(sClipPlaneAABBVertexIndices[i * 2 + 0], sFrustum.mClipPlanes[i]) > 0.0f)
-			{
-				//-- outside
-				node->mPreferredPlane = i;
-				return 0;
-			}
-
-			//-- test the p-vertex
-			if (node->mBox.GetDistance(sClipPlaneAABBVertexIndices[i * 2 + 1], sFrustum.mClipPlanes[i]) <= 0.0f)
-			{
-				//-- completely inside: children don't need to check against this plane no more
-				node->mPlaneMask^=	1 << i;
-			}
-			else 
-			{
-				bIntersect = true;
-			}
-		}
+		if (!TestPlane(node, i, bIntersect)) return 0;
 	}
 
@@ -334,28 +355,7 @@
 	for (int i = 0; i < node->mPreferredPlane; ++ i)
 	{
-		// do the test only if necessary
-		if (node->mPlaneMask & (1 << i))
-		{
-			//-- test the n-vertex
-			if (node->mBox.GetDistance(sClipPlaneAABBVertexIndices[i * 2 + 0], sFrustum.mClipPlanes[i]) > 0.0f)
-			{
-				// outside
-				node->mPreferredPlane = i;
-				return 0;
-			}
-
-			//-- test the p-vertex
-			if (node->mBox.GetDistance(sClipPlaneAABBVertexIndices[i * 2 + 1], sFrustum.mClipPlanes[i]) <= 0.0f)
-			{
-				// completely inside: children don't need to check against this plane no more
-				node->mPlaneMask^= 1 << i;
-			}
-			else 
-			{
-				bIntersect = true;
-			}
-		}
-	}
-
+		if (!TestPlane(node, i, bIntersect)) return 0;
+	}
+*/
 	return bIntersect ? -1 : 1;
 }
@@ -373,7 +373,12 @@
 	sFrustum.CalcNPVertexIndices(sClipPlaneAABBVertexIndices);
 
-	// calc near plane
-	sNearPlane = Plane3(mCamera->GetDirection(), 
-		                -mCamera->GetDirection() * mCamera->GetPosition());
+	for (int i = 0; i<12; ++ i)
+//cout<<" x " << sClipPlaneAABBVertexIndices[i];
+//	cout<<"\n********\n";
+	// near plane
+	sNearPlane = Plane3(mCamera->GetDirection(), mCamera->GetPosition());
+
+//	Debug << "near: " << sNearPlane << " d " << mCamera->GetDirection() << " " << mCamera->GetPosition() << std::endl;
+//	for (int i = 0; i < 6; ++ i) Debug << "plane: " << sFrustum.mClipPlanes[i] << std::endl;
 }
 
@@ -865,4 +870,55 @@
 
 
+void Bvh::Dummy()
+{
+	for (int i = 0; i < mGeometrySize; ++ i)
+		Debug << mGeometry[i]->id << " " << mGeometry[i]->GetGeometry()->GetBoundingBox() << endl;
+
+	AxisAlignedBox3 boxl; boxl.Initialize();
+	AxisAlignedBox3 boxr; boxr.Initialize();
+
+
+	for (int i = 0; i <= 107; ++ i)
+		boxl.Include(mGeometry[i]->GetBoundingBox());
+
+	for (int i = 108; i <= 193; ++ i)
+		boxr.Include(mGeometry[i]->GetBoundingBox());
+
+	Debug << "dummy " << boxl << " " << boxr << endl;
+
+	queue<BvhNode *> tStack;
+	tStack.push(mRoot);
+
+	while (!tStack.empty())
+	{
+		BvhNode *node = tStack.front();//top();
+		tStack.pop();
+
+		AxisAlignedBox3 box;
+		box.Initialize();
+
+		int i = 0;
+		for (int i = node->mFirst; i <= node->mLast; ++ i)
+		{
+			if ((mGeometry[i]->id < node->mFirst) || (mGeometry[i]->id > node->mLast))
+				cout << "big error!! " << mGeometry[i]->id << endl;
+			else cout << "ok"<<mGeometry[i]->id;
+			box.Include(mGeometry[i]->GetBoundingBox());
+		}
+
+		Debug<< box << " " << node->GetBox() << " f " << node->mFirst << " l " << node->mLast << " id " << node->GetId() << " l " << node->IsLeaf() << endl;
+
+		//node->mBox = box;
+		if (!node->IsLeaf())
+		{
+			BvhInterior *interior = static_cast<BvhInterior *>(node);
+
+			tStack.push(interior->mFront);
+			tStack.push(interior->mBack);
+		}
+	}
+}
+
+
 void Bvh::SetVirtualLeaves(int numTriangles) 
 {
Index: GTP/trunk/App/Demos/Vis/CHC_revisited/Plane3.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/CHC_revisited/Plane3.cpp	(revision 2755)
+++ GTP/trunk/App/Demos/Vis/CHC_revisited/Plane3.cpp	(revision 2762)
@@ -14,8 +14,8 @@
 
 
-Plane3::Plane3(Vector3 &normal, float dist): 
+/*Plane3::Plane3(const Vector3 &normal, float dist): 
 mNormal(normal), mD(dist)
 {
-}
+}*/
 
 
Index: GTP/trunk/App/Demos/Vis/CHC_revisited/Vector3.h
===================================================================
--- GTP/trunk/App/Demos/Vis/CHC_revisited/Vector3.h	(revision 2756)
+++ GTP/trunk/App/Demos/Vis/CHC_revisited/Vector3.h	(revision 2762)
@@ -47,6 +47,5 @@
 	{}
 
-	Vector3(float v): x(v), y(v), z(v)
-	{}
+	Vector3(float v): x(v), y(v), z(v){}
 	/** Copy constructor.
 	*/
Index: GTP/trunk/App/Demos/Vis/CHC_revisited/Camera.h
===================================================================
--- GTP/trunk/App/Demos/Vis/CHC_revisited/Camera.h	(revision 2756)
+++ GTP/trunk/App/Demos/Vis/CHC_revisited/Camera.h	(revision 2762)
@@ -55,4 +55,7 @@
 	void CalcFrustum(Frustum &frustum);
 
+	void ComputePoints(Vector3 &ftl, Vector3 &ftr, Vector3 &fbl, Vector3 &fbr,
+		               Vector3 &ntl, Vector3 &ntr, Vector3 &nbl, Vector3 &nbr);
+
 
 protected:
Index: GTP/trunk/App/Demos/Vis/CHC_revisited/chcdemo.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/CHC_revisited/chcdemo.cpp	(revision 2760)
+++ GTP/trunk/App/Demos/Vis/CHC_revisited/chcdemo.cpp	(revision 2762)
@@ -128,5 +128,6 @@
 	//const string filename("house_test.dem");
 	//const string filename("city_demo.dem");
-	const string filename("city.dem");
+	//const string filename("city.dem");
+	const string filename("roofs.dem");
 
 	if (loader.Load(filename, sceneEntities))
@@ -136,5 +137,9 @@
 
 	BvhLoader bvhLoader;
-	bvh = bvhLoader.Load("city.bvh", sceneEntities);
+	bvh = bvhLoader.Load("roofs.bvh", sceneEntities);
+	
+
+	//bvh = bvhLoader.Load("city.bvh", sceneEntities);
+	//bvh = bvhLoader.Load("house_test.bvh", sceneEntities);
 
 	sceneBox = bvh->GetBox();
@@ -171,4 +176,5 @@
 	
 	glDepthFunc(GL_LESS);
+	glEnable(GL_DEPTH_TEST);
 
 	SetupLighting();
@@ -185,4 +191,5 @@
 	//glDisable(GL_CULL_FACE);
 	
+
 	GLfloat ambientColor[] = {0.5, 0.5, 0.5, 1.0};
 	GLfloat diffuseColor[] = {1.0, 0.0, 0.0, 1.0};
@@ -322,6 +329,4 @@
 
 	glMatrixMode(GL_MODELVIEW);
-	glLoadIdentity();	
-
 	camera->SetupCameraView();
 
@@ -389,4 +394,8 @@
 
 	t1 = GetTime();
+
+	traverser->SetCamera(camera);
+
+	//traverser->RenderFrustum();
 
 	glEnableClientState(GL_VERTEX_ARRAY);
@@ -446,5 +455,4 @@
 	
 
-	
 	begin2D();
 	
@@ -473,5 +481,4 @@
 		}
 	}
-
 	end2D();
 
Index: GTP/trunk/App/Demos/Vis/CHC_revisited/BvhLoader.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/CHC_revisited/BvhLoader.cpp	(revision 2761)
+++ GTP/trunk/App/Demos/Vis/CHC_revisited/BvhLoader.cpp	(revision 2762)
@@ -46,6 +46,10 @@
 	stream.read(reinterpret_cast<char *>(&(node->mFirst)), sizeof(int));
 	stream.read(reinterpret_cast<char *>(&(node->mLast)), sizeof(int));
+
 	stream.read(reinterpret_cast<char *>(&bMin), sizeof(Vector3));
 	stream.read(reinterpret_cast<char *>(&bMax), sizeof(Vector3));
+
+	//if ((bMin.x >= bMax.x)||(bMin.y >= bMax.y)||(bMin.z >= bMax.z))
+	//	cout << "error: " << bMin << " " << bMax << endl;
 
 	node->mBox = AxisAlignedBox3(bMin, bMax);
@@ -54,4 +58,5 @@
 
 	//cout << "box: " << node->mBox << " area: " << node->mArea << endl;
+	cout << node->mBox << " f " << node->mFirst << " l " << node->mLast << endl;
 
 	return node;
@@ -107,5 +112,5 @@
 	bvh->PostProcess();
 	// set virtual leaves for 500 triangles
-	bvh->SetVirtualLeaves(500);
+	bvh->SetVirtualLeaves(0);
 
 	bvh->UpdateNumLeaves(bvh->mRoot);
@@ -113,9 +118,9 @@
 	bvh->ComputeIds();
 	// specify bounds for occlusion tests
-	bvh->RecomputeBounds();
+	//bvh->RecomputeBounds();
 	// compute and print stats
 	bvh->ComputeBvhStats();
 	bvh->PrintBvhStats();
-
+bvh->Dummy();
 	return bvh;
 }
Index: GTP/trunk/App/Demos/Vis/CHC_revisited/BinaryLoader.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/CHC_revisited/BinaryLoader.cpp	(revision 2760)
+++ GTP/trunk/App/Demos/Vis/CHC_revisited/BinaryLoader.cpp	(revision 2762)
@@ -173,10 +173,17 @@
 	istr.read(reinterpret_cast<char *>(&shapeCount), sizeof(int));
 
+	geometry.resize(shapeCount);
+
 	int progress = 0;
 
 	for (int i = 0; i < shapeCount; ++ i)
 	{
+		int id;
+		istr.read(reinterpret_cast<char *>(&id), sizeof(int));
+
 		SceneEntity *ent = LoadSceneEntity(istr);
-		geometry.push_back(ent);
+		ent->id = id;
+
+		geometry[id] = ent;
 		
 		int p = (i + 1) * 100 / shapeCount;
@@ -184,5 +191,5 @@
 		if (p >= progress)
 		{
-			cout << "% loaded: " << p << endl;
+			//cout << "% loaded: " << p << endl;
 			progress += 10;
 		}
Index: GTP/trunk/App/Demos/Vis/CHC_revisited/FrustumCullingTraverser.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/CHC_revisited/FrustumCullingTraverser.cpp	(revision 2761)
+++ GTP/trunk/App/Demos/Vis/CHC_revisited/FrustumCullingTraverser.cpp	(revision 2762)
@@ -1,4 +1,6 @@
 #include "FrustumCullingTraverser.h"
 #include "SceneEntity.h"
+
+using namespace std;
 
 
@@ -16,4 +18,5 @@
 	mDistanceQueue.push(mBvh->GetRoot());
 
+
 	int traversed = 0;
 	while (!mDistanceQueue.empty())
@@ -27,6 +30,6 @@
 
 		//bool intersects;
-	
-		if (mBvh->IsWithinViewFrustum(node))
+		int intersect;
+		if (mBvh->IsWithinViewFrustum(node)!=0)
 		{
 			// update node's visited flag => needed for rendering
@@ -36,12 +39,21 @@
 			++ traversed;
 			TraverseNode(node);
+			RenderBox(node->GetBox());
 		}
 		else
-		{
+		{RenderBox(node->GetBox());
+			if (node->IsLeaf()) 
+			{
+			
+			//cout <<"b: " << node->GetBox() << endl;
+			}
 			//mNumFrustumCulledNodes ++;
 		}
+		//cout << "intersect: " << intersect << " bx " << node->GetBox() << endl;
 	}
+		
+	//RenderFrustum();
 
-	std::cout << "traversed: " << traversed << std::endl;
+	//std::cout << "traversed: " << traversed << std::endl;
 }
 
Index: GTP/trunk/App/Demos/Vis/CHC_revisited/RenderTraverser.h
===================================================================
--- GTP/trunk/App/Demos/Vis/CHC_revisited/RenderTraverser.h	(revision 2760)
+++ GTP/trunk/App/Demos/Vis/CHC_revisited/RenderTraverser.h	(revision 2762)
@@ -68,5 +68,5 @@
 	/** Sets the camera.
 	*/
-	void SetCamera(Camera *camera);
+	void SetCamera(Camera *cam)  {mCamera = cam;}
 	/** sets view projection matrix
 	*/
@@ -87,4 +87,6 @@
 	*/
 	void SetRenderState(RenderState *state);
+	
+	void RenderFrustum();
 
 
@@ -117,4 +119,7 @@
 
 	void EnqueueNode(BvhNode *node);
+
+	void RenderBox(const AxisAlignedBox3 &box);
+
 
 
Index: GTP/trunk/App/Demos/Vis/CHC_revisited/AxisAlignedBox3.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/CHC_revisited/AxisAlignedBox3.cpp	(revision 2755)
+++ GTP/trunk/App/Demos/Vis/CHC_revisited/AxisAlignedBox3.cpp	(revision 2762)
@@ -720,48 +720,4 @@
 }
 
-#if TOIMPLEMENT
-int AxisAlignedBox3::Side(const Plane3 &plane) const
-{
-	Vector3 v;
-	int i, m=3, M=-3, s;
-
-	for (i=0;i<8;i++) {
-		GetVertex(i, v);
-		if((s = plane.Side(v)) < m)
-			m=s;
-		if(s > M)
-			M=s;
-		if (m && m==-M)
-			return 0;
-	}
-
-	return (m == M) ? m : m + M;
-}
-
-
-Plane3 AxisAlignedBox3::GetPlane(const int face) const
-{
-	switch (face) 
-	{
-
-	case 0:
-		return Plane3(Vector3(-1, 0, 0), mMin);
-	case 1: 
-		return Plane3(Vector3(1, 0, 0), mMax);
-	case 2:
-		return Plane3(Vector3(0, -1, 0), mMin);
-	case 3:
-		return Plane3(Vector3(0, 1, 0), mMax);
-	case 4:
-		return Plane3(Vector3(0, 0, -1), mMin);
-	case 5:
-		return Plane3(Vector3(0, 0, 1), mMax);
-	}
-
-	// should not come here
-	return Plane3();
-}
-#endif
-
 
 void AxisAlignedBox3::Scale(const float scale) 
@@ -1032,21 +988,29 @@
 }
 
-
+//int AxisAlignedBox3::GetIndexFarthestVertex(const Vector3 &vecPlaneNormal)
 int AxisAlignedBox3::GetIndexNearestVertex(const Vector3 &vecPlaneNormal)
 {
-	int index;
-
-	if (vecPlaneNormal.x > 0.0f)
-		index = (vecPlaneNormal.y > 0.0f) ? 0 : 3;
-	else
-		index = (vecPlaneNormal.y > 0.0f) ? 1 : 2;
-
-	return (vecPlaneNormal.z > 0.0f) ? index : 7 - index;
-}
-
-
+	int x, y, z;
+
+	x = (vecPlaneNormal.x > 0.0f) ? 0 : 1;
+	y = (vecPlaneNormal.y > 0.0f) ? 0 : 1;
+	z = (vecPlaneNormal.z > 0.0f) ? 0 : 1;
+	
+	return 4 * x + 2 * y + z;
+}
+
+
+//int AxisAlignedBox3::GetIndexNearestVertex(const Vector3 &vecPlaneNormal)
 int AxisAlignedBox3::GetIndexFarthestVertex(const Vector3 &vecPlaneNormal)
 {
-	int index;
+	int x, y, z;
+
+	x = (vecPlaneNormal.x <= 0.0f) ? 0 : 1;
+	y = (vecPlaneNormal.y <= 0.0f) ? 0 : 1;
+	z = (vecPlaneNormal.z <= 0.0f) ? 0 : 1;
+	
+	return 4 * x + 2 * y + z;
+
+	/*int index;
 
 	if (vecPlaneNormal.x <= 0.0f)
@@ -1055,5 +1019,5 @@
 		index = (vecPlaneNormal.y <= 0.0f) ? 1 : 2;
 
-	return (vecPlaneNormal.z <= 0.0f) ? index : 7 - index;
+	return (vecPlaneNormal.z <= 0.0f) ? index : 7 - index;*/
 }
 
Index: GTP/trunk/App/Demos/Vis/CHC_revisited/Bvh.h
===================================================================
--- GTP/trunk/App/Demos/Vis/CHC_revisited/Bvh.h	(revision 2761)
+++ GTP/trunk/App/Demos/Vis/CHC_revisited/Bvh.h	(revision 2762)
@@ -440,5 +440,5 @@
 
 public:
-
+void Dummy();
 	/** Destructor.
 	*/
@@ -597,4 +597,8 @@
 	*/
 	void UpdateNumLeaves(BvhNode *node) const;
+	/** Frustum tests the ith plane.
+	*/
+	inline bool TestPlane(BvhNode *node, int i, bool &bIntersect);
+
 
 	////////////////////////
Index: GTP/trunk/App/Demos/Vis/CHC_revisited/Plane3.h
===================================================================
--- GTP/trunk/App/Demos/Vis/CHC_revisited/Plane3.h	(revision 2755)
+++ GTP/trunk/App/Demos/Vis/CHC_revisited/Plane3.h	(revision 2762)
@@ -16,5 +16,5 @@
 	Plane3() {}
 
-	Plane3(Vector3 &normal, float dist);
+	//Plane3(const Vector3 &normal, float dist);
 
 	Plane3(const Vector3 &a, const Vector3 &b, const Vector3 &c);
Index: GTP/trunk/App/Demos/Vis/CHC_revisited/Camera.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/CHC_revisited/Camera.cpp	(revision 2760)
+++ GTP/trunk/App/Demos/Vis/CHC_revisited/Camera.cpp	(revision 2762)
@@ -65,6 +65,6 @@
 void Camera::LookAtBox(const AxisAlignedBox3 &box)
 {
-	mDirection = box.Min() - box.Max();
-	mPosition = box.Max() - mDirection;
+	mDirection = Vector3(0, 0, box.Min().z - box.Max().z);
+	mPosition = Vector3(0);//box.Max() - mDirection;
 
 	Precompute();
@@ -92,8 +92,9 @@
 	GetProjectionMatrix(matProjectionView);
 
-	matProjectionView *= matViewing;
-
-	float fInvLength;
+	matProjectionView = matViewing * matProjectionView;
+	//matProjectionView = matProjectionView * matViewing;
+	
 	float planes[6][4];
+
 
 	//////////
@@ -118,7 +119,8 @@
 		// the clipping planes look outward the frustum,
 		// so distances > 0 mean that a point is outside
-		fInvLength	= -1.0f / sqrt(planes[i][0] * planes[i][0] +	
-								   planes[i][1] * planes[i][1] +	
-								   planes[i][2] * planes[i][2]);
+		float fInvLength = -1.0f / 
+			sqrt(planes[i][0] * planes[i][0] +	
+			     planes[i][1] * planes[i][1] +	
+				 planes[i][2] * planes[i][2]);
 
 		planes[i][0] *= fInvLength;
@@ -127,6 +129,6 @@
 		planes[i][3] *= fInvLength;
 
-		Vector3 normal(planes[i][0], planes[i][1], planes[i][2]);
-		frustum.mClipPlanes[i] = Plane3(normal, planes[i][3]);
+		frustum.mClipPlanes[i].mNormal = Vector3(planes[i][0], planes[i][1], planes[i][2]);
+		frustum.mClipPlanes[i].mD = planes[i][3];
 	}
 }
@@ -156,4 +158,45 @@
 
 
-}
-
+
+void Camera::ComputePoints(Vector3 &ftl, Vector3 &ftr, Vector3 &fbl, Vector3 &fbr,
+						   Vector3 &ntl, Vector3 &ntr, Vector3 &nbl, Vector3 &nbr)
+{
+	float z_near = 0.1f;
+	float z_far = 300;
+
+	const float h_near = 2.0f * tan(mFovy / 2) * z_near;
+	const float w_near = h_near * GetAspect();
+	const float h_far = 2.0f * tan(mFovy / 2) * z_far;
+	const float w_far = h_far * GetAspect();
+
+	const Vector3 view = mDirection;
+	const Vector3 fc = mPosition + view * z_far; 
+	
+	const Vector3 up = mUp;
+
+	const Vector3 right = mRight;
+
+	Vector3 t1, t2;
+
+	t1 = h_far * 0.5f * up;
+	t2 = w_far * 0.5f * right;
+
+	ftl = fc + t1 - t2;
+	ftr = fc + t1 + t2;
+	fbl = fc - t1 - t2;
+	fbr = fc - t1 + t2;
+
+	const Vector3 nc = mPosition + mDirection * z_near;
+	
+	t1 = h_near * 0.5f * up;
+	t2 = w_near * 0.5f * right;
+
+	ntl = nc + t1 - t2;
+	ntr = nc + t1 + t2;
+	nbl = nc - t1 - t2;
+	nbr = nc - t1 + t2;
+}
+
+
+}
+
