From: curt Date: Wed, 6 Dec 2000 22:16:12 +0000 (+0000) Subject: More night ground lighting tweaks. X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=5fecec2bba6465ac31101e8adc012db90c6d638d;p=flightgear.git More night ground lighting tweaks. --- diff --git a/src/Main/main.cxx b/src/Main/main.cxx index 2af616382..69c89b42d 100644 --- a/src/Main/main.cxx +++ b/src/Main/main.cxx @@ -1363,7 +1363,7 @@ int main( int argc, char **argv ) { << FLIGHTGEAR_VERSION << endl ); // seed the random number generater - sg_srandom(); + sg_srandom_time(); // Allocate global data structures. This needs to happen before // we parse command line options diff --git a/src/Objects/obj.cxx b/src/Objects/obj.cxx index 001c55fb6..25e420b8c 100644 --- a/src/Objects/obj.cxx +++ b/src/Objects/obj.cxx @@ -337,32 +337,39 @@ static void random_pt_inside_tri( float *res, static void gen_random_surface_points( ssgLeaf *leaf, ssgVertexArray *lights, double factor ) { int num = leaf->getNumTriangles(); - short int n1, n2, n3; - float *p1, *p2, *p3; - sgVec3 result; - - for ( int i = 0; i < num; ++i ) { - leaf->getTriangle( i, &n1, &n2, &n3 ); - p1 = leaf->getVertex(n1); - p2 = leaf->getVertex(n2); - p3 = leaf->getVertex(n3); - double area = sgTriArea( p1, p2, p3 ); - double num = area / factor; - - // generate a light point for each unit of area - while ( num > 1.0 ) { - random_pt_inside_tri( result, p1, p2, p3 ); - lights->add( result ); - num -= 1.0; - } - // for partial units of area, use a zombie door method to - // create the proper random chance of a light being created - // for this triangle - if ( num > 0.0 ) { - if ( sg_random() <= num ) { - // a zombie made it through our door + if ( num > 0 ) { + short int n1, n2, n3; + float *p1, *p2, *p3; + sgVec3 result; + + // generate a repeatable random seed + p1 = leaf->getVertex( 0 ); + unsigned int *seed = (unsigned int *)p1; + sg_srandom( *seed ); + + for ( int i = 0; i < num; ++i ) { + leaf->getTriangle( i, &n1, &n2, &n3 ); + p1 = leaf->getVertex(n1); + p2 = leaf->getVertex(n2); + p3 = leaf->getVertex(n3); + double area = sgTriArea( p1, p2, p3 ); + double num = area / factor; + + // generate a light point for each unit of area + while ( num > 1.0 ) { random_pt_inside_tri( result, p1, p2, p3 ); lights->add( result ); + num -= 1.0; + } + // for partial units of area, use a zombie door method to + // create the proper random chance of a light being created + // for this triangle + if ( num > 0.0 ) { + if ( sg_random() <= num ) { + // a zombie made it through our door + random_pt_inside_tri( result, p1, p2, p3 ); + lights->add( result ); + } } } } diff --git a/src/Scenery/newcache.cxx b/src/Scenery/newcache.cxx index 8ec1e841a..1fe5307c5 100644 --- a/src/Scenery/newcache.cxx +++ b/src/Scenery/newcache.cxx @@ -134,6 +134,11 @@ static void print_refs( ssgSelector *sel, ssgTransform *trans, static ssgLeaf *gen_lights( ssgVertexArray *lights, int inc, float bright ) { + // generate a repeatable random seed + float *p1 = lights->get( 0 ); + unsigned int *seed = (unsigned int *)p1; + sg_srandom( *seed ); + int size = lights->getNum() / inc; // Allocate ssg structure @@ -143,25 +148,31 @@ static ssgLeaf *gen_lights( ssgVertexArray *lights, int inc, float bright ) { ssgColourArray *cl = new ssgColourArray( size + 1 ); sgVec4 color; - for ( int i = 0; i < lights->getNum(); i += inc ) { - vl->add( lights->get(i) ); - - // yellow = 1,1,0 + for ( int i = 0; i < lights->getNum(); ++i ) { + // this loop is slightly less efficient than it otherwise + // could be, but we want a red light to always be red, and a + // yellow light to always be yellow, etc. so we are trying to + // preserve the random sequence. float zombie = sg_random(); - if ( zombie > 0.5 ) { - // 50% chance of yellowish - sgSetVec4( color, 0.9, 0.9, 0.3, bright ); - } else if ( zombie > 0.15 ) { - // 35% chance of whitish - sgSetVec4( color, 0.9, 0.9, 0.6, bright ); - } else if ( zombie > 0.05 ) { - // 10% chance of orangish - sgSetVec4( color, 0.9, 0.6, 0.2, bright ); - } else { - // 5% chance of redish - sgSetVec4( color, 0.9, 0.2, 0.2, bright ); + if ( i % inc == 0 ) { + vl->add( lights->get(i) ); + + // yellow = 1,1,0 + if ( zombie > 0.5 ) { + // 50% chance of yellowish + sgSetVec4( color, 0.9, 0.9, 0.3, bright ); + } else if ( zombie > 0.15 ) { + // 35% chance of whitish + sgSetVec4( color, 0.9, 0.9, 0.8, bright ); + } else if ( zombie > 0.05 ) { + // 10% chance of orangish + sgSetVec4( color, 0.9, 0.6, 0.2, bright ); + } else { + // 5% chance of redish + sgSetVec4( color, 0.9, 0.2, 0.2, bright ); + } + cl->add( color ); } - cl->add( color ); } // create ssg leaf diff --git a/src/Scenery/tileentry.cxx b/src/Scenery/tileentry.cxx index c1cc51470..5370d7858 100644 --- a/src/Scenery/tileentry.cxx +++ b/src/Scenery/tileentry.cxx @@ -218,9 +218,9 @@ void FGTileEntry::prep_ssg_node( const Point3D& p, float vis) { // select which set of lights based on sun angle float sun_angle = cur_light_params.sun_angle * RAD_TO_DEG; - if ( sun_angle > 98 ) { + if ( sun_angle > 95 ) { lights_brightness->select(0x04); - } else if ( sun_angle > 93.5 ) { + } else if ( sun_angle > 92 ) { lights_brightness->select(0x02); } else if ( sun_angle > 89 ) { lights_brightness->select(0x01);