Changeset 2759 for GTP/trunk/App/Demos
- Timestamp:
- 06/14/08 05:43:39 (17 years ago)
- Location:
- GTP/trunk/App/Demos/Vis/CHC_revisited
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/CHC_revisited/Material.cpp
r2756 r2759 18 18 mTexture = NULL; 19 19 20 mAmbientColor = RgbColor(0 , 0, 0);20 mAmbientColor = RgbColor(0.2, 0.2, 0.2); 21 21 mDiffuseColor = RgbColor(1, 1, 1); 22 mSpecularColor = RgbColor(0, 0, 0); 22 //mSpecularColor = RgbColor(0.5, 0.5, 0.5); 23 mSpecularColor = RgbColor(1, 1, 1); 23 24 } 24 25 -
GTP/trunk/App/Demos/Vis/CHC_revisited/chcdemo.cpp
r2758 r2759 34 34 float nearDist = 0.1f; 35 35 int winWidth, winHeight; 36 float winAspectRatio = 1.0f; 36 37 37 38 float visZoomFactor = 1.5f; … … 48 49 Vector3 lightDir = Vector3(0.0f, 0.0f, 1.0f); // light dir 49 50 50 Matrix4x4 eyeView; // eye view matrix51 Matrix4x4 eyeProjection; // eye projection matrix52 Matrix4x4 eyeProjView; //= eyeProjection*eyeView53 Matrix4x4 invEyeProjView; //= eyeProjView^(-1)54 51 Matrix4x4 visView; // visualisation view matrix 55 52 … … 58 55 //int renderMode = RenderTraverser::RENDER_COHERENT; 59 56 60 // relative size of an object61 float objectSize = 3.5f;62 63 int numObjects = 2000;64 int numNextObjects = numObjects;65 float zLength = 30.0f;66 67 // this defines the volume where objects can be drawn68 Vector3 minTranslation(-2.5f, -2.5f, -3.0f);69 Vector3 maxTranslation(2.5f, 2.5f, -3.0 - zLength);70 71 const float minAngle = 0;72 const float maxAngle = 360;73 57 74 58 const int renderTimeSize = 100; … … 84 68 Vector3 spec[2]; 85 69 86 void InitExtensions( void);70 void InitExtensions(); 87 71 void DisplayVisualization(); 88 void InitGLstate( void);89 void CleanUp( void);90 void SetupEyeView( void);91 void UpdateEyeMtx( void);92 93 94 void begin2D( void);95 void end2D( void);72 void InitGLstate(); 73 void CleanUp(); 74 void SetupEyeView(); 75 void UpdateEyeMtx(); 76 void SetupLighting(); 77 78 void begin2D(); 79 void end2D(); 96 80 void output(int x, int y, const char *string); 97 void keyboard( constunsigned char c, int x, int y);98 void drawHelpMessage( void);99 void drawStatistics( void);81 void keyboard(unsigned char c, int x, int y); 82 void drawHelpMessage(); 83 void drawStatistics(); 100 84 void display(void); 101 85 void special(int c, int x, int y); … … 140 124 141 125 //const string filename("house_test.dem"); 142 const string filename("city .dem");126 const string filename("city_demo.dem"); 143 127 144 128 if (loader.Load(filename, sceneEntities)) … … 154 138 sceneBox.Include((*it)->GetBoundingBox()); 155 139 156 Debug << "scene box: " << sceneBox << endl; 140 cout << "scene box: " << sceneBox << endl; 141 157 142 158 143 //SetupProjection(800, 600, 60, sceneBox); … … 177 162 void InitGLstate(void) 178 163 { 179 glClearColor(0.0f, 1.0f, 0.0f, 0.0);164 glClearColor(0.0f, 0.0f, 0.0f, 0.0); 180 165 181 166 glPixelStorei(GL_UNPACK_ALIGNMENT, 1); … … 184 169 glDepthFunc(GL_LESS); 185 170 186 glEnable(GL_LIGHTING); 187 glEnable(GL_LIGHT0); 188 //glDisable(GL_LIGHTING); 171 SetupLighting(); 189 172 190 173 glColor3f(1.0f, 0.0f, 0.0f); 191 174 glShadeModel(GL_SMOOTH); 192 175 193 GLfloat ambient[] = {0.5, 0.5, 0.5, 1.0}; 194 GLfloat diffuse[] = {1.0, 1.0, 1.0, 1.0}; 195 GLfloat specular[] = {1.0, 1.0, 1.0, 1.0}; 196 GLfloat position[] = {0.0, 3.0, 3.0, 0.0}; 197 198 GLfloat lmodel_ambient[] = {0.2, 0.2, 0.2, 1.0}; 199 GLfloat local_view[] = {0.0}; 200 201 glLightfv(GL_LIGHT0, GL_AMBIENT, ambient); 202 glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse); 203 glLightfv(GL_LIGHT0, GL_POSITION, position); 204 205 glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient); 206 glLightModelfv(GL_LIGHT_MODEL_LOCAL_VIEWER, local_view); 207 176 208 177 glMaterialf(GL_FRONT, GL_SHININESS, 64); 209 178 glEnable(GL_NORMALIZE); … … 216 185 GLfloat ambientColor[] = {0.5, 0.5, 0.5, 1.0}; 217 186 GLfloat diffuseColor[] = {1.0, 0.0, 0.0, 1.0}; 218 GLfloat specularColor[] = { 1.0, 1.0, 1.0, 1.0};187 GLfloat specularColor[] = {0.0, 0.0, 0.0, 1.0}; 219 188 220 189 glMaterialfv(GL_FRONT, GL_AMBIENT, ambientColor); … … 297 266 298 267 299 void UpdateEyeMtx(void) 300 { 301 /*const Vector3 up(0.0, 1.0, 0.0); 302 303 look(eyeView, eyePos, viewDir, up); 304 mult(eyeProjView, eyeProjection, eyeView); //eyeProjView = eyeProjection*eyeView 305 invert(invEyeProjView, eyeProjView); //invert matrix 306 */ 307 } 308 268 void SetupLighting() 269 { 270 glEnable(GL_LIGHTING); 271 glEnable(GL_LIGHT0); 272 glEnable(GL_LIGHT1); 273 //glDisable(GL_LIGHT1); 274 //glDisable(GL_LIGHTING); 275 276 //GLfloat ambient[] = {0.5, 0.5, 0.5, 1.0}; 277 GLfloat ambient[] = {0.2, 0.2, 0.2, 1.0}; 278 GLfloat diffuse[] = {1.0, 1.0, 1.0, 1.0}; 279 GLfloat specular[] = {1.0, 1.0, 1.0, 1.0}; 280 281 //GLfloat lmodel_ambient[] = {0.5f, 0.5f, 0.5f, 1.0}; 282 GLfloat lmodel_ambient[] = {0.2f, 0.2f, 0.2f, 1.0f}; 283 284 glLightfv(GL_LIGHT0, GL_AMBIENT, ambient); 285 glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse); 286 glLightfv(GL_LIGHT0, GL_SPECULAR, specular); 287 288 GLfloat position[] = {0.0, 3.0, 3.0, 0.0}; 289 glLightfv(GL_LIGHT0, GL_POSITION, position); 290 291 292 //////////// 293 //-- second light 294 295 GLfloat ambient1[] = {0.2, 0.2, 0.2, 1.0}; 296 GLfloat diffuse1[] = {0.5, 0.5, 0.5, 1.0}; 297 GLfloat specular1[] = {0.0, 0.0, 0.0, 1.0}; 298 299 glLightfv(GL_LIGHT1, GL_AMBIENT, ambient1); 300 glLightfv(GL_LIGHT1, GL_DIFFUSE, diffuse1); 301 glLightfv(GL_LIGHT1, GL_SPECULAR, specular1); 302 303 GLfloat position1[] = {0.0, 1.0, 0.0, 1.0}; 304 glLightfv(GL_LIGHT1, GL_POSITION, position1); 305 306 glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient); 307 glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_TRUE); 308 //glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_FALSE); 309 //glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL_EXT, GL_SEPARATE_SPECULAR_COLOR_EXT); 310 glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL_EXT, GL_SINGLE_COLOR_EXT); 311 312 } 309 313 310 314 void SetupEyeView(void) 311 315 { 312 //SetupProjection(800,600,60,sceneBox); 316 317 glMatrixMode(GL_PROJECTION); 318 glLoadIdentity(); 319 320 gluPerspective(60.0f, 1.0f / winAspectRatio, nearDist, 2.0f * Magnitude(sceneBox.Diagonal())); 321 313 322 glMatrixMode(GL_MODELVIEW); 323 glLoadIdentity(); 324 325 GLfloat position[] = {0.0f, 3.0f, 3.0f, 0.0f}; 326 glLightfv(GL_LIGHT0, GL_POSITION, position); 327 328 GLfloat position1[] = {sceneBox.Center().x, sceneBox.Center().y, sceneBox.Center().z, 1.0f}; 329 glLightfv(GL_LIGHT1, GL_POSITION, position1); 330 314 331 camera->SetupCameraView(); 315 332 316 /* glMatrixMode(GL_PROJECTION); 317 glLoadMatrixf((float *)eyeProjection.x); 318 319 glMatrixMode(GL_MODELVIEW); 320 glLoadMatrixf((float *)eyeView.x); 321 */ 333 322 334 } 323 335 … … 336 348 char msg8[100]; 337 349 338 /* 339 sprintf_s(msg2, "Traversed: %4d, frustum culled: %4d, query culled: %4d (of %d nodes)",350 351 /*sprintf_s(msg2, "Traversed: %4d, frustum culled: %4d, query culled: %4d (of %d nodes)", 340 352 traverser.GetNumTraversedNodes(), traverser.GetNumFrustumCulledNodes(), 341 353 traverser.GetNumQueryCulledNodes(), 342 354 traverser.GetHierarchy()->GetNumHierarchyNodes()); 343 355 */ 344 356 char *optstr[2] = {"", ", using optimization"}; 345 char *querystr[2] = {"NV", "ARB"}; 346 357 347 358 float fps = 1e3f; 348 359 long renderTime = calcRenderTime(); 349 if (renderTime) fps = 1e6f / (float)calcRenderTime(); 350 351 sprintf_s(msg3, "Threshold: %4d, algorithm rendering time: %ld ms (%3.3f fps), queries: %s%s", 352 traverser.GetVisibilityThreshold(), renderTime / 1000, fps, querystr[useArbQueries], optstr[useOptimization]); 360 if (renderTime) fps = 1e3f / (float)renderTime; 361 362 //sprintf_s(msg3, "Threshold: %4d, algorithm rendering time: %ld ms (%3.3f fps), queries: %s", 363 // traverser.GetVisibilityThreshold(), renderTime / 1000, fps, optstr[useOptimization]); 364 sprintf_s(msg3, "render time: %ld ms (%3.3f fps), queries: %s", renderTime, fps, optstr[useOptimization]); 353 365 354 366 string str; 355 367 string str2; 356 368 357 calcDecimalPoint(str, Geometry::CountTriangles(objectType) * traverser.GetNumRenderedGeometry());369 /*calcDecimalPoint(str, Geometry::CountTriangles(objectType) * traverser.GetNumRenderedGeometry()); 358 370 calcDecimalPoint(str2, Geometry::CountTriangles(objectType) * numObjects); 359 371 360 372 sprintf_s(msg4, "Rendered objects %d (of %d), rendered triangles: %s (of %s)", 361 373 traverser.GetNumRenderedGeometry(), numObjects, str.c_str(), str2.c_str()); 362 363 sprintf_s(msg5, "Next object num: %d", numNextObjects);364 sprintf_s(msg6, "Next length in z dir: %3.3f", zLength);365 366 char *objectTypeStr[3] = {"teapot", "torus", "sphere"};367 368 sprintf_s(msg7, "Next object type: %s", objectTypeStr[nextObjectType]);369 sprintf_s(msg8, "Next object size: %3.3f", objectSize);370 374 */ 375 371 376 372 377 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 373 378 374 379 // bring eye modelview matrix up-to-date 375 UpdateEyeMtx();376 380 SetupEyeView(); 381 382 InitTiming(); 383 384 long t1, t2; 385 386 t1 = GetTime(); 377 387 378 388 glEnableClientState(GL_VERTEX_ARRAY); … … 408 418 glDisable(GL_TEXTURE_2D); 409 419 glDisableClientState(GL_TEXTURE_COORD_ARRAY); 420 421 422 t2 = GetTime(); 423 long loop_time = TimeDiff(t1, t2); 424 //cout<<"t: " << loop_time<<endl; 410 425 411 426 /* … … 413 428 traverser.SetProjViewMatrix(eyeProjView); 414 429 traverser.Render(renderMode); 430 */ 431 415 432 // cycle through rendertime array 416 renderTimes[renderTimesIdx] = traverser.GetRenderTime();433 renderTimes[renderTimesIdx] = loop_time;// traverser.GetRenderTime(); 417 434 renderTimesIdx = (renderTimesIdx + 1) % renderTimeSize; 418 435 … … 420 437 renderTimesValid = renderTimesIdx; 421 438 422 if(visMode) 423 displayVisualization(); 424 */ 439 //if(visMode) displayVisualization(); 440 425 441 426 442 … … 445 461 output(10, winHeight-90, msg5); 446 462 } 463 447 464 output(10, winHeight-70, msg3); 448 output(10, winHeight-50, msg4);449 output(10, winHeight-30, msg2);465 //output(10, winHeight-50, msg4); 466 //output(10, winHeight-30, msg2); 450 467 } 451 468 } … … 469 486 break; 470 487 case 32: //space 471 472 // renderMode = (renderMode + 1) % RenderTraverser::NUM_RENDERMODES; 473 488 // renderMode = (renderMode + 1) % RenderTraverser::NUM_RENDERMODES; 474 489 resetTimer(); 475 490 //traverser.Render(renderMode); // render once so stats are updated … … 568 583 break; 569 584 case GLUT_KEY_F4: 570 zLength -= 1;571 if(zLength < 0) zLength = 0;585 //zLength -= 1; 586 //if(zLength < 0) zLength = 0; 572 587 break; 573 588 case GLUT_KEY_F5: 574 zLength += 1;589 //zLength += 1; 575 590 break; 576 591 case GLUT_KEY_F6: 577 objectSize -= 0.1;578 if(objectSize < 0.1) objectSize = 0.1;592 //objectSize -= 0.1; 593 //if(objectSize < 0.1) objectSize = 0.1; 579 594 break; 580 595 case GLUT_KEY_F7: 581 objectSize += 0.1;596 //objectSize += 0.1; 582 597 break; 583 598 case GLUT_KEY_F8: … … 608 623 void reshape(const int w, const int h) 609 624 { 610 double winAspectRatio = 1.0;625 winAspectRatio = 1.0f; 611 626 612 627 glViewport(0, 0, w, h); … … 615 630 winHeight = h; 616 631 617 if (w) winAspectRatio = ( double) h / (double) w;632 if (w) winAspectRatio = (float) h / (float) w; 618 633 619 634 glMatrixMode(GL_PROJECTION); 620 635 glLoadIdentity(); 621 636 622 gluPerspective(60.0f, 1.0f / winAspectRatio, nearDist, 2.0 * Magnitude(sceneBox.Diagonal()));637 gluPerspective(60.0f, 1.0f / winAspectRatio, nearDist, 2.0f * Magnitude(sceneBox.Diagonal())); 623 638 glMatrixMode(GL_MODELVIEW); 624 625 //perspectiveDeg(eyeProjection, 60.0, 1.0f/winAspectRatio, nearDist, 150.0);626 639 627 640 glutPostRedisplay(); … … 790 803 for (i = 0; i < len; i++) 791 804 { 792 glutBitmapCharacter(GLUT_BITMAP_8_BY_13, string[i]);805 glutBitmapCharacter(GLUT_BITMAP_8_BY_13, string[i]); 793 806 } 794 807 }
Note: See TracChangeset
for help on using the changeset viewer.