#endif
-static ssgLeaf *gen_lights( ssgVertexArray *lights ) {
+static ssgLeaf *gen_lights( ssgVertexArray *lights, float bright ) {
// Allocate ssg structure
ssgNormalArray *nl = NULL;
ssgTexCoordArray *tl = NULL;
// default to slightly yellow lights for now
sgVec4 color;
- sgSetVec4( color, 1.0, 1.0, 0.7, 1.0 );
+ sgSetVec4( color, 1.0 * bright, 1.0 * bright, 0.7 * bright, 1.0 );
cl->add( color );
// create ssg leaf
terrain->addKid( e->terra_transform );
e->lights_transform = NULL;
+ e->lights_range = NULL;
/* uncomment this section for testing ground lights */
- ssgLeaf *lights = gen_lights( light_pts );
- if ( lights ) {
+ if ( light_pts->getNum() ) {
+ cout << "generating lights" << endl;
e->lights_transform = new ssgTransform;
e->lights_range = new ssgRangeSelector;
- e->lights_range->addKid( lights );
+ e->lights_brightness = new ssgSelector;
+ ssgLeaf *lights;
+
+ lights = gen_lights( light_pts, 0.6 );
+ e->lights_brightness->addKid( lights );
+
+ lights = gen_lights( light_pts, 0.8 );
+ e->lights_brightness->addKid( lights );
+
+ lights = gen_lights( light_pts, 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 );
#include <Aircraft/aircraft.hxx>
#include <Main/globals.hxx>
#include <Scenery/scenery.hxx>
+#include <Time/light.hxx>
#include "tileentry.hxx"
ranges[0] = SG_ZERO;
ranges[1] = vis + bounding_radius;
terra_range->setRanges( ranges, 2 );
- ranges[1] = vis * 1.5 + bounding_radius;
- lights_range->setRanges( ranges, 2 );
+ if ( lights_range ) {
+ ranges[1] = vis * 1.5 + bounding_radius;
+ lights_range->setRanges( ranges, 2 );
+ }
#endif
sgVec3 sgTrans;
sgSetVec3( sgTrans, offset.x(), offset.y(), offset.z() );
sgScaleVec3( up, 10.0 + agl / 100.0 + dist / 10000 );
sgAddVec3( sgTrans, up );
lights_transform->setTransform( sgTrans );
+
+ // select which set of lights based on sun angle
+ float sun_angle = cur_light_params.sun_angle * RAD_TO_DEG;
+ if ( sun_angle > 100 ) {
+ lights_brightness->select(0x04);
+ } else if ( sun_angle > 95.5 ) {
+ lights_brightness->select(0x02);
+ } else if ( sun_angle > 91 ) {
+ lights_brightness->select(0x01);
+ } else {
+ lights_brightness->select(0x00);
+ }
}
}
ssgRangeSelector *terra_range;
ssgRangeSelector *lights_range;
+ // we create several preset brightness and can choose which one we
+ // want based on lighting conditions.
+ ssgSelector *lights_brightness;
+
public:
// Constructor
if ( t == NULL ) {
FG_LOG( FG_TERRAIN, FG_DEBUG, "Loading tile " << b );
global_tile_cache.fill_in( b );
- FGTileEntry *t = global_tile_cache.get_tile( b );
+ t = global_tile_cache.get_tile( b );
t->prep_ssg_node( scenery.center, vis);
} else {
FG_LOG( FG_TERRAIN, FG_DEBUG, "Tile already in cache " << b );