Stuart Buchanan :
Attached is yet another 3D clouds patch, to fix the following: 1) The 3D clouds were not modified by the cloud coverage, due to some problems with osg::Switch 2) METAR changes to cloud coverage were not obeyed. 3) Making changes via the Cloud dialog had no effect unless 3D clouds were toggled. 4) Cloud cover was too sparse. 5) 3D Stratus clouds caused performance issues on some hardware (fixed by removing 3D stratus from cloudlayers.xml - it will now be a 2D layer).
This commit is contained in:
parent
35f7f55507
commit
b0b4ab5003
3 changed files with 47 additions and 35 deletions
|
@ -502,6 +502,7 @@ FGMetarEnvironmentCtrl::update_env_config ()
|
||||||
double aircraft_alt = fgGetDouble("/position/altitude-ft");
|
double aircraft_alt = fgGetDouble("/position/altitude-ft");
|
||||||
char s[128];
|
char s[128];
|
||||||
int i;
|
int i;
|
||||||
|
bool rebuild_clouds = false;
|
||||||
|
|
||||||
for (i = 0, layer = layers.begin(); layer != layers_end; ++layer, i++) {
|
for (i = 0, layer = layers.begin(); layer != layers_end; ++layer, i++) {
|
||||||
double currentval;
|
double currentval;
|
||||||
|
@ -517,8 +518,10 @@ FGMetarEnvironmentCtrl::update_env_config ()
|
||||||
snprintf(s, 128, cl, i);
|
snprintf(s, 128, cl, i);
|
||||||
strncat(s, "/coverage", 128);
|
strncat(s, "/coverage", 128);
|
||||||
const char* coverage = (*layer)->getStringValue("coverage", "clear");
|
const char* coverage = (*layer)->getStringValue("coverage", "clear");
|
||||||
if (strncmp(fgGetString(s), coverage, 128) != 0)
|
if (strncmp(fgGetString(s), coverage, 128) != 0) {
|
||||||
fgSetString(s, coverage);
|
fgSetString(s, coverage);
|
||||||
|
rebuild_clouds = true;
|
||||||
|
}
|
||||||
|
|
||||||
snprintf(s, 128, cl, i);
|
snprintf(s, 128, cl, i);
|
||||||
strncat(s, "/elevation-ft", 128);
|
strncat(s, "/elevation-ft", 128);
|
||||||
|
@ -567,6 +570,10 @@ FGMetarEnvironmentCtrl::update_env_config ()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (rebuild_clouds) {
|
||||||
|
// Force an update of the 3D clouds
|
||||||
|
fgSetDouble("/environment/rebuild-layers", 1.0);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// We haven't already loaded a METAR, so apply it immediately.
|
// We haven't already loaded a METAR, so apply it immediately.
|
||||||
dir_from = fgGetDouble("/environment/metar/base-wind-range-from");
|
dir_from = fgGetDouble("/environment/metar/base-wind-range-from");
|
||||||
|
|
|
@ -51,7 +51,6 @@ FGClouds::FGClouds(FGEnvironmentCtrl * controller) :
|
||||||
station_elevation_ft(0.0),
|
station_elevation_ft(0.0),
|
||||||
_controller( controller ),
|
_controller( controller ),
|
||||||
snd_lightning(NULL),
|
snd_lightning(NULL),
|
||||||
rebuild_required(true),
|
|
||||||
last_scenario( "unset" ),
|
last_scenario( "unset" ),
|
||||||
last_env_config( new SGPropertyNode() ),
|
last_env_config( new SGPropertyNode() ),
|
||||||
last_env_clouds( new SGPropertyNode() )
|
last_env_clouds( new SGPropertyNode() )
|
||||||
|
@ -78,8 +77,6 @@ void FGClouds::init(void) {
|
||||||
soundMgr->add( snd_lightning, "thunder" );
|
soundMgr->add( snd_lightning, "thunder" );
|
||||||
sgEnviro.set_soundMgr( soundMgr );
|
sgEnviro.set_soundMgr( soundMgr );
|
||||||
}
|
}
|
||||||
|
|
||||||
rebuild_required = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void FGClouds::buildCloud(SGPropertyNode *cloud_def_root, SGPropertyNode *box_def_root, const string& name, sgVec3 pos, SGCloudField *layer) {
|
void FGClouds::buildCloud(SGPropertyNode *cloud_def_root, SGPropertyNode *box_def_root, const string& name, sgVec3 pos, SGCloudField *layer) {
|
||||||
|
@ -157,20 +154,19 @@ void FGClouds::buildLayer(int iLayer, const string& name, double alt, double cov
|
||||||
int CloudVarietyCount = 0;
|
int CloudVarietyCount = 0;
|
||||||
double totalCount = 0.0;
|
double totalCount = 0.0;
|
||||||
|
|
||||||
if (! clouds_3d_enabled) return;
|
|
||||||
|
|
||||||
SGPropertyNode *cloud_def_root = fgGetNode("/environment/cloudlayers/clouds", false);
|
SGPropertyNode *cloud_def_root = fgGetNode("/environment/cloudlayers/clouds", false);
|
||||||
SGPropertyNode *box_def_root = fgGetNode("/environment/cloudlayers/boxes", false);
|
SGPropertyNode *box_def_root = fgGetNode("/environment/cloudlayers/boxes", false);
|
||||||
SGPropertyNode *layer_def_root = fgGetNode("/environment/cloudlayers/layers", false);
|
SGPropertyNode *layer_def_root = fgGetNode("/environment/cloudlayers/layers", false);
|
||||||
SGCloudField *layer = thesky->get_cloud_layer(iLayer)->get_layer3D();
|
SGCloudField *layer = thesky->get_cloud_layer(iLayer)->get_layer3D();
|
||||||
|
|
||||||
layer->clear();
|
layer->clear();
|
||||||
|
|
||||||
// when we don't generate clouds the layer is rendered in 2D
|
// when we don't generate clouds the layer is rendered in 2D
|
||||||
if( coverage == 0.0 )
|
if ((! clouds_3d_enabled) || coverage == 0.0 ||
|
||||||
return;
|
layer_def_root == NULL || cloud_def_root == NULL || box_def_root == NULL)
|
||||||
if( layer_def_root == NULL || cloud_def_root == NULL || box_def_root == NULL)
|
{
|
||||||
|
thesky->get_cloud_layer(iLayer)->set_enable3dClouds(false);
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
SGPropertyNode *layer_def=NULL;
|
SGPropertyNode *layer_def=NULL;
|
||||||
|
|
||||||
|
@ -181,8 +177,11 @@ void FGClouds::buildLayer(int iLayer, const string& name, double alt, double cov
|
||||||
layer_def = layer_def_root->getChild(base_name.c_str());
|
layer_def = layer_def_root->getChild(base_name.c_str());
|
||||||
}
|
}
|
||||||
if( !layer_def )
|
if( !layer_def )
|
||||||
|
{
|
||||||
|
thesky->get_cloud_layer(iLayer)->set_enable3dClouds(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
double grid_x_size = layer_def->getDoubleValue("grid-x-size", 1000.0);
|
double grid_x_size = layer_def->getDoubleValue("grid-x-size", 1000.0);
|
||||||
double grid_y_size = layer_def->getDoubleValue("grid-y-size", 1000.0);
|
double grid_y_size = layer_def->getDoubleValue("grid-y-size", 1000.0);
|
||||||
|
@ -217,22 +216,31 @@ void FGClouds::buildLayer(int iLayer, const string& name, double alt, double cov
|
||||||
double x = px + grid_x_rand * (sg_random() - 0.5) - (SGCloudField::fieldSize / 2.0);
|
double x = px + grid_x_rand * (sg_random() - 0.5) - (SGCloudField::fieldSize / 2.0);
|
||||||
double y = py + grid_y_rand * (sg_random() - 0.5) - (SGCloudField::fieldSize / 2.0);
|
double y = py + grid_y_rand * (sg_random() - 0.5) - (SGCloudField::fieldSize / 2.0);
|
||||||
double z = grid_z_rand * (sg_random() - 0.5);
|
double z = grid_z_rand * (sg_random() - 0.5);
|
||||||
|
|
||||||
|
if (sg_random() < coverage)
|
||||||
|
{
|
||||||
double choice = sg_random();
|
double choice = sg_random();
|
||||||
|
|
||||||
for(int i = 0; i < CloudVarietyCount ; i ++) {
|
for(int i = 0; i < CloudVarietyCount ; i ++) {
|
||||||
choice -= tCloudVariety[i].count * totalCount;
|
choice -= tCloudVariety[i].count * totalCount;
|
||||||
if( choice <= 0.0 ) {
|
if( choice <= 0.0 ) {
|
||||||
sgVec3 pos={x,z,y};
|
sgVec3 pos={x,z,y};
|
||||||
buildCloud(cloud_def_root, box_def_root, tCloudVariety[i].name, pos, layer);
|
|
||||||
|
buildCloud(cloud_def_root,
|
||||||
|
box_def_root,
|
||||||
|
tCloudVariety[i].name,
|
||||||
|
pos,
|
||||||
|
layer);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Now we've built any clouds, enable them and set the density (coverage)
|
// Now we've built any clouds, enable them and set the density (coverage)
|
||||||
layer->setCoverage(coverage);
|
//layer->setCoverage(coverage);
|
||||||
layer->applyCoverage();
|
//layer->applyCoverage();
|
||||||
thesky->get_cloud_layer(iLayer)->set_enable3dClouds(clouds_3d_enabled);
|
thesky->get_cloud_layer(iLayer)->set_enable3dClouds(clouds_3d_enabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -282,7 +290,7 @@ void FGClouds::buildCloudLayers(void) {
|
||||||
} else if( alt_ft > 6500 ) {
|
} else if( alt_ft > 6500 ) {
|
||||||
// layer_type = "as|ac|ns";
|
// layer_type = "as|ac|ns";
|
||||||
layer_type = "ac";
|
layer_type = "ac";
|
||||||
if( pressure_mb < 1005.0 && coverage_norm >= 5.5 )
|
if( pressure_mb < 1005.0 && coverage_norm >= 0.5 )
|
||||||
layer_type = "ns";
|
layer_type = "ns";
|
||||||
} else {
|
} else {
|
||||||
// layer_type = "st|cu|cb|sc";
|
// layer_type = "st|cu|cb|sc";
|
||||||
|
@ -492,8 +500,8 @@ void FGClouds::buildScenario( const string& scenario ) {
|
||||||
void FGClouds::build() {
|
void FGClouds::build() {
|
||||||
string scenario = fgGetString("/environment/weather-scenario", "METAR");
|
string scenario = fgGetString("/environment/weather-scenario", "METAR");
|
||||||
|
|
||||||
if(!rebuild_required && (scenario == last_scenario))
|
// if(!rebuild_required && (scenario == last_scenario))
|
||||||
return;
|
// return;
|
||||||
|
|
||||||
if( last_scenario == "none" ) {
|
if( last_scenario == "none" ) {
|
||||||
// save clouds and weather conditions
|
// save clouds and weather conditions
|
||||||
|
@ -536,7 +544,6 @@ void FGClouds::build() {
|
||||||
}
|
}
|
||||||
|
|
||||||
last_scenario = scenario;
|
last_scenario = scenario;
|
||||||
rebuild_required = false;
|
|
||||||
|
|
||||||
if( snd_lightning == NULL )
|
if( snd_lightning == NULL )
|
||||||
init();
|
init();
|
||||||
|
@ -556,7 +563,6 @@ void FGClouds::set_3dClouds(bool enable)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (enable) {
|
if (enable) {
|
||||||
rebuild_required = true;
|
|
||||||
build();
|
build();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,12 +55,13 @@ void buildCloud(SGPropertyNode *cloud_def_root, SGPropertyNode *box_def_root, co
|
||||||
|
|
||||||
void update_env_config ();
|
void update_env_config ();
|
||||||
|
|
||||||
|
void build(void);
|
||||||
|
|
||||||
int update_event;
|
int update_event;
|
||||||
SGSoundSample *snd_lightning;
|
SGSoundSample *snd_lightning;
|
||||||
FGEnvironmentCtrl * _controller;
|
FGEnvironmentCtrl * _controller;
|
||||||
float station_elevation_ft;
|
float station_elevation_ft;
|
||||||
bool clouds_3d_enabled;
|
bool clouds_3d_enabled;
|
||||||
bool rebuild_required;
|
|
||||||
string last_scenario;
|
string last_scenario;
|
||||||
SGPropertyNode *last_env_config, *last_env_clouds;
|
SGPropertyNode *last_env_config, *last_env_clouds;
|
||||||
|
|
||||||
|
@ -68,8 +69,6 @@ public:
|
||||||
FGClouds(FGEnvironmentCtrl * controller);
|
FGClouds(FGEnvironmentCtrl * controller);
|
||||||
~FGClouds();
|
~FGClouds();
|
||||||
|
|
||||||
void build(void);
|
|
||||||
|
|
||||||
void init(void);
|
void init(void);
|
||||||
|
|
||||||
int get_update_event(void) const;
|
int get_update_event(void) const;
|
||||||
|
|
Loading…
Add table
Reference in a new issue