1
0
Fork 0

More night ground lighting tweaks.

This commit is contained in:
curt 2000-12-06 22:16:12 +00:00
parent 40d68c5627
commit 5fecec2bba
4 changed files with 60 additions and 42 deletions

View file

@ -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

View file

@ -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;
if ( num > 0 ) {
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 repeatable random seed
p1 = leaf->getVertex( 0 );
unsigned int *seed = (unsigned int *)p1;
sg_srandom( *seed );
// 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
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 );
}
}
}
}

View file

@ -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

View file

@ -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);