- Timestamp:
- 09/12/08 18:07:04 (16 years ago)
- Location:
- GTP/trunk/App/Demos/Vis/FriendlyCulling/src
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Camera.cpp
r2932 r2936 279 279 mClipPlanes[Frustum::RIGHT_PLANE][i] = trafo.x[i][3] - trafo.x[i][0]; 280 280 mClipPlanes[Frustum::LEFT_PLANE][i] = trafo.x[i][3] + trafo.x[i][0]; 281 281 282 mClipPlanes[Frustum::BOTTOM_PLANE][i] = trafo.x[i][3] + trafo.x[i][1]; 282 283 mClipPlanes[Frustum::TOP_PLANE][i] = trafo.x[i][3] - trafo.x[i][1]; 284 283 285 mClipPlanes[Frustum::FAR_PLANE][i] = trafo.x[i][3] - trafo.x[i][2]; 284 286 mClipPlanes[Frustum::NEAR_PLANE][i] = trafo.x[i][3] + trafo.x[i][2]; -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Camera.h
r2932 r2936 25 25 Frustum(const Matrix4x4 &trafo); 26 26 27 enum { RIGHT_PLANE, LEFT_PLANE, BOTTOM_PLANE, TOP_PLANE, FAR_PLANE, NEAR_PLANE}; 27 enum { LEFT_PLANE, RIGHT_PLANE, BOTTOM_PLANE, TOP_PLANE, NEAR_PLANE, FAR_PLANE}; 28 28 29 /** Resizes the current frustum so that it fully encloses the given polyhedron 29 30 */ -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Matrix4x4.cpp
r2934 r2936 763 763 Matrix4x4 m(nRight, nUp, nDir); 764 764 765 /*m.x[3][0] = -DotProd(nRight, position); 766 m.x[3][1] = -DotProd(nUp, position); 767 m.x[3][2] = -DotProd(nDir, position);*/ 768 769 Vector3 position = m * -pos; 770 771 // note: left handed system => we go into positive z 772 m.x[3][0] = position.x; 773 m.x[3][1] = position.y; 774 m.x[3][2] = position.z; 765 m.x[3][0] = -DotProd(nRight, pos); 766 m.x[3][1] = -DotProd(nUp, pos); 767 m.x[3][2] = -DotProd(nDir, pos); 775 768 776 769 return m; -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Polyhedron.cpp
r2931 r2936 275 275 } 276 276 277 // add the new polygon to the polyhedron278 clippedPolyhedron->Add(planePoly);279 280 281 277 282 278 ///////////// 283 279 //-- clip polyhedron: plane splits all polygons 284 280 285 for ( int i = 0; i < (int)mPolygons.size(); ++ i)281 for (size_t i = 0; i < mPolygons.size(); ++ i) 286 282 { 287 283 Polygon3 *poly = mPolygons[i]; … … 320 316 } 321 317 } 318 319 // we can now savely add the new polygon 320 clippedPolyhedron->Add(planePoly); 322 321 323 322 return clippedPolyhedron; -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShadowMapping.cpp
r2935 r2936 40 40 41 41 42 static Polyhedron *CreatePolyhedron(const Matrix4x4 &lightMatrix, const AxisAlignedBox3 &sceneBox) 42 static Polyhedron *CreatePolyhedron(const Matrix4x4 &lightMatrix, 43 const AxisAlignedBox3 &sceneBox) 43 44 { 44 45 Frustum frustum(lightMatrix); … … 57 58 frustum.mClipPlanes[i].mD *= invLength; 58 59 frustum.mClipPlanes[i].mNormal *= invLength; 59 60 //clipPlanes.push_back(frustum.mClipPlanes[i]); 61 } 62 63 clipPlanes.push_back(frustum.mClipPlanes[5]); 60 } 61 64 62 clipPlanes.push_back(frustum.mClipPlanes[0]); 65 63 clipPlanes.push_back(frustum.mClipPlanes[1]); 66 64 clipPlanes.push_back(frustum.mClipPlanes[2]); 67 65 clipPlanes.push_back(frustum.mClipPlanes[3]); 66 clipPlanes.push_back(frustum.mClipPlanes[5]); 67 68 68 clipPlanes.push_back(frustum.mClipPlanes[4]); 69 69 … … 158 158 159 159 160 void ShadowMap::DrawPoly(Polyhedron *poly, const Vector3 &color )160 void ShadowMap::DrawPoly(Polyhedron *poly, const Vector3 &color, const Vector3 &color2) 161 161 { 162 162 if (!poly) return; … … 166 166 glColor3f(color.x, color.y, color.z); 167 167 168 if (i == poly->NumPolygons() - 1) // hack: different color for near 169 { 170 //glLineWidth(2); 171 glColor3f(color2.x, color2.y, color2.z); 172 173 } 168 174 glBegin(GL_LINE_LOOP); 169 175 … … 177 183 178 184 glEnd(); 185 186 //if (i == poly->NumPolygons() - 1) glLineWidth(1); 179 187 } 180 188 } … … 183 191 void ShadowMap::DrawPolys() 184 192 { 185 DrawPoly(lightPoly, Vector3(1, 0, 1) );186 DrawPoly(polyhedron, Vector3(0, 1, 0) );193 DrawPoly(lightPoly, Vector3(1, 0, 1), Vector3(1, 1, 1)); 194 DrawPoly(polyhedron, Vector3(0, 1, 0), Vector3(0, 1, 1)); 187 195 188 196 glPointSize(10.0f); 189 197 190 198 Vector3 pt = Vector3::ZERO(); 199 //Vector3 pt = dummyPt; 191 200 192 201 Matrix4x4 myMat = Invert(dummyMat); … … 225 234 //-- first find the free parameter values n, and P (the projection center), and the projection depth 226 235 227 const float n = 1e 1f;236 const float n = 1e2f; 228 237 //const float n = 1e6f; 229 238 //const float n = ComputeN(bounds_ls) * 100; … … 237 246 238 247 //c start has the x and y coordinate of e, the z coord of the near plane of the light volume 239 //const Vector3 startPt = Vector3(lsNear.x, lsNear.y, bounds_ls.Max().z);240 248 const Vector3 startPt = Vector3(lsNear.x, lsNear.y, bounds_ls.Max().z); 249 //const Vector3 schas = lightSpace * mCamera->GetPosition(); 250 //const Vector3 startPt = Vector3(schas.x, schas.y, schas.y);//bounds_ls.Max().z); 241 251 242 252 cout << "mx: " << bounds_ls.Max() << endl; … … 244 254 245 255 // the new projection center 246 Vector3projCenter = startPt + Vector3::UNIT_Z() * n;256 const Vector3 projCenter = startPt + Vector3::UNIT_Z() * n; 247 257 248 258 cout <<"start: " << startPt << " " << projCenter << " " << Distance(lightSpace * mCamera->GetPosition(), startPt) << endl; 249 //dummyPt = -projCenter; 259 260 dummyPt = startPt; 250 261 251 262 //construct a translation that moves to the projection center … … 416 427 transform2LispSM.x[3][3] = 1.0f; 417 428 429 418 430 //switch to the lightspace used in the article 419 lightProj = lightProj *transform2LispSM;431 lightProj *= transform2LispSM; 420 432 421 433 const Vector3 projViewDir = GetProjViewDir(lightView * lightProj, frustumPoints); 422 423 434 424 435 cout << "projViewDir: " << projViewDir << " orig " << mCamera->GetDirection() << endl; … … 428 439 //calculate a frame matrix that uses the projViewDir[lightspace] as up vector 429 440 //look(from position, into the direction of the projected direction, with unchanged up-vector) 430 const Matrix4x4 frame = MyLookAt2(Vector3::ZERO(), -projViewDir, -Vector3::UNIT_Y());431 //const Matrix4x4 frame = MyLookAt(Vector3::ZERO(), projViewDir, Vector3::UNIT_ Z());441 const Matrix4x4 frame = MyLookAt2(Vector3::ZERO(), projViewDir, Vector3::UNIT_Y()); 442 //const Matrix4x4 frame = MyLookAt(Vector3::ZERO(), projViewDir, Vector3::UNIT_Y()); 432 443 433 444 cout << "frame\n " << frame << endl; 434 lightProj = lightProj *frame;445 lightProj *= frame; 435 446 436 447 cout << "here9\n" << lightProj << endl; 448 449 Matrix4x4 refl2 = ScaleMatrix(-1, -1, 1); 450 //lightProj = refl2 * lightProj; 437 451 438 452 const Matrix4x4 matLispSM = 439 453 CalcLispSMTransform(lightView * lightProj, extremalPoints, frustumPoints); 440 454 441 lightProj = lightProj *matLispSM;455 lightProj *= matLispSM; 442 456 443 457 // change back to GL coordinate system … … 449 463 transformToGL.x[3][3] = 1.0f; 450 464 451 lightProj = lightProj *transformToGL;465 lightProj *= transformToGL; 452 466 //cout << "here4 \n" << lightProj << endl; 453 467 454 468 AxisAlignedBox3 lightPts = GetExtremalPoints(lightView * lightProj, frustumPoints); 455 469 456 //cout << "ma2: " << lightPts.Max() << endl; 457 //cout << "mi2: " << lightPts.Min() << endl; 470 //cout << "max2: " << lightPts.Max() << endl; 471 //cout << "min2: " << lightPts.Min() << endl; 472 473 AxisAlignedBox3 dummyBox = GetExtremalPoints(IdentityMatrix(), frustumPoints); 458 474 459 475 // focus projection matrix on the extremal points => scale to unit cube 476 //Matrix4x4 scaleTranslate = GetFittingProjectionMatrix(extremalPoints); 460 477 Matrix4x4 scaleTranslate = GetFittingProjectionMatrix(lightPts); 461 478 lightProj *= scaleTranslate; 462 479 463 cout << "max: " << light Proj * extremalPoints.Max() << endl;464 cout << "min: " << light Proj * extremalPoints.Min() << endl;480 cout << "max: " << lightView * lightProj * dummyBox.Max() << endl; 481 cout << "min: " << lightView * lightProj * dummyBox.Min() << endl; 465 482 466 483 // we have to flip the signs in order to tranform to opengl right handed system … … 569 586 Vector3 upVec = CalcUpVec(mCamera->GetDirection(), dir); 570 587 Matrix4x4 lightView = MyLookAt2(mShadowCam->GetPosition(), -dir, upVec); 588 //Matrix4x4 lightView = MyLookAt(mShadowCam->GetPosition(), -dir, mCamera->GetDirection()); 589 590 Matrix4x4 refl = ScaleMatrix(-1, 1, 1); 591 lightView = lightView * refl; 571 592 572 593 mShadowCam->mViewOrientation = lightView; … … 682 703 Vector3 upVec = CalcUpVec(mCamera->GetDirection(), dir); 683 704 Matrix4x4 lightView = MyLookAt2(mShadowCam->GetPosition(), -dir, upVec); 705 //Matrix4x4 lightView = MyLookAt(mShadowCam->GetPosition(), -dir, mCamera->GetDirection()); 706 707 //Matrix4x4 refl = ScaleMatrix(-1, 1, 1); 708 //lightView = lightView * refl; 684 709 685 710 mShadowCam->mViewOrientation = lightView; … … 727 752 glDisable(GL_POLYGON_OFFSET_FILL); 728 753 729 glPushAttrib(GL_CURRENT_BIT);730 754 glDisable(GL_LIGHTING); 731 755 glDisable(GL_DEPTH_TEST); 732 glDepthMask(GL_FALSE); 733 756 757 glLineWidth(2); 734 758 Polyhedron *hpoly = CreatePolyhedron(projView, mSceneBox); 735 //Polyhedron *hpoly = CalcClippedFrustum(mSceneBox); 736 737 DrawPoly(hpoly, Vector3(1, 1, 1)); 759 DrawPoly(hpoly, Vector3(1, 1, 1), Vector3(0, 1, 1)); 738 760 739 761 DEL_PTR(hpoly); 740 762 741 glEnable(GL_CULL_FACE); 742 763 //glEnable(GL_CULL_FACE); 764 765 glEnable(GL_LIGHTING); 743 766 glEnable(GL_DEPTH_TEST); 744 glDepthMask(GL_TRUE);745 glPopAttrib();746 767 747 768 glMatrixMode(GL_MODELVIEW); -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShadowMapping.h
r2932 r2936 87 87 Vector3 GetProjViewDir(const Matrix4x4 &lightSpace, const VertexArray &pts) const; 88 88 89 static void DrawPoly(Polyhedron *poly, const Vector3 &color );89 static void DrawPoly(Polyhedron *poly, const Vector3 &color, const Vector3 &color2); 90 90 91 91 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp
r2932 r2936 1035 1035 // this would conveniently solves some issues (e.g, skys without shadows) 1036 1036 1037 RenderSky();1037 //RenderSky(); 1038 1038 1039 1039
Note: See TracChangeset
for help on using the changeset viewer.