Changeset 2780 for GTP/trunk/App/Demos/Vis/CHC_revisited
- Timestamp:
- 06/19/08 18:43:17 (17 years ago)
- Location:
- GTP/trunk/App/Demos/Vis/CHC_revisited
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/CHC_revisited/Camera.cpp
r2779 r2780 7 7 { 8 8 9 using namespace std;10 11 9 12 10 Camera::Camera() … … 15 13 mHeight = 100; 16 14 mFovy = 90.0f * M_PI / 180.0f; 17 mIsOrtho = false;18 19 SetPosition(Vector3(0, 0, 0));20 21 mPitch = mYaw = 0;22 Precompute();23 15 } 24 16 … … 30 22 31 23 mFovy = fieldOfView * M_PI / 180.0f; 32 33 mIsOrtho = false;34 35 SetPosition(Vector3(0, 0, 0));36 37 SetPosition(Vector3(0, 0, 0));38 39 mPitch = mYaw = 0;40 Precompute();41 24 } 42 25 … … 44 27 void Camera::Precompute() 45 28 { 46 Vector3 direction = Vector3(0, 1, 0); 47 48 Vector3 side = CrossProd(Vector3(1, 0, 0), direction); 49 50 Vector3 up = -Normalize(CrossProd(side, direction)); 51 Vector3 right = -Normalize(CrossProd(direction, up)); 52 53 mBaseOrientation = Matrix4x4(right, up, direction); 54 mViewOrientation = mBaseOrientation; 55 cout<<"view: " << direction << " right: " << right << " up " << up << endl; 56 } 57 29 mDirection.Normalize(); 30 31 //Vector3 side = CrossProd(Vector3(0, 1, 0), mDirection); 32 Vector3 side = CrossProd(Vector3(0, 0, 1), mDirection); 33 34 mUp = -Normalize(CrossProd(side, mDirection)); 35 mRight = -Normalize(CrossProd(mDirection, mUp)); 36 37 38 float k = tan(mFovy/2); 39 mUp *= k; 40 mRight *= k*mWidth/mHeight; 41 } 58 42 59 43 … … 61 45 { 62 46 mPosition = pos; 47 Precompute(); 48 } 49 50 51 void Camera::SetDirection(const Vector3 &dir) 52 { 53 mDirection = dir; 54 Precompute(); 63 55 } 64 56 … … 67 59 { 68 60 mNear = nearDist; 61 } 62 63 64 void Camera::LookInBox(const AxisAlignedBox3 &box) 65 { 66 //mDirection = Vector3(0, 0, 1); 67 mDirection = Vector3(0, 1, 0); 68 mPosition = box.Center(); 69 mPosition.z = box.Min(2) + 0.9f * box.Size(2); 70 71 Precompute(); 72 } 73 74 75 void Camera::LookAtBox(const AxisAlignedBox3 &box) 76 { 77 mDirection = Vector3(0, box.Min().y - box.Max().y, 0); 78 mPosition = Vector3(0);//box.Max() - mDirection; 79 80 Precompute(); 69 81 } 70 82 … … 147 159 void Camera::SetupCameraView() 148 160 { 149 Matrix4x4 viewOrientation = mViewOrientation;150 Vector3 pos = -mPosition;151 pos = mViewOrientation * pos;152 153 viewOrientation.x[3][0] = pos.x;154 viewOrientation.x[3][1] = pos.y;155 viewOrientation.x[3][2] = pos.z;156 157 161 glLoadIdentity(); 158 glMultMatrixf((float *)viewOrientation.x); 162 gluLookAt(mPosition.x, mPosition.y, mPosition.z, 163 mPosition.x + mDirection.x, mPosition.y + mDirection.y, mPosition.z + mDirection.z, 164 mUp.x, mUp.y, mUp.z); 165 166 //std::cout << "dir: " << mDirection << " pos: " << mPosition << " up: " << mUp << std::endl; 159 167 } 160 168 … … 172 180 const float w_far = h_far * GetAspect(); 173 181 174 const Vector3 view = GetDirection();182 const Vector3 view = mDirection; 175 183 const Vector3 fc = mPosition + view * z_far; 176 184 177 const Vector3 up = GetUpVector();178 179 const Vector3 right = GetRightVector();185 const Vector3 up = mUp; 186 187 const Vector3 right = mRight; 180 188 181 189 Vector3 t1, t2; … … 189 197 fbr = fc - t1 + t2; 190 198 191 const Vector3 nc = mPosition + view* z_near;199 const Vector3 nc = mPosition + mDirection * z_near; 192 200 193 201 t1 = h_near * 0.5f * up; … … 201 209 202 210 203 void Camera::SetOrtho(bool ortho) 204 { 205 mIsOrtho = true; 206 } 207 208 209 void Camera::Yaw(float angle) 210 { 211 mYaw += angle; 212 CalculateFromPitchAndYaw(); 213 /* 214 Matrix4x4 viewOrientation(mRight, mUp, mDirection); 215 Matrix4x4 rot = RotationYMatrix(angle); 216 217 viewOrientation = viewOrientation * rot; 218 219 mDirection = Vector3(viewOrientation.x[2][0], viewOrientation.x[2][1], viewOrientation.x[2][2]); 220 mRight = Vector3(viewOrientation.x[0][0], viewOrientation.x[0][1], viewOrientation.x[0][2]); 221 mUp = Vector3(viewOrientation.x[1][0], viewOrientation.x[1][1], viewOrientation.x[1][2]);*/ 222 } 223 224 225 void Camera::Pitch(float angle) 226 { 227 mPitch += angle; 228 CalculateFromPitchAndYaw(); 229 } 230 231 232 void Camera::CalculateFromPitchAndYaw() 233 { 234 mViewOrientation = mBaseOrientation; 235 236 Matrix4x4 roty = RotationYMatrix(mPitch); 237 Matrix4x4 rotx = RotationXMatrix(mYaw); 238 239 mViewOrientation *= roty; 240 mViewOrientation *= rotx; 241 } 242 243 244 Vector3 Camera::GetDirection() const 245 { 246 return Vector3(mViewOrientation.x[0][2], mViewOrientation.x[1][2], mViewOrientation.x[2][2]); 247 } 248 249 250 Vector3 Camera::GetUpVector() const 251 { 252 return Vector3(mViewOrientation.x[0][1], mViewOrientation.x[1][1], mViewOrientation.x[2][1]); 253 } 254 255 256 Vector3 Camera::GetRightVector() const 257 { 258 return Vector3(mViewOrientation.x[0][0], mViewOrientation.x[1][0], mViewOrientation.x[2][0]); 259 260 } 261 262 263 } 264 211 } 212 -
GTP/trunk/App/Demos/Vis/CHC_revisited/Camera.h
r2778 r2780 20 20 { 21 21 /// the 6 clip planes 22 //float mClipPlane[6][4]; 22 23 Plane3 mClipPlanes[6]; 23 24 … … 29 30 Camera(int width, int height, float fieldOfView = 90.f); 30 31 32 void Precompute(); 33 34 void LookInBox(const AxisAlignedBox3 &box); 35 36 void LookAtBox(const AxisAlignedBox3 &box); 31 37 32 38 void SetPosition(const Vector3 &pos); 33 39 40 void SetDirection(const Vector3 &dir); 41 34 42 inline Vector3 GetPosition() const { return mPosition; } 35 Vector3 GetDirection() const;36 Vector3 GetUpVector() const;37 Vector3 GetRightVector() const;43 inline Vector3 GetDirection() const { return mDirection; } 44 inline Vector3 GetUpVector() const { return mUp; } 45 inline Vector3 GetRightVector() const { return mRight; } 38 46 39 47 inline float GetFov() const { return mFovy; } … … 52 60 inline float GetNear() const { return mNear; } 53 61 void SetNear(float nearDist); 54 55 inline float GetFar() const { return mFar; }56 57 void SetFar(float farDist) { mFar = farDist; }58 59 void SetOrtho(bool ortho);60 61 void Yaw(float angle);62 void Pitch(float angle);63 /** Sets up viewing in gl64 */65 void Render();66 62 67 63 68 64 protected: 69 65 70 void Precompute();71 72 void CalculateFromPitchAndYaw();73 74 66 //////////////// 75 67 68 Vector3 mPosition; 69 Vector3 mDirection; 70 71 /// up vector takes into account the FOV at a unit distance from the origin 72 Vector3 mUp; 73 /// right vector takes into account the FOV at a unit distance from the origin 74 Vector3 mRight; 76 75 77 76 float mFovy; … … 80 79 81 80 float mNear; 82 83 float mFar;84 85 bool mIsOrtho;86 87 Matrix4x4 mBaseOrientation;88 Matrix4x4 mViewOrientation;89 90 float mPitch;91 float mYaw;92 93 Vector3 mPosition;94 81 }; 95 82 -
GTP/trunk/App/Demos/Vis/CHC_revisited/SceneQuery.cpp
r2778 r2780 63 63 64 64 Camera *orthoCam = new Camera(len.x, len.y); 65 orthoCam->SetOrtho(true);65 //orthoCam->SetOrtho(true); 66 66 67 67 orthoCam->SetNear(0.0f); 68 orthoCam->SetFar(len.z);68 //orthoCam->SetFar(len.z); 69 69 70 70 orthoCam->SetPosition(pos); … … 72 72 cout << "fov: " << orthoCam->GetFov() << endl; 73 73 cout << "near: " << orthoCam->GetNear() << endl; 74 cout << "far: " << orthoCam->GetFar() << endl;74 //cout << "far: " << orthoCam->GetFar() << endl; 75 75 cout << "aspect: " << orthoCam->GetAspect() << endl; 76 76 … … 80 80 81 81 //orthoCam->SetDirection(Vector3(0, 1, 0)); 82 orthoCam->Yaw(M_PI * 0.5f);82 //orthoCam->Yaw(M_PI * 0.5f); 83 83 84 84 renderer->SetCamera(orthoCam); -
GTP/trunk/App/Demos/Vis/CHC_revisited/chcdemo.cpp
r2779 r2780 163 163 //camera->LookInBox(bvh->GetBox()); 164 164 165 //camera->SetDirection(Vector3(0.961829f, 0.273652f, 0.0f)); 166 //camera->SetDirection(Vector3(0.0f, 1.0f, 0.0f)); 165 camera->SetDirection(Vector3(0.961829f, 0.273652f, 0.0f)); 167 166 camera->SetPosition(Vector3(483.398f, 242.364f, 186.078f)); 168 167 … … 295 294 break; 296 295 case RenderTraverser::CHC: 297 cout << "using chc" << endl;298 296 traverser = new CHCTraverser(); 299 297 break; … … 490 488 case 'A': 491 489 { 492 camera->Pitch(keyRotation); 490 Vector3 viewDir = camera->GetDirection(); 491 // rotate view vector 492 Matrix4x4 rot = RotationZMatrix(keyRotation); 493 viewDir = rot * viewDir; 494 camera->SetDirection(viewDir); 493 495 } 494 496 break; … … 496 498 case 'D': 497 499 { 498 camera->Pitch(-keyRotation); 500 Vector3 viewDir = camera->GetDirection(); 501 // rotate view vector 502 Matrix4x4 rot = RotationZMatrix(-keyRotation); 503 viewDir = rot * viewDir; 504 camera->SetDirection(viewDir); 499 505 } 500 506 break; 501 507 case 'w': 502 508 case 'W': 509 { 510 Vector3 pos = camera->GetPosition(); 511 pos += hvec * keyForwardMotion; 512 camera->SetPosition(pos); 513 } 514 break; 515 case 'x': 516 case 'X': 503 517 { 504 518 Vector3 pos = camera->GetPosition(); … … 507 521 } 508 522 break; 509 case 'x':510 case 'X':511 {512 Vector3 pos = camera->GetPosition();513 pos += hvec * keyForwardMotion;514 camera->SetPosition(pos);515 }516 break;517 523 case 'r': 518 524 case 'R': … … 541 547 case GLUT_KEY_LEFT: 542 548 { 543 camera->Pitch(keyRotation); 549 Vector3 viewDir = camera->GetDirection(); 550 // rotate view vector 551 Matrix4x4 rot = RotationZMatrix(keyRotation); 552 viewDir = rot * viewDir; 553 camera->SetDirection(viewDir); 544 554 } 545 555 break; 546 556 case GLUT_KEY_RIGHT: 547 557 { 548 camera->Pitch(-keyRotation); 558 Vector3 viewDir = camera->GetDirection(); 559 // rotate view vector 560 Matrix4x4 rot = RotationZMatrix(-keyRotation); 561 viewDir = rot * viewDir; 562 camera->SetDirection(viewDir); 549 563 } 550 564 break; 551 565 case GLUT_KEY_UP: 566 { 567 Vector3 pos = camera->GetPosition(); 568 pos += hvec * 0.6f; 569 camera->SetPosition(pos); 570 } 571 break; 572 case GLUT_KEY_DOWN: 552 573 { 553 574 Vector3 pos = camera->GetPosition(); 554 575 pos -= hvec * 0.6f; 555 camera->SetPosition(pos);556 }557 break;558 case GLUT_KEY_DOWN:559 {560 Vector3 pos = camera->GetPosition();561 pos += hvec * 0.6f;562 576 camera->SetPosition(pos); 563 577 } … … 627 641 void leftMotion(int x, int y) 628 642 { 643 static float eyeXAngle = 0.0f; 644 629 645 Vector3 viewDir = camera->GetDirection(); 630 646 Vector3 pos = camera->GetPosition(); … … 633 649 Vector3 horView(viewDir[0], viewDir[1], 0); 634 650 635 float eyeXAngle = 0.2f * M_PI * (xEyeBegin - x) / 180.0; 636 637 camera->Pitch(eyeXAngle); 638 639 pos -= horView * (yMotionBegin - y) * 0.2f; 640 651 eyeXAngle = 0.2f * M_PI * (xEyeBegin - x) / 180.0; 652 653 // rotate view vector 654 Matrix4x4 rot = RotationZMatrix(eyeXAngle); 655 viewDir = rot * viewDir; 656 657 pos += horView * (yMotionBegin - y) * 0.2f; 658 659 camera->SetDirection(viewDir); 641 660 camera->SetPosition(pos); 642 661 … … 653 672 void rightMotion(int x, int y) 654 673 { 655 float eyeYAngle = -0.2f * M_PI * (yEyeBegin - y) / 180.0; 656 657 camera->Yaw(eyeYAngle); 658 674 static float eyeYAngle = 0.0f; 675 676 Vector3 viewDir = camera->GetDirection(); 677 Vector3 right = camera->GetRightVector(); 678 679 eyeYAngle = -0.2f * M_PI * (yEyeBegin - y) / 180.0; 680 681 // rotate view vector 682 Matrix4x4 rot = RotationAxisMatrix(right, eyeYAngle); 683 viewDir = rot * viewDir; 684 685 camera->SetDirection(viewDir); 686 659 687 yEyeBegin = y; 660 688 … … 678 706 rVec = rot * rVec; 679 707 680 pos += rVec * (x - horizontalMotionBegin) * 0.1f;708 pos -= rVec * (x - horizontalMotionBegin) * 0.1f; 681 709 //pos[1] += (verticalMotionBegin - y) * 0.1f; 682 710 pos[2] += (verticalMotionBegin - y) * 0.1f; … … 771 799 //////////// 772 800 // --- visualization of the occlusion culling 773 774 801 visualization->Render(); 775 802
Note: See TracChangeset
for help on using the changeset viewer.