Tweaks to ground lighting infrastructure.
This commit is contained in:
parent
90d30b023e
commit
f14e155533
2 changed files with 18 additions and 54 deletions
src/Scenery
|
@ -133,61 +133,20 @@ static void print_refs( ssgSelector *sel, ssgTransform *trans,
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
static ssgLeaf *gen_lights( const FGBucket &b ) {
|
static ssgLeaf *gen_lights( ssgVertexArray *lights ) {
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Allocate ssg structure
|
// Allocate ssg structure
|
||||||
ssgVertexArray *vl = new ssgVertexArray( num );
|
|
||||||
ssgNormalArray *nl = NULL;
|
ssgNormalArray *nl = NULL;
|
||||||
ssgTexCoordArray *tl = NULL;
|
ssgTexCoordArray *tl = NULL;
|
||||||
ssgColourArray *cl = new ssgColourArray( 1 );
|
ssgColourArray *cl = new ssgColourArray( 1 );
|
||||||
|
|
||||||
// default to white lights for now
|
// default to slightly yellow lights for now
|
||||||
sgVec4 color;
|
sgVec4 color;
|
||||||
sgSetVec4( color, 1.0, 1.0, 1.0, 1.0 );
|
sgSetVec4( color, 1.0, 1.0, 0.7, 1.0 );
|
||||||
cl->add( color );
|
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;
|
|
||||||
}
|
|
||||||
// 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
|
// create ssg leaf
|
||||||
ssgLeaf *leaf =
|
ssgLeaf *leaf =
|
||||||
new ssgVtxTable ( GL_POINTS, vl, nl, tl, cl );
|
new ssgVtxTable ( GL_POINTS, lights, nl, tl, cl );
|
||||||
|
|
||||||
// assign state
|
// assign state
|
||||||
FGNewMat *newmat = material_lib.find( "LIGHTS" );
|
FGNewMat *newmat = material_lib.find( "LIGHTS" );
|
||||||
|
@ -222,8 +181,6 @@ void FGNewCache::fill_in( const FGBucket& b ) {
|
||||||
|
|
||||||
e->terra_transform = new ssgTransform;
|
e->terra_transform = new ssgTransform;
|
||||||
e->terra_range = new ssgRangeSelector;
|
e->terra_range = new ssgRangeSelector;
|
||||||
e->lights_transform = new ssgTransform;
|
|
||||||
e->lights_range = new ssgRangeSelector;
|
|
||||||
e->tile_bucket = b;
|
e->tile_bucket = b;
|
||||||
|
|
||||||
FGPath tile_path;
|
FGPath tile_path;
|
||||||
|
@ -235,10 +192,13 @@ void FGNewCache::fill_in( const FGBucket& b ) {
|
||||||
}
|
}
|
||||||
tile_path.append( b.gen_base_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
|
// Load the appropriate data file
|
||||||
FGPath tile_base = tile_path;
|
FGPath tile_base = tile_path;
|
||||||
tile_base.append( b.gen_index_str() );
|
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 ) {
|
if ( new_tile != NULL ) {
|
||||||
e->terra_range->addKid( new_tile );
|
e->terra_range->addKid( new_tile );
|
||||||
|
@ -270,7 +230,8 @@ void FGNewCache::fill_in( const FGBucket& b ) {
|
||||||
|
|
||||||
FGPath custom_path = tile_path;
|
FGPath custom_path = tile_path;
|
||||||
custom_path.append( name );
|
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) ) {
|
if ( (new_tile != NULL) && (custom_obj != NULL) ) {
|
||||||
new_tile -> addKid( custom_obj );
|
new_tile -> addKid( custom_obj );
|
||||||
}
|
}
|
||||||
|
@ -289,15 +250,17 @@ void FGNewCache::fill_in( const FGBucket& b ) {
|
||||||
terrain->addKid( e->terra_transform );
|
terrain->addKid( e->terra_transform );
|
||||||
|
|
||||||
e->lights_transform = NULL;
|
e->lights_transform = NULL;
|
||||||
/* uncomment this section for testing ground lights
|
/* uncomment this section for testing ground lights */
|
||||||
ssgLeaf *lights = gen_lights( b );
|
ssgLeaf *lights = gen_lights( light_pts );
|
||||||
if ( lights ) {
|
if ( lights ) {
|
||||||
|
e->lights_transform = new ssgTransform;
|
||||||
|
e->lights_range = new ssgRangeSelector;
|
||||||
e->lights_range->addKid( lights );
|
e->lights_range->addKid( lights );
|
||||||
e->lights_transform->addKid( e->lights_range );
|
e->lights_transform->addKid( e->lights_range );
|
||||||
e->lights_transform->setTransform( &sgcoord );
|
e->lights_transform->setTransform( &sgcoord );
|
||||||
ground->addKid( e->lights_transform );
|
ground->addKid( e->lights_transform );
|
||||||
}
|
}
|
||||||
*/
|
/* end of ground light section */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -168,12 +168,13 @@ void FGTileEntry::prep_ssg_node( const Point3D& p, float vis) {
|
||||||
terra_range->setRange( 0, SG_ZERO );
|
terra_range->setRange( 0, SG_ZERO );
|
||||||
terra_range->setRange( 1, vis + bounding_radius );
|
terra_range->setRange( 1, vis + bounding_radius );
|
||||||
lights_range->setRange( 0, SG_ZERO );
|
lights_range->setRange( 0, SG_ZERO );
|
||||||
lights_range->setRange( 1, vis + bounding_radius );
|
lights_range->setRange( 1, vis * 1.5 + bounding_radius );
|
||||||
#else
|
#else
|
||||||
float ranges[2];
|
float ranges[2];
|
||||||
ranges[0] = SG_ZERO;
|
ranges[0] = SG_ZERO;
|
||||||
ranges[1] = vis + bounding_radius;
|
ranges[1] = vis + bounding_radius;
|
||||||
terra_range->setRanges( ranges, 2 );
|
terra_range->setRanges( ranges, 2 );
|
||||||
|
ranges[1] = vis * 1.5 + bounding_radius;
|
||||||
lights_range->setRanges( ranges, 2 );
|
lights_range->setRanges( ranges, 2 );
|
||||||
#endif
|
#endif
|
||||||
sgVec3 sgTrans;
|
sgVec3 sgTrans;
|
||||||
|
@ -203,7 +204,7 @@ void FGTileEntry::prep_ssg_node( const Point3D& p, float vis) {
|
||||||
sgCopyVec3( to, sgTrans );
|
sgCopyVec3( to, sgTrans );
|
||||||
double dist = sgLengthVec3( to );
|
double dist = sgLengthVec3( to );
|
||||||
|
|
||||||
sgScaleVec3( up, agl / 20.0 + dist / 10000 );
|
sgScaleVec3( up, 10.0 + agl / 100.0 + dist / 10000 );
|
||||||
sgAddVec3( sgTrans, up );
|
sgAddVec3( sgTrans, up );
|
||||||
lights_transform->setTransform( sgTrans );
|
lights_transform->setTransform( sgTrans );
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue