Changeset 2796 for GTP/trunk/App/Demos/Vis/FriendlyCulling/src
- Timestamp:
- 06/22/08 09:23:45 (16 years ago)
- Location:
- GTP/trunk/App/Demos/Vis/FriendlyCulling/src
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Bvh.cpp
r2795 r2796 141 141 mGeometrySize = entities.size(); 142 142 mGeometry = new SceneEntity*[mGeometrySize]; 143 143 144 144 mBox.Initialize(); 145 145 … … 153 153 } 154 154 155 cout << "scene box: " << mBox << endl;155 //cout << "scene box: " << mBox << endl; 156 156 } 157 157 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/BvhLoader.cpp
r2795 r2796 94 94 cout << "... finished loading " << bvh->mNumNodes << " nodes, updating boxes" << endl; 95 95 96 bvh->mBox = bvh->mRoot->GetBox(); 97 98 cout << "scene box: " << bvh->mBox << endl; 99 96 100 /////////// 97 101 //-- post process nodes -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Camera.cpp
r2787 r2796 7 7 { 8 8 9 using namespace std; 10 9 11 10 12 Camera::Camera() … … 12 14 mWidth = 100; 13 15 mHeight = 100; 14 mFovy = 90.0f * M_PI / 180.0f; 16 mFovy = 60.0f * M_PI / 180.0f; 17 mIsOrtho = false; 18 19 SetPosition(Vector3(0, 0, 0)); 20 21 mPitch = mYaw = 0; 22 Precompute(Vector3(0, 1, 0)); 15 23 } 16 24 … … 22 30 23 31 mFovy = fieldOfView * M_PI / 180.0f; 24 } 25 26 27 void Camera::Precompute() 28 { 29 mDirection.Normalize(); 30 31 /*Vector3 side = CrossProd(Vector3(0, 0, 1), mDirection); 32 mUp = -Normalize(CrossProd(side, mDirection)); 33 mRight = -Normalize(CrossProd(mDirection, mUp));*/ 34 35 mUp = Vector3(0, 0, 1); 36 mRight = -CrossProd(mDirection, mUp); 37 mUp = -Normalize(CrossProd(mRight, mDirection)); 38 } 32 33 mIsOrtho = false; 34 35 SetPosition(Vector3(0, 0, 0)); 36 37 mPitch = mYaw = 0; 38 Precompute(Vector3(0, 1, 0)); 39 } 40 41 42 void Camera::Precompute(const Vector3 &direction) 43 { 44 /* 45 Vector3 side = CrossProd(Vector3(1, 0, 0), direction); 46 Vector3 up = -Normalize(CrossProd(side, direction)); 47 Vector3 right = -Normalize(CrossProd(direction, up)); 48 */ 49 Vector3 up = Vector3(0, 0, 1); 50 Vector3 right = -Normalize(-CrossProd(direction, up)); 51 up = -Normalize(CrossProd(right, direction)); 52 53 mBaseOrientation = Matrix4x4(right, up, direction); 54 mViewOrientation = mBaseOrientation; 55 } 56 39 57 40 58 … … 42 60 { 43 61 mPosition = pos; 44 Precompute();45 }46 47 48 void Camera::SetDirection(const Vector3 &dir)49 {50 mDirection = dir;51 Precompute();52 62 } 53 63 … … 56 66 { 57 67 mNear = nearDist; 58 }59 60 61 void Camera::LookInBox(const AxisAlignedBox3 &box)62 {63 //mDirection = Vector3(0, 0, 1);64 mDirection = Vector3(0, 1, 0);65 mPosition = box.Center();66 mPosition.z = box.Min(2) + 0.9f * box.Size(2);67 68 Precompute();69 }70 71 72 void Camera::LookAtBox(const AxisAlignedBox3 &box)73 {74 mDirection = Vector3(0, box.Min().y - box.Max().y, 0);75 mPosition = Vector3(0);//box.Max() - mDirection;76 77 Precompute();78 68 } 79 69 … … 156 146 void Camera::SetupCameraView() 157 147 { 158 glLoadIdentity(); 159 gluLookAt(mPosition.x, mPosition.y, mPosition.z, 160 mPosition.x + mDirection.x, mPosition.y + mDirection.y, mPosition.z + mDirection.z, 161 mUp.x, mUp.y, mUp.z); 162 163 //std::cout << "dir: " << mDirection << " pos: " << mPosition << " up: " << mUp << std::endl; 148 Matrix4x4 tview = mViewOrientation; 149 150 Vector3 pos = -mPosition; 151 pos = tview * pos; 152 153 Matrix4x4 viewOrientation = mViewOrientation; 154 155 viewOrientation.x[3][0] = pos.x; 156 viewOrientation.x[3][1] = pos.y; 157 viewOrientation.x[3][2] = pos.z; 158 159 glLoadMatrixf((float *)viewOrientation.x); 164 160 } 165 161 … … 177 173 const float w_far = h_far * GetAspect(); 178 174 179 //const Vector3 view = mDirection; 180 const Vector3 view = mDirection; 175 const Vector3 view = GetDirection(); 181 176 const Vector3 fc = mPosition + view * z_far; 182 177 183 const Vector3 up = mUp; 184 const Vector3 right = mRight; 178 const Vector3 up = GetUpVector(); 179 180 const Vector3 right = GetRightVector(); 185 181 186 182 Vector3 t1, t2; … … 194 190 fbr = fc - t1 + t2; 195 191 196 const Vector3 nc = mPosition + mDirection* z_near;192 const Vector3 nc = mPosition + view * z_near; 197 193 198 194 t1 = h_near * 0.5f * up; … … 206 202 207 203 208 } 209 204 void Camera::SetOrtho(bool ortho) 205 { 206 mIsOrtho = true; 207 } 208 209 210 void Camera::Yaw(float angle) 211 { 212 mYaw += angle; 213 CalculateFromPitchAndYaw(); 214 /* 215 Matrix4x4 viewOrientation(mRight, mUp, mDirection); 216 Matrix4x4 rot = RotationYMatrix(angle); 217 218 viewOrientation = viewOrientation * rot; 219 220 mDirection = Vector3(viewOrientation.x[2][0], viewOrientation.x[2][1], viewOrientation.x[2][2]); 221 mRight = Vector3(viewOrientation.x[0][0], viewOrientation.x[0][1], viewOrientation.x[0][2]); 222 mUp = Vector3(viewOrientation.x[1][0], viewOrientation.x[1][1], viewOrientation.x[1][2]);*/ 223 } 224 225 226 void Camera::Pitch(float angle) 227 { 228 mPitch += angle; 229 CalculateFromPitchAndYaw(); 230 } 231 232 233 void Camera::CalculateFromPitchAndYaw() 234 { 235 mViewOrientation = mBaseOrientation; 236 237 Matrix4x4 roty = RotationYMatrix(mPitch); 238 Matrix4x4 rotx = RotationXMatrix(mYaw); 239 240 mViewOrientation *= roty; 241 mViewOrientation *= rotx; 242 } 243 244 245 Vector3 Camera::GetDirection() const 246 { 247 return -Vector3(mViewOrientation.x[0][2], mViewOrientation.x[1][2], mViewOrientation.x[2][2]); 248 } 249 250 251 Vector3 Camera::GetUpVector() const 252 { 253 return Vector3(mViewOrientation.x[0][1], mViewOrientation.x[1][1], mViewOrientation.x[2][1]); 254 } 255 256 257 Vector3 Camera::GetRightVector() const 258 { 259 return Vector3(mViewOrientation.x[0][0], mViewOrientation.x[1][0], mViewOrientation.x[2][0]); 260 261 } 262 263 264 } 265 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Camera.h
r2782 r2796 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; } … … 49 41 inline float GetAspect() const { return (float) mWidth / mHeight; } 50 42 43 /** Sets up viewing in gl 44 */ 51 45 void SetupCameraView(); 52 46 void GetProjectionMatrix(Matrix4x4 &mat); … … 60 54 inline float GetNear() const { return mNear; } 61 55 void SetNear(float nearDist); 56 57 inline float GetFar() const { return mFar; } 58 59 void SetFar(float farDist) { mFar = farDist; } 60 61 void SetOrtho(bool ortho); 62 63 void Yaw(float angle); 64 void Pitch(float angle); 65 62 66 63 67 64 68 protected: 65 69 70 void Precompute(const Vector3 &direction); 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 //-- members 75 77 76 78 float mFovy; … … 79 81 80 82 float mNear; 83 84 float mFar; 85 86 bool mIsOrtho; 87 88 Matrix4x4 mBaseOrientation; 89 Matrix4x4 mViewOrientation; 90 91 float mPitch; 92 float mYaw; 93 94 Vector3 mPosition; 81 95 }; 82 96 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SceneQuery.cpp
r2782 r2796 18 18 19 19 const static int viewport[4] = {0, 0, 512, 512}; 20 // static DepthComponent<float> *sDepth = NULL;20 //const static int viewport[4] = {0, 0, 1024, 768}; 21 21 22 22 23 23 24 24 SceneQuery::SceneQuery(const AxisAlignedBox3 &sceneBox, RenderTraverser *renderer): 25 mSceneBox(sceneBox) 25 mSceneBox(sceneBox), mDepth(NULL) 26 26 { 27 27 Prepare(renderer); … … 32 32 { 33 33 int px = (pt.x - mSceneBox.Min(0)) * (viewport[2] - 1) / mSceneBox.Size(0); 34 int py = (pt.y - mSceneBox.Min( 2)) * (viewport[3] - 1) / mSceneBox.Size(2);34 int py = (pt.y - mSceneBox.Min(1)) * (viewport[3] - 1) / mSceneBox.Size(1); 35 35 36 const float d = 1.0f;// - sDepth->getPixel(px, py);36 const float d = mDepth[px + py * viewport[1]]; 37 37 38 38 if (d > 0.0f) 39 39 { 40 pt.z = mSceneBox.Size(2) * d + mSceneBox.Min(2);40 pt.z = mSceneBox.Min().z + mSceneBox.Size().z * d; 41 41 cout << "new depth " << pt.z << " (" << d << ")" << endl; 42 42 … … 52 52 cout << "Preparing scene queries" << endl; 53 53 54 // center camera on "highest" point 55 Vector3 pos; 56 57 pos.x = mSceneBox.Center(0); 58 pos.y = mSceneBox.Max(1); 59 pos.z = mSceneBox.Center(2); 60 61 // for ortho cam this is the width 62 const Vector3 len = mSceneBox.Size(); 63 64 Camera *orthoCam = new Camera(len.x, len.y); 65 //orthoCam->SetOrtho(true); 54 const float xlen = mSceneBox.Size().x * 0.5f; 55 const float ylen = mSceneBox.Size().y * 0.5f; 56 57 Camera *orthoCam = new Camera(xlen, ylen); 58 orthoCam->SetOrtho(true); 66 59 67 60 orthoCam->SetNear(0.0f); 68 //orthoCam->SetFar(len.z);61 orthoCam->Yaw(M_PI * 0.5f); 69 62 63 Vector3 pos = Vector3(mSceneBox.Center().x, mSceneBox.Center().y, mSceneBox.Max().z); 70 64 orthoCam->SetPosition(pos); 71 65 72 cout << "fov: " << orthoCam->GetFov() << endl; 73 cout << "near: " << orthoCam->GetNear() << endl; 74 //cout << "far: " << orthoCam->GetFar() << endl; 75 cout << "aspect: " << orthoCam->GetAspect() << endl; 66 glPixelStorei(GL_PACK_ROW_LENGTH, viewport[2]); 76 67 77 cout << "pos: " << orthoCam->GetPosition() << endl; 78 cout << "view: " << orthoCam->GetDirection() << endl; 79 cout << "up: " << orthoCam->GetUpVector() << endl; 68 // hack: should create offscreen buffer for this 69 glViewport(0, 0, viewport[2], viewport[3]); 80 70 81 //orthoCam->SetDirection(Vector3(0, 1, 0));82 //orthoCam->Yaw(M_PI * 0.5f);71 glMatrixMode(GL_PROJECTION); 72 glLoadIdentity(); 83 73 84 renderer->SetCamera(orthoCam); 74 glOrtho(-xlen, xlen, -ylen, ylen, 0.0f, mSceneBox.Size().z); 75 76 glMatrixMode(GL_MODELVIEW); 77 78 orthoCam->SetupCameraView(); 85 79 86 //OffscreenRenderArea *of = new OffscreenRenderArea(); 87 //of->Init(viewport[2], viewport[3]); 80 glClear(GL_DEPTH_BUFFER_BIT); 81 82 mDepth = new float[viewport[2] * viewport[3]]; 83 84 //renderer->SetCamera(orthoCam); 88 85 89 86 renderer->RenderScene(); 90 //sDepth = of->GetDepthFloat();91 87 92 delete orthoCam; 88 glReadPixels(0, 0, viewport[2], viewport[3], GL_DEPTH_COMPONENT, GL_FLOAT, mDepth); 89 90 DEL_PTR(orthoCam); 93 91 } 94 92 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SceneQuery.h
r2782 r2796 19 19 20 20 SceneQuery(const AxisAlignedBox3 &sceneBox, RenderTraverser *traverser); 21 21 ~SceneQuery() { DEL_ARRAY_PTR(mDepth); } 22 22 bool CalcIntersection(Vector3 &pt); 23 23 … … 31 31 32 32 AxisAlignedBox3 mSceneBox; 33 34 float *mDepth; 33 35 }; 34 36 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Visualization.cpp
r2790 r2796 14 14 namespace CHCDemoEngine 15 15 { 16 17 GLUquadric *mSphere;18 16 19 17 … … 84 82 85 83 84 Visualization::~Visualization() 85 { 86 //DEL_PTR(mSphere); 87 } 88 89 86 90 void Visualization::SetHierarchy(Bvh *bvh) 87 91 { -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Visualization.h
r2790 r2796 12 12 class RenderState; 13 13 class AxisAlignedBox3; 14 class GLUquadric; 14 15 15 16 … … 22 23 Visualization(Bvh *bvh, Camera *camera, Camera *vizCamera, RenderState *renderState); 23 24 24 ~Visualization() {}25 ~Visualization(); 25 26 26 27 /** Renders the visualizatioin … … 66 67 /// the current frame id 67 68 int mFrameId; 69 70 GLUquadric *mSphere; 68 71 }; 69 72 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp
r2795 r2796 21 21 #include "RenderState.h" 22 22 #include "Timer/PerfTimer.h" 23 #include "SceneQuery.h" 23 24 24 25 … … 58 59 int trianglesPerVirtualLeaf = 1000; 59 60 61 SceneQuery *sceneQuery = NULL; 62 60 63 /// these values get scaled with the frame rate 61 64 const float keyForwardMotion = 50.0f; … … 98 101 /// the accumulated z axis rotation 99 102 float rotation = 0; 100 101 Matrix4x4 visView = IdentityMatrix();102 103 103 104 SceneEntityContainer skyGeometry; … … 121 122 void Output(int x, int y, const char *string); 122 123 void DrawHelpMessage(); 124 void RenderSky(); 123 125 124 126 void Begin2D(); … … 135 137 void RightMotion(int x, int y); 136 138 void MiddleMotion(int x, int y); 137 void SetupVisView();138 139 void CalcDecimalPoint(string &str, int d); 139 140 void ResetTraverser(); … … 156 157 157 158 visCamera = new Camera(winWidth, winHeight, fov); 158 visCamera->SetNear(nearDist); 159 visCamera->SetNear(0.0f); 160 visCamera->Yaw(.5 * M_PI); 159 161 160 162 glutInitWindowSize(winWidth, winHeight); … … 222 224 223 225 bvh->SetCamera(camera); 226 224 227 ResetTraverser(); 225 228 … … 229 232 230 233 visualization = new Visualization(bvh, camera, NULL, &state); 234 235 sceneQuery = new SceneQuery(bvh->GetBox(), traverser); 231 236 232 237 glutMainLoop(); … … 488 493 KeyVerticalMotion(KeyShift()); 489 494 495 496 Vector3 playerPos = camera->GetPosition(); 497 sceneQuery->CalcIntersection(playerPos); 498 camera->SetPosition(playerPos); 499 490 500 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 491 501 … … 497 507 498 508 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 509 /////////////// 510 //-- render sky 511 512 RenderSky(); 513 512 514 if (visMode) DisplayVisualization(); 513 515 … … 764 766 glLoadIdentity(); 765 767 766 gluPerspective(fov, 1.0f / winAspectRatio, nearDist, 2.0f * Magnitude(bvh->GetBox().Diagonal()));768 gluPerspective(fov, 1.0f / winAspectRatio, nearDist, 10.0f * Magnitude(bvh->GetBox().Diagonal())); 767 769 768 770 glMatrixMode(GL_MODELVIEW); … … 926 928 // displays the visualisation of culling algorithm 927 929 void DisplayVisualization() 928 {cout<<"here34"<<endl; 929 SetupVisView(); 930 930 { 931 931 visualization->SetFrameId(traverser->GetCurrentFrameId()); 932 932 … … 940 940 End2D(); 941 941 942 glViewport(winWidth - winWidth / 4, winHeight - winHeight / 3, winWidth, winHeight); 942 943 AxisAlignedBox3 box = bvh->GetBox(); 944 945 const float xoffs = box.Size().x * 0.5f; 946 const float yoffs = box.Size().y * 0.5f; 947 948 Vector3 vizpos = Vector3(box.Center().x, box.Center().y, box.Max().z); 949 visCamera->SetPosition(vizpos); 950 951 glViewport(winWidth - winWidth / 4, winHeight - winHeight / 3, winWidth / 4, winHeight / 3); 943 952 944 953 glMatrixMode(GL_PROJECTION); 945 954 glLoadIdentity(); 946 955 947 gluPerspective(fov, 1.0f / winAspectRatio, nearDist, 20.0f * Magnitude(bvh->GetBox().Diagonal())); 948 949 AxisAlignedBox3 box = bvh->GetBox(); 950 const float offs = 2000; 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; 956 glOrtho(-xoffs, xoffs, -yoffs, yoffs, 0.0f, box.Size().z); 957 960 958 glMatrixMode(GL_MODELVIEW); 961 glLoadIdentity();962 959 963 960 visCamera->SetupCameraView(); 964 //glMultMatrixf((float *)visView.x); 965 966 //SetupLighting(); 961 967 962 GLfloat position[] = {0.8f, 1.0f, 1.5f, 0.0f}; 968 963 glLightfv(GL_LIGHT0, GL_POSITION, position); … … 978 973 visualization->Render(); 979 974 980 //glPopMatrix();981 982 975 glViewport(0, 0, winWidth, winHeight); 983 976 } 984 977 985 986 /** Sets up view matrix for bird eye view987 */988 void SetupVisView()989 {990 Vector3 pos(-bvh->GetBox().Center());991 992 pos.z = -15.0f * bvh->GetBox().Size().z;993 pos.y += 1400;994 pos.x -= 1170;995 996 Vector3 dir(0, 0, 1);997 Vector3 up(0, 1, 0);998 999 Vector3 left = Normalize(CrossProd(dir, up));1000 up = Normalize(CrossProd(left, dir));1001 1002 visView = Matrix4x4(up, left, dir);1003 pos = visView * pos;1004 1005 visView.x[3][0] = pos.x;1006 visView.x[3][1] = pos.y;1007 visView.x[3][2] = pos.z;1008 1009 //cout << visView<< endl;1010 }1011 978 1012 979 // cleanup routine after the main loop … … 1014 981 { 1015 982 DEL_PTR(traverser); 983 DEL_PTR(sceneQuery); 1016 984 DEL_PTR(bvh); 1017 985 DEL_PTR(visualization); … … 1139 1107 End2D(); 1140 1108 } 1109 1110 1111 void RenderSky() 1112 { 1113 glEnableClientState(GL_VERTEX_ARRAY); 1114 glEnableClientState(GL_NORMAL_ARRAY); 1115 1116 SceneEntityContainer::const_iterator sit, sit_end = skyGeometry.end(); 1117 1118 for (sit = skyGeometry.begin(); sit != sit_end; ++ sit) 1119 (*sit)->Render(&state); 1120 1121 glDisableClientState(GL_VERTEX_ARRAY); 1122 glDisableClientState(GL_NORMAL_ARRAY); 1123 1124 state.Reset(); 1125 }
Note: See TracChangeset
for help on using the changeset viewer.