Changeset 3061 for GTP/trunk/App/Demos/Vis
- Timestamp:
- 10/23/08 12:26:37 (16 years ago)
- Location:
- GTP/trunk/App/Demos/Vis/FriendlyCulling/src
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Bvh.cpp
r3053 r3061 1189 1189 // no split could be achieved => just halve number of objects 1190 1190 split = (leaf->mLast - leaf->mFirst) / 2; 1191 cerr << "no reduction " << leaf->CountPrimitives() << " " << leaf->mFirst << " " << split << " " <<leaf->mLast << endl;1191 cerr << "no reduction " << leaf->CountPrimitives() << " " << leaf->mFirst << " " << leaf->mLast << endl; 1192 1192 } 1193 1193 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Camera.cpp
r2988 r3061 18 18 Camera::Camera() 19 19 { 20 mWidth = 100; 21 mHeight = 100; 22 mFovy = 60.0f * M_PI / 180.0f; 23 mIsOrtho = false; 20 mFOVy = 60.0f * M_PI / 180.0f; 21 //mIsOrtho = false; 24 22 25 23 SetPosition(Vector3(0, 0, 0)); … … 32 30 33 31 34 Camera::Camera(int width, int height, float fieldOfView) 35 { 36 mWidth = width; 37 mHeight = height; 38 39 mFovy = fieldOfView * M_PI / 180.0f; 40 41 mIsOrtho = false; 32 Camera::Camera(float aspect, float fieldOfView) 33 { 34 mFOVy = fieldOfView * M_PI / 180.0f; 35 mAspect = aspect; 36 //mIsOrtho = false; 42 37 43 38 SetPosition(Vector3::ZERO()); … … 53 48 { 54 49 Vector3 up = Vector3::UNIT_Z(); 55 //Vector3 right = Normalize(CrossProd(dir, up)); 56 //up = Normalize(CrossProd(right, dir)); 57 58 //mBaseOrientation = Matrix4x4(right, up, -dir); 59 mBaseOrientation = LookAt(Vector3::ZERO(), dir, up);//Matrix4x4(right, up, -dir); 50 51 mBaseOrientation = LookAt(Vector3::ZERO(), dir, up); 60 52 mViewOrientation = mBaseOrientation; 61 53 } … … 128 120 frustum.mClipPlanes[i].mNormal *= invLength; 129 121 } 122 } 123 124 125 void Camera::SetupViewProjection() 126 { 127 glMatrixMode(GL_PROJECTION); 128 SetupProjection(); 129 130 glMatrixMode(GL_MODELVIEW); 131 // set up the view matrix 132 SetupCameraView(); 133 } 134 135 136 void Camera::SetupProjection() 137 { 138 glLoadIdentity(); 139 gluPerspective(mFOVy * 180.0f / M_PI, mAspect, mNear, mFar); 130 140 } 131 141 … … 147 157 float farthestVisibleDistance) const 148 158 { 149 float z_near = mNear;150 float z_far = min(mFar, farthestVisibleDistance);151 152 float fov = mFovy;159 const float z_near = mNear; 160 const float z_far = min(mFar, farthestVisibleDistance); 161 162 const float fov = mFOVy; 153 163 154 164 const float aspectRatio = GetAspect(); … … 162 172 const Vector3 fc = pos + view * z_far; 163 173 174 164 175 Vector3 t1, t2; 165 176 … … 194 205 195 206 196 void Camera::SetOrtho(bool ortho)197 { 198 mIsOrtho = true;199 } 207 /*void Camera::SetOrtho(bool ortho) 208 { 209 mIsOrtho = ortho; 210 }*/ 200 211 201 212 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Camera.h
r3045 r3061 39 39 40 40 41 /** Classs representing a camera. 42 */ 41 43 class Camera 42 44 { … … 44 46 45 47 public: 46 48 /** Default constructor. 49 */ 47 50 Camera(); 48 49 Camera(int width, int height, float fieldOfView = 90.f);50 51 /** Camera taking the image width and height and the field of view. 52 */ 53 Camera(float aspect, float fieldOfView = 90.f); 51 54 /** Sets the current camera position. 52 55 */ 53 56 void SetPosition(const Vector3 &pos); 54 57 /** See set. 58 */ 55 59 inline Vector3 GetPosition() const { return mPosition; } 56 60 /** Returns view direction. 61 */ 57 62 Vector3 GetDirection() const; 63 /** Returns up vector. 64 */ 58 65 Vector3 GetUpVector() const; 66 /** Returns right vector. 67 */ 59 68 Vector3 GetRightVector() const; 60 69 … … 62 71 Vector3 GetBaseUpVector() const; 63 72 Vector3 GetBaseRightVector() const; 64 65 inline float GetFov() const { return mFovy; }66 inline float Get Aspect() const { return (float) mWidth / mHeight; }67 inline int GetWidth() const { return mWidth; }68 inline int GetHeight() const { return mHeight; }69 70 /** Sets up viewing in gl73 /** Returns the field of view. 74 */ 75 inline float GetFov() const { return mFOVy; } 76 /** Returns the aspect ratio. 77 */ 78 inline float GetAspect() const { return mAspect; } 79 /** Sets up viewing matrices in for opengl rendering 71 80 */ 72 81 void SetupCameraView(); … … 102 111 */ 103 112 void SetFar(float farDist); 104 105 void SetOrtho(bool ortho); 106 113 /** Sets this camera to orthographic projection. 114 */ 115 //void SetOrtho(bool ortho); 116 /** Set yaw (rotation around vertical axis. 117 */ 107 118 void Yaw(float angle); 119 /** Set pitch. 120 */ 108 121 void Pitch(float angle); 109 122 /** Returns pitch. 123 */ 110 124 float GetPitch() const { return mPitch; } 125 /** Returns yaw. 126 */ 111 127 float GetYaw() const { return mYaw; } 128 /** Resets pitch and yaw. 129 */ 112 130 void ResetPitchAndYaw() { mPitch = 0; mYaw = 0; } 113 /** Sets the cameradirection.131 /** Sets the view direction. 114 132 */ 115 133 void SetDirection(const Vector3 &direction); … … 117 135 */ 118 136 Polyhedron *ComputeFrustum(float farthestVisibleDistance = 1e25f) const; 137 /** Sets up projection matrix in OpenGl. 138 */ 139 void SetupProjection(); 140 /** Sets up view + projection matrix in OpenGl. 141 */ 142 void SetupViewProjection(); 143 119 144 120 145 protected: … … 133 158 //-- members 134 159 135 float mFovy; 136 int mWidth; 137 int mHeight; 138 160 float mFOVy; 139 161 float mNear; 140 141 162 float mFar; 142 143 bool mIsOrtho; 163 164 /// if this camera is orthgraphic or perspective 165 //bool mIsOrtho; 144 166 145 167 Matrix4x4 mBaseOrientation; … … 150 172 151 173 Vector3 mPosition; 174 175 float mAspect; 152 176 }; 153 177 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderQueue.cpp
r3060 r3061 14 14 { 15 15 16 17 /*inline static bool CompDist(RenderQueueBucket *b1, RenderQueueBucket *b2)18 {19 return (b1->mMinDistance < b2->mMinDistance);20 }*/21 16 RenderQueue::RenderQueue(): 22 17 mState(NULL), 23 mCamera(NULL),24 18 mNumEntries(0) 25 19 { … … 27 21 28 22 29 RenderQueue::RenderQueue(RenderState *state , Camera *cam):23 RenderQueue::RenderQueue(RenderState *state): 30 24 mState(state), 31 mCamera(cam),32 25 mNumEntries(0) 33 26 { … … 158 151 if (bucket->IsEmpty()) 159 152 { 160 // add tocurrently active buckets that will be rendered153 // add bucket to the list of currently active buckets that will be rendered 161 154 // assume that the incoming nodes are ordered by distance 162 155 // => active buckets are sorted by distance 163 156 mActiveBuckets.push_back(bucket); 164 165 // => set min dist on first incoming node 166 //const Vector3 v = shape->GetCenter() - mCamera->GetPosition(); 167 //const float dist = SqrMagnitude(v); 168 //bucket->mMinDistance = dist; 169 170 } 157 } 171 158 172 159 bucket->mShapes.push_back(shape); … … 178 165 for (size_t i = 0; i < mActiveBuckets.size(); ++ i) 179 166 { 180 //mBuckets[i]->mMinDistance = -1;181 167 mActiveBuckets[i]->mShapes.clear(); 182 168 } 183 169 184 170 mNumEntries = 0; 185 186 171 mActiveBuckets.clear(); 187 172 } … … 196 181 void RenderQueue::Render() 197 182 { 198 // sort the buckets199 //Sort();200 201 183 // render all buckets 202 for (size_t i = 0; i < m Buckets.size(); ++ i)203 { 204 ShapeContainer::const_iterator sit, sit_end = m Buckets[i]->mShapes.end();205 206 for (sit = m Buckets[i]->mShapes.begin(); sit != sit_end; ++ sit)184 for (size_t i = 0; i < mActiveBuckets.size(); ++ i) 185 { 186 ShapeContainer::const_iterator sit, sit_end = mActiveBuckets[i]->mShapes.end(); 187 188 for (sit = mActiveBuckets[i]->mShapes.begin(); sit != sit_end; ++ sit) 207 189 { 208 190 Shape *shape = *sit; … … 210 192 } 211 193 } 212 //Print(); 213 } 214 215 216 void RenderQueue::Print() 217 { 218 for (size_t i = 0; i < mBuckets.size(); ++ i) 219 { 220 Debug << "\n******\nbucket " << (int)i << endl; 221 222 ShapeContainer::const_iterator sit, sit_end = mBuckets[i]->mShapes.end(); 223 224 for (sit = mBuckets[i]->mShapes.begin(); sit != sit_end; ++ sit) 225 { 226 Shape *shape = *sit; 227 228 Technique *tech = shape->GetMaterial()->GetTechnique(mState->GetRenderTechnique()); 229 int tsize = tech->GetTexture() ? tech->GetTexture()->GetByteSize() : 0; 230 231 float dist = SqrMagnitude(shape->GetBoundingBox().Center() - mCamera->GetPosition()); 232 233 Debug << "e: " << shape << " a: " << tech->IsAlphaTestEnabled() << " s: " << tsize << " d: " << dist << " " << endl; 234 } 235 } 236 } 237 238 239 /*void RenderQueue::Sort() 240 { 241 // sort buckets itself by distance 242 sort(mBuckets.begin(), mBuckets.end(), CompDist); 243 }*/ 194 //cout << "active: " << (int)mActiveBuckets.size() << endl; 195 } 244 196 245 197 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderQueue.h
r3060 r3061 63 63 */ 64 64 RenderQueue(); 65 /** Constructor taking a render queue65 /** Constructor passing the current render state 66 66 */ 67 RenderQueue(RenderState *state , Camera *cam);67 RenderQueue(RenderState *state); 68 68 69 69 ~RenderQueue(); … … 77 77 */ 78 78 void SetRenderState(RenderState *state); 79 /** Sets the current render state80 */81 void SetCamera(Camera *cam);82 79 /** Returns the number of entries currently in the queue. 83 80 */ … … 98 95 */ 99 96 void Render(); 100 /** Prints the current state of the render queue.101 */102 void Print();103 97 104 98 … … 108 102 // the current render state 109 103 RenderState *mState; 110 111 Camera *mCamera;112 104 /// each bucket contains objects with similar materials that don't cause a hard state change 113 105 std::vector<RenderQueueBucket *> mBuckets; -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderState.h
r3055 r3061 13 13 class Material; 14 14 15 /** The current render state.15 /** Class representing the current render state. 16 16 */ 17 17 class RenderState -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SceneQuery.cpp
r3021 r3061 139 139 const float ylen = mSceneBox.Size().y * 0.5f; 140 140 141 Camera *orthoCam = new Camera(xlen ,ylen);142 orthoCam->SetOrtho(true);141 Camera *orthoCam = new Camera(xlen / ylen); 142 //orthoCam->SetOrtho(true); 143 143 144 144 orthoCam->SetNear(0.0f); -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShadowMapping.cpp
r3038 r3061 148 148 149 149 150 mShadowCam = new Camera( mSize, mSize);151 mShadowCam->SetOrtho(true);150 mShadowCam = new Camera(1); 151 //mShadowCam->SetOrtho(true); 152 152 } 153 153 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Shape.h
r3054 r3061 22 22 23 23 24 /** Class representing a shape.25 A shape basically consists of geometryand a material24 /** Class representing a 3D shape consisting 25 of geometry (with texture coordinates, normals) and a material 26 26 */ 27 27 class Shape -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Transform3.h
r3028 r3061 15 15 16 16 17 /** Class representing a wrapper class for a 3D transformation17 /** Wrapper class for a 3D transformation 18 18 */ 19 19 class Transform3 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp
r3059 r3061 369 369 /////////////////////////// 370 370 371 camera = new Camera(winWidth ,winHeight, fov);371 camera = new Camera(winWidth / winHeight, fov); 372 372 camera->SetNear(nearDist); 373 373 camera->SetFar(1000); … … 376 376 camera->SetPosition(camPos); 377 377 378 visCamera = new Camera(winWidth ,winHeight, fov);378 visCamera = new Camera(winWidth / winHeight, fov); 379 379 visCamera->SetNear(0.0f); 380 380 visCamera->Yaw(.5 * M_PI); … … 382 382 // create a new light 383 383 light = new DirectionalLight(lightDir, RgbaColor(1, 1, 1, 1), RgbaColor(1, 1, 1, 1)); 384 385 386 renderQueue = new RenderQueue(&state, camera); 384 // the render queue for material sorting 385 renderQueue = new RenderQueue(&state); 387 386 388 387 glutInitWindowSize(winWidth, winHeight); … … 761 760 oldViewProjMat = viewProjMat; 762 761 763 glMatrixMode(GL_PROJECTION); 764 glLoadIdentity(); 765 gluPerspective(fov, winAspectRatio, nearDist, farDist); 766 767 glMatrixMode(GL_MODELVIEW); 768 769 // set up the camera view 770 camera->SetupCameraView(); 771 762 camera->SetupViewProjection(); 763 764 772 765 ///////////////// 773 766 //-- compute view projection matrix and store for later use … … 1581 1574 1582 1575 glLoadIdentity(); 1583 1584 1576 glOrtho(-offs, offs, -offs, offs, 0.0f, box.Size().z * 100.0f); 1585 1577
Note: See TracChangeset
for help on using the changeset viewer.