<< 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
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 );
+ }
}
}
}
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
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
// 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);