]> git.mxchange.org Git - simgear.git/blobdiff - simgear/scene/sky/oursun.cxx
Initialize some variables before using them
[simgear.git] / simgear / scene / sky / oursun.cxx
index 03d2a251e1f89779321d17ccebea9106e2d853d6..923ae3f832b2b81a4f8c962c8e5441873e21eaf7 100644 (file)
@@ -49,7 +49,6 @@
 #include "sphere.hxx"
 #include "oursun.hxx"
 
-
 // Set up sun rendering call backs
 static int sgSunOrbPreDraw( ssgEntity *e ) {
     /* cout << endl << "Sun orb pre draw" << endl << "----------------" 
@@ -91,7 +90,8 @@ static int sgSunHaloPreDraw( ssgEntity *e ) {
     // cout << "push error = " << glGetError() << endl;
 
     glDisable( GL_DEPTH_TEST );
-//    glDisable( GL_FOG );
+    // glDisable( GL_FOG );
+    glFogf (GL_FOG_DENSITY, sun_exp2_punch_through);
     glBlendFunc ( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ) ;
 
     return true;
@@ -113,6 +113,8 @@ static int sgSunHaloPostDraw( ssgEntity *e ) {
 
 // Constructor
 SGSun::SGSun( void ) {
+    prev_sun_angle = -9999.0;
+    visibility = -9999.0;
 }
 
 
@@ -259,7 +261,7 @@ ssgBranch * SGSun::build( SGPath path, double sun_size ) {
                                    sgSunOrbPreDraw, sgSunOrbPostDraw );
 
     // force a repaint of the sun colors with arbitrary defaults
-    repaint( 0.0 );
+    repaint( 0.0, 1.0 );
 
     // build the halo
     // sun_texbuf = new GLubyte[64*64*3];
@@ -334,12 +336,15 @@ ssgBranch * SGSun::build( SGPath path, double sun_size ) {
 // 0 degrees = high noon
 // 90 degrees = sun rise/set
 // 180 degrees = darkest midnight
-bool SGSun::repaint( double sun_angle ) {
-    static float prev_sun_angle = 9999.0;
+bool SGSun::repaint( double sun_angle, double new_visibility ) {
+    if ( visibility != new_visibility ) {
+        visibility = new_visibility;
 
-    if (prev_sun_angle != sun_angle)
-    {
+        static double sqrt_m_log01 = sqrt( -log( 0.01 ) );
+        sun_exp2_punch_through = sqrt_m_log01 / (visibility * 15);
+    }
 
+    if (prev_sun_angle != sun_angle) {
         prev_sun_angle = sun_angle;
 
         float sun_factor = 4*cos(sun_angle);