Changeset 2936


Ignore:
Timestamp:
09/12/08 18:07:04 (16 years ago)
Author:
mattausch
Message:

totally broken

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  
    279279                mClipPlanes[Frustum::RIGHT_PLANE][i] = trafo.x[i][3] - trafo.x[i][0]; 
    280280                mClipPlanes[Frustum::LEFT_PLANE][i] = trafo.x[i][3] + trafo.x[i][0];  
     281                 
    281282                mClipPlanes[Frustum::BOTTOM_PLANE][i] = trafo.x[i][3] + trafo.x[i][1]; 
    282283                mClipPlanes[Frustum::TOP_PLANE][i] = trafo.x[i][3] - trafo.x[i][1];  
     284 
    283285                mClipPlanes[Frustum::FAR_PLANE][i] = trafo.x[i][3] - trafo.x[i][2];  
    284286                mClipPlanes[Frustum::NEAR_PLANE][i] = trafo.x[i][3] + trafo.x[i][2]; 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Camera.h

    r2932 r2936  
    2525        Frustum(const Matrix4x4 &trafo); 
    2626 
    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 
    2829        /** Resizes the current frustum so that it fully encloses the given polyhedron 
    2930        */ 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Matrix4x4.cpp

    r2934 r2936  
    763763        Matrix4x4 m(nRight, nUp, nDir); 
    764764 
    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); 
    775768 
    776769        return m; 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Polyhedron.cpp

    r2931 r2936  
    275275        } 
    276276 
    277         // add the new polygon to the polyhedron 
    278         clippedPolyhedron->Add(planePoly); 
    279  
    280  
    281277 
    282278        ///////////// 
    283279        //-- clip polyhedron: plane splits all polygons 
    284280 
    285         for (int i = 0; i < (int)mPolygons.size(); ++ i) 
     281        for (size_t i = 0; i < mPolygons.size(); ++ i) 
    286282        { 
    287283                Polygon3 *poly = mPolygons[i]; 
     
    320316                } 
    321317        } 
     318 
     319        // we can now savely add the new polygon 
     320        clippedPolyhedron->Add(planePoly); 
    322321 
    323322        return clippedPolyhedron; 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShadowMapping.cpp

    r2935 r2936  
    4040 
    4141 
    42 static Polyhedron *CreatePolyhedron(const Matrix4x4 &lightMatrix, const AxisAlignedBox3 &sceneBox) 
     42static Polyhedron *CreatePolyhedron(const Matrix4x4 &lightMatrix,  
     43                                                                        const AxisAlignedBox3 &sceneBox) 
    4344{ 
    4445        Frustum frustum(lightMatrix); 
     
    5758                frustum.mClipPlanes[i].mD *= invLength; 
    5859                frustum.mClipPlanes[i].mNormal *= invLength; 
    59  
    60                 //clipPlanes.push_back(frustum.mClipPlanes[i]); 
    61         } 
    62  
    63         clipPlanes.push_back(frustum.mClipPlanes[5]); 
     60        } 
     61 
    6462        clipPlanes.push_back(frustum.mClipPlanes[0]); 
    6563        clipPlanes.push_back(frustum.mClipPlanes[1]); 
    6664        clipPlanes.push_back(frustum.mClipPlanes[2]); 
    6765        clipPlanes.push_back(frustum.mClipPlanes[3]); 
     66        clipPlanes.push_back(frustum.mClipPlanes[5]); 
     67 
    6868        clipPlanes.push_back(frustum.mClipPlanes[4]); 
    6969 
     
    158158 
    159159 
    160 void ShadowMap::DrawPoly(Polyhedron *poly, const Vector3 &color) 
     160void ShadowMap::DrawPoly(Polyhedron *poly, const Vector3 &color, const Vector3 &color2) 
    161161{ 
    162162        if (!poly) return; 
     
    166166                glColor3f(color.x, color.y, color.z); 
    167167 
     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                } 
    168174                glBegin(GL_LINE_LOOP); 
    169175 
     
    177183 
    178184                glEnd(); 
     185                 
     186                //if (i == poly->NumPolygons() - 1) glLineWidth(1); 
    179187        } 
    180188} 
     
    183191void ShadowMap::DrawPolys() 
    184192{ 
    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)); 
    187195 
    188196        glPointSize(10.0f); 
    189197 
    190198        Vector3 pt = Vector3::ZERO(); 
     199        //Vector3 pt = dummyPt; 
    191200 
    192201        Matrix4x4 myMat = Invert(dummyMat); 
     
    225234        //-- first find the free parameter values n, and P (the projection center), and the projection depth 
    226235 
    227         const float n = 1e1f; 
     236        const float n = 1e2f; 
    228237        //const float n = 1e6f; 
    229238        //const float n = ComputeN(bounds_ls) * 100; 
     
    237246 
    238247        //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); 
    240248        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); 
    241251 
    242252        cout << "mx: " <<  bounds_ls.Max() << endl; 
     
    244254 
    245255        // the new projection center 
    246         Vector3 projCenter = startPt + Vector3::UNIT_Z() * n; 
     256        const Vector3 projCenter = startPt + Vector3::UNIT_Z() * n; 
    247257 
    248258        cout <<"start: " << startPt << " " << projCenter << " " << Distance(lightSpace * mCamera->GetPosition(), startPt) << endl; 
    249 //dummyPt = -projCenter; 
     259 
     260        dummyPt = startPt; 
    250261 
    251262        //construct a translation that moves to the projection center 
     
    416427        transform2LispSM.x[3][3] =  1.0f; 
    417428 
     429 
    418430        //switch to the lightspace used in the article 
    419         lightProj = lightProj * transform2LispSM; 
     431        lightProj *= transform2LispSM; 
    420432 
    421433        const Vector3 projViewDir = GetProjViewDir(lightView * lightProj, frustumPoints); 
    422  
    423434 
    424435        cout << "projViewDir: " << projViewDir << " orig " << mCamera->GetDirection() << endl; 
     
    428439        //calculate a frame matrix that uses the projViewDir[lightspace] as up vector 
    429440        //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()); 
    432443 
    433444        cout << "frame\n " << frame << endl; 
    434         lightProj = lightProj * frame; 
     445        lightProj *= frame; 
    435446 
    436447        cout << "here9\n" << lightProj << endl; 
     448 
     449        Matrix4x4 refl2 = ScaleMatrix(-1, -1, 1);  
     450        //lightProj = refl2 * lightProj; 
    437451 
    438452        const Matrix4x4 matLispSM =  
    439453                CalcLispSMTransform(lightView * lightProj, extremalPoints, frustumPoints); 
    440454 
    441         lightProj = lightProj * matLispSM; 
     455        lightProj *= matLispSM; 
    442456 
    443457        // change back to GL coordinate system 
     
    449463        transformToGL.x[3][3] =  1.0f; 
    450464 
    451         lightProj = lightProj * transformToGL; 
     465        lightProj *= transformToGL; 
    452466        //cout << "here4 \n" << lightProj << endl; 
    453467 
    454468        AxisAlignedBox3 lightPts = GetExtremalPoints(lightView * lightProj, frustumPoints); 
    455469 
    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); 
    458474 
    459475        // focus projection matrix on the extremal points => scale to unit cube 
     476        //Matrix4x4 scaleTranslate = GetFittingProjectionMatrix(extremalPoints); 
    460477        Matrix4x4 scaleTranslate = GetFittingProjectionMatrix(lightPts); 
    461478        lightProj *= scaleTranslate; 
    462479 
    463         cout << "max: " << lightProj * extremalPoints.Max() << endl; 
    464         cout << "min: " << lightProj * extremalPoints.Min() << endl; 
     480        cout << "max: " << lightView * lightProj * dummyBox.Max() << endl; 
     481        cout << "min: " << lightView * lightProj * dummyBox.Min() << endl; 
    465482 
    466483        // we have to flip the signs in order to tranform to opengl right handed system 
     
    569586        Vector3 upVec = CalcUpVec(mCamera->GetDirection(), dir); 
    570587        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; 
    571592 
    572593        mShadowCam->mViewOrientation = lightView; 
     
    682703        Vector3 upVec = CalcUpVec(mCamera->GetDirection(), dir); 
    683704        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; 
    684709 
    685710        mShadowCam->mViewOrientation = lightView; 
     
    727752        glDisable(GL_POLYGON_OFFSET_FILL); 
    728753 
    729         glPushAttrib(GL_CURRENT_BIT); 
    730754        glDisable(GL_LIGHTING); 
    731755        glDisable(GL_DEPTH_TEST); 
    732         glDepthMask(GL_FALSE); 
    733  
     756 
     757        glLineWidth(2); 
    734758        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)); 
    738760 
    739761        DEL_PTR(hpoly); 
    740762 
    741         glEnable(GL_CULL_FACE); 
    742  
     763        //glEnable(GL_CULL_FACE); 
     764 
     765        glEnable(GL_LIGHTING); 
    743766        glEnable(GL_DEPTH_TEST); 
    744         glDepthMask(GL_TRUE); 
    745         glPopAttrib(); 
    746767 
    747768        glMatrixMode(GL_MODELVIEW); 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShadowMapping.h

    r2932 r2936  
    8787        Vector3 GetProjViewDir(const Matrix4x4 &lightSpace, const VertexArray &pts) const; 
    8888 
    89         static void DrawPoly(Polyhedron *poly, const Vector3 &color); 
     89        static void DrawPoly(Polyhedron *poly, const Vector3 &color, const Vector3 &color2); 
    9090 
    9191 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp

    r2932 r2936  
    10351035        // this would conveniently solves some issues (e.g, skys without shadows) 
    10361036 
    1037         RenderSky(); 
     1037        //RenderSky(); 
    10381038         
    10391039 
Note: See TracChangeset for help on using the changeset viewer.