#endif
-static ssgLeaf *gen_lights( const FGBucket &b ) {
+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 );
- FGTileEntry *t = global_tile_cache.get_tile( b );
- Point3D center = t->get_offset() + scenery.center;
-
- double lon, lat, elev;
- double w = b.get_width();
- double h = b.get_height();
-
- double area = b.get_width_m() * b.get_height_m();
- int num = (int)(area / 1000000); // number of point lights to create
- cout << "generating " << num << " lights" << endl;
-
- if ( num <= 0 ) {
- return NULL;
- }
+ int size = lights->getNum() / inc;
// Allocate ssg structure
- ssgVertexArray *vl = new ssgVertexArray( num );
+ ssgVertexArray *vl = new ssgVertexArray( size + 1 );
ssgNormalArray *nl = NULL;
ssgTexCoordArray *tl = NULL;
- ssgColourArray *cl = new ssgColourArray( 1 );
+ ssgColourArray *cl = new ssgColourArray( size + 1 );
- // default to white lights for now
sgVec4 color;
- sgSetVec4( color, 1.0, 1.0, 1.0, 1.0 );
- cl->add( color );
-
- for ( int i = 0; i < num; ++i ) {
- lon = b.get_center_lon() - w * 0.5 + sg_random() * w;
- lat = b.get_center_lat() - h * 0.5 + sg_random() * h;
-
- Point3D geod = Point3D( lon * DEG_TO_RAD, lat * DEG_TO_RAD, 0.0);
- Point3D tmp = sgGeodToCart( geod );
- sgdVec3 cart;
- sgdSetVec3( cart, tmp.x(), tmp.y(), tmp.z() );
-
- if ( ! global_tile_mgr.current_elev_ssg( cart, &elev ) ) {
- elev = 0.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 ( 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 );
}
- // cout << " lon = " << lon << " lat = " << lat << " elev = " << elev
- // << endl;
-
- geod.setz( elev + 8.0 + sg_random() * 4);
- tmp = sgGeodToCart( geod ) - center;
- sgVec3 p;
- sgSetVec3( p, tmp.x(), tmp.y(), tmp.z() );
- // cout << " x = " << cart[0] << " y = " << cart[1]
- // << " z = " << cart[2] << endl;
- vl->add( p );
}
// create ssg leaf
e->terra_transform = new ssgTransform;
e->terra_range = new ssgRangeSelector;
- e->lights_transform = new ssgTransform;
- e->lights_range = new ssgRangeSelector;
e->tile_bucket = b;
FGPath tile_path;
}
tile_path.append( b.gen_base_path() );
+ // fgObjLoad will generate ground lighting for us ...
+ ssgVertexArray *light_pts = new ssgVertexArray( 100 );
+
// Load the appropriate data file
FGPath tile_base = tile_path;
tile_base.append( b.gen_index_str() );
- ssgBranch *new_tile = fgObjLoad( tile_base.str(), e, true );
+ ssgBranch *new_tile = fgObjLoad( tile_base.str(), e, light_pts, true );
if ( new_tile != NULL ) {
e->terra_range->addKid( new_tile );
FGPath custom_path = tile_path;
custom_path.append( name );
- ssgBranch *custom_obj = fgObjLoad( custom_path.str(), e, false );
+ ssgBranch *custom_obj =
+ fgObjLoad( custom_path.str(), e, NULL, false );
if ( (new_tile != NULL) && (custom_obj != NULL) ) {
new_tile -> addKid( custom_obj );
}
terrain->addKid( e->terra_transform );
e->lights_transform = NULL;
- /* uncomment this section for testing ground lights
- ssgLeaf *lights = gen_lights( b );
- if ( lights ) {
- e->lights_range->addKid( lights );
+ e->lights_range = NULL;
+ /* uncomment this section for testing ground lights */
+ if ( light_pts->getNum() ) {
+ cout << "generating lights" << endl;
+ e->lights_transform = new ssgTransform;
+ e->lights_range = new ssgRangeSelector;
+ e->lights_brightness = new ssgSelector;
+ ssgLeaf *lights;
+
+ lights = gen_lights( light_pts, 4, 0.7 );
+ e->lights_brightness->addKid( lights );
+
+ lights = gen_lights( light_pts, 2, 0.85 );
+ e->lights_brightness->addKid( lights );
+
+ lights = gen_lights( light_pts, 1, 1.0 );
+ e->lights_brightness->addKid( lights );
+
+ e->lights_range->addKid( e->lights_brightness );
e->lights_transform->addKid( e->lights_range );
e->lights_transform->setTransform( &sgcoord );
ground->addKid( e->lights_transform );
}
- */
+ /* end of ground light section */
}