Changeset 2929 for GTP/trunk/App/Demos
- Timestamp:
- 09/11/08 10:10:48 (16 years ago)
- Location:
- GTP/trunk/App/Demos/Vis/FriendlyCulling/src
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/AxisAlignedBox3.cpp
r2913 r2929 1344 1344 1345 1345 1346 } 1347 1346 void AxisAlignedBox3::ExtractPolygons(PolygonContainer &polys) const 1347 { 1348 Polygon3 *face1 = new Polygon3(); 1349 polys.push_back(face1); 1350 1351 face1->mVertices.push_back(Vector3(mMin.x, mMin.y, mMax.z)); 1352 face1->mVertices.push_back(Vector3(mMin.x, mMax.y, mMax.z)); 1353 face1->mVertices.push_back(Vector3(mMin.x, mMax.y ,mMin.z)); 1354 face1->mVertices.push_back(Vector3(mMin.x, mMin.y, mMin.z)); 1355 1356 Polygon3 *face2 = new Polygon3(); 1357 polys.push_back(face2); 1358 1359 face2->mVertices.push_back(Vector3(mMax.x, mMin.y, mMin.z)); 1360 face2->mVertices.push_back(Vector3(mMax.x, mMax.y, mMin.z)); 1361 face2->mVertices.push_back(Vector3(mMax.x, mMax.y, mMax.z)); 1362 face2->mVertices.push_back(Vector3(mMax.x, mMin.y, mMax.z)); 1363 1364 Polygon3 *face3 = new Polygon3(); 1365 polys.push_back(face3); 1366 1367 face3->mVertices.push_back(Vector3(mMax.x, mMin.y ,mMin.z)); 1368 face3->mVertices.push_back(Vector3(mMax.x, mMin.y, mMax.z)); 1369 face3->mVertices.push_back(Vector3(mMin.x, mMin.y, mMax.z)); 1370 face3->mVertices.push_back(Vector3(mMin.x, mMin.y, mMin.z)); 1371 1372 Polygon3 *face4 = new Polygon3(); 1373 polys.push_back(face4); 1374 1375 face4->mVertices.push_back(Vector3(mMin.x, mMax.y, mMin.z)); 1376 face4->mVertices.push_back(Vector3(mMin.x, mMax.y, mMax.z)); 1377 face4->mVertices.push_back(Vector3(mMax.x, mMax.y, mMax.z)); 1378 face4->mVertices.push_back(Vector3(mMax.x, mMax.y, mMin.z)); 1379 1380 Polygon3 *face5 = new Polygon3(); 1381 polys.push_back(face5); 1382 1383 face5->mVertices.push_back(Vector3(mMin.x, mMax.y, mMin.z)); 1384 face5->mVertices.push_back(Vector3(mMax.x, mMax.y, mMin.z)); 1385 face5->mVertices.push_back(Vector3(mMax.x, mMin.y, mMin.z)); 1386 face5->mVertices.push_back(Vector3(mMin.x, mMin.y, mMin.z)); 1387 1388 Polygon3 *face6 = new Polygon3(); 1389 polys.push_back(face6); 1390 1391 face6->mVertices.push_back(Vector3(mMin.x, mMin.y, mMax.z)); 1392 face6->mVertices.push_back(Vector3(mMax.x, mMin.y, mMax.z)); 1393 face6->mVertices.push_back(Vector3(mMax.x, mMax.y, mMax.z)); 1394 face6->mVertices.push_back(Vector3(mMin.x, mMax.y, mMax.z)); 1395 } 1396 1397 } 1398 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/AxisAlignedBox3.h
r2913 r2929 206 206 */ 207 207 Polyhedron *CalcIntersection(const Polyhedron &polyhedron) const; 208 209 208 /** Tests for intersection of the ray with the box. 209 */ 210 210 bool Intersects(const SimpleRay &ray, float &tnear, float &tfar) const; 211 /** Extracts the box sides as polygons. 212 */ 213 void ExtractPolygons(PolygonContainer &polys) const; 214 211 215 212 216 //////////// -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Polyhedron.cpp
r2913 r2929 13 13 static const float epsilon = 1e-6f; 14 14 15 16 15 17 /**********************************************************/ 16 18 /* class Polyhedron Implementation */ … … 42 44 for (it = rhs.mPolygons.begin(); it != it_end; ++ it) 43 45 Add(new Polygon3(*(*it))); 46 } 47 48 49 Polyhedron *Polyhedron::CreatePolyhedron(const vector<Plane3> &planes, 50 const AxisAlignedBox3 &sceneBox) 51 { 52 // add the bounding box 53 PolygonContainer polygons; 54 sceneBox.ExtractPolygons(polygons); 55 56 Polyhedron *oldPolyhedron = new Polyhedron(polygons); 57 58 if (!oldPolyhedron->Valid()) cerr << "******************* not valid!! ************* " << endl; 59 60 //oldPolyhedron->mBox = sceneBox; 61 62 vector<Plane3>::const_iterator it, it_end = planes.end(); 63 64 Polyhedron *newPolyhedron = NULL; 65 66 // intersect bounding box with planes 67 for (it = planes.begin(); it != it_end; ++ it) 68 { 69 Plane3 plane = *it; 70 71 newPolyhedron = oldPolyhedron->CalcIntersection(plane); 72 73 if (!newPolyhedron) 74 { 75 cerr << "polyhedron not valid or NULL!" << endl; 76 return NULL; 77 } 78 79 // hack: set bounding box temporarily to scene bounding box 80 //newPolyhedron->mBox = sceneBox; 81 82 DEL_PTR(oldPolyhedron); 83 oldPolyhedron = newPolyhedron; 84 } 85 86 return newPolyhedron; 44 87 } 45 88 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Polyhedron.h
r2913 r2929 73 73 inline friend std::ostream &operator<<(std::ostream &s, const Polyhedron &a); 74 74 75 /** Computes polyhedron from a couple of intersecting planes and a bounding box. 76 */ 77 static Polyhedron *CreatePolyhedron(const std::vector<Plane3> &planes, const AxisAlignedBox3 &box); 78 75 79 protected: 76 80 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShadowMapping.cpp
r2928 r2929 19 19 20 20 static Polyhedron *polyhedron = NULL; 21 static Polyhedron *lightPoly = NULL; 21 22 22 23 … … 125 126 126 127 127 void ShadowMap::DrawPolys() 128 { 129 if (!polyhedron) return; 130 131 for (size_t i = 0; i < polyhedron->NumPolygons(); ++ i) 132 { 133 float r = (float)i / polyhedron->NumPolygons(); 134 float g = 1; 135 float b = 1; 136 137 glColor3f(r, g, b); 128 void ShadowMap::DrawPoly(Polyhedron *poly, const Vector3 &color) 129 { 130 if (!poly) return; 131 132 for (size_t i = 0; i < poly->NumPolygons(); ++ i) 133 { 134 glColor3f(color.x, color.y, color.z); 138 135 139 136 glBegin(GL_LINE_LOOP); 140 137 141 Polygon3 *p oly = polyhedron->GetPolygons()[i];142 143 for (size_t j = 0; j < p oly->mVertices.size(); ++ j)138 Polygon3 *p = poly->GetPolygons()[i]; 139 140 for (size_t j = 0; j < p->mVertices.size(); ++ j) 144 141 { 145 Vector3 v = p oly->mVertices[j];142 Vector3 v = p->mVertices[j]; 146 143 glVertex3d(v.x, v.y, v.z); 147 144 } … … 152 149 153 150 154 void ShadowMap::IncludeLightVolume(const Polyhedron &polyhedron, 155 VertexArray &frustumPoints, 156 const Vector3 lightDir, 157 const AxisAlignedBox3 &sceneBox 158 ) 159 { 160 // we don't need closed form anymore => just store vertices 161 VertexArray vertices; 162 polyhedron.CollectVertices(vertices); 163 164 // we 'look' at each point and calculate intersections of rays with scene bounding box 165 VertexArray::const_iterator it, it_end = vertices.end(); 166 167 for (it = vertices.begin(); it != it_end; ++ it) 168 { 169 Vector3 v = *it; 170 171 frustumPoints.push_back(v); 172 173 // hack: get point surely outside of box 174 v -= Magnitude(mSceneBox.Diagonal()) * lightDir; 175 176 SimpleRay ray(v, lightDir); 177 178 float tNear, tFar; 179 180 if (sceneBox.Intersects(ray, tNear, tFar)) 181 { 182 Vector3 newpt = ray.Extrap(tNear); 183 frustumPoints.push_back(newpt); 184 } 185 } 151 void ShadowMap::DrawPolys() 152 { 153 DrawPoly(lightPoly, Vector3(1, 0, 1)); 154 DrawPoly(polyhedron, Vector3(0, 1, 0)); 186 155 } 187 156 … … 214 183 215 184 //const float n = 1e6f; 216 //const float n = 1e1f;217 const float n = ComputeN(bounds_ls) * 100;185 const float n = 1e3f; 186 //const float n = ComputeN(bounds_ls) * 100; 218 187 219 188 cout << "n: " << n << endl; … … 566 535 mLightProjView = lightView * lightProj; 567 536 537 Frustum frustum(mLightProjView); 538 //Frustum frustum(projView); 539 540 DEL_PTR(lightPoly); 541 542 vector<Plane3> clipPlanes; 543 544 for (int i = 0; i < 6; ++ i) 545 { 546 frustum.mClipPlanes[i].mNormal *= -1; 547 frustum.mClipPlanes[i].mD *= -1; 548 549 clipPlanes.push_back(frustum.mClipPlanes[i]); 550 } 551 552 DEL_PTR(lightPoly); 553 lightPoly = Polyhedron::CreatePolyhedron(clipPlanes, mSceneBox); 554 568 555 //cout << "new:\n" << lightProj << endl; 569 556 … … 638 625 } 639 626 627 628 void ShadowMap::IncludeLightVolume(const Polyhedron &polyhedron, 629 VertexArray &frustumPoints, 630 const Vector3 lightDir, 631 const AxisAlignedBox3 &sceneBox 632 ) 633 { 634 // we don't need closed form anymore => just store vertices 635 VertexArray vertices; 636 polyhedron.CollectVertices(vertices); 637 638 // we 'look' at each point and calculate intersections of rays with scene bounding box 639 VertexArray::const_iterator it, it_end = vertices.end(); 640 641 for (it = vertices.begin(); it != it_end; ++ it) 642 { 643 Vector3 v = *it; 644 645 frustumPoints.push_back(v); 646 647 // hack: get point surely outside of box 648 v -= Magnitude(mSceneBox.Diagonal()) * lightDir; 649 650 SimpleRay ray(v, lightDir); 651 652 float tNear, tFar; 653 654 if (sceneBox.Intersects(ray, tNear, tFar)) 655 { 656 Vector3 newpt = ray.Extrap(tNear); 657 frustumPoints.push_back(newpt); 658 } 659 } 660 } 661 662 640 663 } // namespace -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShadowMapping.h
r2928 r2929 84 84 Vector3 GetProjViewDir(const Matrix4x4 &lightSpace, const VertexArray &pts) const; 85 85 86 static void DrawPoly(Polyhedron *poly, const Vector3 &color); 86 87 87 88 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Visualization.cpp
r2913 r2929 150 150 glDisable(GL_LIGHTING); 151 151 glDisable(GL_DEPTH_TEST); 152 glDepthMask(GL_FALSE); 152 153 153 154 RenderFrustum(); … … 171 172 172 173 //RenderBoxForViz(mBvh->GetBox()); 173 174 175 glDepthMask(GL_TRUE); 176 174 177 glPopAttrib(); 175 178 } -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp
r2928 r2929 1560 1560 //camera->SetFar(1000); 1561 1561 1562 const float offs = box.Size().x * 0.3f; 1562 //const float offs = box.Size().x * 0.3f; 1563 const float offs = box.Size().x * 0.4f; 1563 1564 1564 1565 Vector3 vizpos = Vector3(box.Min().x, box.Min().y - box.Size().y * 0.35f, box.Min().z + box.Size().z * 50); … … 1582 1583 visCamera->SetupCameraView(); 1583 1584 1584 //Matrix4x4 rotX = RotationXMatrix(camera->GetYaw());1585 //glMultMatrixf((float *)rotX.x);1586 1585 Matrix4x4 rotZ = RotationZMatrix(-camera->GetPitch()); 1587 1586 glMultMatrixf((float *)rotZ.x);
Note: See TracChangeset
for help on using the changeset viewer.