From: Edward d'Auvergne Date: Tue, 3 May 2016 07:56:06 +0000 (+0200) Subject: Shift of management of the precipitation OSG scene graph to the scenery manager. X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=6462f464bba4b7c87bf04d699c56dbb28eb618d0;p=flightgear.git Shift of management of the precipitation OSG scene graph to the scenery manager. The precipitation branch of the OSG scene graph is now centrally managed by the scenery manager rather the precipitation manager itself. The scene graph initialisation from the constructor has also been shifted into the new FGPrecipitationMgr::sceneGraphSetup() function. --- diff --git a/src/Environment/precipitation_mgr.cxx b/src/Environment/precipitation_mgr.cxx index 9e83ab852..ee48da79a 100644 --- a/src/Environment/precipitation_mgr.cxx +++ b/src/Environment/precipitation_mgr.cxx @@ -51,22 +51,10 @@ */ FGPrecipitationMgr::FGPrecipitationMgr() { - group = new osg::Group(); - transform = new osg::MatrixTransform(); - precipitation = new SGPrecipitation(); - - - // 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()); + // Try to set up the scenegraph. + setupSceneGraph(); } - /** * @brief FGPrecipitaiton Manager destructor */ @@ -87,9 +75,6 @@ void FGPrecipitationMgr::init() 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); } @@ -106,19 +91,29 @@ void FGPrecipitationMgr::unbind () _tiedProperties.Untie(); } -void FGPrecipitationMgr::setPrecipitationLevel(double a) +// Set up the precipitation manager scenegraph. +void FGPrecipitationMgr::setupSceneGraph(void) { - fgSetDouble("environment/params/precipitation-level-ft",a); + FGScenery* scenery = globals->get_scenery(); + osg::Group* group = scenery->get_precipitation_branch(); + transform = new osg::MatrixTransform(); + precipitation = new SGPrecipitation(); + + + // 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()); } -/** - * @brief Get OSG precipitation object - * - * @returns A pointer on the OSG object (osg::Group *) - */ -osg::Group * FGPrecipitationMgr::getObject(void) + +void FGPrecipitationMgr::setPrecipitationLevel(double a) { - return this->group.get(); + fgSetDouble("environment/params/precipitation-level-ft",a); } /** diff --git a/src/Environment/precipitation_mgr.hxx b/src/Environment/precipitation_mgr.hxx index 449f7f47c..3c3b8a614 100644 --- a/src/Environment/precipitation_mgr.hxx +++ b/src/Environment/precipitation_mgr.hxx @@ -36,7 +36,6 @@ class FGPrecipitationMgr : public SGSubsystem { private: - osg::ref_ptr group; osg::ref_ptr transform; osg::ref_ptr precipitation; float getPrecipitationAtAltitudeMax(void); @@ -52,10 +51,8 @@ public: virtual void init (); virtual void update (double dt); + void setupSceneGraph(void); void setPrecipitationLevel(double l); - - osg::Group * getObject(void); - }; #endif diff --git a/src/Scenery/scenery.cxx b/src/Scenery/scenery.cxx index 48334337e..b64c16d5c 100644 --- a/src/Scenery/scenery.cxx +++ b/src/Scenery/scenery.cxx @@ -340,6 +340,11 @@ void FGScenery::init() { scene_graph->addChild(particles_branch.get()); simgear::GlobalParticleCallback::setSwitch(fgGetNode("/sim/rendering/particles", true)); + // Set up the precipitation system. + precipitation_branch = new osg::Group; + precipitation_branch->setName("Precipitation"); + scene_graph->addChild(precipitation_branch.get()); + _listener = new ScenerySwitchListener(this); // Toggle the setup flag. @@ -353,6 +358,7 @@ void FGScenery::shutdown() models_branch = NULL; aircraft_branch = NULL; particles_branch = NULL; + precipitation_branch = NULL; // Toggle the setup flag. _inited = false; diff --git a/src/Scenery/scenery.hxx b/src/Scenery/scenery.hxx index 55176ca55..c4f8cec36 100644 --- a/src/Scenery/scenery.hxx +++ b/src/Scenery/scenery.hxx @@ -57,6 +57,7 @@ class FGScenery : public SGSubsystem osg::ref_ptr aircraft_branch; osg::ref_ptr interior_branch; osg::ref_ptr particles_branch; + osg::ref_ptr precipitation_branch; osg::ref_ptr _pager; ScenerySwitchListener* _listener; @@ -117,6 +118,7 @@ public: osg::Group *get_aircraft_branch () const { return aircraft_branch.get(); } osg::Group *get_interior_branch () const { return interior_branch.get(); } osg::Group *get_particles_branch () const { return particles_branch.get(); } + osg::Group *get_precipitation_branch () const { return precipitation_branch.get(); } /// Returns true if scenery is available for the given lat, lon position /// within a range of range_m.