Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Transform3.h
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Transform3.h	(revision 3028)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Transform3.h	(revision 3061)
@@ -15,5 +15,5 @@
 
 
-/** Class representing a wrapper class for a 3D transformation
+/** Wrapper class for a 3D transformation
 */
 class Transform3
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Camera.h
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Camera.h	(revision 3045)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Camera.h	(revision 3061)
@@ -39,4 +39,6 @@
 
 
+/** Classs representing a camera.
+*/
 class Camera
 {
@@ -44,17 +46,24 @@
 
 public:
-	
+	/** Default constructor.
+	*/
 	Camera();
-
-	Camera(int width, int height, float fieldOfView = 90.f);
-
+	/** Camera taking the image width and height and the field of view.
+	*/
+	Camera(float aspect, float fieldOfView = 90.f);
 	/** Sets the current camera position.
 	*/
 	void SetPosition(const Vector3 &pos);
-
+	/** See set.
+	*/
 	inline Vector3 GetPosition() const { return mPosition; }
-	
+	/** Returns view direction.
+	*/
 	Vector3 GetDirection() const;
+	/** Returns up vector.
+	*/
 	Vector3 GetUpVector() const;
+	/** Returns right vector.
+	*/
 	Vector3 GetRightVector() const;
 
@@ -62,11 +71,11 @@
 	Vector3 GetBaseUpVector() const;
 	Vector3 GetBaseRightVector() const;
-
-	inline float GetFov() const { return mFovy; }
-	inline float GetAspect() const { return (float) mWidth / mHeight; }
-	inline int GetWidth() const { return mWidth; }
-	inline int GetHeight() const { return mHeight; }
-
-	/** Sets up viewing in gl
+	/** Returns the field of view.
+	*/
+	inline float GetFov() const { return mFOVy; }
+	/** Returns the aspect ratio.
+	*/
+	inline float GetAspect() const { return mAspect; }
+	/** Sets up viewing matrices in for opengl rendering
 	*/
 	void SetupCameraView();
@@ -102,14 +111,23 @@
 	*/
 	void SetFar(float farDist);
-	
-	void SetOrtho(bool ortho);
-
+	/** Sets this camera to orthographic projection.
+	*/
+	//void SetOrtho(bool ortho);
+	/** Set yaw (rotation around vertical axis.
+	*/
 	void Yaw(float angle);
+	/** Set pitch.
+	*/
 	void Pitch(float angle);
-	
+	/** Returns pitch.
+	*/
 	float GetPitch() const { return mPitch; }
+	/** Returns yaw.
+	*/
 	float GetYaw() const { return mYaw; }
+	/** Resets pitch and yaw.
+	*/
 	void ResetPitchAndYaw() { mPitch = 0; mYaw = 0; }
-	/** Sets the camera direction.
+	/** Sets the view direction.
 	*/
 	void SetDirection(const Vector3 &direction);
@@ -117,4 +135,11 @@
 	*/
 	Polyhedron *ComputeFrustum(float farthestVisibleDistance = 1e25f) const;
+	/** Sets up projection matrix in OpenGl.
+	*/
+	void SetupProjection();
+	/** Sets up view + projection matrix in OpenGl.
+	*/
+	void SetupViewProjection();
+
 
 protected:
@@ -133,13 +158,10 @@
 	//-- members
 
-	float mFovy;
-	int mWidth;
-	int mHeight;
-
+	float mFOVy;
 	float mNear;
-
 	float mFar;
-
-	bool mIsOrtho;
+	
+	/// if this camera is orthgraphic or perspective
+	//bool mIsOrtho;
 
 	Matrix4x4 mBaseOrientation;
@@ -150,4 +172,6 @@
 
 	Vector3 mPosition;
+
+	float mAspect;
 };
 
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SceneQuery.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SceneQuery.cpp	(revision 3021)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SceneQuery.cpp	(revision 3061)
@@ -139,6 +139,6 @@
 	const float ylen = mSceneBox.Size().y * 0.5f;
 	
-	Camera *orthoCam = new Camera(xlen, ylen);
-	orthoCam->SetOrtho(true);
+	Camera *orthoCam = new Camera(xlen / ylen);
+	//orthoCam->SetOrtho(true);
 
 	orthoCam->SetNear(0.0f);
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderQueue.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderQueue.cpp	(revision 3060)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderQueue.cpp	(revision 3061)
@@ -14,12 +14,6 @@
 {
 
-
-/*inline static bool CompDist(RenderQueueBucket *b1, RenderQueueBucket *b2)
-{
-	return (b1->mMinDistance < b2->mMinDistance);
-}*/
 RenderQueue::RenderQueue(): 
 mState(NULL), 
-mCamera(NULL),
 mNumEntries(0)
 {
@@ -27,7 +21,6 @@
 
 
-RenderQueue::RenderQueue(RenderState *state, Camera *cam):
+RenderQueue::RenderQueue(RenderState *state):
 mState(state), 
-mCamera(cam),
 mNumEntries(0)
 {
@@ -158,15 +151,9 @@
 	if (bucket->IsEmpty())
 	{
-		// add to currently active buckets that will be rendered
+		// add bucket to the list of currently active buckets that will be rendered
 		// assume that the incoming nodes are ordered by distance 
 		// => active buckets are sorted by distance
 		mActiveBuckets.push_back(bucket);
-	
-		// => set min dist on first incoming node
-		//const Vector3 v = shape->GetCenter() - mCamera->GetPosition();
-		//const float dist = SqrMagnitude(v);
-		//bucket->mMinDistance = dist;
-
-		}
+	}
 
 	bucket->mShapes.push_back(shape);
@@ -178,10 +165,8 @@
 	for (size_t i = 0; i < mActiveBuckets.size(); ++ i)
 	{
-		//mBuckets[i]->mMinDistance = -1;
 		mActiveBuckets[i]->mShapes.clear();
 	}
 
 	mNumEntries = 0;
-
 	mActiveBuckets.clear();
 }
@@ -196,13 +181,10 @@
 void RenderQueue::Render()
 {
-	// sort the buckets
-	//Sort();
-
 	// render all buckets
-	for (size_t i = 0; i < mBuckets.size(); ++ i)
-	{
-		ShapeContainer::const_iterator sit, sit_end = mBuckets[i]->mShapes.end();
-
-		for (sit = mBuckets[i]->mShapes.begin(); sit != sit_end; ++ sit)
+	for (size_t i = 0; i < mActiveBuckets.size(); ++ i)
+	{
+		ShapeContainer::const_iterator sit, sit_end = mActiveBuckets[i]->mShapes.end();
+
+		for (sit = mActiveBuckets[i]->mShapes.begin(); sit != sit_end; ++ sit)
 		{
 			Shape *shape = *sit;
@@ -210,36 +192,6 @@
 		}
 	}
-	//Print();
-}
-
-
-void RenderQueue::Print()
-{
-	for (size_t i = 0; i < mBuckets.size(); ++ i)
-	{
-		Debug << "\n******\nbucket " << (int)i << endl;
-
-		ShapeContainer::const_iterator sit, sit_end = mBuckets[i]->mShapes.end();
-
-		for (sit = mBuckets[i]->mShapes.begin(); sit != sit_end; ++ sit)
-		{
-			Shape *shape = *sit;
-			
-			Technique *tech = shape->GetMaterial()->GetTechnique(mState->GetRenderTechnique());
-			int tsize = tech->GetTexture() ? tech->GetTexture()->GetByteSize() : 0;
-			
-			float dist = SqrMagnitude(shape->GetBoundingBox().Center() - mCamera->GetPosition());
-			
-			Debug << "e: " << shape << " a: " << tech->IsAlphaTestEnabled() << " s: " << tsize << " d: " << dist << " " << endl;
-		}
-	}
-}
-
-
-/*void RenderQueue::Sort()
-{
-	// sort buckets itself by distance
-	sort(mBuckets.begin(), mBuckets.end(), CompDist);
-}*/
+	//cout << "active: " << (int)mActiveBuckets.size() << endl;
+}
 
 
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Shape.h
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Shape.h	(revision 3054)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Shape.h	(revision 3061)
@@ -22,6 +22,6 @@
 
 
-/** Class representing a shape.
-    A shape basically consists of geometry and a material
+/** Class representing a 3D shape consisting 
+	of geometry (with texture coordinates, normals) and a material
 */
 class Shape
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Bvh.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Bvh.cpp	(revision 3053)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Bvh.cpp	(revision 3061)
@@ -1189,5 +1189,5 @@
 		// no split could be achieved => just halve number of objects
 		split = (leaf->mLast - leaf->mFirst) / 2;
-		cerr << "no reduction " << leaf->CountPrimitives() << " " << leaf->mFirst << " " << split << " " << leaf->mLast << endl;
+		cerr << "no reduction " << leaf->CountPrimitives() << " " << leaf->mFirst << " " << leaf->mLast << endl;
 	}
 
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderState.h
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderState.h	(revision 3055)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderState.h	(revision 3061)
@@ -13,5 +13,5 @@
 class Material;
 
-/** The current render state.
+/** Class representing the current render state.
 */
 class RenderState
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderQueue.h
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderQueue.h	(revision 3060)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderQueue.h	(revision 3061)
@@ -63,7 +63,7 @@
 	*/
 	RenderQueue();
-	/** Constructor taking a render queue
+	/** Constructor passing the current render state
 	*/
-	RenderQueue(RenderState *state, Camera *cam);
+	RenderQueue(RenderState *state);
 
 	~RenderQueue();
@@ -77,7 +77,4 @@
 	*/
 	void SetRenderState(RenderState *state);
-	/** Sets the current render state
-	*/
-	void SetCamera(Camera *cam);
 	/** Returns the number of entries currently in the queue.
 	*/
@@ -98,7 +95,4 @@
 	*/
 	void Render();
-	/** Prints the current state of the render queue.
-	*/
-	void Print();
 
 
@@ -108,6 +102,4 @@
 	// the current render state
 	RenderState *mState;
-	
-	Camera *mCamera;
 	/// each bucket contains objects with similar materials that don't cause a hard state change
 	std::vector<RenderQueueBucket *> mBuckets;
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShadowMapping.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShadowMapping.cpp	(revision 3038)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShadowMapping.cpp	(revision 3061)
@@ -148,6 +148,6 @@
 
 
-	mShadowCam = new Camera(mSize, mSize);
-	mShadowCam->SetOrtho(true);
+	mShadowCam = new Camera(1);
+	//mShadowCam->SetOrtho(true);
 }
 
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp	(revision 3059)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp	(revision 3061)
@@ -369,5 +369,5 @@
 	///////////////////////////
 
-	camera = new Camera(winWidth, winHeight, fov);
+	camera = new Camera(winWidth / winHeight, fov);
 	camera->SetNear(nearDist);
 	camera->SetFar(1000);
@@ -376,5 +376,5 @@
 	camera->SetPosition(camPos);
 
-	visCamera = new Camera(winWidth, winHeight, fov);
+	visCamera = new Camera(winWidth / winHeight, fov);
 	visCamera->SetNear(0.0f);
 	visCamera->Yaw(.5 * M_PI);
@@ -382,7 +382,6 @@
 	// create a new light
 	light = new DirectionalLight(lightDir, RgbaColor(1, 1, 1, 1), RgbaColor(1, 1, 1, 1));
-
-
-	renderQueue = new RenderQueue(&state, camera);
+	// the render queue for material sorting
+	renderQueue = new RenderQueue(&state);
 
 	glutInitWindowSize(winWidth, winHeight);
@@ -761,13 +760,7 @@
 	oldViewProjMat = viewProjMat;
 
-	glMatrixMode(GL_PROJECTION);
-	glLoadIdentity();
-	gluPerspective(fov, winAspectRatio, nearDist, farDist);
-
-	glMatrixMode(GL_MODELVIEW);
-	
-	// set up the camera view
-	camera->SetupCameraView();
-		
+	camera->SetupViewProjection();
+
+
 	/////////////////
 	//-- compute view projection matrix and store for later use
@@ -1581,5 +1574,4 @@
 
 	glLoadIdentity();
-	
 	glOrtho(-offs, offs, -offs, offs, 0.0f, box.Size().z * 100.0f); 
 
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Camera.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Camera.cpp	(revision 2988)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Camera.cpp	(revision 3061)
@@ -18,8 +18,6 @@
 Camera::Camera() 
 {
-	mWidth = 100;
-	mHeight = 100;
-	mFovy = 60.0f * M_PI / 180.0f;
-	mIsOrtho = false;
+	mFOVy = 60.0f * M_PI / 180.0f;
+	//mIsOrtho = false;
 	
 	SetPosition(Vector3(0, 0, 0));
@@ -32,12 +30,9 @@
 
 
-Camera::Camera(int width, int height, float fieldOfView) 
-{
-	mWidth = width;
-	mHeight = height;
-	
-	mFovy = fieldOfView * M_PI / 180.0f;
-
-	mIsOrtho = false;
+Camera::Camera(float aspect, float fieldOfView) 
+{
+	mFOVy = fieldOfView * M_PI / 180.0f;
+	mAspect = aspect;
+	//mIsOrtho = false;
 
 	SetPosition(Vector3::ZERO());
@@ -53,9 +48,6 @@
 {
 	Vector3 up = Vector3::UNIT_Z();
-	//Vector3 right = Normalize(CrossProd(dir, up));
-	//up = Normalize(CrossProd(right, dir));
-
-	//mBaseOrientation = Matrix4x4(right, up, -dir);
-	mBaseOrientation = LookAt(Vector3::ZERO(), dir, up);//Matrix4x4(right, up, -dir);
+	
+	mBaseOrientation = LookAt(Vector3::ZERO(), dir, up);
 	mViewOrientation = mBaseOrientation;
 }
@@ -128,4 +120,22 @@
 		frustum.mClipPlanes[i].mNormal *= invLength;
 	}
+}
+
+
+void Camera::SetupViewProjection()
+{
+	glMatrixMode(GL_PROJECTION);
+	SetupProjection();
+
+	glMatrixMode(GL_MODELVIEW);
+	// set up the view matrix
+	SetupCameraView();
+}
+
+
+void Camera::SetupProjection()
+{
+	glLoadIdentity();
+	gluPerspective(mFOVy * 180.0f / M_PI, mAspect, mNear, mFar);
 }
 
@@ -147,8 +157,8 @@
 								   float farthestVisibleDistance) const
 {
-	float z_near = mNear;
-	float z_far = min(mFar, farthestVisibleDistance);
-
-	float fov = mFovy;
+	const float z_near = mNear;
+	const float z_far = min(mFar, farthestVisibleDistance);
+
+	const float fov = mFOVy;
 
 	const float aspectRatio = GetAspect();
@@ -162,4 +172,5 @@
 	const Vector3 fc = pos + view * z_far; 
 	
+
 	Vector3 t1, t2;
 
@@ -194,8 +205,8 @@
 
 
-void Camera::SetOrtho(bool ortho)
-{
-	mIsOrtho = true;
-}
+/*void Camera::SetOrtho(bool ortho)
+{
+	mIsOrtho = ortho;
+}*/
 
 
