00001 00027 #include "precipitation.hxx" 00028 #include "visual_enviro.hxx" 00029 00030 #include <simgear/constants.h> 00031 00037 SGPrecipitation::SGPrecipitation() : 00038 _freeze(false), _snow_intensity(0.0), _rain_intensity(0.0) 00039 { 00040 _precipitationEffect = new osgParticle::PrecipitationEffect; 00041 } 00042 00043 00050 osg::Group* SGPrecipitation::build(void) 00051 { 00052 osg::Group* group = new osg::Group; 00053 00054 _precipitationEffect->snow(0); 00055 _precipitationEffect->rain(0); 00056 00057 group->addChild(_precipitationEffect.get()); 00058 00059 return group; 00060 } 00061 00062 00069 void SGPrecipitation::setSnowIntensity(float intensity) 00070 { 00071 if (this->_snow_intensity < intensity-0.001) 00072 this->_snow_intensity += 0.001; 00073 else if (this->_snow_intensity > intensity+0.001) 00074 this->_snow_intensity -= 0.001; 00075 else 00076 this->_snow_intensity = intensity; 00077 } 00078 00079 00086 void SGPrecipitation::setRainIntensity(float intensity) 00087 { 00088 if (this->_rain_intensity < intensity-0.001) 00089 this->_rain_intensity += 0.001; 00090 else if (this->_rain_intensity > intensity+0.001) 00091 this->_rain_intensity -= 0.001; 00092 else 00093 this->_rain_intensity = intensity; 00094 } 00095 00096 00104 void SGPrecipitation::setFreezing(bool freeze) 00105 { 00106 this->_freeze = freeze; 00107 } 00108 00109 00119 void SGPrecipitation::setWindProperty(double heading, double speed) 00120 { 00121 double x, y, z; 00122 00123 heading = (heading + 180) * SGD_DEGREES_TO_RADIANS; 00124 speed = speed * SG_FEET_TO_METER; 00125 00126 x = -cos(heading) * speed; 00127 y = sin(heading) * speed; 00128 z = 0; 00129 00130 this->_wind_vec = osg::Vec3(x, y, z); 00131 } 00132 00133 00143 bool SGPrecipitation::update(void) 00144 { 00145 if (this->_freeze) { 00146 if (this->_rain_intensity > 0) 00147 this->_snow_intensity = this->_rain_intensity; 00148 } 00149 00150 bool enabled = sgEnviro.get_precipitation_enable_state(); 00151 if (enabled && this->_snow_intensity > 0) { 00152 _precipitationEffect->setWind(_wind_vec); 00153 _precipitationEffect->setParticleSpeed( -0.75f - 0.25f*_snow_intensity); 00154 00155 _precipitationEffect->setParticleSize(0.02f + 0.03f*_snow_intensity); 00156 _precipitationEffect->setMaximumParticleDensity(_snow_intensity * 7.2f); 00157 _precipitationEffect->setCellSize(osg::Vec3(5.0f / (0.25f+_snow_intensity), 5.0f / (0.25f+_snow_intensity), 5.0f)); 00158 00159 _precipitationEffect->setNearTransition(25.f); 00160 _precipitationEffect->setFarTransition(100.0f - 60.0f*sqrtf(_snow_intensity)); 00161 00162 _precipitationEffect->setParticleColor(osg::Vec4(0.85, 0.85, 0.85, 1.0) - osg::Vec4(0.1, 0.1, 0.1, 1.0) * _snow_intensity); 00163 } else if (enabled && this->_rain_intensity > 0) { 00164 _precipitationEffect->setWind(_wind_vec); 00165 _precipitationEffect->setParticleSpeed( -2.0f + -5.0f*_rain_intensity); 00166 00167 _precipitationEffect->setParticleSize(0.01 + 0.02*_rain_intensity); 00168 _precipitationEffect->setMaximumParticleDensity(_rain_intensity * 7.5f); 00169 _precipitationEffect->setCellSize(osg::Vec3(5.0f / (0.25f+_rain_intensity), 5.0f / (0.25f+_rain_intensity), 5.0f)); 00170 00171 _precipitationEffect->setNearTransition(25.f); 00172 _precipitationEffect->setFarTransition(100.0f - 60.0f*sqrtf(_rain_intensity)); 00173 00174 _precipitationEffect->setParticleColor( osg::Vec4(0x7A, 0xCE, 0xFF, 0x80)); 00175 } else { 00176 _precipitationEffect->snow(0); 00177 _precipitationEffect->rain(0); 00178 } 00179 00180 return true; 00181 }