Changeset 2756 for GTP/trunk/App/Demos/Vis/CHC_revisited/chcdemo.cpp
- Timestamp:
- 06/13/08 18:06:32 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/CHC_revisited/chcdemo.cpp
r2753 r2756 1 1 // occquery.cpp : Defines the entry point for the console application. 2 2 // 3 #if TOIMPLEMENT4 5 3 #include <math.h> 6 4 #include <time.h> 5 #include "common.h" 7 6 #include "glInterface.h" 8 7 #include "RenderTraverser.h" 9 10 11 12 bool arbQuerySupport = false; 13 bool nvQuerySupport = false; 14 15 double nearDist = 0.1; // eye near plane distance 8 #include "SceneEntity.h" 9 #include "Vector3.h" 10 #include "Matrix4x4.h" 11 #include "BinaryLoader.h" 12 #include "Bvh.h" 13 #include "Camera.h" 14 #include "Geometry.h" 15 16 17 using namespace std; 18 using namespace CHCDemo; 19 20 21 22 /// the renderable scene geometry 23 SceneEntityContainer sceneEntities; 24 // traverses and renders the hierarchy 25 RenderTraverser *traverser; 26 /// the hierarchy 27 Bvh *bvh; 28 /// the scene camera 29 Camera *camera; 30 /// the scene bounding box 31 AxisAlignedBox3 sceneBox; 32 33 // eye near plane distance 34 float nearDist = 0.1f; 16 35 int winWidth, winHeight; 17 int objectType = Geometry::TEAPOT;18 int nextObjectType = objectType;19 36 20 37 float visZoomFactor = 1.5f; … … 26 43 bool showCreateParams = false; 27 44 28 // traverses and renders the hierarchy 29 RenderTraverser traverser; 30 31 Vector3 eyePos = {0.0, 0.0, 3.0}; // eye position 32 Vector3 viewDir = {0.0, 0.0, -1.0}; // eye view dir 33 Vector3 lightDir = {0.0, 0.0, 1.0}; // light dir 45 46 Vector3 eyePos = Vector3(0.0f, 0.0f, 3.0f); // eye position 47 Vector3 viewDir = Vector3(0.0f, 0.0f, -1.0f); // eye view dir 48 Vector3 lightDir = Vector3(0.0f, 0.0f, 1.0f); // light dir 34 49 35 50 Matrix4x4 eyeView; // eye view matrix … … 41 56 //mouse navigation state 42 57 int xEyeBegin, yEyeBegin, yMotionBegin, verticalMotionBegin, horizontalMotionBegin = 0; 43 int renderMode = RenderTraverser::RENDER_COHERENT;58 //int renderMode = RenderTraverser::RENDER_COHERENT; 44 59 45 60 // relative size of an object … … 51 66 52 67 // this defines the volume where objects can be drawn 53 Vector3 minTranslation = {-2.5f, -2.5f, -3.0f};54 Vector3 maxTranslation = {2.5f, 2.5f, -3.0 - zLength};68 Vector3 minTranslation(-2.5f, -2.5f, -3.0f); 69 Vector3 maxTranslation(2.5f, 2.5f, -3.0 - zLength); 55 70 56 71 const float minAngle = 0; … … 62 77 int renderTimesValid = 0; 63 78 64 typedef vector<Geometry *> GeometryList;65 GeometryList geometry;66 67 79 bool useOptimization = true; 68 bool useArbQueries = false; 80 69 81 70 82 Vector3 amb[2]; … … 72 84 Vector3 spec[2]; 73 85 86 void InitExtensions(void); 87 void DisplayVisualization(); 88 void InitGLstate(void); 89 void CleanUp(void); 90 void SetupEyeView(void); 91 void UpdateEyeMtx(void); 92 93 74 94 void begin2D(void); 75 95 void end2D(void); 76 void output(const int x, const int y, const char *string); 77 void initGLstate(void); 78 void keyboard(const unsigned char c, const int x, const int y); 96 void output(int x, int y, const char *string); 97 void keyboard(const unsigned char c, int x, int y); 79 98 void drawHelpMessage(void); 80 99 void drawStatistics(void); 81 100 void display(void); 82 void special( const int c, const int x, constint y);83 void reshape( const int w, constint h);101 void special(int c, int x, int y); 102 void reshape(int w, int h); 84 103 void mouse(int button, int state, int x, int y); 85 void initExtensions(void);86 104 void leftMotion(int x, int y); 87 //void rightMotion(int x, int y);88 105 void middleMotion(int x, int y); 89 106 void drawEyeView(void); 90 void setupEyeView(void);91 107 void setupVisView(void); 92 void updateEyeMtx(void);93 108 long calcRenderTime(void); 94 109 void resetTimer(void); 95 void cleanUp(void); 96 void calcDecimalPoint(string &str, int d); 97 98 HierarchyNode* generateHierarchy(int numObjects); 99 Geometry *generateGeometry(Vector3 translateRatio, float xRotRatio, 100 float yRotRatio, float zRotRatio, int materialIdx); 101 void displayVisualization(); 102 103 void deleteGeometry(); 104 105 #endif 110 void calcDecimalPoint(std::string &str, int d); 111 112 113 114 void SetupProjection(int w, int h, float angle, const AxisAlignedBox3 &sceneBox) 115 { 116 glViewport(0, 0, w, h); 117 glMatrixMode(GL_PROJECTION); 118 glLoadIdentity(); 119 120 gluPerspective(angle, 1.0, 1.0f, 2.0 * Magnitude(sceneBox.Diagonal())); 121 glMatrixMode(GL_MODELVIEW); 122 } 123 106 124 107 125 int main(int argc, char* argv[]) 108 126 { 109 #if 0 110 glutInitWindowSize(800,600); 111 glutInit(&argc,argv); 127 glutInitWindowSize(800, 600); 128 glutInit(&argc, argv); 112 129 glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH); 113 130 114 131 glutCreateWindow("Coherent Hierarchical Culling"); 115 132 … … 120 137 glutMouseFunc(mouse); 121 138 glutIdleFunc(display); 122 initExtensions(); 123 initGLstate(); 124 125 leftMotion(0,0); 126 middleMotion(0,0); 127 128 HierarchyNode *hierarchy = generateHierarchy(numObjects); 129 traverser.SetHierarchy(hierarchy); 139 140 InitExtensions(); 141 InitGLstate(); 142 143 leftMotion(0, 0); 144 middleMotion(0, 0); 145 146 BinaryLoader loader; 147 148 const string filename("house_test.dem"); 149 //const string filename("city.dem"); 150 151 camera = new Camera(800, 600); 152 153 if (loader.Load(filename, sceneEntities)) 154 cout << "scene " << filename << " loaded" << endl; 155 else 156 cerr << "loading scene " << filename << " failed" << endl; 157 158 sceneBox.Initialize(); 159 160 SceneEntityContainer::const_iterator it, it_end = sceneEntities.end(); 161 162 for (it = sceneEntities.begin(); it != it_end; ++ it) 163 sceneBox.Include((*it)->GetBoundingBox()); 164 165 Debug << "scene box: " << sceneBox << endl; 166 167 SetupProjection(800, 600, 60, sceneBox); 168 camera->LookAtBox(sceneBox); 169 //camera->LookInBox(sceneBox); 170 //camera->SetPosition(Vector3(0, 0, -3)); 171 //camera->SetDirection(Vector3(0, 0, 1)); 130 172 131 173 /// initialise rendertime array … … 136 178 137 179 // clean up 138 cleanUp();139 #endif 180 CleanUp(); 181 140 182 return 0; 141 183 } 142 184 143 #if 0 144 void initGLstate(void)145 { 146 glClearColor(0. 6, 0.6, 0.8, 1.0);185 186 void InitGLstate(void) 187 { 188 glClearColor(0.0f, 1.0f, 0.0f, 0.0); 147 189 148 190 glPixelStorei(GL_UNPACK_ALIGNMENT, 1); 149 191 glPixelStorei(GL_PACK_ALIGNMENT,1); 150 192 151 glDepthRange(0.0, 1.0);152 glClearDepth(1.0);153 193 glDepthFunc(GL_LESS); 154 194 155 195 glEnable(GL_LIGHTING); 156 196 glEnable(GL_LIGHT0); 157 197 //glDisable(GL_LIGHTING); 198 199 glColor3f(1.0f, 0.0f, 0.0f); 158 200 glShadeModel(GL_SMOOTH); 159 201 160 GLfloat ambient[] = { 0.0, 0.0, 0.0, 1.0};161 GLfloat diffuse[] = { 1.0, 1.0, 1.0, 1.0};162 GLfloat specular[] = { 1.0, 1.0, 1.0, 1.0};163 GLfloat position[] = { 0.0, 3.0, 3.0, 0.0};202 GLfloat ambient[] = {0.5, 0.5, 0.5, 1.0}; 203 GLfloat diffuse[] = {1.0, 1.0, 1.0, 1.0}; 204 GLfloat specular[] = {1.0, 1.0, 1.0, 1.0}; 205 GLfloat position[] = {0.0, 3.0, 3.0, 0.0}; 164 206 165 GLfloat lmodel_ambient[] = { 0.2, 0.2, 0.2, 1.0};166 GLfloat local_view[] = { 0.0};207 GLfloat lmodel_ambient[] = {0.2, 0.2, 0.2, 1.0}; 208 GLfloat local_view[] = {0.0}; 167 209 168 210 glLightfv(GL_LIGHT0, GL_AMBIENT, ambient); … … 179 221 glCullFace(GL_BACK); 180 222 glEnable(GL_CULL_FACE); 181 182 glClearColor(0.2, 0.2, 0.8, 0.0); 183 184 setupVisView(); 223 //glDisable(GL_CULL_FACE); 224 225 GLfloat ambientColor[] = {0.5, 0.5, 0.5, 1.0}; 226 GLfloat diffuseColor[] = {1.0, 0.0, 0.0, 1.0}; 227 GLfloat specularColor[] = {1.0, 1.0, 1.0, 1.0}; 228 229 glMaterialfv(GL_FRONT, GL_AMBIENT, ambientColor); 230 glMaterialfv(GL_FRONT, GL_DIFFUSE, diffuseColor); 231 glMaterialfv(GL_FRONT, GL_SPECULAR, specularColor); 232 233 glColor3f(1.0f, 0.0f, 0.0f); 234 //setupVisView(); 185 235 } 186 236 … … 226 276 }; 227 277 228 int i;278 229 279 int x = 40, y = 42; 280 230 281 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 231 282 glEnable(GL_BLEND); 232 glColor4f(0.0 ,1.0,0.0,0.2); // 20% green.283 glColor4f(0.0f, 1.0f , 0.0f, 0.2f); // 20% green. 233 284 234 285 // Drawn clockwise because the flipped Y axis flips CCW and CW. … … 237 288 glDisable(GL_BLEND); 238 289 239 240 glColor3f(1.0,1.0,1.0); 241 for(i = 0; message[i] != 0; i++) { 242 if(message[i][0] == '\0') { 290 glColor3f(1.0f, 1.0f, 1.0f); 291 292 for(int i = 0; message[i] != 0; i++) 293 { 294 if(message[i][0] == '\0') 295 { 243 296 y += 7; 244 } else { 245 output(x,y,message[i]); 297 } 298 else 299 { 300 output(x, y, message[i]); 246 301 y += 14; 247 302 } … … 250 305 } 251 306 252 // generates a teapot, all parameters between zero and one 253 Geometry *generateGeometry(Vector3 translationRatio, float xRotRatio, 254 float yRotRatio, float zRotRatio, int materialIdx) 255 { 256 float xRot = minAngle + xRotRatio * (maxAngle - minAngle); 257 float yRot = minAngle + yRotRatio * (maxAngle - minAngle); 258 float zRot = minAngle + zRotRatio * (maxAngle - minAngle); 259 260 Vector3 translation; 261 translation[0] = minTranslation[0] + translationRatio[0] * (maxTranslation[0] - minTranslation[0]); 262 translation[1] = minTranslation[1] + translationRatio[1] * (maxTranslation[1] - minTranslation[1]); 263 translation[2] = minTranslation[2] + translationRatio[2] * (maxTranslation[2] - minTranslation[2]); 264 265 Geometry *result = new Geometry(translation, xRot, yRot, zRot, objectSize, objectType); 266 267 result->SetAmbientColor(amb[materialIdx][0], amb[materialIdx][1], amb[materialIdx][2]); 268 result->SetDiffuseColor(dif[materialIdx][0], dif[materialIdx][1], dif[materialIdx][2]); 269 result->SetSpecularColor(spec[materialIdx][0], spec[materialIdx][1], spec[materialIdx][2]); 270 271 return result; 272 } 273 274 // generates a the scene hierarchy with random values 275 HierarchyNode* generateHierarchy(int numObjects) 276 { 277 HierarchyNode *hierarchy = new HierarchyNode(); 278 279 // initialise materials 280 copyVector3Values(amb[0], 0.0215, 0.1745, 0.0215); 281 copyVector3Values(dif[0], 0.727811, 0.633, 0.6); 282 copyVector3Values(spec[0], 0.633, 0.727811, 0.633); 283 284 copyVector3Values(amb[1], 0.1745, 0.01175, 0.01175); 285 copyVector3Values(dif[1], 0.61424, 0.04136, 0.04136); 286 copyVector3Values(spec[1], 0.727811, 0.626959, 0.626959); 287 288 srand (time (0)); 289 290 printf("generating geometry with random position and orientation ... "); 291 292 for(int i=0; i < numObjects; i++) 293 { 294 float xRotRatio = rand() / (float) RAND_MAX; 295 float yRotRatio = rand() / (float) RAND_MAX; 296 float zRotRatio = rand() / (float) RAND_MAX; 297 298 Vector3 translationRatio = {rand() / (float) RAND_MAX, 299 rand() / (float) RAND_MAX, 300 rand() / (float) RAND_MAX}; 301 302 int materialIdx = int(2 * rand() / (float) RAND_MAX); 303 304 Geometry *geo = generateGeometry(translationRatio, xRotRatio, 305 yRotRatio, zRotRatio, materialIdx); 306 hierarchy->AddGeometry(geo); 307 308 // put into global geometry list for later deletion 309 geometry.push_back(geo); 310 } 311 312 printf("finished\n"); 313 printf("generating new kd-tree hierarchy ... "); 314 HierarchyNode::InitKdTree(hierarchy); 315 hierarchy->GenerateKdTree(); 316 printf("finished\n"); 317 318 return hierarchy; 319 } 320 321 322 void updateEyeMtx(void) 323 { 324 const Vector3 up = {0.0, 1.0, 0.0}; 307 308 void UpdateEyeMtx(void) 309 { 310 /*const Vector3 up(0.0, 1.0, 0.0); 325 311 326 312 look(eyeView, eyePos, viewDir, up); 327 313 mult(eyeProjView, eyeProjection, eyeView); //eyeProjView = eyeProjection*eyeView 328 314 invert(invEyeProjView, eyeProjView); //invert matrix 329 } 330 331 332 void setupEyeView(void) 333 { 334 glMatrixMode(GL_PROJECTION); 335 glLoadMatrixd(eyeProjection); 336 315 */ 316 } 317 318 319 void SetupEyeView(void) 320 { 321 SetupProjection(800,600,60,sceneBox); 337 322 glMatrixMode(GL_MODELVIEW); 338 glLoadMatrixd(eyeView); 323 camera->SetupCameraView(); 324 325 /* glMatrixMode(GL_PROJECTION); 326 glLoadMatrixf((float *)eyeProjection.x); 327 328 glMatrixMode(GL_MODELVIEW); 329 glLoadMatrixf((float *)eyeView.x); 330 */ 339 331 } 340 332 … … 353 345 char msg8[100]; 354 346 347 /* 355 348 sprintf_s(msg2, "Traversed: %4d, frustum culled: %4d, query culled: %4d (of %d nodes)", 356 349 traverser.GetNumTraversedNodes(), traverser.GetNumFrustumCulledNodes(), 357 350 traverser.GetNumQueryCulledNodes(), 358 351 traverser.GetHierarchy()->GetNumHierarchyNodes()); 359 352 360 353 char *optstr[2] = {"", ", using optimization"}; 361 354 char *querystr[2] = {"NV", "ARB"}; … … 384 377 sprintf_s(msg7, "Next object type: %s", objectTypeStr[nextObjectType]); 385 378 sprintf_s(msg8, "Next object size: %3.3f", objectSize); 379 */ 386 380 387 381 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 388 382 389 updateEyeMtx(); // bring eye modelview matrix up-to-date 390 setupEyeView(); 391 383 // bring eye modelview matrix up-to-date 384 UpdateEyeMtx(); 385 SetupEyeView(); 386 387 glEnableClientState(GL_VERTEX_ARRAY); 388 glEnableClientState(GL_NORMAL_ARRAY); 389 390 bool usesTextures = false; 391 392 SceneEntityContainer::const_iterator sit, sit_end = sceneEntities.end(); 393 394 for (sit = sceneEntities.begin(); sit != sit_end; ++ sit) 395 { 396 SceneEntity *entity = *sit; 397 398 if (!usesTextures && entity->GetGeometry()->HasTexture()) 399 { 400 glEnable(GL_TEXTURE_2D); 401 glEnableClientState(GL_TEXTURE_COORD_ARRAY); 402 usesTextures = true; 403 } 404 else if (usesTextures && !entity->GetGeometry()->HasTexture()) 405 { 406 glDisable(GL_TEXTURE_2D); 407 glDisableClientState(GL_TEXTURE_COORD_ARRAY); 408 usesTextures = false; 409 } 410 411 entity->Render(); 412 } 413 414 glDisableClientState(GL_VERTEX_ARRAY); 415 glDisableClientState(GL_NORMAL_ARRAY); 416 417 glDisable(GL_TEXTURE_2D); 418 glDisableClientState(GL_TEXTURE_COORD_ARRAY); 419 420 /* 392 421 traverser.SetViewpoint(eyePos); 393 422 traverser.SetProjViewMatrix(eyeProjView); 394 423 traverser.Render(renderMode); 395 396 424 // cycle through rendertime array 397 425 renderTimes[renderTimesIdx] = traverser.GetRenderTime(); … … 402 430 403 431 if(visMode) 404 {405 432 displayVisualization(); 406 } 433 */ 434 407 435 408 436 begin2D(); 437 409 438 if(showHelp) 439 { 410 440 drawHelpMessage(); 441 } 411 442 else 412 443 { 413 444 glColor3f(1.0,1.0,1.0); 414 output(10,winHeight-10, msg[renderMode]);445 //output(10, winHeight-10, msg[renderMode]); 415 446 416 447 if(showStatistics) … … 428 459 } 429 460 } 461 430 462 end2D(); 431 463 … … 437 469 void keyboard(const unsigned char c, const int x, const int y) 438 470 { 439 int threshold;440 HierarchyNode *hierarchy;471 //int threshold; 472 //HierarchyNode *hierarchy; 441 473 442 474 switch(c) … … 446 478 break; 447 479 case 32: //space 448 renderMode = (renderMode + 1) % RenderTraverser::NUM_RENDERMODES; 480 481 // renderMode = (renderMode + 1) % RenderTraverser::NUM_RENDERMODES; 449 482 450 483 resetTimer(); 451 traverser.Render(renderMode); // render once so stats are updated484 //traverser.Render(renderMode); // render once so stats are updated 452 485 break; 453 486 case 'h': … … 458 491 case 'V': 459 492 showBoundingVolumes = !showBoundingVolumes; 460 HierarchyNode::SetRenderBoundingVolume(showBoundingVolumes);493 //HierarchyNode::SetRenderBoundingVolume(showBoundingVolumes); 461 494 break; 462 495 case 's': … … 465 498 break; 466 499 case '+': 467 threshold = traverser.GetVisibilityThreshold() + 10;468 traverser.SetVisibilityThreshold(threshold);500 //threshold = traverser.GetVisibilityThreshold() + 10; 501 //traverser.SetVisibilityThreshold(threshold); 469 502 break; 470 503 case '-': 471 threshold = traverser.GetVisibilityThreshold() - 10;472 if(threshold < 0) threshold = 0;473 474 traverser.SetVisibilityThreshold(threshold);504 //threshold = traverser.GetVisibilityThreshold() - 10; 505 //if(threshold < 0) threshold = 0; 506 507 //traverser.SetVisibilityThreshold(threshold); 475 508 break; 476 509 case '1': … … 495 528 case 'G': 496 529 useOptimization = !useOptimization; 497 traverser.SetUseOptimization(useOptimization); 498 break; 499 case 'n': 500 case 'N': 501 useArbQueries = !useArbQueries; 502 traverser.SetUseArbQueries(useArbQueries); 503 break; 530 //traverser.SetUseOptimization(useOptimization); 531 break; 532 /* 504 533 case 'c': 505 534 case 'C': 506 507 535 hierarchy = traverser.GetHierarchy(); 508 536 // delete old hierarchy 509 if (hierarchy) delete hierarchy;537 if (hierarchy) delete hierarchy; 510 538 deleteGeometry(); 511 539 … … 522 550 resetTimer(); 523 551 break; 524 552 */ 525 553 default: 526 554 return; … … 534 562 { 535 563 // used to avoid vertical motion with the keys 536 Vector3 hvec = {viewDir[0], 0, viewDir[2]};564 Vector3 hvec = Vector3(viewDir[0], 0, viewDir[2]); 537 565 538 566 switch(c) … … 542 570 break; 543 571 case GLUT_KEY_F2: 544 numNextObjects -= 100;545 if(numNextObjects < 100) numNextObjects = 100;572 //numNextObjects -= 100; 573 //if(numNextObjects < 100) numNextObjects = 100; 546 574 break; 547 575 case GLUT_KEY_F3: 548 numNextObjects += 100;576 // numNextObjects += 100; 549 577 break; 550 578 case GLUT_KEY_F4: … … 563 591 break; 564 592 case GLUT_KEY_F8: 565 nextObjectType = (nextObjectType + 1) % Geometry::NUM_OBJECTS;593 //nextObjectType = (nextObjectType + 1) % Geometry::NUM_OBJECTS; 566 594 break; 567 595 case GLUT_KEY_LEFT: 568 rotateVectorY(viewDir, 0.2);596 // rotateVectorY(viewDir, 0.2); 569 597 break; 570 598 case GLUT_KEY_RIGHT: 571 rotateVectorY(viewDir, -0.2);599 //rotateVectorY(viewDir, -0.2); 572 600 break; 573 601 case GLUT_KEY_UP: 574 linCombVector3(eyePos, eyePos, hvec, 0.6);602 // linCombVector3(eyePos, eyePos, hvec, 0.6); 575 603 break; 576 604 case GLUT_KEY_DOWN: 577 linCombVector3(eyePos, eyePos, hvec, -0.6);605 //linCombVector3(eyePos, eyePos, hvec, -0.6); 578 606 break; 579 607 default: … … 598 626 if(w) winAspectRatio = (double) h / (double) w; 599 627 600 perspectiveDeg(eyeProjection, 60.0, 1.0/winAspectRatio, nearDist, 150.0);628 //perspectiveDeg(eyeProjection, 60.0, 1.0/winAspectRatio, nearDist, 150.0); 601 629 602 630 glutPostRedisplay(); … … 631 659 static double eyeXAngle = 0.0; 632 660 // not move in the vertical direction 633 Vector3 horView = {viewDir[0], 0, viewDir[2]}; 634 635 eyeXAngle = 0.6 * PI * (xEyeBegin - x) / 180.0; 661 Vector3 horView = Vector3(viewDir[0], 0, viewDir[2]); 662 663 eyeXAngle = 0.6 * M_PI * (xEyeBegin - x) / 180.0; 664 665 /* 636 666 linCombVector3(eyePos, eyePos, horView, (yMotionBegin - y) * 0.1); 637 667 … … 640 670 xEyeBegin = x; 641 671 yMotionBegin = y; 642 672 */ 643 673 glutPostRedisplay(); 644 674 } … … 649 679 // the 90 degree rotated view vector 650 680 // y zero so we don't move in the vertical 651 Vector3 rVec = {viewDir[0], 0, viewDir[2]};652 653 rotateVectorY(rVec, PI / 2.0);681 Vector3 rVec = Vector3(viewDir[0], 0, viewDir[2]); 682 683 /*rotateVectorY(rVec, PI / 2.0); 654 684 linCombVector3(eyePos, eyePos, rVec, (horizontalMotionBegin - x) * 0.1); 655 685 … … 658 688 horizontalMotionBegin = x; 659 689 verticalMotionBegin = y; 660 690 */ 661 691 glutPostRedisplay(); 662 692 } 663 693 664 694 665 void initExtensions(void)695 void InitExtensions(void) 666 696 { 667 697 GLenum err = glewInit(); 698 668 699 if (GLEW_OK != err) 669 700 { … … 672 703 exit(1); 673 704 } 674 675 if (GLEW_ARB_occlusion_query) 676 arbQuerySupport = true; 677 678 if (GLEW_NV_occlusion_query) 679 nvQuerySupport = true; 680 681 682 if (!arbQuerySupport && !nvQuerySupport) 683 { 684 printf("I require the GL_ARB_occlusion_query or the GL_NV_occlusion_query OpenGL extension to work.\n"); 705 if (!GLEW_ARB_occlusion_query) 706 { 707 printf("I require the GL_ARB_occlusion_query to work.\n"); 685 708 exit(1); 686 709 } … … 729 752 } 730 753 731 // explicitly deletes geometry generated for hierarchy732 // (deleting the hierarchy does not delete the geometry)733 void deleteGeometry()734 {735 for (GeometryList::iterator it = geometry.begin(); it != geometry.end(); it++)736 if(*it) delete (*it);737 738 geometry.clear();739 }740 741 754 // displays the visualisation of the kd tree node culling 742 755 void displayVisualization() … … 753 766 glViewport(winWidth / 2, winHeight / 2, winWidth, winHeight); 754 767 glPushMatrix(); 755 glLoadMatrix d(visView);768 glLoadMatrixf((float *)visView.x); 756 769 757 770 glClear(GL_DEPTH_BUFFER_BIT); 758 771 759 772 // --- visualization of the occlusion culling 760 HierarchyNode::SetRenderBoundingVolume(true);773 /*HierarchyNode::SetRenderBoundingVolume(true); 761 774 traverser.RenderVisualization(); 762 775 HierarchyNode::SetRenderBoundingVolume(showBoundingVolumes); 763 776 */ 764 777 glPopMatrix(); 765 778 glViewport(0, 0, winWidth, winHeight); 766 779 } 767 780 768 /** 769 sets up view matrix in order to get a good position 781 /** Sets up view matrix in order to get a good position 770 782 for viewing the kd tree node culling 771 783 */ 772 784 void setupVisView() 773 785 { 774 const Vector3 up = {0.0, 1.0, 0.0};775 776 Vector3 visPos = {24, 23, -6};786 const Vector3 up(0.0, 1.0, 0.0); 787 788 Vector3 visPos(24, 23, -6); 777 789 778 790 visPos[0] *= visZoomFactor; … … 780 792 visPos[2] *= visZoomFactor; 781 793 782 Vector3 visDir = {-1.3,-1,-1};783 784 normalize(visDir);785 look(visView, visPos, visDir, up);794 Vector3 visDir = Vector3(-1.3, -1, -1); 795 796 //normalize(visDir); 797 //look(visView, visPos, visDir, up); 786 798 } 787 799 … … 810 822 811 823 // cleanup routine after the main loop 812 void cleanUp() 813 { 814 if(traverser.GetHierarchy()) 815 delete traverser.GetHierarchy(); 816 817 deleteGeometry(); 818 819 Geometry::CleanUp(); 824 void CleanUp() 825 { 826 CLEAR_CONTAINER(sceneEntities); 827 DEL_PTR(traverser); 828 829 DEL_PTR(bvh); 820 830 } 821 831 … … 846 856 } 847 857 } 848 849 #endif
Note: See TracChangeset
for help on using the changeset viewer.