Index: GTP/trunk/Lib/Vis/Preprocessing/src/QtGlRenderer.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/QtGlRenderer.cpp	(revision 1387)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/QtGlRenderer.cpp	(revision 1581)
@@ -10,4 +10,9 @@
 #include "KdTree.h"
 #include "Environment.h"
+#include "RssPreprocessor.h"
+#include "RssTree.h"
+#include "Trackball.h"
+
+
 #include <Cg/cg.h>
 #include <Cg/cgGL.h>
@@ -17,4 +22,7 @@
 namespace GtpVisibilityPreprocessor {
 
+
+#define CAMERA_VIEW_WIDTH 0.5f
+  
 class ViewCellsManager;
 
@@ -380,7 +388,5 @@
   makeCurrent();
 
-
   SetupProjection(GetWidth(), GetHeight());
-
   
   for (int i=0; i < mPvsStatFrames; i++) {
@@ -797,5 +803,6 @@
 	
 	glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, depthMapSize, 
-		depthMapSize, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, NULL);
+				 depthMapSize, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, NULL);
+
 	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
 	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
@@ -906,15 +913,35 @@
 
 void
-QtGlRendererWidget::SetupProjection(const int w, const int h, const float angle)
-{
-  if (!mTopView)
-	GlRenderer::SetupProjection(w, h, angle);
-  else {
-	glViewport(0, 0, w, h);
+QtGlRendererWidget::SetupCameraProjection(const int w, const int h, const float angle)
+{
+  if (!mTopView) {
+	int ww = w*CAMERA_VIEW_WIDTH;
+	int hh = h;
+	glViewport(0, 0, ww, hh);
 	glMatrixMode(GL_PROJECTION);
 	glLoadIdentity();
-	gluPerspective(50.0, 1.0, 0.1, 20.0*Magnitude(mSceneGraph->GetBox().Diagonal()));
+	gluPerspective(angle, ww/(float)hh, 0.1, 2.0*Magnitude(mSceneGraph->GetBox().Diagonal()));
 	glMatrixMode(GL_MODELVIEW);
-  }
+  } else {
+	int ww = w*CAMERA_VIEW_WIDTH;
+	int hh = h;
+	glViewport(0, 0, ww, hh);
+	glMatrixMode(GL_PROJECTION);
+	glLoadIdentity();
+	gluPerspective(50.0, ww/(float)hh, 0.1, 20.0*Magnitude(mSceneGraph->GetBox().Diagonal()));
+	glMatrixMode(GL_MODELVIEW);
+  }
+}
+
+void
+QtGlRendererWidget::SetupManipulatorProjection(const int w, const int h, const float angle)
+{
+  int ww = w*(1.0f - CAMERA_VIEW_WIDTH);
+  int hh = h;
+  glViewport(w - ww, 0, ww, hh);
+  glMatrixMode(GL_PROJECTION);
+  glLoadIdentity();
+  gluPerspective(angle, ww/(float)hh, 1.0f, 40.0f);
+  glMatrixMode(GL_MODELVIEW);
 }
 
@@ -922,6 +949,5 @@
 QtGlRendererWidget::RenderPvs()
 {
-  SetupCamera();
-  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+  
   
   ViewCell *viewcell = NULL;
@@ -987,5 +1013,4 @@
   mUseFalseColors = true;
 
-  SetupCamera();
   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
   
@@ -1125,14 +1150,36 @@
   int x = e->pos().x();
   int y = e->pos().y();
-  
-  if (e->modifiers() & Qt::ControlModifier) {
-	mViewPoint.y += (y-mousePoint.y)*MOVE_SENSITIVITY/2.0;
-	mViewPoint.x += (x-mousePoint.x)*MOVE_SENSITIVITY/2.0;
+
+  int diffx = -(mousePoint.x - x);
+  int diffy = -(mousePoint.y - y);
+  
+  if (x < width()*CAMERA_VIEW_WIDTH) {
+	if (e->modifiers() & Qt::ControlModifier) {
+	  mViewPoint.y += (y-mousePoint.y)*MOVE_SENSITIVITY/2.0;
+	  mViewPoint.x += (x-mousePoint.x)*MOVE_SENSITIVITY/2.0;
+	} else {
+	  mViewPoint += mViewDirection*((mousePoint.y - y)*MOVE_SENSITIVITY);
+	  float adiff = TURN_ANGLE*(x - mousePoint.x)*-TURN_SENSITIVITY;
+	  float angle = atan2(mViewDirection.x, mViewDirection.z);
+	  mViewDirection.x = sin(angle+adiff);
+	  mViewDirection.z = cos(angle+adiff);
+	}
   } else {
-	mViewPoint += mViewDirection*((mousePoint.y - y)*MOVE_SENSITIVITY);
-	float adiff = TURN_ANGLE*(x - mousePoint.x)*-TURN_SENSITIVITY;
-	float angle = atan2(mViewDirection.x, mViewDirection.z);
-	mViewDirection.x = sin(angle+adiff);
-	mViewDirection.z = cos(angle+adiff);
+	float W = width()*(1.0f-CAMERA_VIEW_WIDTH);
+	float H = height();
+	int xx = x - width()*CAMERA_VIEW_WIDTH;
+	int mxx = mousePoint.x - width()*CAMERA_VIEW_WIDTH;
+    if (e->modifiers() & Qt::ControlModifier) {
+	  mManipulatorScale = mManipulatorScale * (1.0 + (((float) (-diffy)) / H));
+	} else {
+	  float quat[4];
+	  trackball(quat,
+				(2.0 * mxx - W) / W,
+				(H - 2.0 * mousePoint.y) / H,
+				(2.0 * xx - W) / W,
+				(H - 2.0 * y) / H
+				);
+	  add_quats(quat, mManipulatorLastQuat, mManipulatorLastQuat);
+	}
   }
   
@@ -1153,5 +1200,5 @@
 QtGlRendererWidget::resizeGL(int w, int h)
 {
-  SetupProjection(w, h);
+  SetupCameraProjection(w, h);
   updateGL();
 }
@@ -1162,22 +1209,46 @@
   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
 
-  
-  if (!mRenderViewCells) {
-	if (mRenderErrors)
+  if (1) {
+	SetupCameraProjection(width(), height());
+	SetupCamera();
+	
+	if (mRenderErrors) {
 	  RenderErrors();
-	else
+	} else {
 	  RenderPvs();
+	}
+	
 	RenderInfo();
-  } else {
-	RenderViewCells();
-	
-	mWireFrame = true;
-	RenderScene();
-	mWireFrame = false;
-	
-	RenderInfo();
   }
 
   mFrame++;
+
+  if (1) {
+	// render into the right side of the window buffer
+	SetupManipulatorProjection(width(), height());
+	SetupManipulator();
+	
+	
+	if (mRenderViewCells) 
+	  RenderViewCells();
+	
+	RenderPvs();
+	
+	if (0) {
+	  mWireFrame = true;
+	  RenderScene();
+	  mWireFrame = false;
+	}
+	
+	if (mShowRays) {
+	  RssPreprocessor *p = (RssPreprocessor *)mViewCellsManager->GetPreprocessor();
+	  VssRayContainer rays;
+	  p->mRssTree->CollectRays(rays, 10000);
+	  RenderRays(rays);
+	}
+	
+  }
+  mFrame++;
+  
 }
 
@@ -1222,4 +1293,25 @@
 
 void
+QtGlRendererWidget::SetupManipulator()
+{
+  float m[4][4];
+
+  glLoadIdentity();
+  gluLookAt(0.0, 0.0, 30.0,  /* eye is at (0,0,30) */
+			0.0, 0.0, 0.0,      /* center is at (0,0,0) */
+			0.0, 1.0, 0.);      /* up is in positive Y direction */
+  
+  build_rotmatrix(m, mManipulatorLastQuat);
+  glMultMatrixf(&m[0][0]);
+  
+  float scale = mManipulatorScale*20.0f/Magnitude(mSceneGraph->GetBox().Diagonal());
+  glScalef(scale, scale, scale);
+  
+  Vector3 t = -mSceneGraph->GetBox().Center();
+  glTranslatef(t.x, t.y, t.z);
+  
+}
+
+void
 QtGlRendererWidget::keyPressEvent ( QKeyEvent * e )
 {
@@ -1227,5 +1319,5 @@
   case Qt::Key_T:
 	mTopView = !mTopView;
-	SetupProjection(width(), height());
+	SetupCameraProjection(width(), height());
 	updateGL();
 	break;
@@ -1248,5 +1340,6 @@
   
 
-QtGlRendererWidget::QtGlRendererWidget(SceneGraph *sceneGraph,
+QtGlRendererWidget::QtGlRendererWidget(
+									   SceneGraph *sceneGraph,
 									   ViewCellsManager *viewcells,
 									   KdTree *tree,
@@ -1265,5 +1358,6 @@
   mRenderErrors = false;
   mRenderFilter = true;
-
+  mManipulatorScale = 1.0f;
+  trackball(mManipulatorLastQuat, 0.0f, 0.0f, 0.0f, 0.0f);
   bool tmp;
 
@@ -1281,4 +1375,6 @@
   mPvsSize = 0;
   mRenderError = 0.0f;
+  mShowRays = false;
+  
   mControlWidget = new QtRendererControlWidget(NULL);
   
@@ -1302,5 +1398,10 @@
 		  this, SLOT(SetUseSpatialFilter(bool)));
 
-  
+  connect(mControlWidget,
+		  SIGNAL(SetShowRays(bool)),
+		  this,
+		  SLOT(SetShowRays(bool)));
+
+  resize(1000, 500);
   mControlWidget->show();
 }
@@ -1368,4 +1469,6 @@
 	  // init ortographic projection
 	  glMatrixMode(GL_PROJECTION);
+
+
 	  glPushMatrix();
 	  
@@ -1484,5 +1587,6 @@
   mUseFalseColors = true;
 
-  SetupCamera();
+  glPushAttrib(GL_CURRENT_BIT | GL_ENABLE_BIT | GL_POLYGON_BIT);
+  
   glEnable(GL_CULL_FACE);
   //glDisable(GL_CULL_FACE);
@@ -1529,5 +1633,6 @@
   }
 
-  glDisable(GL_CLIP_PLANE0);
+
+  glPopAttrib();
 
 }
@@ -1633,4 +1738,9 @@
   cb->setChecked(false);
   connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetShowPvsSizes(bool)));
+
+  cb = new QCheckBox("Show rays", hbox);
+  hlayout->addWidget(cb);
+  cb->setChecked(false);
+  connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetShowRays(bool)));
 
   vbox->resize(800,100);
