Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Matrix4x4.h
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Matrix4x4.h	(revision 2916)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Matrix4x4.h	(revision 2917)
@@ -114,4 +114,7 @@
 	friend Matrix4x4 GetFrustum(float left, float right, float bottom, float top, float near, float far);
 
+	// look from position into given direction with given up vector
+	Matrix4x4 LookAt(const Vector3 &pos, const Vector3 &dir, const Vector3& up);
+
 	// Overloaded output operator.
 	friend std::ostream& operator<< (std::ostream &s, const Matrix4x4 &M);
@@ -156,5 +159,5 @@
 Matrix4x4 GetFittingProjectionMatrix(const AxisAlignedBox3 &box);
 Matrix4x4 GetFrustum(float left, float right, float bottom, float top, float near, float far);
-
+Matrix4x4 LookAt(const Vector3 &pos, const Vector3 &dir, const Vector3& up);
 }
 
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShadowMapping.h
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShadowMapping.h	(revision 2916)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShadowMapping.h	(revision 2917)
@@ -65,5 +65,5 @@
 	
 	bool CalcLightProjection(Matrix4x4 &lightProj);
-	Matrix4x4 ShadowMap::CalcLispSMTransform(const Matrix4x4 &lightProjView);
+	Matrix4x4 CalcLispSMTransform(const Matrix4x4 &lightProjView, const AxisAlignedBox3 &bounds);
 
 	void IncludeLightVolume(const Polyhedron &polyhedron, 
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShadowMapping.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShadowMapping.cpp	(revision 2916)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShadowMapping.cpp	(revision 2917)
@@ -180,10 +180,51 @@
 
 
-Matrix4x4 ShadowMap::CalcLispSMTransform(const Matrix4x4 &lightProjView)
-{/*
-	Matrix4x4 lispMtx = IdentityMatrix();
-
-	const float dotProd = DotProd(mCamera->GetDirection(), mShadowCam->GetDirection());
-	const float sinGamma = sqrt(1.0f - dotProd * dotProd);
+Matrix4x4 ShadowMap::CalcLispSMTransform(const Matrix4x4 &lightProjView, const AxisAlignedBox3 &extremalPoints)
+{
+	Matrix4x4 lispMtx;
+
+	///////////////
+	//-- We apply the lispsm algorithm in order to calculate an optimal light projection matrix
+
+	const float n = 1e20f;//ComputeN();
+
+	cout << "n: " << n << endl;
+
+	const Vector3 nearPt = mShadowCam->GetNear() * mShadowCam->GetDirection() + mShadowCam->GetPosition();
+
+	//get the coordinates of the near camera point in light space
+	const Vector3 lsNear = lightProjView * nearPt;
+
+	//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.Min().y);
+
+	// the new projection center
+	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);
+
+	// light space y size
+	const float d = fabs(extremalPoints.Max()[2] - extremalPoints.Min()[2]); 
+
+	lispMtx = GetFrustum(-1.0, 1.0, -1.0, 1.0, n, n + d);
+
+	cout << "lispsm\n" << lispMtx << endl;
+
+	lispMtx *= projectionCenter;
+
+	// transform into OpenGL right handed system
+	Matrix4x4 scale = ScaleMatrix(1.0f, 1.0f, -1.0f);
+
+	lispMtx *= scale;
+	
+	return IdentityMatrix();
+}
+
+
+bool ShadowMap::CalcLightProjection(Matrix4x4 &lightProj)
+{
+	DEL_PTR(polyhedron);
 
 
@@ -191,5 +232,4 @@
 	//-- First step: calc frustum clipped by scene box
 
-	DEL_PTR(polyhedron);
 	polyhedron = CalcClippedFrustum(mSceneBox);
 
@@ -222,94 +262,26 @@
 	}
 
-
-	///////////////
-	//-- We apply the lispsm algorithm in order to calculate an optimal light projection matrix
-
-	const float n = 1e20f;//ComputeN();
-
-	cout << "n: " << n << endl;
-
-	const Vector3 nearPt = mShadowCam->GetNear() * mShadowCam->GetDirection() + mShadowCam->GetPosition();
-
-	//get the coordinates of the near camera point in light space
-	const Vector3 lsNear = lightView * nearPt;
-
-	//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.Min().y);
-
-	// the new projection center
-	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);
-
-	// 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;
-
-	// transform into OpenGL right handed system
-	Matrix4x4 scale = ScaleMatrix(1.0f, 1.0f, -1.0f);
-
-	lightProj = projectionCenter * scale * lightProj;
-
-	Vector3 pmax = extremalPoints.Max();
-	Vector3 pmin = extremalPoints.Min();
-
-	cout << "min: " << lightProj * pmin << endl;
-	cout << "max: " << lightProj * pmax << endl;
-	
-*/
-	return IdentityMatrix();
-}
-
-
-bool ShadowMap::CalcLightProjection(Matrix4x4 &lightProj)
-{
-	DEL_PTR(polyhedron);
-
-
-	///////////////////
-	//-- First step: calc frustum clipped by scene box
-
-	polyhedron = CalcClippedFrustum(mSceneBox);
-
-	if (!polyhedron) return false; // something is wrong
-
-	// include the part of the light volume that "sees" the frustum
-	// we only require frustum vertices
-
-	VertexArray frustumPoints;
-	IncludeLightVolume(*polyhedron, frustumPoints, mShadowCam->GetDirection(), mSceneBox);
-
-
-	///////////////
-	//-- transform points from world view to light view and calculate extremal points
-
-	AxisAlignedBox3 extremalPoints;
-	extremalPoints.Initialize();
-
-	Matrix4x4 lightView;
-	mShadowCam->GetModelViewMatrix(lightView);
-
-	VertexArray::const_iterator it, it_end = frustumPoints.end();
-		
-	for (it = frustumPoints.begin(); it != it_end; ++ it)
-	{
-		Vector3 pt = *it;
-		pt = lightView * pt;
-
-		extremalPoints.Include(pt);
-	}
-
-	//Matrix4x4 m = CalcLispSMTransform(lightProj);
-
-	// focus projection matrix on the extremal points
-	lightProj = GetFittingProjectionMatrix(extremalPoints);
-
-	//Matrix4x4 scale = ScaleMatrix(1, 1, -1); lightProj *= scale;
+	lightProj = IdentityMatrix(); // we use directional lights
+
+	Matrix4x4 shadowView;
+	mShadowCam->GetModelViewMatrix(shadowView);
+
+	//do Light Space Perspective shadow mapping
+	//rotate the lightspace so that the proj light view always points upwards
+	//calculate a frame matrix that uses the projViewDir[light-space] as up vector
+	//look(from position, into the direction of the projected direction, with unchanged up-vector)
+	//lightProj = Math::look<REAL>(M4(),V3::ZERO(),projViewDir,V3::UNIT_Y())*lightProj
+
+	const Matrix4x4 matLispSM = 
+		CalcLispSMTransform(shadowView * lightProj, extremalPoints);
+
+	lightProj *= matLispSM;
+
+	// focus projection matrix on the extremal points => scale to unit cube
+	lightProj *= GetFittingProjectionMatrix(extremalPoints);
+
+	// we have to flip the signs in order tp opengl style projection matrix
+	Matrix4x4 scale = ScaleMatrix(-1, -1, -1); 
+	lightProj *= scale;
 	
 	return true;
@@ -339,9 +311,4 @@
 	sides[5][0] = ftl; sides[5][1] = ftr; sides[5][2] = fbr; sides[5][3] = fbl; 
 
-	//sides[4][0] = ntl; sides[4][1] = ntr; sides[4][2] = nbr; sides[4][3] = nbl; 
-	//sides[5][0] = ftr; sides[5][1] = ftl; sides[5][2] = fbl; sides[5][3] = fbr;
-
-
-
 	//////////
 	//-- compute polyhedron
@@ -424,5 +391,7 @@
 	glLoadMatrixf((float *)lightProj.x);
 
-	cout << "new:\n" << lightProj << endl;
+	mLightProjView = lightView * lightProj;
+
+	//cout << "new:\n" << lightProj << endl;
 
 	glMatrixMode(GL_MODELVIEW);
@@ -431,6 +400,4 @@
 
 	mShadowCam->SetupCameraView();
-
-	mLightProjView = lightView * lightProj;
 
 
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Matrix4x4.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Matrix4x4.cpp	(revision 2916)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Matrix4x4.cpp	(revision 2917)
@@ -655,32 +655,4 @@
 	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;
-}
-
-/*
-Matrix4x4 GetFittingProjectionMatrix(const AxisAlignedBox3 &box)
-{
-	Matrix4x4 m;
-
 	m.x[0][0] = 2.0f / (box.Max()[0] - box.Min()[0]);
 	m.x[0][1] = .0f;
@@ -704,5 +676,6 @@
 
 	return m;
-}*/
+}
+
 
 //output is initialized with the same result as glFrustum
@@ -734,7 +707,27 @@
 	m.x[3][2] = 2.0f * near * far * zDif;
 	m.x[3][3] = .0f;
-}
-
-
-
-}
+
+	return m;
+}
+
+
+Matrix4x4 LookAt(const Vector3 &pos, const Vector3 &dir, const Vector3& up) 
+{
+	const Vector3 nDir = Normalize(dir);
+	
+	Vector3 nUp = Normalize(up);
+
+	Vector3 nRight = Normalize(CrossProd(nDir, nUp));
+	nUp = Normalize(CrossProd(nRight, nDir));
+
+	Matrix4x4 m;
+	Matrix4x4(nRight, nUp, -nDir);
+
+	m.x[3][0] = -DotProd(nRight, pos);
+	m.x[3][1] = -DotProd(nUp, pos);
+	m.x[3][2] = DotProd(nDir, pos);
+
+	return m;
+}
+
+}
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Camera.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Camera.cpp	(revision 2914)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Camera.cpp	(revision 2917)
@@ -11,8 +11,6 @@
 using namespace std;
 
-// this is the start vector. 
-// warning: our coordinate system has the negative z axis pointing up
-// which is different from the system used in opengl!!
-static Vector3 startVector = Vector3(0, 1, 0);
+// our coordinate system has the positive z axis pointing up
+static Vector3 baseDir = Vector3(0, 1, 0);
 
 
@@ -27,5 +25,5 @@
 
 	mPitch = mYaw = 0;
-	Precompute(startVector);
+	Precompute(baseDir);
 
 	CalculateFromPitchAndYaw();
