Changeset 2758 for GTP/trunk/App/Demos/Vis/CHC_revisited
- Timestamp:
- 06/14/08 03:38:30 (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/Texture.cpp
r2757 r2758 67 67 68 68 gluBuild2DMipmaps(GL_TEXTURE_2D, 3, mWidth, mHeight, 69 69 GL_RGBA, GL_UNSIGNED_BYTE, mImage); 70 70 71 71 //glTexImage2D(GL_TEXTURE_2D, 0, 3, mWidth, mHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, mImage); … … 119 119 120 120 int Texture::GetPixelSize() const 121 122 121 { 123 122 if (mFormat == FORMAT_RGBA) -
GTP/trunk/App/Demos/Vis/CHC_revisited/chcdemo.cpp
r2757 r2758 103 103 void mouse(int button, int state, int x, int y); 104 104 void leftMotion(int x, int y); 105 void rightMotion(int x, int y); 105 106 void middleMotion(int x, int y); 106 107 void drawEyeView(void); … … 112 113 113 114 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 124 115 125 116 int main(int argc, char* argv[]) 126 117 { 118 camera = new Camera(800, 600); 119 127 120 glutInitWindowSize(800, 600); 128 121 glutInit(&argc, argv); … … 149 142 const string filename("city.dem"); 150 143 151 camera = new Camera(800, 600);152 153 144 if (loader.Load(filename, sceneEntities)) 154 145 cout << "scene " << filename << " loaded" << endl; … … 165 156 Debug << "scene box: " << sceneBox << endl; 166 157 167 SetupProjection(800, 600, 60, sceneBox);158 //SetupProjection(800, 600, 60, sceneBox); 168 159 //camera->LookAtBox(sceneBox); 169 160 camera->LookInBox(sceneBox); … … 319 310 void SetupEyeView(void) 320 311 { 321 SetupProjection(800,600,60,sceneBox);312 //SetupProjection(800,600,60,sceneBox); 322 313 glMatrixMode(GL_MODELVIEW); 323 314 camera->SetupCameraView(); … … 624 615 winHeight = h; 625 616 626 if(w) winAspectRatio = (double) h / (double) w; 627 628 //perspectiveDeg(eyeProjection, 60.0, 1.0/winAspectRatio, nearDist, 150.0); 617 if (w) winAspectRatio = (double) h / (double) w; 618 619 glMatrixMode(GL_PROJECTION); 620 glLoadIdentity(); 621 622 gluPerspective(60.0f, 1.0f / winAspectRatio, nearDist, 2.0 * Magnitude(sceneBox.Diagonal())); 623 glMatrixMode(GL_MODELVIEW); 624 625 //perspectiveDeg(eyeProjection, 60.0, 1.0f/winAspectRatio, nearDist, 150.0); 629 626 630 627 glutPostRedisplay(); … … 634 631 void mouse(int button, int state, int x, int y) 635 632 { 636 if (((button == GLUT_LEFT_BUTTON) || (button == GLUT_RIGHT_BUTTON)) && state == GLUT_DOWN)633 if ((button == GLUT_LEFT_BUTTON) && (state == GLUT_DOWN)) 637 634 { 638 635 xEyeBegin = x; … … 641 638 glutMotionFunc(leftMotion); 642 639 } 643 else if(button == GLUT_MIDDLE_BUTTON && state == GLUT_DOWN) 640 else if ((button == GLUT_RIGHT_BUTTON) && (state == GLUT_DOWN)) 641 { 642 yEyeBegin = y; 643 yMotionBegin = y; 644 645 glutMotionFunc(rightMotion); 646 } 647 else if ((button == GLUT_MIDDLE_BUTTON) && (state == GLUT_DOWN)) 644 648 { 645 649 horizontalMotionBegin = x; … … 651 655 } 652 656 653 /** 654 rotation for left/right mouse drag657 658 /** rotation for left/right mouse drag 655 659 motion for up/down mouse drag 656 660 */ 657 661 void leftMotion(int x, int y) 658 662 { 659 static double eyeXAngle = 0.0; 660 // not move in the vertical direction 661 Vector3 horView = Vector3(viewDir[0], 0, viewDir[2]); 662 663 eyeXAngle = 0.6 * M_PI * (xEyeBegin - x) / 180.0; 664 665 /* 666 linCombVector3(eyePos, eyePos, horView, (yMotionBegin - y) * 0.1); 667 668 rotateVectorY(viewDir, eyeXAngle); 663 static float eyeXAngle = 0.0f; 664 665 Vector3 viewDir = camera->GetDirection(); 666 Vector3 pos = camera->GetPosition(); 667 668 // don't move in the vertical direction 669 Vector3 horView(viewDir[0], 0, viewDir[2]); 670 671 eyeXAngle = -0.2f * M_PI * (xEyeBegin - x) / 180.0; 672 673 // rotate view vector 674 Matrix4x4 rot = RotationYMatrix(eyeXAngle); 675 viewDir = rot * viewDir; 676 677 pos += horView * (yMotionBegin - y) * 0.2f; 678 679 camera->SetDirection(viewDir); 680 camera->SetPosition(pos); 669 681 670 682 xEyeBegin = x; 671 683 yMotionBegin = y; 672 */ 684 673 685 glutPostRedisplay(); 674 686 } 687 688 689 /** rotation for left/right mouse drag 690 motion for up/down mouse drag 691 */ 692 void rightMotion(int x, int y) 693 { 694 static float eyeYAngle = 0.0f; 695 696 Vector3 viewDir = camera->GetDirection(); 697 Vector3 right = camera->GetRightVector(); 698 699 eyeYAngle = -0.2f * M_PI * (yEyeBegin - y) / 180.0; 700 701 // rotate view vector 702 Matrix4x4 rot = RotationAxisMatrix(right, eyeYAngle); 703 viewDir = rot * viewDir; 704 705 camera->SetDirection(viewDir); 706 707 yEyeBegin = y; 708 709 glutPostRedisplay(); 710 } 711 675 712 676 713 // strafe 677 714 void middleMotion(int x, int y) 678 715 { 716 Vector3 viewDir = camera->GetDirection(); 717 Vector3 pos = camera->GetPosition(); 718 679 719 // the 90 degree rotated view vector 680 720 // y zero so we don't move in the vertical 681 Vector3 rVec = Vector3(viewDir[0], 0, viewDir[2]); 682 683 /*rotateVectorY(rVec, PI / 2.0); 684 linCombVector3(eyePos, eyePos, rVec, (horizontalMotionBegin - x) * 0.1); 685 686 eyePos[1] += (verticalMotionBegin - y) * 0.1; 721 Vector3 rVec(viewDir[0], 0, viewDir[2]); 722 723 Matrix4x4 rot = RotationYMatrix(M_PI * 0.5f); 724 rVec = rot * rVec; 725 726 pos += rVec * (x - horizontalMotionBegin) * 0.1f; 727 pos[1] += (verticalMotionBegin - y) * 0.1f; 728 729 camera->SetPosition(pos); 687 730 688 731 horizontalMotionBegin = x; 689 732 verticalMotionBegin = y; 690 */ 733 691 734 glutPostRedisplay(); 692 735 }
Note: See TracChangeset
for help on using the changeset viewer.