#include <osg/MatrixTransform>
#include <simgear/constants.h>
-#include <simgear/math/SGMath.hxx>
#include <simgear/scene/sky/sky.hxx>
#include <simgear/scene/sky/cloud.hxx>
-#include <simgear/environment/visual_enviro.hxx>
+#include <simgear/scene/util/OsgMath.hxx>
#include <Main/fg_props.hxx>
#include <Main/globals.hxx>
+#include <Viewer/renderer.hxx>
#include <Scenery/scenery.hxx>
#include "precipitation_mgr.hxx"
-extern SGSky *thesky;
-
-
/**
* @brief FGPrecipitation Manager constructor
*
// By default, no precipitation
precipitation->setRainIntensity(0);
precipitation->setSnowIntensity(0);
+
+ // set the clip distance from the config
+ precipitation->setClipDistance(fgGetFloat("/environment/precipitation-control/clip-distance",5.0));
transform->addChild(precipitation->build());
group->addChild(transform.get());
}
SGGeod geod = SGGeod::fromDegM(fgGetDouble("/position/longitude-deg", 0.0),
fgGetDouble("/position/latitude-deg", 0.0),
0.0);
- osg::Matrix position(geod.makeZUpFrame());
+ osg::Matrix position(makeZUpFrame(geod));
// Move the precipitation object to player position
transform->setMatrix(position);
// Add to scene graph
fgGetNode("environment/params/precipitation-level-ft", true);
}
+void FGPrecipitationMgr::bind ()
+{
+ _tiedProperties.setRoot( fgGetNode("/sim/rendering", true ) );
+ _tiedProperties.Tie("precipitation-enable", precipitation.get(),
+ &SGPrecipitation::getEnabled,
+ &SGPrecipitation::setEnabled);
+}
+
+void FGPrecipitationMgr::unbind ()
+{
+ _tiedProperties.Untie();
+}
+
void FGPrecipitationMgr::setPrecipitationLevel(double a)
{
fgSetDouble("environment/params/precipitation-level-ft",a);
* @returns Elevation max in meter
*
* This function permits you to know what is the altitude max where we can
- * find precipitation. The value is returned in meter.
+ * find precipitation. The value is returned in meters.
*/
float FGPrecipitationMgr::getPrecipitationAtAltitudeMax(void)
{
int i;
int max;
- double elev;
float result;
SGPropertyNode *boundaryNode, *boundaryEntry;
+
+ if (fgGetBool("/environment/params/use-external-precipitation-level", false)) {
+ // If we're not modeling the precipitation level based on the cloud
+ // layers, take it directly from the property tree.
+ return fgGetFloat("/environment/params/external-precipitation-level-m", 0.0);
+ }
// By default (not cloud layer)
max = SGCloudLayer::SG_MAX_CLOUD_COVERAGES;
result = 0;
+ SGSky* thesky = globals->get_renderer()->getSky();
+
// To avoid messing up
if (thesky == NULL)
return result;
// For each boundary layers
while ( ( boundaryEntry = boundaryNode->getNode( "entry", i ) ) != NULL ) {
- elev = boundaryEntry->getDoubleValue( "elevation-ft" );
+ double elev = boundaryEntry->getDoubleValue( "elevation-ft" );
if (elev > result)
result = elev;
float altitudeAircraft;
float altitudeCloudLayer;
+ float rainDropletSize;
+ float snowFlakeSize;
+ float illumination;
altitudeCloudLayer = this->getPrecipitationAtAltitudeMax() * SG_METER_TO_FEET;
setPrecipitationLevel(altitudeCloudLayer);
- // Does the user enable the precipitation ?
- if (!sgEnviro.get_precipitation_enable_state()) {
- // Disable precipitations
- precipitation->setRainIntensity(0);
- precipitation->setSnowIntensity(0);
- // Update the drawing...
- precipitation->update();
- // Exit
- return;
- }
+ // Does the user enable the precipitation ?
+ if (!precipitation->getEnabled() ) {
+ // Disable precipitations
+ precipitation->setRainIntensity(0);
+ precipitation->setSnowIntensity(0);
+
+ // Update the drawing...
+ precipitation->update();
+
+ // Exit
+ return;
+ }
+
+ // See if external droplet size and illumination are used
+ if (fgGetBool("/environment/precipitation-control/detailed-precipitation", false)) {
+ precipitation->setDropletExternal(true);
+ rainDropletSize = fgGetFloat("/environment/precipitation-control/rain-droplet-size", 0.015);
+ snowFlakeSize = fgGetFloat("/environment/precipitation-control/snow-flake-size", 0.03);
+ illumination = fgGetFloat("/environment/precipitation-control/illumination", 1.0);
+ precipitation->setRainDropletSize(rainDropletSize);
+ precipitation->setSnowFlakeSize(snowFlakeSize);
+ precipitation->setIllumination(illumination);
+ }
// Get the elevation of aicraft and of the cloud layer
altitudeAircraft = fgGetDouble("/position/altitude-ft", 0.0);
}
else {
// The aircraft is bellow the cloud layer
- rain_intensity = fgGetDouble("/environment/metar/rain-norm", 0.0);
- snow_intensity = fgGetDouble("/environment/metar/snow-norm", 0.0);
+ rain_intensity = fgGetDouble("/environment/rain-norm", 0.0);
+ snow_intensity = fgGetDouble("/environment/snow-norm", 0.0);
}
// Get the current and dew temperature