Ignore:
Timestamp:
10/07/06 22:54:13 (18 years ago)
Author:
bittner
Message:

Qtglwidget changes - second view + trackball - ray casting seems not functional

File:
1 edited

Legend:

Unmodified
Added
Removed
  • GTP/trunk/Lib/Vis/Preprocessing/src/QtGlRenderer.cpp

    r1387 r1581  
    1010#include "KdTree.h" 
    1111#include "Environment.h" 
     12#include "RssPreprocessor.h" 
     13#include "RssTree.h" 
     14#include "Trackball.h" 
     15 
     16 
    1217#include <Cg/cg.h> 
    1318#include <Cg/cgGL.h> 
     
    1722namespace GtpVisibilityPreprocessor { 
    1823 
     24 
     25#define CAMERA_VIEW_WIDTH 0.5f 
     26   
    1927class ViewCellsManager; 
    2028 
     
    380388  makeCurrent(); 
    381389 
    382  
    383390  SetupProjection(GetWidth(), GetHeight()); 
    384  
    385391   
    386392  for (int i=0; i < mPvsStatFrames; i++) { 
     
    797803         
    798804        glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, depthMapSize,  
    799                 depthMapSize, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, NULL); 
     805                                 depthMapSize, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, NULL); 
     806 
    800807        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 
    801808        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 
     
    906913 
    907914void 
    908 QtGlRendererWidget::SetupProjection(const int w, const int h, const float angle) 
    909 { 
    910   if (!mTopView) 
    911         GlRenderer::SetupProjection(w, h, angle); 
    912   else { 
    913         glViewport(0, 0, w, h); 
     915QtGlRendererWidget::SetupCameraProjection(const int w, const int h, const float angle) 
     916{ 
     917  if (!mTopView) { 
     918        int ww = w*CAMERA_VIEW_WIDTH; 
     919        int hh = h; 
     920        glViewport(0, 0, ww, hh); 
    914921        glMatrixMode(GL_PROJECTION); 
    915922        glLoadIdentity(); 
    916         gluPerspective(50.0, 1.0, 0.1, 20.0*Magnitude(mSceneGraph->GetBox().Diagonal())); 
     923        gluPerspective(angle, ww/(float)hh, 0.1, 2.0*Magnitude(mSceneGraph->GetBox().Diagonal())); 
    917924        glMatrixMode(GL_MODELVIEW); 
    918   } 
     925  } else { 
     926        int ww = w*CAMERA_VIEW_WIDTH; 
     927        int hh = h; 
     928        glViewport(0, 0, ww, hh); 
     929        glMatrixMode(GL_PROJECTION); 
     930        glLoadIdentity(); 
     931        gluPerspective(50.0, ww/(float)hh, 0.1, 20.0*Magnitude(mSceneGraph->GetBox().Diagonal())); 
     932        glMatrixMode(GL_MODELVIEW); 
     933  } 
     934} 
     935 
     936void 
     937QtGlRendererWidget::SetupManipulatorProjection(const int w, const int h, const float angle) 
     938{ 
     939  int ww = w*(1.0f - CAMERA_VIEW_WIDTH); 
     940  int hh = h; 
     941  glViewport(w - ww, 0, ww, hh); 
     942  glMatrixMode(GL_PROJECTION); 
     943  glLoadIdentity(); 
     944  gluPerspective(angle, ww/(float)hh, 1.0f, 40.0f); 
     945  glMatrixMode(GL_MODELVIEW); 
    919946} 
    920947 
     
    922949QtGlRendererWidget::RenderPvs() 
    923950{ 
    924   SetupCamera(); 
    925   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 
     951   
    926952   
    927953  ViewCell *viewcell = NULL; 
     
    9871013  mUseFalseColors = true; 
    9881014 
    989   SetupCamera(); 
    9901015  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 
    9911016   
     
    11251150  int x = e->pos().x(); 
    11261151  int y = e->pos().y(); 
    1127    
    1128   if (e->modifiers() & Qt::ControlModifier) { 
    1129         mViewPoint.y += (y-mousePoint.y)*MOVE_SENSITIVITY/2.0; 
    1130         mViewPoint.x += (x-mousePoint.x)*MOVE_SENSITIVITY/2.0; 
     1152 
     1153  int diffx = -(mousePoint.x - x); 
     1154  int diffy = -(mousePoint.y - y); 
     1155   
     1156  if (x < width()*CAMERA_VIEW_WIDTH) { 
     1157        if (e->modifiers() & Qt::ControlModifier) { 
     1158          mViewPoint.y += (y-mousePoint.y)*MOVE_SENSITIVITY/2.0; 
     1159          mViewPoint.x += (x-mousePoint.x)*MOVE_SENSITIVITY/2.0; 
     1160        } else { 
     1161          mViewPoint += mViewDirection*((mousePoint.y - y)*MOVE_SENSITIVITY); 
     1162          float adiff = TURN_ANGLE*(x - mousePoint.x)*-TURN_SENSITIVITY; 
     1163          float angle = atan2(mViewDirection.x, mViewDirection.z); 
     1164          mViewDirection.x = sin(angle+adiff); 
     1165          mViewDirection.z = cos(angle+adiff); 
     1166        } 
    11311167  } else { 
    1132         mViewPoint += mViewDirection*((mousePoint.y - y)*MOVE_SENSITIVITY); 
    1133         float adiff = TURN_ANGLE*(x - mousePoint.x)*-TURN_SENSITIVITY; 
    1134         float angle = atan2(mViewDirection.x, mViewDirection.z); 
    1135         mViewDirection.x = sin(angle+adiff); 
    1136         mViewDirection.z = cos(angle+adiff); 
     1168        float W = width()*(1.0f-CAMERA_VIEW_WIDTH); 
     1169        float H = height(); 
     1170        int xx = x - width()*CAMERA_VIEW_WIDTH; 
     1171        int mxx = mousePoint.x - width()*CAMERA_VIEW_WIDTH; 
     1172    if (e->modifiers() & Qt::ControlModifier) { 
     1173          mManipulatorScale = mManipulatorScale * (1.0 + (((float) (-diffy)) / H)); 
     1174        } else { 
     1175          float quat[4]; 
     1176          trackball(quat, 
     1177                                (2.0 * mxx - W) / W, 
     1178                                (H - 2.0 * mousePoint.y) / H, 
     1179                                (2.0 * xx - W) / W, 
     1180                                (H - 2.0 * y) / H 
     1181                                ); 
     1182          add_quats(quat, mManipulatorLastQuat, mManipulatorLastQuat); 
     1183        } 
    11371184  } 
    11381185   
     
    11531200QtGlRendererWidget::resizeGL(int w, int h) 
    11541201{ 
    1155   SetupProjection(w, h); 
     1202  SetupCameraProjection(w, h); 
    11561203  updateGL(); 
    11571204} 
     
    11621209  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 
    11631210 
    1164    
    1165   if (!mRenderViewCells) { 
    1166         if (mRenderErrors) 
     1211  if (1) { 
     1212        SetupCameraProjection(width(), height()); 
     1213        SetupCamera(); 
     1214         
     1215        if (mRenderErrors) { 
    11671216          RenderErrors(); 
    1168         else 
     1217        } else { 
    11691218          RenderPvs(); 
     1219        } 
     1220         
    11701221        RenderInfo(); 
    1171   } else { 
    1172         RenderViewCells(); 
    1173          
    1174         mWireFrame = true; 
    1175         RenderScene(); 
    1176         mWireFrame = false; 
    1177          
    1178         RenderInfo(); 
    11791222  } 
    11801223 
    11811224  mFrame++; 
     1225 
     1226  if (1) { 
     1227        // render into the right side of the window buffer 
     1228        SetupManipulatorProjection(width(), height()); 
     1229        SetupManipulator(); 
     1230         
     1231         
     1232        if (mRenderViewCells)  
     1233          RenderViewCells(); 
     1234         
     1235        RenderPvs(); 
     1236         
     1237        if (0) { 
     1238          mWireFrame = true; 
     1239          RenderScene(); 
     1240          mWireFrame = false; 
     1241        } 
     1242         
     1243        if (mShowRays) { 
     1244          RssPreprocessor *p = (RssPreprocessor *)mViewCellsManager->GetPreprocessor(); 
     1245          VssRayContainer rays; 
     1246          p->mRssTree->CollectRays(rays, 10000); 
     1247          RenderRays(rays); 
     1248        } 
     1249         
     1250  } 
     1251  mFrame++; 
     1252   
    11821253} 
    11831254 
     
    12221293 
    12231294void 
     1295QtGlRendererWidget::SetupManipulator() 
     1296{ 
     1297  float m[4][4]; 
     1298 
     1299  glLoadIdentity(); 
     1300  gluLookAt(0.0, 0.0, 30.0,  /* eye is at (0,0,30) */ 
     1301                        0.0, 0.0, 0.0,      /* center is at (0,0,0) */ 
     1302                        0.0, 1.0, 0.);      /* up is in positive Y direction */ 
     1303   
     1304  build_rotmatrix(m, mManipulatorLastQuat); 
     1305  glMultMatrixf(&m[0][0]); 
     1306   
     1307  float scale = mManipulatorScale*20.0f/Magnitude(mSceneGraph->GetBox().Diagonal()); 
     1308  glScalef(scale, scale, scale); 
     1309   
     1310  Vector3 t = -mSceneGraph->GetBox().Center(); 
     1311  glTranslatef(t.x, t.y, t.z); 
     1312   
     1313} 
     1314 
     1315void 
    12241316QtGlRendererWidget::keyPressEvent ( QKeyEvent * e ) 
    12251317{ 
     
    12271319  case Qt::Key_T: 
    12281320        mTopView = !mTopView; 
    1229         SetupProjection(width(), height()); 
     1321        SetupCameraProjection(width(), height()); 
    12301322        updateGL(); 
    12311323        break; 
     
    12481340   
    12491341 
    1250 QtGlRendererWidget::QtGlRendererWidget(SceneGraph *sceneGraph, 
     1342QtGlRendererWidget::QtGlRendererWidget( 
     1343                                                                           SceneGraph *sceneGraph, 
    12511344                                                                           ViewCellsManager *viewcells, 
    12521345                                                                           KdTree *tree, 
     
    12651358  mRenderErrors = false; 
    12661359  mRenderFilter = true; 
    1267  
     1360  mManipulatorScale = 1.0f; 
     1361  trackball(mManipulatorLastQuat, 0.0f, 0.0f, 0.0f, 0.0f); 
    12681362  bool tmp; 
    12691363 
     
    12811375  mPvsSize = 0; 
    12821376  mRenderError = 0.0f; 
     1377  mShowRays = false; 
     1378   
    12831379  mControlWidget = new QtRendererControlWidget(NULL); 
    12841380   
     
    13021398                  this, SLOT(SetUseSpatialFilter(bool))); 
    13031399 
    1304    
     1400  connect(mControlWidget, 
     1401                  SIGNAL(SetShowRays(bool)), 
     1402                  this, 
     1403                  SLOT(SetShowRays(bool))); 
     1404 
     1405  resize(1000, 500); 
    13051406  mControlWidget->show(); 
    13061407} 
     
    13681469          // init ortographic projection 
    13691470          glMatrixMode(GL_PROJECTION); 
     1471 
     1472 
    13701473          glPushMatrix(); 
    13711474           
     
    14841587  mUseFalseColors = true; 
    14851588 
    1486   SetupCamera(); 
     1589  glPushAttrib(GL_CURRENT_BIT | GL_ENABLE_BIT | GL_POLYGON_BIT); 
     1590   
    14871591  glEnable(GL_CULL_FACE); 
    14881592  //glDisable(GL_CULL_FACE); 
     
    15291633  } 
    15301634 
    1531   glDisable(GL_CLIP_PLANE0); 
     1635 
     1636  glPopAttrib(); 
    15321637 
    15331638} 
     
    16331738  cb->setChecked(false); 
    16341739  connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetShowPvsSizes(bool))); 
     1740 
     1741  cb = new QCheckBox("Show rays", hbox); 
     1742  hlayout->addWidget(cb); 
     1743  cb->setChecked(false); 
     1744  connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetShowRays(bool))); 
    16351745 
    16361746  vbox->resize(800,100); 
Note: See TracChangeset for help on using the changeset viewer.