]> git.mxchange.org Git - simgear.git/blobdiff - simgear/environment/precipitation.cxx
fix SGPagedLOD change for 2.8.3
[simgear.git] / simgear / environment / precipitation.cxx
index b5467a600b816f0b86a114a0c4c4bd113e7601d7..075fac1d868744611c8183b66201feeef0c46d39 100644 (file)
  */
 
 #include "precipitation.hxx"
+#include "visual_enviro.hxx"
 
 #include <simgear/constants.h>
+#include <osg/ClipNode>
 
 /**
  * @brief SGPrecipitation constructor
@@ -34,7 +36,7 @@
  * Build a new OSG object from osgParticle.
  */
 SGPrecipitation::SGPrecipitation() :
-    _freeze(false), _snow_intensity(0.0), _rain_intensity(0.0)
+    _freeze(false), _snow_intensity(0.0), _rain_intensity(0.0), _clip_distance(5.0)
 {
     _precipitationEffect = new osgParticle::PrecipitationEffect;
 }
@@ -53,7 +55,20 @@ osg::Group* SGPrecipitation::build(void)
     _precipitationEffect->snow(0);     
     _precipitationEffect->rain(0);     
 
-    group->addChild(_precipitationEffect.get());
+    if (_clip_distance!=0.0)
+    {    
+        osg::ref_ptr<osg::ClipNode> clipNode = new osg::ClipNode;
+        clipNode->addClipPlane( new osg::ClipPlane( 0 ) );
+        clipNode->getClipPlane(0)->setClipPlane( 0.0, 0.0, -1.0, -_clip_distance );
+        clipNode->setReferenceFrame(osg::ClipNode::ABSOLUTE_RF);
+        clipNode->addChild(_precipitationEffect.get());
+
+        group->addChild(clipNode.get());
+    }
+    else
+    {
+        group->addChild(_precipitationEffect.get());
+    }
 
     return group;
 }
@@ -146,7 +161,8 @@ bool SGPrecipitation::update(void)
             this->_snow_intensity = this->_rain_intensity;
     }
 
-    if (this->_snow_intensity > 0) {
+    bool enabled = sgEnviro.get_precipitation_enable_state();
+    if (enabled && this->_snow_intensity > 0) {
         _precipitationEffect->setWind(_wind_vec);
         _precipitationEffect->setParticleSpeed( -0.75f - 0.25f*_snow_intensity);
                
@@ -158,7 +174,7 @@ bool SGPrecipitation::update(void)
         _precipitationEffect->setFarTransition(100.0f - 60.0f*sqrtf(_snow_intensity));
                
         _precipitationEffect->setParticleColor(osg::Vec4(0.85, 0.85, 0.85, 1.0) - osg::Vec4(0.1, 0.1, 0.1, 1.0) * _snow_intensity);
-    } else if (this->_rain_intensity > 0){
+    } else if (enabled && this->_rain_intensity > 0) {
         _precipitationEffect->setWind(_wind_vec);
         _precipitationEffect->setParticleSpeed( -2.0f + -5.0f*_rain_intensity);