diff --git a/src/Environment/environment_mgr.cxx b/src/Environment/environment_mgr.cxx index b029316e1..98178b5b2 100644 --- a/src/Environment/environment_mgr.cxx +++ b/src/Environment/environment_mgr.cxx @@ -36,6 +36,7 @@ #include "environment_ctrl.hxx" #include "environment_mgr.hxx" #include "fgclouds.hxx" +#include "precipitation_mgr.hxx" class SGSky; extern SGSky *thesky; @@ -54,14 +55,18 @@ FGEnvironmentMgr::FGEnvironmentMgr () _controller->setEnvironment(_environment); set_subsystem("controller", _controller, 0.5); fgClouds = new FGClouds( _controller ); + _precipitationManager = new FGPrecipitationMgr; + set_subsystem("precipitation", _precipitationManager); } FGEnvironmentMgr::~FGEnvironmentMgr () { delete _environment; remove_subsystem("controller"); + remove_subsystem("precipitation"); delete _controller; delete fgClouds; + delete _precipitationManager; } void diff --git a/src/Environment/environment_mgr.hxx b/src/Environment/environment_mgr.hxx index a0633b170..e45e35330 100644 --- a/src/Environment/environment_mgr.hxx +++ b/src/Environment/environment_mgr.hxx @@ -35,6 +35,7 @@ class FGEnvironment; class FGEnvironmentCtrl; class FGClouds; +class FGPrecipitationMgr; /** * Manage environment information. @@ -86,6 +87,7 @@ private: FGEnvironment * _environment; // always the same, for now FGEnvironmentCtrl * _controller; // always the same, for now + FGPrecipitationMgr* _precipitationManager; FGClouds *fgClouds; }; diff --git a/src/Environment/precipitation_mgr.cxx b/src/Environment/precipitation_mgr.cxx index fcabe72ba..b6e6e6e31 100644 --- a/src/Environment/precipitation_mgr.cxx +++ b/src/Environment/precipitation_mgr.cxx @@ -24,28 +24,18 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * @par CVS - * $Id$ */ -#include -#include -#include -#include -#include - -#include -#include -#include -#include #include -#include #include +#include #include #include #include
+#include
+#include #include "precipitation_mgr.hxx" @@ -53,9 +43,6 @@ extern SGSky *thesky; -void WorldCoordinate( osg::Matrix&, double, - double, double, double); - /** * @brief FGPrecipitation Manager constructor * @@ -63,32 +50,17 @@ void WorldCoordinate( osg::Matrix&, double, */ FGPrecipitationMgr::FGPrecipitationMgr() { - osg::Matrix position; - double latitude, longitude; + group = new osg::Group(); + transform = new osg::MatrixTransform(); + precipitation = new SGPrecipitation(); - group = new osg::Group(); - transform = new osg::MatrixTransform(); - precipitation = new SGPrecipitation(); + // By default, no precipitation + precipitation->setRainIntensity(0); + precipitation->setSnowIntensity(0); - - // By default, none precipitation - precipitation->setRainIntensity(0); - precipitation->setSnowIntensity(0); - - - // Read latitude and longitude position - latitude = fgGetDouble("/position/latitude-deg", 0.0); - longitude = fgGetDouble("/position/longitude-deg", 0.0); - - WorldCoordinate(position, latitude, longitude, 0, 0); - - - // Move the precipitation object to player position - transform->setMatrix(position); - transform->addChild(precipitation->build()); - - group->addChild(transform); + transform->addChild(precipitation->build()); + group->addChild(transform.get()); } @@ -97,9 +69,25 @@ FGPrecipitationMgr::FGPrecipitationMgr() */ FGPrecipitationMgr::~FGPrecipitationMgr() { - delete precipitation; + } +/** + * SGSubsystem initialization + */ +void FGPrecipitationMgr::init() +{ + // Read latitude and longitude position + SGGeod geod = SGGeod::fromDegM(fgGetDouble("/position/longitude-deg", 0.0), + fgGetDouble("/position/latitude-deg", 0.0), + 0.0); + osg::Matrix position(geod.makeZUpFrame()); + // 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()); +} /** * @brief Get OSG precipitation object @@ -108,7 +96,7 @@ FGPrecipitationMgr::~FGPrecipitationMgr() */ osg::Group * FGPrecipitationMgr::getObject(void) { - return this->group; + return this->group.get(); } @@ -122,107 +110,99 @@ osg::Group * FGPrecipitationMgr::getObject(void) */ float FGPrecipitationMgr::getPrecipitationAtAltitudeMax(void) { - int i; - int max; - float result; + int i; + int max; + float result; - // By default (not cloud layer) - max = SGCloudLayer::SG_MAX_CLOUD_COVERAGES; - result = 0; + // By default (not cloud layer) + max = SGCloudLayer::SG_MAX_CLOUD_COVERAGES; + result = 0; - // To avoid messing up - if (thesky == NULL) - return result; + // To avoid messing up + if (thesky == NULL) + return result; - // For each cloud layer - for (i=0; iget_cloud_layer_count(); i++) { - int q; + // For each cloud layer + for (i=0; iget_cloud_layer_count(); i++) { + int q; - // Get coverage - // Value for q are (meaning / thickness) : - // 5 : "clear" / 0 - // 4 : "cirrus" / ?? - // 3 : "few" / 65 - // 2 : "scattered" / 600 - // 1 : "broken" / 750 - // 0 : "overcast" / 1000 - q = thesky->get_cloud_layer(i)->getCoverage(); + // Get coverage + // Value for q are (meaning / thickness) : + // 5 : "clear" / 0 + // 4 : "cirrus" / ?? + // 3 : "few" / 65 + // 2 : "scattered" / 600 + // 1 : "broken" / 750 + // 0 : "overcast" / 1000 + q = thesky->get_cloud_layer(i)->getCoverage(); - // Save the coverage max - if (q < max) { - max = q; - result = thesky->get_cloud_layer(i)->getElevation_m(); - } - } + // Save the coverage max + if (q < max) { + max = q; + result = thesky->get_cloud_layer(i)->getElevation_m(); + } + } - return result; + return result; } /** * @brief Update the precipitation drawing * - * @returns true is all is OK - * - * This function permits you to update the precipitation drawing. - * This function is called by the renderer. */ -bool FGPrecipitationMgr::update(void) +void FGPrecipitationMgr::update(double dt) { - double dewtemp; - double currtemp; - double rain_intensity; - double snow_intensity; + double dewtemp; + double currtemp; + double rain_intensity; + double snow_intensity; - float altitudeAircraft; - float altitudeCloudLayer; + float altitudeAircraft; + float altitudeCloudLayer; - // Get the elevation of aicraft and of the cloud layer - altitudeAircraft = fgGetDouble("/position/altitude-ft", 0.0); - altitudeCloudLayer = this->getPrecipitationAtAltitudeMax() * SG_METER_TO_FEET; + // 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 (altitudeAircraft > altitudeCloudLayer) { - // The aircraft is above the cloud layer - rain_intensity = 0; - snow_intensity = 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); - } + if (altitudeAircraft > altitudeCloudLayer) { + // The aircraft is above the cloud layer + rain_intensity = 0; + snow_intensity = 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); + } - // Get the current and dew temperature - dewtemp = fgGetDouble("/environment/dewpoint-degc", 0.0); - currtemp = fgGetDouble("/environment/temperature-degc", 0.0); + // Get the current and dew temperature + dewtemp = fgGetDouble("/environment/dewpoint-degc", 0.0); + currtemp = fgGetDouble("/environment/temperature-degc", 0.0); - if (currtemp < dewtemp) { - // There is fog... and the weather is very steamy - if (rain_intensity == 0) - rain_intensity = 0.15; - } + if (currtemp < dewtemp) { + // There is fog... and the weather is very steamy + if (rain_intensity == 0) + rain_intensity = 0.15; + } - // If the current temperature is below 0°C, we turn off the rain to snow... - if (currtemp < 0) - precipitation->setFreezing(true); - else - precipitation->setFreezing(false); + // If the current temperature is below 0°C, we turn off the rain to snow... + if (currtemp < 0) + precipitation->setFreezing(true); + else + precipitation->setFreezing(false); - // Set the wind property - precipitation->setWindProperty( - fgGetDouble("/environment/wind-from-heading-deg", 0.0), - fgGetDouble("/environment/wind-speed-kt", 0.0)); + // Set the wind property + precipitation->setWindProperty( + fgGetDouble("/environment/wind-from-heading-deg", 0.0), + fgGetDouble("/environment/wind-speed-kt", 0.0)); - // Set the intensity of precipitation - precipitation->setRainIntensity(rain_intensity); - precipitation->setSnowIntensity(snow_intensity); + // Set the intensity of precipitation + precipitation->setRainIntensity(rain_intensity); + precipitation->setSnowIntensity(snow_intensity); - // Update the drawing... - precipitation->update(); - - return true; + // Update the drawing... + precipitation->update(); } - - diff --git a/src/Environment/precipitation_mgr.hxx b/src/Environment/precipitation_mgr.hxx index 2d2457976..6f2ab8dd7 100644 --- a/src/Environment/precipitation_mgr.hxx +++ b/src/Environment/precipitation_mgr.hxx @@ -24,31 +24,32 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * @par CVS - * $Id$ */ #ifndef _PRECIPITATION_MGR_HXX #define _PRECIPITATION_MGR_HXX +#include #include -#include "precipitation_mgr.hxx" - - -class FGPrecipitationMgr { +class FGPrecipitationMgr : public SGSubsystem +{ private: - osg::Group *group; - osg::MatrixTransform *transform; - SGPrecipitation *precipitation; - float getPrecipitationAtAltitudeMax(void); + osg::ref_ptr group; + osg::ref_ptr transform; + osg::ref_ptr precipitation; + float getPrecipitationAtAltitudeMax(void); public: - FGPrecipitationMgr(); - ~FGPrecipitationMgr(); - bool update(void); - osg::Group * getObject(void); + FGPrecipitationMgr(); + virtual ~FGPrecipitationMgr(); + + // SGSubsystem methods + virtual void init (); + virtual void update (double dt); + + osg::Group * getObject(void); }; #endif diff --git a/src/Main/main.cxx b/src/Main/main.cxx index dd29fb8b8..615ed6c54 100644 --- a/src/Main/main.cxx +++ b/src/Main/main.cxx @@ -71,7 +71,6 @@ #include