Changeset 1581 for GTP/trunk/Lib/Vis/Preprocessing/src/QtGlRenderer.cpp
- Timestamp:
- 10/07/06 22:54:13 (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Vis/Preprocessing/src/QtGlRenderer.cpp
r1387 r1581 10 10 #include "KdTree.h" 11 11 #include "Environment.h" 12 #include "RssPreprocessor.h" 13 #include "RssTree.h" 14 #include "Trackball.h" 15 16 12 17 #include <Cg/cg.h> 13 18 #include <Cg/cgGL.h> … … 17 22 namespace GtpVisibilityPreprocessor { 18 23 24 25 #define CAMERA_VIEW_WIDTH 0.5f 26 19 27 class ViewCellsManager; 20 28 … … 380 388 makeCurrent(); 381 389 382 383 390 SetupProjection(GetWidth(), GetHeight()); 384 385 391 386 392 for (int i=0; i < mPvsStatFrames; i++) { … … 797 803 798 804 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 800 807 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 801 808 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); … … 906 913 907 914 void 908 QtGlRendererWidget::Setup Projection(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);915 QtGlRendererWidget::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); 914 921 glMatrixMode(GL_PROJECTION); 915 922 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())); 917 924 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 936 void 937 QtGlRendererWidget::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); 919 946 } 920 947 … … 922 949 QtGlRendererWidget::RenderPvs() 923 950 { 924 SetupCamera(); 925 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 951 926 952 927 953 ViewCell *viewcell = NULL; … … 987 1013 mUseFalseColors = true; 988 1014 989 SetupCamera();990 1015 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 991 1016 … … 1125 1150 int x = e->pos().x(); 1126 1151 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 } 1131 1167 } 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 } 1137 1184 } 1138 1185 … … 1153 1200 QtGlRendererWidget::resizeGL(int w, int h) 1154 1201 { 1155 Setup Projection(w, h);1202 SetupCameraProjection(w, h); 1156 1203 updateGL(); 1157 1204 } … … 1162 1209 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 1163 1210 1164 1165 if (!mRenderViewCells) { 1166 if (mRenderErrors) 1211 if (1) { 1212 SetupCameraProjection(width(), height()); 1213 SetupCamera(); 1214 1215 if (mRenderErrors) { 1167 1216 RenderErrors(); 1168 else1217 } else { 1169 1218 RenderPvs(); 1219 } 1220 1170 1221 RenderInfo(); 1171 } else {1172 RenderViewCells();1173 1174 mWireFrame = true;1175 RenderScene();1176 mWireFrame = false;1177 1178 RenderInfo();1179 1222 } 1180 1223 1181 1224 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 1182 1253 } 1183 1254 … … 1222 1293 1223 1294 void 1295 QtGlRendererWidget::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 1315 void 1224 1316 QtGlRendererWidget::keyPressEvent ( QKeyEvent * e ) 1225 1317 { … … 1227 1319 case Qt::Key_T: 1228 1320 mTopView = !mTopView; 1229 Setup Projection(width(), height());1321 SetupCameraProjection(width(), height()); 1230 1322 updateGL(); 1231 1323 break; … … 1248 1340 1249 1341 1250 QtGlRendererWidget::QtGlRendererWidget(SceneGraph *sceneGraph, 1342 QtGlRendererWidget::QtGlRendererWidget( 1343 SceneGraph *sceneGraph, 1251 1344 ViewCellsManager *viewcells, 1252 1345 KdTree *tree, … … 1265 1358 mRenderErrors = false; 1266 1359 mRenderFilter = true; 1267 1360 mManipulatorScale = 1.0f; 1361 trackball(mManipulatorLastQuat, 0.0f, 0.0f, 0.0f, 0.0f); 1268 1362 bool tmp; 1269 1363 … … 1281 1375 mPvsSize = 0; 1282 1376 mRenderError = 0.0f; 1377 mShowRays = false; 1378 1283 1379 mControlWidget = new QtRendererControlWidget(NULL); 1284 1380 … … 1302 1398 this, SLOT(SetUseSpatialFilter(bool))); 1303 1399 1304 1400 connect(mControlWidget, 1401 SIGNAL(SetShowRays(bool)), 1402 this, 1403 SLOT(SetShowRays(bool))); 1404 1405 resize(1000, 500); 1305 1406 mControlWidget->show(); 1306 1407 } … … 1368 1469 // init ortographic projection 1369 1470 glMatrixMode(GL_PROJECTION); 1471 1472 1370 1473 glPushMatrix(); 1371 1474 … … 1484 1587 mUseFalseColors = true; 1485 1588 1486 SetupCamera(); 1589 glPushAttrib(GL_CURRENT_BIT | GL_ENABLE_BIT | GL_POLYGON_BIT); 1590 1487 1591 glEnable(GL_CULL_FACE); 1488 1592 //glDisable(GL_CULL_FACE); … … 1529 1633 } 1530 1634 1531 glDisable(GL_CLIP_PLANE0); 1635 1636 glPopAttrib(); 1532 1637 1533 1638 } … … 1633 1738 cb->setChecked(false); 1634 1739 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))); 1635 1745 1636 1746 vbox->resize(800,100);
Note: See TracChangeset
for help on using the changeset viewer.