]> git.mxchange.org Git - flightgear.git/blobdiff - src/Environment/precipitation_mgr.cxx
Better fix for a compilation problem with MSVC 2012
[flightgear.git] / src / Environment / precipitation_mgr.cxx
index 7d97674a14c9c104f0d9860892ed7281d5a85458..e4ca0c0f638723d3bb367cd1b0d532d6fcdda3b5 100644 (file)
 #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 
  *
@@ -63,7 +59,6 @@ FGPrecipitationMgr::FGPrecipitationMgr()
     // By default, no precipitation
     precipitation->setRainIntensity(0);
     precipitation->setSnowIntensity(0);
-
     transform->addChild(precipitation->build());
     group->addChild(transform.get());
 }
@@ -86,12 +81,31 @@ void FGPrecipitationMgr::init()
     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
     osg::Group* scenery = globals->get_scenery()->get_scene_graph();
     scenery->addChild(getObject());
+    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);
 }
 
 /** 
@@ -104,7 +118,6 @@ osg::Group * FGPrecipitationMgr::getObject(void)
     return this->group.get();
 }
 
-
 /** 
  * @brief Calculate the max alitutude with precipitation
  * 
@@ -117,7 +130,6 @@ float FGPrecipitationMgr::getPrecipitationAtAltitudeMax(void)
 {
     int i;
     int max;
-       double elev;
     float result;
     SGPropertyNode *boundaryNode, *boundaryEntry;
 
@@ -126,6 +138,8 @@ float FGPrecipitationMgr::getPrecipitationAtAltitudeMax(void)
     max = SGCloudLayer::SG_MAX_CLOUD_COVERAGES;
     result = 0;
 
+     SGSky* thesky = globals->get_renderer()->getSky();
+    
     // To avoid messing up
     if (thesky == NULL)
         return result;
@@ -165,7 +179,7 @@ float FGPrecipitationMgr::getPrecipitationAtAltitudeMax(void)
 
         // 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;
@@ -199,8 +213,11 @@ void FGPrecipitationMgr::update(double dt)
     float altitudeAircraft;
     float altitudeCloudLayer;
 
+    altitudeCloudLayer = this->getPrecipitationAtAltitudeMax() * SG_METER_TO_FEET;
+    setPrecipitationLevel(altitudeCloudLayer);
+
        // Does the user enable the precipitation ?
-       if (!sgEnviro.get_precipitation_enable_state()) {
+       if (!precipitation->getEnabled() ) {
                // Disable precipitations
            precipitation->setRainIntensity(0);
            precipitation->setSnowIntensity(0);
@@ -214,7 +231,6 @@ void FGPrecipitationMgr::update(double dt)
 
     // Get the elevation of aicraft and of the cloud layer
     altitudeAircraft = fgGetDouble("/position/altitude-ft", 0.0);
-    altitudeCloudLayer = this->getPrecipitationAtAltitudeMax() * SG_METER_TO_FEET;
 
     if ((altitudeCloudLayer > 0) && (altitudeAircraft > altitudeCloudLayer)) {
         // The aircraft is above the cloud layer
@@ -223,8 +239,8 @@ void FGPrecipitationMgr::update(double dt)
     }
     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