Index: GTP/trunk/App/Demos/Vis/CHC_revisited/Camera.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/CHC_revisited/Camera.cpp	(revision 2776)
+++ GTP/trunk/App/Demos/Vis/CHC_revisited/Camera.cpp	(revision 2778)
@@ -7,4 +7,6 @@
 {
 
+using namespace std;
+
 
 Camera::Camera() 
@@ -13,4 +15,10 @@
 	mHeight = 100;
 	mFovy = 90.0f * M_PI / 180.0f;
+	mIsOrtho = false;
+	
+	SetPosition(Vector3(0, 0, 0));
+
+	mPitch = mYaw = 0;
+	Precompute();
 }
 
@@ -22,4 +30,13 @@
 	
 	mFovy = fieldOfView * M_PI / 180.0f;
+
+	mIsOrtho = false;
+
+	SetPosition(Vector3(0, 0, 0));
+
+	SetPosition(Vector3(0, 0, 0));
+
+	mPitch = mYaw = 0;
+	Precompute();
 }
 
@@ -27,17 +44,15 @@
 void Camera::Precompute() 
 {
-	mDirection.Normalize();
-
-	//Vector3 side = CrossProd(Vector3(0, 1, 0), 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;
-}
+	Vector3 direction = Vector3(0, 1, 0);
+
+	Vector3 side = CrossProd(Vector3(1, 0, 0), direction);
+	
+	Vector3 up = -Normalize(CrossProd(side, direction));
+	Vector3 right = -Normalize(CrossProd(direction, up));
+
+	mBaseOrientation = Matrix4x4(right, up, direction);
+	mViewOrientation = mBaseOrientation;
+}
+
 
 
@@ -45,12 +60,4 @@
 {
 	mPosition = pos;
-	Precompute();
-}
-
-
-void Camera::SetDirection(const Vector3 &dir) 
-{
-	mDirection = dir;
-	Precompute();
 }
 
@@ -59,24 +66,4 @@
 {
 	mNear = nearDist;
-}
-
-
-void Camera::LookInBox(const AxisAlignedBox3 &box)
-{
-	//mDirection = Vector3(0, 0, 1);
-	mDirection = Vector3(0, 1, 0);
-	mPosition = box.Center();
-	mPosition.z = box.Min(2) + 0.9f * box.Size(2);
-
-	Precompute();
-}
-
-
-void Camera::LookAtBox(const AxisAlignedBox3 &box)
-{
-	mDirection = Vector3(0, box.Min().y - box.Max().y, 0);
-	mPosition = Vector3(0);//box.Max() - mDirection;
-
-	Precompute();
 }
 
@@ -159,9 +146,32 @@
 void Camera::SetupCameraView()
 {
+#if 1
+	//Matrix4x4 viewOrientation(mRight, mDirection, mUp);
+	//Matrix4x4 viewOrientation(mRight, mUp, mDirection);
+	Matrix4x4 tview = mViewOrientation;
+
+	//Vector3 pos = tview * mPosition;
+	Vector3 pos = -mPosition;
+	pos = tview * pos;
+
+	Debug << "vieworient:\n" << mViewOrientation << " pos " << pos << " position " << mPosition << endl;
+
+	Matrix4x4 viewOrientation = mViewOrientation;
+
+	viewOrientation.x[3][0] = pos.x;
+	viewOrientation.x[3][1] = pos.y;
+	viewOrientation.x[3][2] = pos.z;
+
 	glLoadIdentity();
+	glMultMatrixf((float *)viewOrientation.x);
+	//glMultMatrixf((float *)tm.x);
+	Debug << "matrix:\n" << viewOrientation << endl;
+#else
+	glLoadIdentity();
+
 	gluLookAt(mPosition.x, mPosition.y, mPosition.z,
          	  mPosition.x + mDirection.x, mPosition.y + mDirection.y, mPosition.z + mDirection.z, 
 			  mUp.x, mUp.y, mUp.z);
-
+#endif
 	//std::cout << "dir: " << mDirection << " pos: " << mPosition << " up: " << mUp << std::endl;
 }
@@ -180,10 +190,10 @@
 	const float w_far = h_far * GetAspect();
 
-	const Vector3 view = mDirection;
+	const Vector3 view = GetDirection();
 	const Vector3 fc = mPosition + view * z_far; 
 	
-	const Vector3 up = mUp;
-
-	const Vector3 right = mRight;
+	const Vector3 up = GetUpVector();
+
+	const Vector3 right = GetRightVector();
 
 	Vector3 t1, t2;
@@ -197,5 +207,5 @@
 	fbr = fc - t1 + t2;
 
-	const Vector3 nc = mPosition + mDirection * z_near;
+	const Vector3 nc = mPosition + view * z_near;
 	
 	t1 = h_near * 0.5f * up;
@@ -209,4 +219,64 @@
 
 
-}
-
+void Camera::SetOrtho(bool ortho)
+{
+	mIsOrtho = true;
+}
+
+
+void Camera::Yaw(float angle)
+{
+	mYaw += angle;
+	CalculateFromPitchAndYaw();
+	/*
+	Matrix4x4 viewOrientation(mRight, mUp, mDirection);
+	Matrix4x4 rot = RotationYMatrix(angle);
+
+	viewOrientation = viewOrientation * rot;
+
+	mDirection = Vector3(viewOrientation.x[2][0], viewOrientation.x[2][1], viewOrientation.x[2][2]);
+	mRight =     Vector3(viewOrientation.x[0][0], viewOrientation.x[0][1], viewOrientation.x[0][2]);
+	mUp =        Vector3(viewOrientation.x[1][0], viewOrientation.x[1][1], viewOrientation.x[1][2]);*/
+}
+
+
+void Camera::Pitch(float angle)
+{
+	mPitch += angle;
+	CalculateFromPitchAndYaw();
+}
+
+
+void Camera::CalculateFromPitchAndYaw()
+{
+	mViewOrientation = mBaseOrientation;
+
+	Matrix4x4 roty = RotationYMatrix(mPitch);
+	Matrix4x4 rotx = RotationXMatrix(mYaw);
+
+	mViewOrientation *= roty;
+	mViewOrientation *= rotx;
+}
+
+
+Vector3 Camera::GetDirection() const
+{ 
+	return Vector3(mViewOrientation.x[0][2], mViewOrientation.x[1][2], mViewOrientation.x[2][2]);
+}
+
+
+Vector3 Camera::GetUpVector() const 
+{ 
+	return Vector3(mViewOrientation.x[0][1], mViewOrientation.x[1][1], mViewOrientation.x[2][1]);
+}
+
+
+Vector3 Camera::GetRightVector() const 
+{ 
+	return Vector3(mViewOrientation.x[0][0], mViewOrientation.x[1][0], mViewOrientation.x[2][0]);
+		
+}
+
+
+}
+
