Changeset 2795 for GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp
- Timestamp:
- 06/22/08 05:24:22 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp
r2794 r2795 9 9 #include "Vector3.h" 10 10 #include "Matrix4x4.h" 11 #include " BinaryLoader.h"11 #include "ResourceManager.h" 12 12 #include "Bvh.h" 13 13 #include "Camera.h" … … 20 20 #include "Visualization.h" 21 21 #include "RenderState.h" 22 22 #include "Timer/PerfTimer.h" 23 23 24 24 … … 35 35 Bvh *bvh = NULL; 36 36 /// handles scene loading 37 BinaryLoader *loader = NULL;37 ResourceManager *loader = NULL; 38 38 /// the scene camera 39 39 Camera *camera = NULL; 40 /// the scene camera 41 Camera *visCamera = NULL; 40 42 /// the visualization 41 43 Visualization *visualization = NULL; … … 43 45 RenderState state; 44 46 /// the rendering algorithm 45 int renderMode = RenderTraverser::C ULL_FRUSTUM;47 int renderMode = RenderTraverser::CHCPLUSPLUS; 46 48 // eye near plane distance 47 49 float nearDist = 0.1f; … … 49 51 int threshold; 50 52 53 float fov = 50.0f; 54 51 55 int assumedVisibleFrames = 10; 52 56 int maxBatchSize = 50; 53 57 54 const float keyForwardMotion = 0.5f; 55 const float keyRotation = 0.05f; 58 int trianglesPerVirtualLeaf = 1000; 59 60 /// these values get scaled with the frame rate 61 const float keyForwardMotion = 50.0f; 62 const float keyRotation = 2.0f; 63 /// elapsed time in seconds 64 double elapsedTime = 1.0f; 56 65 57 66 int winWidth = 1024; … … 84 93 bool useOptimization = false; 85 94 bool useTightBounds = true; 86 bool useRenderQueue = false;95 bool useRenderQueue = true; 87 96 bool useMultiQueries = true; 88 97 98 /// the accumulated z axis rotation 89 99 float rotation = 0; 90 100 91 101 Matrix4x4 visView = IdentityMatrix(); 102 103 SceneEntityContainer skyGeometry; 92 104 93 105 bool leftKeyPressed = false; … … 129 141 void KeyHorizontalMotion(float shift); 130 142 void KeyVerticalMotion(float shift); 131 void KeyRotate(float angle); 143 144 145 inline float KeyRotationAngle() { return keyRotation * elapsedTime; } 146 inline float KeyShift() { return keyForwardMotion * elapsedTime; } 132 147 133 148 … … 137 152 int returnCode = 0; 138 153 139 #ifdef _CRT_SET 140 141 //Now just call this function at the start of your program and if you're 142 //compiling in debug mode (F5), any leaks will be displayed in the Output 143 //window when the program shuts down. If you're not in debug mode this will 144 //be ignored. Use it as you will! 145 //note: from GDNet Direct [3.8.04 - 3.14.04] void detectMemoryLeaks() { 146 147 _CrtSetDbgFlag(_CRTDBG_LEAK_CHECK_DF|_CRTDBG_ALLOC_MEM_DF); 148 _CrtSetReportMode(_CRT_ASSERT,_CRTDBG_MODE_FILE); 149 _CrtSetReportFile(_CRT_ASSERT,_CRTDBG_FILE_STDERR); 150 #endif 151 152 153 camera = new Camera(winWidth, winHeight, 60); 154 camera = new Camera(winWidth, winHeight, fov); 154 155 camera->SetNear(nearDist); 156 157 visCamera = new Camera(winWidth, winHeight, fov); 158 visCamera->SetNear(nearDist); 155 159 156 160 glutInitWindowSize(winWidth, winHeight); … … 158 162 glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH); 159 163 160 glutCreateWindow(" Coherent HierarchicalCulling");164 glutCreateWindow("FriendlyCulling"); 161 165 162 166 glutDisplayFunc(Display); … … 177 181 178 182 179 loader = new BinaryLoader();183 loader = new ResourceManager(); 180 184 181 185 //const string filename("data/city/model/city.dem"); … … 190 194 exit(0); 191 195 } 196 197 SceneEntityContainer dummy; 198 199 const string envname = string(model_path + "env.dem"); 200 201 if (loader->Load(envname, skyGeometry)) 202 cout << "sky box " << filename << " loaded" << endl; 203 else 204 { 205 cerr << "loading sky box " << filename << " failed" << endl; 206 CleanUp(); 207 exit(0); 208 } 209 192 210 193 211 const string bvh_filename = string(model_path + "city.bvh"); … … 206 224 ResetTraverser(); 207 225 208 camera->SetDirection(Vector3(0.961829f, 0.273652f, 0.0f)); 226 //camera->SetDirection(Vector3(0.961829f, 0.273652f, 0.0f)); 227 camera->Pitch(-M_PI * 0.5); 209 228 camera->SetPosition(Vector3(483.398f, 242.364f, 186.078f)); 210 229 … … 265 284 "", 266 285 "'F1' - shows/dismisses this message", 267 "'F2' - shows/hides statistics",286 "'F2' - shows/hides bird eye view", 268 287 "'F3' - shows/hides bounds (boxes or tight bounds)", 269 "'F4' - shows/hides bird eye view",270 "' f5', - load helpScreen",288 "'F4' - shows/hides statistics", 289 "'F5', - shows/hides parameters", 271 290 "'SPACE' - cycles through occlusion culling algorithms", 272 291 "", … … 281 300 "'-' - decreases max batch size", 282 301 "'+' - increases max batch size", 302 "'4' - decrease triangles per virtual leaf (sets depth of bvh)", 303 "'5' - increase triangles per virtual leaf (sets depth of bvh)", 283 304 "'6' - decrease assumed visible frames", 284 305 "'7' - increase assumed visible frames", 285 "'8' - upward motion",286 "'9' - downward motion",306 "'8' - downward motion", 307 "'9' - upward motion", 287 308 "", 288 309 "'R' - use render queue", … … 405 426 } 406 427 407 void SetupEyeView( void)428 void SetupEyeView() 408 429 { 409 430 glMatrixMode(GL_PROJECTION); 410 431 glLoadIdentity(); 411 432 412 gluPerspective( 60.0f, 1.0f / winAspectRatio, nearDist, 2.0f * Magnitude(bvh->GetBox().Diagonal()));433 gluPerspective(fov, 1.0f / winAspectRatio, nearDist, 10.0f * Magnitude(bvh->GetBox().Diagonal())); 413 434 414 435 glMatrixMode(GL_MODELVIEW); 436 glLoadIdentity(); 415 437 camera->SetupCameraView(); 416 438 … … 423 445 424 446 425 void KeyRotate(float angle)426 {427 Vector3 viewDir = camera->GetDirection();428 // rotate view vector429 Matrix4x4 rot = RotationZMatrix(angle);430 viewDir = rot * viewDir;431 camera->SetDirection(viewDir);432 }433 434 435 447 void KeyHorizontalMotion(float shift) 436 448 { … … 459 471 void Display() 460 472 { 473 PerfTimer frameTimer; 474 475 frameTimer.Start(); 476 461 477 if (leftKeyPressed) 462 KeyRotate(keyRotation);478 camera->Pitch(KeyRotationAngle()); 463 479 if (rightKeyPressed) 464 KeyRotate(-keyRotation);480 camera->Pitch(-KeyRotationAngle()); 465 481 if (upKeyPressed) 466 KeyHorizontalMotion( keyForwardMotion);482 KeyHorizontalMotion(KeyShift()); 467 483 if (downKeyPressed) 468 KeyHorizontalMotion(- keyForwardMotion);484 KeyHorizontalMotion(-KeyShift()); 469 485 if (eightKeyPressed) 470 KeyVerticalMotion( keyForwardMotion);486 KeyVerticalMotion(-KeyShift()); 471 487 if (nineKeyPressed) 472 KeyVerticalMotion( -keyForwardMotion);488 KeyVerticalMotion(KeyShift()); 473 489 474 490 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); … … 479 495 // actually render the scene geometry using one of the specified algorithms 480 496 traverser->RenderScene(); 481 497 498 499 glEnableClientState(GL_VERTEX_ARRAY); 500 glEnableClientState(GL_NORMAL_ARRAY); 501 502 SceneEntityContainer::const_iterator sit, sit_end = skyGeometry.end(); 503 504 for (sit = skyGeometry.begin(); sit != sit_end; ++ sit) 505 (*sit)->Render(&state); 506 507 glDisableClientState(GL_VERTEX_ARRAY); 508 glDisableClientState(GL_NORMAL_ARRAY); 509 510 state.Reset(); 511 482 512 if (visMode) DisplayVisualization(); 483 513 … … 485 515 486 516 glutSwapBuffers(); 517 518 elapsedTime = frameTimer.Elapsed(); 487 519 } 488 520 … … 531 563 { 532 564 eightKeyPressed = true; 533 KeyVerticalMotion( keyForwardMotion);565 KeyVerticalMotion(-KeyShift()); 534 566 break; 535 567 } … … 537 569 { 538 570 nineKeyPressed = true; 539 KeyVerticalMotion( -keyForwardMotion);571 KeyVerticalMotion(+KeyShift()); 540 572 break; 541 573 } … … 549 581 { 550 582 leftKeyPressed = true; 551 KeyRotate(keyRotation);583 camera->Pitch(KeyRotationAngle()); 552 584 } 553 585 break; … … 556 588 { 557 589 rightKeyPressed = true; 558 KeyRotate(-keyRotation);590 camera->Pitch(-KeyRotationAngle()); 559 591 } 560 592 break; … … 563 595 { 564 596 upKeyPressed = true; 565 KeyHorizontalMotion( keyForwardMotion);597 KeyHorizontalMotion(KeyShift()); 566 598 } 567 599 break; … … 570 602 { 571 603 downKeyPressed = true; 572 KeyHorizontalMotion(- keyForwardMotion);604 KeyHorizontalMotion(-KeyShift()); 573 605 } 574 606 break; … … 587 619 } 588 620 break; 589 590 591 621 case '4': 622 if (trianglesPerVirtualLeaf >= 100) 623 trianglesPerVirtualLeaf -= 100; 624 625 bvh->SetVirtualLeaves(trianglesPerVirtualLeaf); 626 break; 627 case '5': 628 trianglesPerVirtualLeaf += 100; 629 bvh->SetVirtualLeaves(trianglesPerVirtualLeaf); 630 break; 592 631 default: 593 632 return; … … 658 697 void Special(int c, int x, int y) 659 698 { 660 // used to avoid vertical motion with the keys661 Vector3 hvec = Vector3(camera->GetDirection()[0], camera->GetDirection()[1], 0.0f);662 663 699 switch(c) 664 700 { … … 667 703 break; 668 704 case GLUT_KEY_F2: 669 showStatistics = !showStatistics;705 visMode = !visMode; 670 706 break; 671 707 case GLUT_KEY_F3: … … 674 710 break; 675 711 case GLUT_KEY_F4: 676 visMode = !visMode;712 showStatistics = !showStatistics; 677 713 break; 678 714 case GLUT_KEY_F5: … … 682 718 { 683 719 leftKeyPressed = true; 684 KeyRotate(keyRotation);720 camera->Pitch(KeyRotationAngle()); 685 721 } 686 722 break; … … 688 724 { 689 725 rightKeyPressed = true; 690 KeyRotate(-keyRotation);726 camera->Pitch(-KeyRotationAngle()); 691 727 } 692 728 break; … … 694 730 { 695 731 upKeyPressed = true; 696 KeyHorizontalMotion( keyForwardMotion);732 KeyHorizontalMotion(KeyShift()); 697 733 } 698 734 break; … … 700 736 { 701 737 downKeyPressed = true; 702 KeyHorizontalMotion(- keyForwardMotion);738 KeyHorizontalMotion(-KeyShift()); 703 739 } 704 740 break; … … 728 764 glLoadIdentity(); 729 765 730 gluPerspective( 60.0f, 1.0f / winAspectRatio, nearDist, 2.0f * Magnitude(bvh->GetBox().Diagonal()));766 gluPerspective(fov, 1.0f / winAspectRatio, nearDist, 2.0f * Magnitude(bvh->GetBox().Diagonal())); 731 767 732 768 glMatrixMode(GL_MODELVIEW); … … 768 804 void LeftMotion(int x, int y) 769 805 { 770 static float eyeXAngle = 0.0f;771 772 806 Vector3 viewDir = camera->GetDirection(); 773 807 Vector3 pos = camera->GetPosition(); … … 776 810 Vector3 horView(viewDir[0], viewDir[1], 0); 777 811 778 eyeXAngle = 0.2f * M_PI * (xEyeBegin - x) / 180.0; 779 780 rotation += eyeXAngle; 781 782 // rotate view vector 783 Matrix4x4 rot = RotationZMatrix(eyeXAngle); 784 viewDir = rot * viewDir; 812 float eyeXAngle = 0.2f * M_PI * (xEyeBegin - x) / 180.0; 813 814 camera->Pitch(eyeXAngle); 785 815 786 816 pos += horView * (yMotionBegin - y) * 0.2f; 787 788 camera->SetDirection(viewDir); 817 789 818 camera->SetPosition(pos); 790 819 … … 801 830 void RightMotion(int x, int y) 802 831 { 803 static float eyeYAngle = 0.0f; 804 805 Vector3 viewDir = camera->GetDirection(); 806 Vector3 right = camera->GetRightVector(); 807 808 eyeYAngle = -0.2f * M_PI * (yEyeBegin - y) / 180.0; 809 810 // rotate view vector 811 Matrix4x4 rot = RotationAxisMatrix(right, eyeYAngle); 812 viewDir = rot * viewDir; 813 814 camera->SetDirection(viewDir); 815 832 float eyeYAngle = -0.2f * M_PI * (yEyeBegin - y) / 180.0; 833 834 camera->Yaw(eyeYAngle); 835 816 836 yEyeBegin = y; 817 818 837 glutPostRedisplay(); 819 838 } … … 907 926 // displays the visualisation of culling algorithm 908 927 void DisplayVisualization() 909 { 928 {cout<<"here34"<<endl; 910 929 SetupVisView(); 911 930 … … 923 942 glViewport(winWidth - winWidth / 4, winHeight - winHeight / 3, winWidth, winHeight); 924 943 925 926 944 glMatrixMode(GL_PROJECTION); 927 945 glLoadIdentity(); 928 946 929 //gluPerspective(60.0f, 1.0f / winAspectRatio, nearDist, 2.0f * Magnitude(bvh->GetBox().Diagonal())); 947 gluPerspective(fov, 1.0f / winAspectRatio, nearDist, 20.0f * Magnitude(bvh->GetBox().Diagonal())); 948 930 949 AxisAlignedBox3 box = bvh->GetBox(); 931 950 const float offs = 2000; 932 glOrtho(box.Min().y - offs, box.Max().y + offs, box.Min().y - offs, box.Max().y + offs, 0.1, 20.0f * Magnitude(bvh->GetBox().Diagonal())); 933 934 935 glPushMatrix(); 936 951 952 //glOrtho(box.Min().y - offs, box.Max().y + offs, box.Min().y - offs, box.Max().y + offs, 0.1, 20.0f * Magnitude(bvh->GetBox().Diagonal())); 953 //glOrtho(-offs, offs, offs, -offs, 0.1, 20.0f * Magnitude(bvh->GetBox().Diagonal())); 954 //glPushMatrix(); 955 956 Vector3 vizpos = Vector3(box.Center().x, box.Center().y, box.Max().z); 957 visCamera->SetPosition(vizpos); 958 visCamera->Yaw(-0.5 * M_PI); 959 cout<<"pos: " << visCamera->GetPosition()<<endl; 937 960 glMatrixMode(GL_MODELVIEW); 938 961 glLoadIdentity(); 939 962 940 glMultMatrixf((float *)visView.x); 963 visCamera->SetupCameraView(); 964 //glMultMatrixf((float *)visView.x); 941 965 942 966 //SetupLighting(); … … 947 971 glLightfv(GL_LIGHT1, GL_POSITION, position1); 948 972 949 950 951 973 glClear(GL_DEPTH_BUFFER_BIT); 952 974 … … 956 978 visualization->Render(); 957 979 958 glPopMatrix();980 //glPopMatrix(); 959 981 960 982 glViewport(0, 0, winWidth, winHeight); … … 991 1013 void CleanUp() 992 1014 { 993 CLEAR_CONTAINER(sceneEntities);994 1015 DEL_PTR(traverser); 995 996 1016 DEL_PTR(bvh); 997 1017 DEL_PTR(visualization); 998 1018 DEL_PTR(camera); 999 1000 1019 DEL_PTR(loader); 1001 1020 } … … 1040 1059 char msg6[200]; 1041 1060 char msg7[200]; 1061 char msg8[200]; 1042 1062 1043 1063 … … 1084 1104 sprintf_s(msg6, "issued queries: %5d, state changes: %5d", issuedQueries, stateChanges); 1085 1105 1106 sprintf_s(msg8, "triangles per virtual leaf: %5d", trianglesPerVirtualLeaf); 1107 1086 1108 sprintf_s(msg7, "fps: %6.1f", fps); 1087 1109 … … 1111 1133 Output(20, 150, msg2); 1112 1134 Output(20, 180, msg3); 1135 Output(20, 210, msg8); 1113 1136 } 1114 1137 }
Note: See TracChangeset
for help on using the changeset viewer.