Changeset 2934


Ignore:
Timestamp:
09/12/08 13:20:42 (16 years ago)
Author:
mattausch
Message:
 
Location:
GTP/trunk/App/Demos/Vis/FriendlyCulling/src
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Matrix4x4.cpp

    r2933 r2934  
    742742        Matrix4x4 m(nRight, nUp, -nDir); 
    743743 
    744         /*m.x[3][0] = -DotProd(nRight, position); 
    745         m.x[3][1] = -DotProd(nUp, position); 
    746         m.x[3][2] = -DotProd(nDir, position);*/ 
    747  
    748744        Vector3 position = m * -pos; 
    749745         
     
    756752} 
    757753 
    758 } 
     754 
     755Matrix4x4 MyLookAt2(const Vector3 &pos, const Vector3 &dir, const Vector3& up)  
     756{ 
     757        const Vector3 nDir = Normalize(dir); 
     758        Vector3 nUp = Normalize(up); 
     759 
     760        Vector3 nRight = Normalize(CrossProd(nDir, nUp)); 
     761        nUp = Normalize(CrossProd(nRight, nDir)); 
     762 
     763        Matrix4x4 m(nRight, nUp, nDir); 
     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; 
     775 
     776        return m; 
     777} 
     778} 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Matrix4x4.h

    r2932 r2934  
    161161Matrix4x4 LookAt(const Vector3 &pos, const Vector3 &dir, const Vector3& up); 
    162162Matrix4x4 MyLookAt(const Vector3 &pos, const Vector3 &dir, const Vector3& up); 
     163Matrix4x4 MyLookAt2(const Vector3 &pos, const Vector3 &dir, const Vector3& up); 
    163164 
    164165 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderState.cpp

    r2933 r2934  
    8989        { 
    9090                mCullFaceEnabled = true; 
    91                 //glEnable(GL_CULL_FACE); 
     91                glEnable(GL_CULL_FACE); 
    9292        } 
    9393 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShadowMapping.cpp

    r2933 r2934  
    2323static Polyhedron *polyhedron = NULL; 
    2424static Polyhedron *lightPoly = NULL; 
    25 static Matrix4x4 dummy = IdentityMatrix(); 
     25static Vector3 dummyPt; 
    2626 
    2727 
     
    185185        DrawPoly(polyhedron, Vector3(0, 1, 0)); 
    186186 
    187         Vector3 pt = Vector3::ZERO(); 
    188  
    189         pt = dummy * pt; 
    190  
    191187        glPointSize(10.0f); 
    192188 
    193189        glBegin(GL_POINTS); 
    194         glVertex3f(pt.x, pt.y, pt.z); 
     190        glVertex3f(dummyPt.x, dummyPt.y, dummyPt.z); 
    195191        glEnd(); 
    196192} 
     
    223219        //-- first find the free parameter values n, and P (the projection center), and the projection depth 
    224220 
    225         const float n = 1e3f; 
    226         //const float n = 1e6f; 
     221        //const float n = 1e1f; 
     222        const float n = 1e6f; 
    227223        //const float n = ComputeN(bounds_ls) * 100; 
    228224 
     
    244240 
    245241        cout <<"start: " << startPt << " " << projCenter << " " << Distance(lightSpace * mCamera->GetPosition(), startPt) << endl; 
     242dummyPt = -projCenter; 
    246243 
    247244        //construct a translation that moves to the projection center 
     
    408405 
    409406        transform2LispSM.x[0][0] =  1.0f; 
    410         transform2LispSM.x[1][2] = -1.0f; // y => -z 
     407        transform2LispSM.x[1][2] =  -1.0f; // y => -z 
    411408        transform2LispSM.x[2][1] =  1.0f; // z => y 
    412409        transform2LispSM.x[3][3] =  1.0f; 
     
    424421        //calculate a frame matrix that uses the projViewDir[lightspace] as up vector 
    425422        //look(from position, into the direction of the projected direction, with unchanged up-vector) 
    426         const Matrix4x4 frame = MyLookAt(Vector3::ZERO(), projViewDir, Vector3::UNIT_Y()); 
     423        const Matrix4x4 frame = MyLookAt2(Vector3::ZERO(), -projViewDir, Vector3::UNIT_Y()); 
    427424        //const Matrix4x4 frame = MyLookAt(Vector3::ZERO(), projViewDir, Vector3::UNIT_Z()); 
    428425 
     
    442439        transformToGL.x[0][0] =  1.0f; 
    443440        transformToGL.x[1][2] =  1.0f; // z => y 
    444         transformToGL.x[2][1] = -1.0f; // y => -z 
     441        transformToGL.x[2][1] =  -1.0f; // y => -z 
    445442        transformToGL.x[3][3] =  1.0f; 
    446443 
     
    564561 
    565562        Vector3 upVec = CalcUpVec(mCamera->GetDirection(), dir); 
    566         Matrix4x4 lightView = MyLookAt(mShadowCam->GetPosition(), -dir, -upVec); 
    567         //Matrix4x4 lightView = MyLookAt(mShadowCam->GetPosition(), dir, mCamera->GetDirection()); 
     563        Matrix4x4 lightView = MyLookAt2(mShadowCam->GetPosition(), -dir, upVec); 
    568564 
    569565        mShadowCam->mViewOrientation = lightView; 
     
    603599 
    604600        mLightProjView = lightView * lightProj; 
    605 glEnable(GL_CULL_FACE); 
     601; 
    606602        cout << "here3" << endl; 
    607603        DEL_PTR(lightPoly); 
     
    676672 
    677673        Vector3 upVec = CalcUpVec(mCamera->GetDirection(), dir); 
    678         Matrix4x4 lightView = MyLookAt(mShadowCam->GetPosition(), -dir, -upVec); 
    679         //Matrix4x4 lightView = Invert(_lightView); 
    680         //Matrix4x4 lightView = MyLookAt(mShadowCam->GetPosition(), dir, mCamera->GetDirection()); 
     674        Matrix4x4 lightView = MyLookAt2(mShadowCam->GetPosition(), -dir, upVec); 
    681675 
    682676        mShadowCam->mViewOrientation = lightView; 
     
    702696        mLightProjView = lightView * lightProj; 
    703697 
    704         dummy = mLightProjView; 
     698        //dummy = mLightProjView; 
    705699 
    706700        DEL_PTR(lightPoly); 
     
    711705        glLoadIdentity(); 
    712706 
    713         glDisable(GL_CULL_FACE); 
     707        //glDisable(GL_CULL_FACE); 
    714708 
    715709        mShadowCam->SetupCameraView(); 
Note: See TracChangeset for help on using the changeset viewer.