Ignore:
Timestamp:
09/11/08 10:10:48 (16 years ago)
Author:
mattausch
Message:
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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 
Note: See TracChangeset for help on using the changeset viewer.