Changeset 2929


Ignore:
Timestamp:
09/11/08 10:10:48 (16 years ago)
Author:
mattausch
Message:
 
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  
    13441344 
    13451345 
    1346 } 
    1347  
     1346void 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  
    206206        */ 
    207207        Polyhedron *CalcIntersection(const Polyhedron &polyhedron) const; 
    208  
    209  
     208        /** Tests for intersection of the ray with the box. 
     209        */ 
    210210        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 
    211215 
    212216        //////////// 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Polyhedron.cpp

    r2913 r2929  
    1313static const float epsilon = 1e-6f; 
    1414 
     15 
     16 
    1517/**********************************************************/ 
    1618/*             class Polyhedron Implementation             */ 
     
    4244        for (it = rhs.mPolygons.begin(); it != it_end; ++ it) 
    4345                Add(new Polygon3(*(*it))); 
     46} 
     47 
     48 
     49Polyhedron *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; 
    4487} 
    4588 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Polyhedron.h

    r2913 r2929  
    7373        inline friend std::ostream &operator<<(std::ostream &s, const Polyhedron &a); 
    7474 
     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 
    7579protected: 
    7680 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShadowMapping.cpp

    r2928 r2929  
    1919 
    2020static Polyhedron *polyhedron = NULL; 
     21static Polyhedron *lightPoly = NULL; 
    2122 
    2223 
     
    125126 
    126127 
    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); 
     128void 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); 
    138135 
    139136                glBegin(GL_LINE_LOOP); 
    140137 
    141                 Polygon3 *poly = polyhedron->GetPolygons()[i]; 
    142  
    143                 for (size_t j = 0; j < poly->mVertices.size(); ++ j) 
     138                Polygon3 *p = poly->GetPolygons()[i]; 
     139 
     140                for (size_t j = 0; j < p->mVertices.size(); ++ j) 
    144141                { 
    145                         Vector3 v = poly->mVertices[j]; 
     142                        Vector3 v = p->mVertices[j]; 
    146143                        glVertex3d(v.x, v.y, v.z); 
    147144                } 
     
    152149 
    153150 
    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         } 
     151void ShadowMap::DrawPolys() 
     152{ 
     153        DrawPoly(lightPoly, Vector3(1, 0, 1)); 
     154        DrawPoly(polyhedron, Vector3(0, 1, 0)); 
    186155} 
    187156 
     
    214183 
    215184        //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; 
    218187 
    219188        cout << "n: " << n << endl; 
     
    566535        mLightProjView = lightView * lightProj; 
    567536 
     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 
    568555        //cout << "new:\n" << lightProj << endl; 
    569556 
     
    638625} 
    639626 
     627 
     628void 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 
    640663} // namespace 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShadowMapping.h

    r2928 r2929  
    8484        Vector3 GetProjViewDir(const Matrix4x4 &lightSpace, const VertexArray &pts) const; 
    8585 
     86        static void DrawPoly(Polyhedron *poly, const Vector3 &color); 
    8687 
    8788 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Visualization.cpp

    r2913 r2929  
    150150        glDisable(GL_LIGHTING); 
    151151        glDisable(GL_DEPTH_TEST); 
     152        glDepthMask(GL_FALSE); 
    152153 
    153154        RenderFrustum(); 
     
    171172 
    172173        //RenderBoxForViz(mBvh->GetBox()); 
    173          
     174 
     175        glDepthMask(GL_TRUE); 
     176 
    174177        glPopAttrib(); 
    175178} 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp

    r2928 r2929  
    15601560        //camera->SetFar(1000); 
    15611561 
    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; 
    15631564         
    15641565        Vector3 vizpos = Vector3(box.Min().x, box.Min().y  - box.Size().y * 0.35f, box.Min().z + box.Size().z * 50); 
     
    15821583        visCamera->SetupCameraView(); 
    15831584 
    1584         //Matrix4x4 rotX = RotationXMatrix(camera->GetYaw()); 
    1585         //glMultMatrixf((float *)rotX.x); 
    15861585        Matrix4x4 rotZ = RotationZMatrix(-camera->GetPitch()); 
    15871586        glMultMatrixf((float *)rotZ.x); 
Note: See TracChangeset for help on using the changeset viewer.