- Timestamp:
- 10/23/08 14:53:23 (16 years ago)
- Location:
- GTP/trunk/App/Demos/Vis/FriendlyCulling/src
- Files:
-
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Camera.cpp
r3061 r3062 16 16 17 17 18 Camera::Camera() 19 { 20 mFOVy = 60.0f * M_PI / 180.0f; 21 //mIsOrtho = false; 22 23 SetPosition(Vector3(0, 0, 0)); 24 25 mPitch = mYaw = 0; 26 Precompute(baseDir); 27 28 CalculateFromPitchAndYaw(); 29 } 30 31 32 Camera::Camera(float aspect, float fieldOfView) 33 { 34 mFOVy = fieldOfView * M_PI / 180.0f; 35 mAspect = aspect; 36 //mIsOrtho = false; 37 38 SetPosition(Vector3::ZERO()); 39 40 mPitch = mYaw = 0; 41 Precompute(baseDir); 42 43 CalculateFromPitchAndYaw(); 44 } 45 46 47 void Camera::Precompute(const Vector3 &dir) 48 { 49 Vector3 up = Vector3::UNIT_Z(); 50 51 mBaseOrientation = LookAt(Vector3::ZERO(), dir, up); 52 mViewOrientation = mBaseOrientation; 53 } 54 55 56 void Camera::SetPosition(const Vector3 &pos) 57 { 58 mPosition = pos; 59 } 60 61 62 void Camera::SetNear(float nearDist) 63 { 64 mNear = nearDist; 65 } 66 67 68 void Camera::SetFar(float farDist) 69 { 70 mFar = farDist; 71 } 72 73 74 void Camera::GetProjectionMatrix(Matrix4x4 &mat) const 75 { 76 glGetFloatv(GL_PROJECTION_MATRIX, (float *)mat.x); 77 } 78 79 80 void Camera::GetModelViewMatrix(Matrix4x4 &mat) const 81 { 82 mat = mViewOrientation; 83 84 // note: left handed system => we go into positive z 85 mat.x[3][0] = -DotProd(GetRightVector(), mPosition); 86 mat.x[3][1] = -DotProd(GetUpVector(), mPosition); 87 mat.x[3][2] = DotProd(GetDirection(), mPosition); 88 } 89 90 91 void Camera::GetViewOrientationMatrix(Matrix4x4 &mat) const 92 { 93 mat = mViewOrientation; 94 } 95 96 97 void Camera::CalcFrustum(Frustum &frustum) 98 { 99 // we grab the plane equations of the six clipplanes of the viewfrustum 100 Matrix4x4 matViewing, matProjectionView; 101 102 GetModelViewMatrix(matViewing); 103 GetProjectionMatrix(matProjectionView); 104 105 matProjectionView = matViewing * matProjectionView; 106 107 frustum = Frustum(matProjectionView); 108 109 110 //////////// 111 //-- normalize the coefficients 112 113 for (int i = 0; i < 6; ++ i) 114 { 115 // the clipping planes look outward the frustum, 116 // so distances > 0 mean that a point is outside 117 const float invLength = -1.0f / Magnitude(frustum.mClipPlanes[i].mNormal); 118 119 frustum.mClipPlanes[i].mD *= invLength; 120 frustum.mClipPlanes[i].mNormal *= invLength; 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); 140 } 141 142 143 void Camera::SetupCameraView() 144 { 145 Matrix4x4 m; 146 GetModelViewMatrix(m); 147 148 glLoadMatrixf((float *)m.x); 149 } 150 151 152 153 void Camera::ComputePointsInternal(Vector3 &ftl, Vector3 &ftr, Vector3 &fbl, Vector3 &fbr, 154 Vector3 &ntl, Vector3 &ntr, Vector3 &nbl, Vector3 &nbr, 155 const Vector3 &view, const Vector3 &right, const Vector3 &up, 156 const Vector3 &pos, 157 float farthestVisibleDistance) const 158 { 159 const float z_near = mNear; 160 const float z_far = min(mFar, farthestVisibleDistance); 161 162 const float fov = mFOVy; 163 164 const float aspectRatio = GetAspect(); 165 166 const float h_near = tan(fov * 0.5f) * z_near; 167 const float w_near = h_near * aspectRatio; 168 169 const float h_far = tan(fov * 0.5f) * z_far; 170 const float w_far = h_far * aspectRatio; 171 172 const Vector3 fc = pos + view * z_far; 173 174 175 Vector3 t1, t2; 176 177 t1 = h_far * up; 178 t2 = w_far * right; 179 180 ftl = fc + t1 - t2; 181 ftr = fc + t1 + t2; 182 fbl = fc - t1 - t2; 183 fbr = fc - t1 + t2; 184 185 const Vector3 nc = pos + view * z_near; 186 187 t1 = h_near * up; 188 t2 = w_near * right; 189 190 ntl = nc + t1 - t2; 191 ntr = nc + t1 + t2; 192 nbl = nc - t1 - t2; 193 nbr = nc - t1 + t2; 194 } 195 196 197 void Camera::ComputePoints(Vector3 &ftl, Vector3 &ftr, Vector3 &fbl, Vector3 &fbr, 198 Vector3 &ntl, Vector3 &ntr, Vector3 &nbl, Vector3 &nbr, 199 float farthestVisibleDistance) const 200 { 201 ComputePointsInternal(ftl, ftr, fbl, fbr, ntl, ntr, nbl, nbr, 202 GetDirection(), GetRightVector(), GetUpVector(), GetPosition(), 203 farthestVisibleDistance); 204 } 205 206 207 /*void Camera::SetOrtho(bool ortho) 208 { 209 mIsOrtho = ortho; 210 }*/ 211 212 213 void Camera::Yaw(float angle) 214 { 215 mYaw += angle; 216 CalculateFromPitchAndYaw(); 217 } 218 219 220 void Camera::Pitch(float angle) 221 { 222 mPitch += angle; 223 CalculateFromPitchAndYaw(); 224 } 225 226 227 void Camera::SetDirection(const Vector3 &dir) 228 { 229 Vector3 ndir = -Normalize(dir); 230 231 mPitch = -atan2(ndir.x, ndir.y); 232 mYaw = atan2(ndir.z, sqrt((ndir.x * ndir.x) + (ndir.y * ndir.y))); 233 234 CalculateFromPitchAndYaw(); 235 } 236 237 238 void Camera::CalculateFromPitchAndYaw() 239 { 240 mViewOrientation = mBaseOrientation; 241 242 Matrix4x4 roty = RotationYMatrix(mPitch); 243 Matrix4x4 rotx = RotationXMatrix(mYaw); 244 245 mViewOrientation *= roty; 246 mViewOrientation *= rotx; 247 } 248 249 250 Vector3 Camera::GetDirection() const 251 { 252 return -Vector3(mViewOrientation.x[0][2], mViewOrientation.x[1][2], mViewOrientation.x[2][2]); 253 } 254 255 256 Vector3 Camera::GetUpVector() const 257 { 258 return Vector3(mViewOrientation.x[0][1], mViewOrientation.x[1][1], mViewOrientation.x[2][1]); 259 } 260 261 262 Vector3 Camera::GetRightVector() const 263 { 264 return Vector3(mViewOrientation.x[0][0], mViewOrientation.x[1][0], mViewOrientation.x[2][0]); 265 } 266 267 268 Vector3 Camera::GetBaseDirection() const 269 { 270 return -Vector3(mBaseOrientation.x[0][2], mBaseOrientation.x[1][2], mBaseOrientation.x[2][2]); 271 } 272 273 274 Vector3 Camera::GetBaseUpVector() const 275 { 276 return Vector3(mBaseOrientation.x[0][1], mBaseOrientation.x[1][1], mBaseOrientation.x[2][1]); 277 } 278 279 280 Vector3 Camera::GetBaseRightVector() const 281 { 282 return Vector3(mBaseOrientation.x[0][0], mBaseOrientation.x[1][0], mBaseOrientation.x[2][0]); 283 } 18 19 /**********************************************************/ 20 /* class Frustum implementation */ 21 /**********************************************************/ 284 22 285 23 … … 312 50 Plane3 &plane = mClipPlanes[i]; 313 51 314 //cout << "p" << i << " " << plane.mD << endl;315 316 52 VertexArray::const_iterator it, it_end = vertices.end(); 317 318 53 float minDist = 1e20; 319 54 … … 346 81 347 82 348 Polyhedron *Camera::ComputeFrustum(float farthestVisibleDistance) const 83 84 /*********************************************************/ 85 /* class Camera implementation */ 86 /*********************************************************/ 87 88 89 Camera::Camera() 90 { 91 SetPosition(Vector3(0, 0, 0)); 92 93 mPitch = mYaw = 0; 94 Precompute(baseDir); 95 96 CalculateFromPitchAndYaw(); 97 } 98 99 100 void Camera::Precompute(const Vector3 &dir) 101 { 102 Vector3 up = Vector3::UNIT_Z(); 103 104 mBaseOrientation = LookAt(Vector3::ZERO(), dir, up); 105 mViewOrientation = mBaseOrientation; 106 } 107 108 109 void Camera::SetPosition(const Vector3 &pos) 110 { 111 mPosition = pos; 112 } 113 114 115 void Camera::SetNear(float nearDist) 116 { 117 mNear = nearDist; 118 } 119 120 121 void Camera::SetFar(float farDist) 122 { 123 mFar = farDist; 124 } 125 126 127 void Camera::GetModelViewMatrix(Matrix4x4 &mat) const 128 { 129 mat = mViewOrientation; 130 131 // note: left handed system => we go into positive z 132 mat.x[3][0] = -DotProd(GetRightVector(), mPosition); 133 mat.x[3][1] = -DotProd(GetUpVector(), mPosition); 134 mat.x[3][2] = DotProd(GetDirection(), mPosition); 135 } 136 137 138 void Camera::GetViewOrientationMatrix(Matrix4x4 &mat) const 139 { 140 mat = mViewOrientation; 141 } 142 143 144 void Camera::SetupViewProjection() 145 { 146 glMatrixMode(GL_PROJECTION); 147 SetupProjection(); 148 149 glMatrixMode(GL_MODELVIEW); 150 // set up the view matrix 151 SetupCameraView(); 152 } 153 154 155 void Camera::SetupProjection() 156 { 157 Matrix4x4 m; 158 159 GetProjectionMatrix(m); 160 glLoadMatrixf((float *)m.x); 161 } 162 163 164 void Camera::SetupCameraView() 165 { 166 Matrix4x4 m; 167 GetModelViewMatrix(m); 168 169 glLoadMatrixf((float *)m.x); 170 } 171 172 173 void Camera::Yaw(float angle) 174 { 175 mYaw += angle; 176 CalculateFromPitchAndYaw(); 177 } 178 179 180 void Camera::Pitch(float angle) 181 { 182 mPitch += angle; 183 CalculateFromPitchAndYaw(); 184 } 185 186 187 void Camera::SetDirection(const Vector3 &dir) 188 { 189 Vector3 ndir = -Normalize(dir); 190 191 mPitch = -atan2(ndir.x, ndir.y); 192 mYaw = atan2(ndir.z, sqrt((ndir.x * ndir.x) + (ndir.y * ndir.y))); 193 194 CalculateFromPitchAndYaw(); 195 } 196 197 198 void Camera::CalculateFromPitchAndYaw() 199 { 200 mViewOrientation = mBaseOrientation; 201 202 Matrix4x4 roty = RotationYMatrix(mPitch); 203 Matrix4x4 rotx = RotationXMatrix(mYaw); 204 205 mViewOrientation *= roty; 206 mViewOrientation *= rotx; 207 } 208 209 210 Vector3 Camera::GetDirection() const 211 { 212 return -Vector3(mViewOrientation.x[0][2], mViewOrientation.x[1][2], mViewOrientation.x[2][2]); 213 } 214 215 216 Vector3 Camera::GetUpVector() const 217 { 218 return Vector3(mViewOrientation.x[0][1], mViewOrientation.x[1][1], mViewOrientation.x[2][1]); 219 } 220 221 222 Vector3 Camera::GetRightVector() const 223 { 224 return Vector3(mViewOrientation.x[0][0], mViewOrientation.x[1][0], mViewOrientation.x[2][0]); 225 } 226 227 228 Vector3 Camera::GetBaseDirection() const 229 { 230 return -Vector3(mBaseOrientation.x[0][2], mBaseOrientation.x[1][2], mBaseOrientation.x[2][2]); 231 } 232 233 234 Vector3 Camera::GetBaseUpVector() const 235 { 236 return Vector3(mBaseOrientation.x[0][1], mBaseOrientation.x[1][1], mBaseOrientation.x[2][1]); 237 } 238 239 240 Vector3 Camera::GetBaseRightVector() const 241 { 242 return Vector3(mBaseOrientation.x[0][0], mBaseOrientation.x[1][0], mBaseOrientation.x[2][0]); 243 } 244 245 246 void Camera::CalcFrustum(Frustum &frustum) 247 { 248 // we grab the plane equations of the six clipplanes of the viewfrustum 249 Matrix4x4 matViewing, matProjectionView; 250 251 GetModelViewMatrix(matViewing); 252 GetProjectionMatrix(matProjectionView); 253 254 matProjectionView = matViewing * matProjectionView; 255 256 frustum = Frustum(matProjectionView); 257 258 259 //////////// 260 //-- normalize the coefficients 261 262 for (int i = 0; i < 6; ++ i) 263 { 264 // the clipping planes look outward the frustum, 265 // so distances > 0 mean that a point is outside 266 const float invLength = -1.0f / Magnitude(frustum.mClipPlanes[i].mNormal); 267 268 frustum.mClipPlanes[i].mD *= invLength; 269 frustum.mClipPlanes[i].mNormal *= invLength; 270 } 271 } 272 273 274 /*********************************************************/ 275 /* Class PerspectiveCamera implementation */ 276 /*********************************************************/ 277 278 279 PerspectiveCamera::PerspectiveCamera() 280 { 281 mFOVy = 60.0f * M_PI / 180.0f; 282 } 283 284 285 PerspectiveCamera::PerspectiveCamera(float aspect, float fieldOfView) 286 { 287 mFOVy = fieldOfView * M_PI / 180.0f; 288 mAspect = aspect; 289 } 290 291 292 Polyhedron *PerspectiveCamera::ComputeFrustum(float farthestVisibleDistance) const 349 293 { 350 294 Vector3 ftl, ftr, fbl, fbr; … … 384 328 385 329 386 } 330 void PerspectiveCamera::ComputePointsInternal(Vector3 &ftl, Vector3 &ftr, Vector3 &fbl, Vector3 &fbr, 331 Vector3 &ntl, Vector3 &ntr, Vector3 &nbl, Vector3 &nbr, 332 const Vector3 &view, const Vector3 &right, const Vector3 &up, 333 const Vector3 &pos, 334 float farthestVisibleDistance) const 335 { 336 const float z_near = mNear; 337 const float z_far = min(mFar, farthestVisibleDistance); 338 339 const float fov = mFOVy; 340 341 const float aspectRatio = GetAspect(); 342 343 const float h_near = tan(fov * 0.5f) * z_near; 344 const float w_near = h_near * aspectRatio; 345 346 const float h_far = tan(fov * 0.5f) * z_far; 347 const float w_far = h_far * aspectRatio; 348 349 const Vector3 fc = pos + view * z_far; 350 351 352 Vector3 t1, t2; 353 354 t1 = h_far * up; 355 t2 = w_far * right; 356 357 ftl = fc + t1 - t2; 358 ftr = fc + t1 + t2; 359 fbl = fc - t1 - t2; 360 fbr = fc - t1 + t2; 361 362 const Vector3 nc = pos + view * z_near; 363 364 t1 = h_near * up; 365 t2 = w_near * right; 366 367 ntl = nc + t1 - t2; 368 ntr = nc + t1 + t2; 369 nbl = nc - t1 - t2; 370 nbr = nc - t1 + t2; 371 } 372 373 374 void PerspectiveCamera::ComputePoints(Vector3 &ftl, Vector3 &ftr, Vector3 &fbl, Vector3 &fbr, 375 Vector3 &ntl, Vector3 &ntr, Vector3 &nbl, Vector3 &nbr, 376 float farthestVisibleDistance) const 377 { 378 ComputePointsInternal(ftl, ftr, fbl, fbr, 379 ntl, ntr, nbl, nbr, 380 GetDirection(), GetRightVector(), GetUpVector(), 381 GetPosition(), 382 farthestVisibleDistance); 383 } 384 385 386 void PerspectiveCamera::GetProjectionMatrix(Matrix4x4 &mat) const 387 { 388 mat = GetPerspective(mFOVy, 1.0f / mAspect, mNear, mFar); 389 390 Matrix4x4 mat2; 391 glGetFloatv(GL_PROJECTION_MATRIX, (float *)mat2.x); 392 393 cout << "my projview:\n" << mat << endl; 394 cout << "gl projview:\n" << mat2 << endl; 395 } 396 397 398 } -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Camera.h
r3061 r3062 12 12 class Matrix4x4; 13 13 class Polyhedron; 14 14 15 15 16 /** Class representing a frustum. … … 43 44 class Camera 44 45 { 45 friend class ShadowMap;46 47 46 public: 48 47 /** Default constructor. 49 48 */ 50 49 Camera(); 51 /** Camera taking the image width and height and the field of view.52 */53 Camera(float aspect, float fieldOfView = 90.f);54 50 /** Sets the current camera position. 55 51 */ … … 71 67 Vector3 GetBaseUpVector() const; 72 68 Vector3 GetBaseRightVector() const; 73 /** 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 69 /** Sets up viewing matrices in for opengl rendering 80 70 */ … … 82 72 /** Returns the current projection matrix. 83 73 */ 84 v oid GetProjectionMatrix(Matrix4x4 &mat) const;74 virtual void GetProjectionMatrix(Matrix4x4 &mat) const = 0; 85 75 /** Returns the current model view matrix. 86 76 */ … … 89 79 */ 90 80 void GetViewOrientationMatrix(Matrix4x4 &mat) const; 91 /** Calculates a frustum from the projection and the modelview matrix.92 */93 void CalcFrustum(Frustum &frustum);94 /** Computes the extremal points of this frustum.95 If farthestVisibleDistance is nearer than the far plane,96 it is used to define the far plane instead.97 */98 void ComputePoints(Vector3 &ftl, Vector3 &ftr, Vector3 &fbl, Vector3 &fbr,99 Vector3 &ntl, Vector3 &ntr, Vector3 &nbl, Vector3 &nbr,100 float farthestVisibleDistance = 1e25f) const;101 81 /** Returns the near plane. 102 82 */ … … 111 91 */ 112 92 void SetFar(float farDist); 113 /** Sets this camera to orthographic projection.114 */115 //void SetOrtho(bool ortho);116 93 /** Set yaw (rotation around vertical axis. 117 94 */ … … 132 109 */ 133 110 void SetDirection(const Vector3 &direction); 134 /** Returns frustum as polyhedron.135 */136 Polyhedron *ComputeFrustum(float farthestVisibleDistance = 1e25f) const;137 111 /** Sets up projection matrix in OpenGl. 138 112 */ … … 141 115 */ 142 116 void SetupViewProjection(); 143 117 /** Calculates a frustum from the projection and the modelview matrix. 118 */ 119 void CalcFrustum(Frustum &frustum); 144 120 145 121 protected: … … 148 124 149 125 void CalculateFromPitchAndYaw(); 126 127 128 //////////////// 129 //-- members 130 131 float mNear; 132 float mFar; 133 134 Matrix4x4 mBaseOrientation; 135 Matrix4x4 mViewOrientation; 136 137 float mPitch; 138 float mYaw; 139 140 Vector3 mPosition; 141 }; 142 143 144 /** Classs representing a perspective camera. 145 */ 146 class PerspectiveCamera: public Camera 147 { 148 friend class ShadowMap; 149 150 public: 151 /** Default constructor. 152 */ 153 PerspectiveCamera(); 154 /** Camera taking the image width and height and the field of view. 155 */ 156 PerspectiveCamera(float aspect, float fieldOfView = 90.f); 157 /** Returns the field of view. 158 */ 159 inline float GetFov() const { return mFOVy; } 160 /** Returns the aspect ratio. 161 */ 162 inline float GetAspect() const { return mAspect; } 163 /** Returns the current projection matrix. 164 */ 165 virtual void GetProjectionMatrix(Matrix4x4 &mat) const; 166 /** Computes the extremal points of this frustum. 167 If farthestVisibleDistance is nearer than the far plane, 168 it is used to define the far plane instead. 169 */ 170 void ComputePoints(Vector3 &ftl, Vector3 &ftr, Vector3 &fbl, Vector3 &fbr, 171 Vector3 &ntl, Vector3 &ntr, Vector3 &nbl, Vector3 &nbr, 172 float farthestVisibleDistance = 1e25f) const; 173 /** Returns frustum as polyhedron. 174 */ 175 Polyhedron *ComputeFrustum(float farthestVisibleDistance = 1e25f) const; 176 177 178 protected: 150 179 151 180 void ComputePointsInternal(Vector3 &ftl, Vector3 &ftr, Vector3 &fbl, Vector3 &fbr, … … 159 188 160 189 float mFOVy; 161 float mNear;162 float mFar;163 164 /// if this camera is orthgraphic or perspective165 //bool mIsOrtho;166 167 Matrix4x4 mBaseOrientation;168 Matrix4x4 mViewOrientation;169 170 float mPitch;171 float mYaw;172 173 Vector3 mPosition;174 175 190 float mAspect; 176 191 }; 177 192 193 178 194 } 179 195 #endif -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp
r3057 r3062 231 231 232 232 233 DeferredRenderer::DeferredRenderer(int w, int h, Camera *cam, float scaleFactor):233 DeferredRenderer::DeferredRenderer(int w, int h, PerspectiveCamera *cam, float scaleFactor): 234 234 mWidth(w), mHeight(h), 235 235 mCamera(cam), … … 298 298 299 299 i = 0; 300 301 300 sCgSsaoProgram->AddParameter("colors", i ++); 302 301 sCgSsaoProgram->AddParameter("normals", i ++); … … 314 313 315 314 i = 0; 316 317 315 sCgGiProgram->AddParameter("colors", i ++); 318 316 sCgGiProgram->AddParameter("normals", i ++); … … 529 527 sCgSsaoProgram->SetValue3f(10, tr.x, tr.y, tr.z); 530 528 529 cout << "new projview:\n" << projViewMatrix << endl; 530 cout << "old projview:\n" << oldProjViewMatrix << endl; 531 531 532 sCgSsaoProgram->SetMatrix(11, projViewMatrix); 532 533 sCgSsaoProgram->SetMatrix(12, oldProjViewMatrix); -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.h
r3038 r3062 15 15 class FrameBufferObject; 16 16 class Vector3; 17 class Camera;17 class PerspectiveCamera; 18 18 class Matrix4x4; 19 19 class ShadowMap; … … 36 36 exact scene size that was scaled in order to improve floating point precision. 37 37 */ 38 DeferredRenderer(int w, int h, Camera *cam, float scaleFactor);38 DeferredRenderer(int w, int h, PerspectiveCamera *cam, float scaleFactor); 39 39 /** The algorithm renders the scene given an fbo consists of 1 color buffer, 40 40 1 position buffer, and 1 normal buffer. … … 122 122 int mHeight; 123 123 124 Camera *mCamera;124 PerspectiveCamera *mCamera; 125 125 126 126 bool mUseTemporalCoherence; -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Matrix4x4.cpp
r2953 r3062 649 649 } 650 650 651 Matrix4x4 652 NormalTransformMatrix(const Matrix4x4 &tform)651 652 Matrix4x4 NormalTransformMatrix(const Matrix4x4 &tform) 653 653 { 654 654 Matrix4x4 m = tform; … … 692 692 return m; 693 693 } 694 /* 695 696 template<class REAL> 697 Matrix4<REAL>& scaleTranslateToFit(Matrix4<REAL>& output, const Vector3<REAL>& vMin, const Vector3<REAL>& vMax) { 698 const REAL diffX = vMax.x()-vMin.x(); 699 output[ 0] = 2/diffX; 700 output[ 4] = 0; 701 output[ 8] = 0; 702 output[12] = -(vMax.x()+vMin.x())/diffX; 703 704 const REAL diffY = vMax.y()-vMin.y(); 705 output[ 1] = 0; 706 output[ 5] = 2/diffY; 707 output[ 9] = 0; 708 output[13] = -(vMax.y()+vMin.y())/diffY; 709 710 const REAL diffZ = vMax.z()-vMin.z(); 711 output[ 2] = 0; 712 output[ 6] = 0; 713 output[10] = 2/diffZ; 714 output[14] = -(vMax.z()+vMin.z())/diffZ; 715 716 output[ 3] = 0; 717 output[ 7] = 0; 718 output[11] = 0; 719 output[15] = 1; 720 return output; 721 } 694 695 696 /** The resultig matrix that is equal to the result of glFrustum 722 697 */ 723 724 725 726 //output is initialized with the same result as glFrustum727 698 Matrix4x4 GetFrustum(float left, float right, 728 699 float bottom, float top, … … 781 752 782 753 783 } 754 /** The resultig matrix that is equal to the result of glOrtho 755 */ 756 Matrix4x4 GetOrtho(float left, float right, float bottom, float top, float far, float near) 757 { 758 Matrix4x4 m; 759 760 const float xDif = 1.0f / (right - left); 761 const float yDif = 1.0f / (top - bottom); 762 const float zDif = 1.0f / (far - near); 763 764 m.x[0][0] = 2.0f * xDif; 765 m.x[0][1] = .0f; 766 m.x[0][2] = .0f; 767 m.x[0][3] = .0f; 768 769 m.x[1][0] = .0f; 770 m.x[1][1] = 2.0f * yDif; 771 m.x[1][2] = .0f; 772 m.x[1][3] = .0f; 773 774 m.x[2][0] = .0f; 775 m.x[2][1] = .0f; 776 m.x[2][2] = -2.0f * zDif; 777 m.x[2][3] = .0f; 778 779 m.x[3][0] = (right + left) * xDif; 780 m.x[3][1] = (top + bottom) * yDif; 781 m.x[3][2] = (far + near) * zDif; 782 m.x[3][3] = 1.0f; 783 784 return m; 785 } 786 787 /** The resultig matrix that is equal to the result of gluPerspective 788 */ 789 Matrix4x4 GetPerspective(float fov, float aspect, float near, float far) 790 { 791 Matrix4x4 m; 792 793 const float x = 1.0f / tan(fov * 0.5f); 794 const float zDif = 1.0f / (near - far); 795 796 m.x[0][0] = x / aspect; 797 m.x[0][1] = .0f; 798 m.x[0][2] = .0f; 799 m.x[0][3] = .0f; 800 801 m.x[1][0] = .0f; 802 m.x[1][1] = x; 803 m.x[1][2] = .0f; 804 m.x[1][3] = .0f; 805 806 m.x[2][0] = .0f; 807 m.x[2][1] = .0f; 808 m.x[2][2] = (far + near) * zDif; 809 m.x[2][3] = -1.0f; 810 811 m.x[3][0] = .0f; 812 m.x[3][1] = .0f; 813 m.x[3][2] = 2.0f *(far * near) * zDif; 814 m.x[3][3] = 0.0f; 815 816 return m; 817 } 818 819 820 } -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Matrix4x4.h
r2944 r3062 165 165 Matrix4x4 GetFrustum(float left, float right, float bottom, float top, float near, float far); 166 166 Matrix4x4 LookAt(const Vector3 &pos, const Vector3 &dir, const Vector3& up); 167 167 Matrix4x4 GetOrtho(float fov, float aspect, float near, float far); 168 Matrix4x4 GetPerspective(float fov, float aspect, float near, float far); 168 169 169 170 } -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SceneQuery.cpp
r3061 r3062 139 139 const float ylen = mSceneBox.Size().y * 0.5f; 140 140 141 Camera *orthoCam = newCamera(xlen / ylen);141 PerspectiveCamera *orthoCam = new PerspectiveCamera(xlen / ylen); 142 142 //orthoCam->SetOrtho(true); 143 143 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShadowMapping.cpp
r3061 r3062 134 134 135 135 136 ShadowMap::ShadowMap(DirectionalLight *light 137 ,int size,136 ShadowMap::ShadowMap(DirectionalLight *light, 137 int size, 138 138 const AxisAlignedBox3 &sceneBox, 139 Camera *cam):139 PerspectiveCamera *cam): 140 140 mSceneBox(sceneBox), mSize(size), mCamera(cam), mLight(light) 141 141 { … … 148 148 149 149 150 mShadowCam = new Camera(1);150 mShadowCam = new PerspectiveCamera(1); 151 151 //mShadowCam->SetOrtho(true); 152 152 } … … 713 713 glDisable(GL_POLYGON_OFFSET_FILL); 714 714 } 715 716 715 717 } // namespace -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShadowMapping.h
r3034 r3062 14 14 class RenderTraverser; 15 15 class Vector3; 16 class Camera;16 class PerspectiveCamera; 17 17 class DirectionalLight; 18 18 19 19 20 /** This class implements a the computation of single shadow map using … … 27 28 The shadow map has resolution size squared. 28 29 */ 29 ShadowMap(DirectionalLight *light, int size, const AxisAlignedBox3 &sceneBox, Camera *cam);30 ShadowMap(DirectionalLight *light, int size, const AxisAlignedBox3 &sceneBox, PerspectiveCamera *cam); 30 31 31 32 ~ShadowMap(); … … 52 53 /** Returns the camera used for light view rendering. 53 54 */ 54 Camera *GetShadowCamera() const { return mShadowCam; }55 PerspectiveCamera *GetShadowCamera() const { return mShadowCam; } 55 56 /** Renders the scene from shadow view using conventional shading. 56 57 */ … … 111 112 int mSize; 112 113 /// the shadow view 113 Camera *mShadowCam;114 PerspectiveCamera *mShadowCam; 114 115 /// the texture matrix 115 116 Matrix4x4 mTextureMatrix; … … 117 118 DirectionalLight *mLight; 118 119 /// the scene camera 119 Camera *mCamera;120 PerspectiveCamera *mCamera; 120 121 121 122 Matrix4x4 mLightProjView; -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Visualization.cpp
r2963 r3062 6 6 #include "RenderState.h" 7 7 #include "ShadowMapping.h" 8 9 8 #include <stack> 10 9 … … 70 69 71 70 Visualization::Visualization(Bvh *bvh, 72 Camera *camera,71 PerspectiveCamera *camera, 73 72 Camera *vizCamera, 74 73 RenderState *renderState): -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Visualization.h
r2889 r3062 9 9 10 10 class Bvh; 11 class PerspectiveCamera; 11 12 class Camera; 12 13 class RenderState; … … 23 24 as parameters 24 25 */ 25 Visualization(Bvh *bvh, Camera *camera, Camera *vizCamera, RenderState *state);26 Visualization(Bvh *bvh, PerspectiveCamera *camera, Camera *vizCamera, RenderState *state); 26 27 27 28 ~Visualization(); … … 38 39 /** Sets the currently used scene camera. 39 40 */ 40 void SetCamera( Camera *cam) {mCamera = cam;}41 void SetCamera(PerspectiveCamera *cam) {mCamera = cam;} 41 42 /** Sets the current render state 42 43 */ … … 45 46 */ 46 47 void SetFrameId(int frameId); 47 48 /** Renders a camera frustum. 48 /** Renders a camera frustum. 49 49 */ 50 50 void RenderFrustum(); … … 56 56 57 57 /// the current camera 58 Camera *mCamera;58 PerspectiveCamera *mCamera; 59 59 /// the visualization camera 60 60 Camera *mVizCamera; -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp
r3061 r3062 79 79 ShaderManager *shaderManager = NULL; 80 80 /// the scene camera 81 Camera *camera = NULL;81 PerspectiveCamera *camera = NULL; 82 82 /// the scene camera 83 Camera *visCamera = NULL;83 PerspectiveCamera *visCamera = NULL; 84 84 /// the visualization 85 85 Visualization *visualization = NULL; … … 257 257 void CalcDecimalPoint(string &str, int d); 258 258 /// Creates the traversal method (vfc, stopandwait, chc, chc++) 259 RenderTraverser *CreateTraverser( Camera *cam);259 RenderTraverser *CreateTraverser(PerspectiveCamera *cam); 260 260 261 261 /// place the viewer on the floor plane … … 369 369 /////////////////////////// 370 370 371 camera = new Camera(winWidth / winHeight, fov);371 camera = new PerspectiveCamera(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 PerspectiveCamera(winWidth / winHeight, fov); 379 379 visCamera->SetNear(0.0f); 380 380 visCamera->Yaw(.5 * M_PI); … … 661 661 662 662 663 RenderTraverser *CreateTraverser( Camera *cam)663 RenderTraverser *CreateTraverser(PerspectiveCamera *cam) 664 664 { 665 665 RenderTraverser *tr;
Note: See TracChangeset
for help on using the changeset viewer.