Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Visualization.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Visualization.cpp	(revision 2782)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Visualization.cpp	(revision 2787)
@@ -4,4 +4,6 @@
 #include "SceneEntity.h"
 #include "Bvh.h"
+#include "RenderState.h"
+
 #include <stack>
 
@@ -22,5 +24,9 @@
 							 Camera *vizCamera, 
 							 RenderState *renderState): 
-mBvh(bvh), mCamera(camera), mVizCamera(vizCamera), mRenderState(renderState)
+mBvh(bvh), 
+mCamera(camera),
+mVizCamera(vizCamera),
+mRenderState(renderState),
+mFrameId(0)
 {
 }
@@ -36,4 +42,10 @@
 {
 	mRenderState = state;
+}
+
+
+void Visualization::SetFrameId(int frameId)
+{
+	mFrameId = frameId;
 }
 
@@ -43,4 +55,9 @@
 	stack<BvhNode *> tStack;
 	tStack.push(mBvh->GetRoot());
+
+	glEnableClientState(GL_VERTEX_ARRAY);
+	glEnableClientState(GL_NORMAL_ARRAY);
+
+	RenderFrustum();
 
 	while (!tStack.empty())
@@ -58,7 +75,23 @@
 		else
 		{
+			if (node->GetLastRenderedFrame() == mFrameId)
+			{
+				int geometrySize;
+				SceneEntity **entities = mBvh->GetGeometry(node, geometrySize);
+
+				for (int i = 0; i < geometrySize; ++ i)
+				{
+					SceneEntity *ent = entities[i];
+					ent->Render(mRenderState);
+				}		
+			}
 			//leaves.push_back(static_cast<BvhLeaf *>(node));
 		}
 	}
+
+	mRenderState->Reset();
+
+	glDisableClientState(GL_VERTEX_ARRAY);
+	glDisableClientState(GL_NORMAL_ARRAY);
 }
 
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp	(revision 2786)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp	(revision 2787)
@@ -85,4 +85,8 @@
 bool useMultiQueries = true;
 
+float rotation = 0;
+
+Matrix4x4 visView = IdentityMatrix();
+
 
 void InitExtensions();
@@ -108,6 +112,6 @@
 void rightMotion(int x, int y);
 void middleMotion(int x, int y);
-void drawEyeView(void);
-void setupVisView(void);
+void drawEyeView();
+void setupVisView();
 void CalcDecimalPoint(std::string &str, int d);
 void ResetTraverser();
@@ -185,4 +189,6 @@
 	camera->SetPosition(Vector3(483.398f, 242.364f, 186.078f));
 
+	visualization = new Visualization(bvh, camera, NULL, &state);
+
 	glutMainLoop();
 
@@ -229,5 +235,4 @@
 	glMaterialfv(GL_FRONT, GL_DIFFUSE, diffuseColor);
 	glMaterialfv(GL_FRONT, GL_SPECULAR, specularColor);
-	//setupVisView();
 }
 
@@ -409,9 +414,8 @@
 	SetupEyeView();
 
-	//cout << camera->GetDirection() << " " << camera->GetPosition() << endl;
 	// actually render the scene geometry using one of the specified algorithms
 	traverser->RenderScene();
 	
-	//if(visMode) displayVisualization();
+	if (visMode) DisplayVisualization();
 	
 	DisplayStats();
@@ -478,11 +482,8 @@
 	case '2':
 		visZoomFactor += 0.1;	
-		setupVisView();
 		break;
 	case '3':
 		visZoomFactor -= 0.1;
-		if(visZoomFactor < 0.1) visZoomFactor = 0.1;
-	
-		setupVisView();
+		if (visZoomFactor < 0.1) visZoomFactor = 0.1;
 		break;
 	case '8':
@@ -561,5 +562,5 @@
 
 
-void special(const int c, const int x, const int y) 
+void special(int c, int x, int y) 
 {
 	// used to avoid vertical motion with the keys
@@ -677,4 +678,6 @@
 	eyeXAngle = 0.2f *  M_PI * (xEyeBegin - x) / 180.0;
 
+	rotation += eyeXAngle;
+
 	// rotate view vector
 	Matrix4x4 rot = RotationZMatrix(eyeXAngle);
@@ -802,7 +805,11 @@
 
 
-// displays the visualisation of the kd tree node culling
-void displayVisualization()
-{
+// displays the visualisation of culling algorithm
+void DisplayVisualization()
+{
+	setupVisView();
+
+	visualization->SetFrameId(traverser->GetCurrentFrameId());
+	
 	begin2D();
 	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
@@ -816,10 +823,29 @@
 	glViewport(winWidth / 2, winHeight / 2, winWidth, winHeight);
 	glPushMatrix();
-	//glLoadMatrixf((float *)visView.x);
-	
+	//glMatrixMode(GL_PROJECTION);
+	glMatrixMode(GL_MODELVIEW);
+	glLoadIdentity();
+
+	Vector3 pos(camera->GetPosition());
+    pos.z = 10.0f * bvh->GetBox().Size().z;
+	pos.y = 800;
+	pos.x += 1000;
+
+	Matrix4x4 m = RotationZMatrix(-rotation);
+	Matrix4x4 t = TranslationMatrix(pos);
+	Matrix4x4 minust = TranslationMatrix(-pos);
+
+	glMultMatrixf((float *)visView.x);
+
+	glMultMatrixf((float *)t.x);
+	glMultMatrixf((float *)m.x);
+	glMultMatrixf((float *)minust.x);
+
 	glClear(GL_DEPTH_BUFFER_BIT);
 
 	////////////
-	// --- visualization of the occlusion culling
+	//-- visualization of the occlusion culling
+
+	//traverser->RenderScene();
 	visualization->Render();
 	
@@ -835,15 +861,23 @@
 void setupVisView()
 {
-	const Vector3 up(0.0, 0.0, 1.0);
-	
-	Vector3 visPos(24, 23, -6);
-	
-	visPos[0] *= visZoomFactor; 
-	visPos[1] *= visZoomFactor; 
-	visPos[2] *= visZoomFactor;
-
-	Vector3 visDir = Vector3(-1.3f, -1, -1);
-}
-
+	Vector3 pos(-camera->GetPosition());
+    pos.z = -10.0f * bvh->GetBox().Size().z;
+	pos.y += 800;
+	pos.x -= 1000;
+
+	Vector3 dir(0, 0, 1);
+	Vector3 up(0, 1, 0);
+	//Vector3 up(camera->GetDirection());up.y = 0;
+
+	Vector3 left = Normalize(CrossProd(dir, up));
+	up = Normalize(CrossProd(left, dir));
+
+	visView = Matrix4x4(up, left, dir);
+	pos = visView * pos;
+
+	visView.x[3][0] = pos.x;
+	visView.x[3][1] = pos.y;
+	visView.x[3][2] = pos.z;
+}
 
 // cleanup routine after the main loop
@@ -855,4 +889,5 @@
 	DEL_PTR(bvh);
 	DEL_PTR(visualization);
+	DEL_PTR(camera);
 }
 
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Visualization.h
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Visualization.h	(revision 2782)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Visualization.h	(revision 2787)
@@ -39,5 +39,7 @@
 	*/
 	void SetRenderState(RenderState *state);
-	
+	/** Sets the currentframe id
+	*/
+	void SetFrameId(int frameId);
 
 protected:
@@ -63,4 +65,6 @@
 	/// the current render state
 	RenderState *mRenderState;
+	/// the current frame id
+	int mFrameId;
 };
 
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderTraverser.h
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderTraverser.h	(revision 2786)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderTraverser.h	(revision 2787)
@@ -79,4 +79,7 @@
 	*/
 	const TraversalStatistics &GetStats() const { return mStats; }
+	/** The current frame id
+	*/
+	int GetCurrentFrameId() const { return mFrameId; }
 
 
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Bvh.h
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Bvh.h	(revision 2786)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Bvh.h	(revision 2787)
@@ -156,5 +156,5 @@
 	
 	/// some flags
-	int mFlags;
+	//int mFlags;
 	/// the depth of this node
 	unsigned char mDepth;
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Camera.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Camera.cpp	(revision 2782)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Camera.cpp	(revision 2787)
@@ -29,13 +29,11 @@
 	mDirection.Normalize();
 
-	//Vector3 side = CrossProd(Vector3(0, 1, 0), mDirection);
-	Vector3 side = CrossProd(Vector3(0, 0, 1), mDirection);
-	
+	/*Vector3 side = CrossProd(Vector3(0, 0, 1), mDirection);
 	mUp = -Normalize(CrossProd(side, mDirection));
-	mRight = -Normalize(CrossProd(mDirection, mUp));
-
-	/*float k = tan(mFovy/2);
-	mUp *= k;
-	mRight *= k*mWidth/mHeight;*/
+	mRight = -Normalize(CrossProd(mDirection, mUp));*/
+
+	mUp = Vector3(0, 0, 1);
+	mRight = -CrossProd(mDirection, mUp);
+	mUp = -Normalize(CrossProd(mRight, mDirection));
 }
 
@@ -179,9 +177,9 @@
 	const float w_far = h_far * GetAspect();
 
+	//const Vector3 view = mDirection;
 	const Vector3 view = mDirection;
 	const Vector3 fc = mPosition + view * z_far; 
 	
 	const Vector3 up = mUp;
-
 	const Vector3 right = mRight;
 
