Changeset 2778 for GTP/trunk/App/Demos
- Timestamp:
- 06/19/08 18:07:09 (17 years ago)
- Location:
- GTP/trunk/App/Demos/Vis/CHC_revisited
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/CHC_revisited/Camera.cpp
r2776 r2778 7 7 { 8 8 9 using namespace std; 10 9 11 10 12 Camera::Camera() … … 13 15 mHeight = 100; 14 16 mFovy = 90.0f * M_PI / 180.0f; 17 mIsOrtho = false; 18 19 SetPosition(Vector3(0, 0, 0)); 20 21 mPitch = mYaw = 0; 22 Precompute(); 15 23 } 16 24 … … 22 30 23 31 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(); 24 41 } 25 42 … … 27 44 void Camera::Precompute() 28 45 { 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 } 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 } 56 42 57 43 58 … … 45 60 { 46 61 mPosition = pos; 47 Precompute();48 }49 50 51 void Camera::SetDirection(const Vector3 &dir)52 {53 mDirection = dir;54 Precompute();55 62 } 56 63 … … 59 66 { 60 67 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();81 68 } 82 69 … … 159 146 void Camera::SetupCameraView() 160 147 { 148 #if 1 149 //Matrix4x4 viewOrientation(mRight, mDirection, mUp); 150 //Matrix4x4 viewOrientation(mRight, mUp, mDirection); 151 Matrix4x4 tview = mViewOrientation; 152 153 //Vector3 pos = tview * mPosition; 154 Vector3 pos = -mPosition; 155 pos = tview * pos; 156 157 Debug << "vieworient:\n" << mViewOrientation << " pos " << pos << " position " << mPosition << endl; 158 159 Matrix4x4 viewOrientation = mViewOrientation; 160 161 viewOrientation.x[3][0] = pos.x; 162 viewOrientation.x[3][1] = pos.y; 163 viewOrientation.x[3][2] = pos.z; 164 161 165 glLoadIdentity(); 166 glMultMatrixf((float *)viewOrientation.x); 167 //glMultMatrixf((float *)tm.x); 168 Debug << "matrix:\n" << viewOrientation << endl; 169 #else 170 glLoadIdentity(); 171 162 172 gluLookAt(mPosition.x, mPosition.y, mPosition.z, 163 173 mPosition.x + mDirection.x, mPosition.y + mDirection.y, mPosition.z + mDirection.z, 164 174 mUp.x, mUp.y, mUp.z); 165 175 #endif 166 176 //std::cout << "dir: " << mDirection << " pos: " << mPosition << " up: " << mUp << std::endl; 167 177 } … … 180 190 const float w_far = h_far * GetAspect(); 181 191 182 const Vector3 view = mDirection;192 const Vector3 view = GetDirection(); 183 193 const Vector3 fc = mPosition + view * z_far; 184 194 185 const Vector3 up = mUp;186 187 const Vector3 right = mRight;195 const Vector3 up = GetUpVector(); 196 197 const Vector3 right = GetRightVector(); 188 198 189 199 Vector3 t1, t2; … … 197 207 fbr = fc - t1 + t2; 198 208 199 const Vector3 nc = mPosition + mDirection* z_near;209 const Vector3 nc = mPosition + view * z_near; 200 210 201 211 t1 = h_near * 0.5f * up; … … 209 219 210 220 211 } 212 221 void Camera::SetOrtho(bool ortho) 222 { 223 mIsOrtho = true; 224 } 225 226 227 void Camera::Yaw(float angle) 228 { 229 mYaw += angle; 230 CalculateFromPitchAndYaw(); 231 /* 232 Matrix4x4 viewOrientation(mRight, mUp, mDirection); 233 Matrix4x4 rot = RotationYMatrix(angle); 234 235 viewOrientation = viewOrientation * rot; 236 237 mDirection = Vector3(viewOrientation.x[2][0], viewOrientation.x[2][1], viewOrientation.x[2][2]); 238 mRight = Vector3(viewOrientation.x[0][0], viewOrientation.x[0][1], viewOrientation.x[0][2]); 239 mUp = Vector3(viewOrientation.x[1][0], viewOrientation.x[1][1], viewOrientation.x[1][2]);*/ 240 } 241 242 243 void Camera::Pitch(float angle) 244 { 245 mPitch += angle; 246 CalculateFromPitchAndYaw(); 247 } 248 249 250 void Camera::CalculateFromPitchAndYaw() 251 { 252 mViewOrientation = mBaseOrientation; 253 254 Matrix4x4 roty = RotationYMatrix(mPitch); 255 Matrix4x4 rotx = RotationXMatrix(mYaw); 256 257 mViewOrientation *= roty; 258 mViewOrientation *= rotx; 259 } 260 261 262 Vector3 Camera::GetDirection() const 263 { 264 return Vector3(mViewOrientation.x[0][2], mViewOrientation.x[1][2], mViewOrientation.x[2][2]); 265 } 266 267 268 Vector3 Camera::GetUpVector() const 269 { 270 return Vector3(mViewOrientation.x[0][1], mViewOrientation.x[1][1], mViewOrientation.x[2][1]); 271 } 272 273 274 Vector3 Camera::GetRightVector() const 275 { 276 return Vector3(mViewOrientation.x[0][0], mViewOrientation.x[1][0], mViewOrientation.x[2][0]); 277 278 } 279 280 281 } 282 -
GTP/trunk/App/Demos/Vis/CHC_revisited/Camera.h
r2776 r2778 20 20 { 21 21 /// the 6 clip planes 22 //float mClipPlane[6][4];23 22 Plane3 mClipPlanes[6]; 24 23 … … 30 29 Camera(int width, int height, float fieldOfView = 90.f); 31 30 32 void Precompute();33 34 void LookInBox(const AxisAlignedBox3 &box);35 36 void LookAtBox(const AxisAlignedBox3 &box);37 31 38 32 void SetPosition(const Vector3 &pos); 39 33 40 void SetDirection(const Vector3 &dir);41 42 34 inline Vector3 GetPosition() const { return mPosition; } 43 inline Vector3 GetDirection() const { return mDirection; }44 inline Vector3 GetUpVector() const { return mUp; }45 inline Vector3 GetRightVector() const { return mRight; }35 Vector3 GetDirection() const; 36 Vector3 GetUpVector() const; 37 Vector3 GetRightVector() const; 46 38 47 39 inline float GetFov() const { return mFovy; } … … 60 52 inline float GetNear() const { return mNear; } 61 53 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 gl 64 */ 65 void Render(); 62 66 63 67 64 68 protected: 65 69 70 void Precompute(); 71 72 void CalculateFromPitchAndYaw(); 73 66 74 //////////////// 67 75 68 Vector3 mPosition;69 Vector3 mDirection;70 71 /// up vector takes into account the FOV at a unit distance from the origin72 Vector3 mUp;73 /// right vector takes into account the FOV at a unit distance from the origin74 Vector3 mRight;75 76 76 77 float mFovy; … … 79 80 80 81 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; 81 94 }; 82 95 -
GTP/trunk/App/Demos/Vis/CHC_revisited/SceneQuery.cpp
r2776 r2778 3 3 #include "Vector3.h" 4 4 #include "Camera.h" 5 #include "SceneQuery.h" 6 #include "RenderTraverser.h" 5 7 6 8 … … 20 22 21 23 22 SceneQuery::SceneQuery(const AxisAlignedBox3 &sceneBox ):24 SceneQuery::SceneQuery(const AxisAlignedBox3 &sceneBox, RenderTraverser *renderer): 23 25 mSceneBox(sceneBox) 24 26 { 25 Prepare( );27 Prepare(renderer); 26 28 } 27 29 … … 45 47 } 46 48 47 void SceneQuery::Prepare() 49 50 void SceneQuery::Prepare(RenderTraverser *renderer) 48 51 { 49 52 cout << "Preparing scene queries" << endl; … … 56 59 pos.z = mSceneBox.Center(2); 57 60 58 Camera *orthoCam = new Camera();59 //orthoCam->SetOrtho(true);60 61 // contain match scene bounding box;62 63 61 // for ortho cam this is the width 64 62 const Vector3 len = mSceneBox.Size(); 65 /* 66 orthoCam->SetFov(len.x);67 orthoCam->Set Aspect(len.x / len.y);63 64 Camera *orthoCam = new Camera(len.x, len.y); 65 orthoCam->SetOrtho(true); 68 66 69 67 orthoCam->SetNear(0.0f); … … 72 70 orthoCam->SetPosition(pos); 73 71 74 OUT1("fov: " << orthoCam->GetFov());75 OUT1("near: " << orthoCam->GetNear());76 OUT1("far: " << orthoCam->GetFar());77 OUT1("aspect: " << orthoCam->GetAspect());72 cout << "fov: " << orthoCam->GetFov() << endl; 73 cout << "near: " << orthoCam->GetNear() << endl; 74 cout << "far: " << orthoCam->GetFar() << endl; 75 cout << "aspect: " << orthoCam->GetAspect() << endl; 78 76 79 OUT1("pos: " << orthoCam->GetPosition());80 OUT1("view: " << orthoCam->GetViewDirection());81 OUT1("up: " << orthoCam->GetViewUpVector());77 cout << "pos: " << orthoCam->GetPosition() << endl; 78 cout << "view: " << orthoCam->GetDirection() << endl; 79 cout << "up: " << orthoCam->GetUpVector() << endl; 82 80 83 const float pitch = 0;84 const float yaw = YA_PI * 0.5f;81 //orthoCam->SetDirection(Vector3(0, 1, 0)); 82 orthoCam->Yaw(M_PI * 0.5f); 85 83 86 OffscreenRenderArea *of = new OffscreenRenderArea();84 renderer->SetCamera(orthoCam); 87 85 88 of->Init(viewport[2], viewport[3]); 89 of->SetRenderAction(new GLRenderAction); 90 91 of->SetCamera(orthoCam); 92 of->SetSceneRoot(mSceneRoot); 93 94 of->Render(); 86 //OffscreenRenderArea *of = new OffscreenRenderArea(); 87 //of->Init(viewport[2], viewport[3]); 95 88 96 sDepth = of->GetDepthFloat(); 97 */ 89 renderer->RenderScene(); 90 //sDepth = of->GetDepthFloat(); 91 92 delete orthoCam; 98 93 } 99 94 -
GTP/trunk/App/Demos/Vis/CHC_revisited/SceneQuery.h
r2776 r2778 8 8 { 9 9 10 class RenderTraverser; 11 12 10 13 /** A simple class that computes the first intersection of a horizontal ray with 11 14 the scene. Can be used to "drop" objects in the scene. … … 15 18 public: 16 19 17 SceneQuery(const AxisAlignedBox3 &sceneBox );20 SceneQuery(const AxisAlignedBox3 &sceneBox, RenderTraverser *traverser); 18 21 19 22 bool CalcIntersection(Vector3 &pt); 20 23 24 21 25 protected: 22 26 23 void Prepare( );27 void Prepare(RenderTraverser *traverser); 24 28 25 29 -
GTP/trunk/App/Demos/Vis/CHC_revisited/chc_revisited.vcproj
r2776 r2778 190 190 <Files> 191 191 <Filter 192 Name="util s"192 Name="util" 193 193 > 194 194 <File -
GTP/trunk/App/Demos/Vis/CHC_revisited/chcdemo.cpp
r2776 r2778 163 163 //camera->LookInBox(bvh->GetBox()); 164 164 165 camera->SetDirection(Vector3(0.961829f, 0.273652f, 0.0f)); 165 //camera->SetDirection(Vector3(0.961829f, 0.273652f, 0.0f)); 166 //camera->SetDirection(Vector3(0.0f, 1.0f, 0.0f)); 166 167 camera->SetPosition(Vector3(483.398f, 242.364f, 186.078f)); 167 168 … … 488 489 case 'A': 489 490 { 490 Vector3 viewDir = camera->GetDirection(); 491 // rotate view vector 492 Matrix4x4 rot = RotationZMatrix(keyRotation); 493 viewDir = rot * viewDir; 494 camera->SetDirection(viewDir); 491 camera->Pitch(keyRotation); 495 492 } 496 493 break; … … 498 495 case 'D': 499 496 { 500 Vector3 viewDir = camera->GetDirection(); 501 // rotate view vector 502 Matrix4x4 rot = RotationZMatrix(-keyRotation); 503 viewDir = rot * viewDir; 504 camera->SetDirection(viewDir); 497 camera->Pitch(-keyRotation); 505 498 } 506 499 break; 507 500 case 'w': 508 501 case 'W': 502 { 503 Vector3 pos = camera->GetPosition(); 504 pos -= hvec * keyForwardMotion; 505 camera->SetPosition(pos); 506 } 507 break; 508 case 'x': 509 case 'X': 509 510 { 510 511 Vector3 pos = camera->GetPosition(); … … 513 514 } 514 515 break; 515 case 'x':516 case 'X':517 {518 Vector3 pos = camera->GetPosition();519 pos -= hvec * keyForwardMotion;520 camera->SetPosition(pos);521 }522 break;523 516 case 'r': 524 517 case 'R': … … 547 540 case GLUT_KEY_LEFT: 548 541 { 549 Vector3 viewDir = camera->GetDirection(); 550 // rotate view vector 551 Matrix4x4 rot = RotationZMatrix(keyRotation); 552 viewDir = rot * viewDir; 553 camera->SetDirection(viewDir); 542 camera->Pitch(keyRotation); 554 543 } 555 544 break; 556 545 case GLUT_KEY_RIGHT: 557 546 { 558 Vector3 viewDir = camera->GetDirection(); 559 // rotate view vector 560 Matrix4x4 rot = RotationZMatrix(-keyRotation); 561 viewDir = rot * viewDir; 562 camera->SetDirection(viewDir); 547 camera->Pitch(-keyRotation); 563 548 } 564 549 break; 565 550 case GLUT_KEY_UP: 551 { 552 Vector3 pos = camera->GetPosition(); 553 pos -= hvec * 0.6f; 554 camera->SetPosition(pos); 555 } 556 break; 557 case GLUT_KEY_DOWN: 566 558 { 567 559 Vector3 pos = camera->GetPosition(); 568 560 pos += hvec * 0.6f; 569 camera->SetPosition(pos);570 }571 break;572 case GLUT_KEY_DOWN:573 {574 Vector3 pos = camera->GetPosition();575 pos -= hvec * 0.6f;576 561 camera->SetPosition(pos); 577 562 } … … 641 626 void leftMotion(int x, int y) 642 627 { 643 static float eyeXAngle = 0.0f;644 645 628 Vector3 viewDir = camera->GetDirection(); 646 629 Vector3 pos = camera->GetPosition(); … … 649 632 Vector3 horView(viewDir[0], viewDir[1], 0); 650 633 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); 634 float eyeXAngle = 0.2f * M_PI * (xEyeBegin - x) / 180.0; 635 636 camera->Pitch(eyeXAngle); 637 638 pos -= horView * (yMotionBegin - y) * 0.2f; 639 660 640 camera->SetPosition(pos); 661 641 … … 672 652 void rightMotion(int x, int y) 673 653 { 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 654 float eyeYAngle = -0.2f * M_PI * (yEyeBegin - y) / 180.0; 655 656 camera->Yaw(eyeYAngle); 657 687 658 yEyeBegin = y; 688 659 … … 706 677 rVec = rot * rVec; 707 678 708 pos -= rVec * (x - horizontalMotionBegin) * 0.1f;679 pos += rVec * (x - horizontalMotionBegin) * 0.1f; 709 680 //pos[1] += (verticalMotionBegin - y) * 0.1f; 710 681 pos[2] += (verticalMotionBegin - y) * 0.1f; … … 799 770 //////////// 800 771 // --- visualization of the occlusion culling 772 801 773 visualization->Render(); 802 774
Note: See TracChangeset
for help on using the changeset viewer.