Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Matrix4x4.h
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Matrix4x4.h	(revision 2915)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Matrix4x4.h	(revision 2916)
@@ -155,5 +155,5 @@
 Vector3 GetTranslation(const Matrix4x4 &M);
 Matrix4x4 GetFittingProjectionMatrix(const AxisAlignedBox3 &box);
-
+Matrix4x4 GetFrustum(float left, float right, float bottom, float top, float near, float far);
 
 }
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Vector3.h
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Vector3.h	(revision 2911)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Vector3.h	(revision 2916)
@@ -47,5 +47,5 @@
 	{}
 
-	Vector3(float v): x(v), y(v), z(v){}
+	explicit Vector3(float v): x(v), y(v), z(v){}
 	/** Copy constructor.
 	*/
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShadowMapping.h
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShadowMapping.h	(revision 2915)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShadowMapping.h	(revision 2916)
@@ -64,6 +64,6 @@
 	Polyhedron *CalcClippedFrustum(const AxisAlignedBox3 &box) const;
 	
-	bool CalcLightProjectionLispSM(Matrix4x4 &lightProj);
 	bool CalcLightProjection(Matrix4x4 &lightProj);
+	Matrix4x4 ShadowMap::CalcLispSMTransform(const Matrix4x4 &lightProjView);
 
 	void IncludeLightVolume(const Polyhedron &polyhedron, 
@@ -71,4 +71,6 @@
 							const Vector3 lightDir,
 							const AxisAlignedBox3 &sceneBox);
+
+	float ComputeN() const;
 
 
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShadowMapping.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShadowMapping.cpp	(revision 2915)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShadowMapping.cpp	(revision 2916)
@@ -166,6 +166,20 @@
 
 
-bool ShadowMap::CalcLightProjectionLispSM(Matrix4x4 &lightProj)
-{
+float ShadowMap::ComputeN() const 
+{
+	const float n = mShadowCam->GetNear();
+	const float f = mShadowCam->GetFar();
+
+	const float d = fabs(f - n);
+	
+	const float dotProd = DotProd(mCamera->GetDirection(), mShadowCam->GetDirection());
+	const float sinGamma = sin(fabs(acos(dotProd)));
+
+	return (n + sqrt(n * (n + d * sinGamma))) /  sinGamma;
+}
+
+
+Matrix4x4 ShadowMap::CalcLispSMTransform(const Matrix4x4 &lightProjView)
+{/*
 	Matrix4x4 lispMtx = IdentityMatrix();
 
@@ -212,17 +226,7 @@
 	//-- We apply the lispsm algorithm in order to calculate an optimal light projection matrix
 
-	// use lispsm formulas
-	const float fac = 1.0f / sinGamma;
-	
-	const float z_n = fac * mCamera->GetNear();
-
-	// light space y size
-	const float d = fabs(extremalPoints.Max()[1] - extremalPoints.Min()[1]); 
-
-	const float z_f = z_n + d * sinGamma;
-
-	// this is the famous n parameter
-	const float n = (z_n + sqrt(z_f * z_n)) /sinGamma;
-	const float f = n + d;
+	const float n = 1e20f;//ComputeN();
+
+	cout << "n: " << n << endl;
 
 	const Vector3 nearPt = mShadowCam->GetNear() * mShadowCam->GetDirection() + mShadowCam->GetPosition();
@@ -232,28 +236,17 @@
 
 	//c start has the x and y coordinate of e, the z coord of B.min()
-	const Vector3 startPt = Vector3(lsNear.x, lsNear.y, extremalPoints.Max().z);
+	const Vector3 startPt = Vector3(lsNear.x, lsNear.y, extremalPoints.Min().y);
 
 	// the new projection center
-	Vector3	projCenter = startPt - Vector3(0, 0, 1) * n;
+	const Vector3 unit_y = Vector3(0, 1, 0);
+	Vector3	projCenter = startPt - unit_y * n;
 
 	//construct a translation that moves to the projection center
 	const Matrix4x4 projectionCenter = TranslationMatrix(-projCenter);
 
-	lightProj = IdentityMatrix();
-
-	//one possibility for a simple perspective transformation matrix
-	//with the two parameters n(near) and f(far) in y direction
-	
-	// a = (f+n)/(f-n); b = -2*f*n/(f-n);
-	// [ 1 0 0 0]
-	// [ 0 a 0 b]
-	// [ 0 0 1 0]
-	// [ 0 1 0 0]
-
-	lightProj.x[1][1] = (f + n) / (f - n);		 
-	lightProj.x[1][3] = 1.0f;
-
-	lightProj.x[3][1] = -2.0f * f * n / (f - n);		
-	lightProj.x[3][3] = 0.0f;				
+	// light space y size
+	const float d = fabs(extremalPoints.Max()[2] - extremalPoints.Min()[2]); 
+
+	lightProj = GetFrustum(-1.0, 1.0, -1.0, 1.0, n, n + d);
 
 	cout << "here4\n" << lightProj << endl;
@@ -270,6 +263,6 @@
 	cout << "max: " << lightProj * pmax << endl;
 	
-
-	return true;
+*/
+	return IdentityMatrix();
 }
 
@@ -313,7 +306,11 @@
 	}
 
+	//Matrix4x4 m = CalcLispSMTransform(lightProj);
+
 	// focus projection matrix on the extremal points
 	lightProj = GetFittingProjectionMatrix(extremalPoints);
 
+	//Matrix4x4 scale = ScaleMatrix(1, 1, -1); lightProj *= scale;
+	
 	return true;
 }
@@ -408,5 +405,4 @@
 	glEnable(GL_DEPTH_TEST);
 
-	
 	// setup projection
 	/*glMatrixMode(GL_PROJECTION);
@@ -418,10 +414,9 @@
 	cout << "old:\n" << dummyMat << endl;
 	*/
+
 	Matrix4x4 lightView, lightProj;
 
 	mShadowCam->GetModelViewMatrix(lightView);
-
-	//CalcLightProjection(lightProj);
-	CalcLightProjectionLispSM(lightProj);
+	CalcLightProjection(lightProj);
 
 	glMatrixMode(GL_PROJECTION);
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Matrix4x4.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Matrix4x4.cpp	(revision 2915)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Matrix4x4.cpp	(revision 2916)
@@ -655,24 +655,4 @@
 	Matrix4x4 m;
 
-/*	m.x[0][0] = 2.0f / (box.Max()[0] - box.Min()[0]);
-	m.x[1][0] = .0f;
-	m.x[2][0] = .0f;
-	m.x[3][0] = -(box.Max()[0] + box.Min()[0]) / (box.Max()[0] - box.Min()[0]);
-
-	m.x[0][1] = .0f;
-	m.x[1][1] = 2.0f / (box.Max()[1] - box.Min()[1]);
-	m.x[2][1] = .0f;
-	m.x[3][1] = -(box.Max()[1] + box.Min()[1]) / (box.Max()[1] - box.Min()[1]);
-
-	m.x[0][2] = .0f;
-	m.x[1][2] = .0f;
-	m.x[2][2] = 2.0f / (box.Max()[2] - box.Min()[2]);
-	m.x[3][2] = -(box.Max()[2] + box.Min()[2]) / (box.Max()[2] - box.Min()[2]);
-
-	m.x[0][3] = .0f;
-	m.x[1][3] = .0f;
-	m.x[2][3] = .0f;
-	m.x[3][3] = 1.0f;*/
-
 	m.x[0][0] = -2.0f / (box.Max()[0] - box.Min()[0]);
 	m.x[0][1] = .0f;
@@ -698,4 +678,31 @@
 }
 
+/*
+Matrix4x4 GetFittingProjectionMatrix(const AxisAlignedBox3 &box)
+{
+	Matrix4x4 m;
+
+	m.x[0][0] = 2.0f / (box.Max()[0] - box.Min()[0]);
+	m.x[0][1] = .0f;
+	m.x[0][2] = .0f;
+	m.x[0][3] = .0f;
+
+	m.x[1][0] = .0f;
+	m.x[1][1] = 2.0f / (box.Max()[1] - box.Min()[1]);
+	m.x[1][2] = .0f;
+	m.x[1][3] = .0f;
+
+	m.x[2][0] = .0f;
+	m.x[2][1] = .0f;
+	m.x[2][2] = 2.0f / (box.Max()[2] - box.Min()[2]);
+	m.x[2][3] = .0f;
+
+	m.x[3][0] = -(box.Max()[0] + box.Min()[0]) / (box.Max()[0] - box.Min()[0]);
+	m.x[3][1] = -(box.Max()[1] + box.Min()[1]) / (box.Max()[1] - box.Min()[1]);
+	m.x[3][2] = -(box.Max()[2] + box.Min()[2]) / (box.Max()[2] - box.Min()[2]);
+	m.x[3][3] = 1.0f;
+
+	return m;
+}*/
 
 //output is initialized with the same result as glFrustum
