]> git.mxchange.org Git - simgear.git/commitdiff
Harald JOHNSEN:
authorehofman <ehofman>
Wed, 6 Jul 2005 08:44:25 +0000 (08:44 +0000)
committerehofman <ehofman>
Wed, 6 Jul 2005 08:44:25 +0000 (08:44 +0000)
Melchior has found another bug, I tried to skip some computation for a few
frames but that introduced some bad rendering bug with the aircraft moving
parts.
I corrected that and reduced a bit the cpu usage for ground objects.

simgear/scene/model/shadowvolume.cxx
simgear/scene/model/shadowvolume.hxx

index 844ddddb45f3533259a37aac59d4284d75e34160..88f065f66d57285c027aa6d21982b3ac0ec2801c 100644 (file)
@@ -361,7 +361,8 @@ bool SGShadowVolume::ShadowCaster::isSelected (  ssgBranch * branch ) {
                     /
        perso2 *-----
 */
-void SGShadowVolume::ShadowCaster::computeShadows(sgMat4 rotation, sgMat4 rotation_translation) {
+void SGShadowVolume::ShadowCaster::computeShadows(sgMat4 rotation, sgMat4 rotation_translation,
+       OccluderType occluder_type) {
   
        // check the select and range ssgSelector node
        // object can't cast shadow if it is not visible
@@ -369,21 +370,19 @@ void SGShadowVolume::ShadowCaster::computeShadows(sgMat4 rotation, sgMat4 rotati
        if( first_select && ! isSelected( first_select) )
                return;
 
-               sgMat4 transform ;
-               sgMat4 invTransform;
                // get the transformations : this comes from animation code for example
                // or static transf
+       sgMat4 transf;
+       sgVec3 lightPos;
+       int deltaFrame = occluder_type == SGShadowVolume::occluderTypeAircraft ? 0 : 9;
+       if( states->frameNumber - frameNumber > deltaFrame) {
+               sgMat4 transform ;
+               sgMat4 invTransform;
                getNetTransform( (ssgBranch *) geometry_leaf, transform );
-               sgMat4 transf;
-               sgCopyMat4( transf, transform );
-               sgPostMultMat4( transf, rotation_translation );
+               sgCopyMat4( last_transform, transform );
                sgPostMultMat4( transform, rotation );
                sgTransposeNegateMat4 ( invTransform, transform ); 
 
-               glLoadMatrixf ( (float *) states->CameraViewM ) ;
-               glMultMatrixf( (float *) transf );
-
-               sgVec3 lightPos;
                sgCopyVec3( lightPos, states->sunPos );
                sgXformPnt3( lightPos, invTransform );
 
@@ -395,12 +394,17 @@ void SGShadowVolume::ShadowCaster::computeShadows(sgMat4 rotation, sgMat4 rotati
                // if the geometry has rotated/moved enought then
                // we need to recompute the silhouette
                // but this computation does not need to be done each frame
-               if( (deltaPos > 0.0) && ( states->frameNumber - frameNumber > 4)) {
+               if( deltaPos > 0.0 ) {
                        CalculateSilhouetteEdges( lightPos );
                        sgCopyVec3( last_lightpos, lightPosNorm );
                        frameNumber = states->frameNumber ;
                        statSilhouette ++;
                }
+       }
+       sgCopyMat4( transf, last_transform );
+       sgPostMultMat4( transf, rotation_translation );
+       glLoadMatrixf ( (float *) states->CameraViewM ) ;
+       glMultMatrixf( (float *) transf );
 
        if( states->shadowsDebug_enabled )
        {
@@ -546,7 +550,7 @@ void SGShadowVolume::SceneryObject::computeShadows(void) {
 
                ShadowCaster_list::iterator iShadowCaster;
                for(iShadowCaster = parts.begin() ; iShadowCaster != parts.end() ; iShadowCaster ++ ) {
-                       (*iShadowCaster)->computeShadows(rotation, rotation_translation);
+                       (*iShadowCaster)->computeShadows(rotation, rotation_translation, occluder_type);
                }
        }
 }
index c5fcec989e4dd2ab48613d6076fd84624563313d..c852b969ce7731db96c25eb0766d3c45ce97ec29 100644 (file)
@@ -77,6 +77,7 @@ private:
                ssgBranch *lib_object;
                ssgBranch *first_select;
                sgVec3 last_lightpos;
+               sgMat4 last_transform;
                int frameNumber;
 
                int *indices;
@@ -94,7 +95,7 @@ private:
                void SetConnectivity();
                void CalculateSilhouetteEdges(sgVec3 lightPosition);
                void DrawInfiniteShadowVolume(sgVec3 lightPosition, bool drawCaps);
-               void computeShadows(sgMat4 rotation, sgMat4 rotation_translation);
+               void computeShadows(sgMat4 rotation, sgMat4 rotation_translation, OccluderType occluder_type);
                void getNetTransform ( ssgBranch * branch, sgMat4 xform );
                bool isSelected (  ssgBranch * branch );