]> git.mxchange.org Git - simgear.git/blobdiff - simgear/scene/model/particles.cxx
Improved tile cache priority scheme.
[simgear.git] / simgear / scene / model / particles.cxx
index 0194e960c4ff9a91a712e659efdf04f1758aa840..acac7dfc6b8696724f42b4c6125df048ce97fab8 100644 (file)
@@ -26,6 +26,7 @@
 #include <simgear/misc/sg_path.hxx>
 #include <simgear/props/props.hxx>
 #include <simgear/props/props_io.hxx>
+#include <simgear/structure/OSGVersion.hxx>
 
 #include <osgParticle/SmokeTrailEffect>
 #include <osgParticle/FireEffect>
 
 #include "particles.hxx"
 
+#if SG_OSG_VERSION >= 27004
+#define OSG_PARTICLE_FIX 1
+#endif
+
 namespace simgear
 {
 void GlobalParticleCallback::operator()(osg::Node* node, osg::NodeVisitor* nv)
 {
+    enabled = !enabledNode || enabledNode->getBoolValue();
+    if (!enabled)
+        return;
     SGQuatd q
         = SGQuatd::fromLonLatDeg(modelRoot->getFloatValue("/position/longitude-deg",0),
                                  modelRoot->getFloatValue("/position/latitude-deg",0));
-    osg::Matrix om(q.osg());
+    osg::Matrix om(toOsg(q));
     osg::Vec3 v(0,0,9.81);
     gravity = om.preMult(v);
+    // NOTE: THIS WIND COMPUTATION DOESN'T SEEM TO AFFECT PARTICLES
     const osg::Vec3& zUpWind = Particles::getWindVector();
-    osg::Vec3 w(zUpWind.y(), zUpWind.x(), - zUpWind.z());
+    osg::Vec3 w(zUpWind.y(), zUpWind.x(), -zUpWind.z());
     wind = om.preMult(w);
 
-    //SG_LOG(SG_GENERAL, SG_ALERT, "wind vector:"<<w[0]<<","<<w[1]<<","<<w[2]<<"\n");
+    // SG_LOG(SG_GENERAL, SG_ALERT,
+    //        "wind vector:" << w[0] << "," <<w[1] << "," << w[2]);
 }
 
 
 //static members
 osg::Vec3 GlobalParticleCallback::gravity;
 osg::Vec3 GlobalParticleCallback::wind;
+bool GlobalParticleCallback::enabled = true;
+SGConstPropertyNode_ptr GlobalParticleCallback::enabledNode = 0;
 
 osg::ref_ptr<osg::Group> Particles::commonRoot;
 osg::ref_ptr<osgParticle::ParticleSystemUpdater> Particles::psu = new osgParticle::ParticleSystemUpdater;
 osg::ref_ptr<osg::Geode> Particles::commonGeode = new osg::Geode;;
 osg::Vec3 Particles::_wind;
+bool Particles::_frozen = false;
 
 Particles::Particles() : 
     useGravity(false),
@@ -106,8 +119,6 @@ osg::Group* Particles::getCommonRoot()
     return commonRoot.get();
 }
 
-// Enable this once particle fix is in OSG.
-// #define OSG_PARTICLE_FIX 1
 void transformParticles(osgParticle::ParticleSystem* particleSys,
                         const osg::Matrix& mat)
 {
@@ -502,6 +513,8 @@ osg::Group * Particles::appendParticles(const SGPropertyNode* configNode,
 void Particles::operator()(osg::Node* node, osg::NodeVisitor* nv)
 {
     //SG_LOG(SG_GENERAL, SG_ALERT, "callback!\n");
+    this->particleSys->setFrozen(_frozen);
+
     using namespace osg;
     if (shooterValue)
         shooter->setInitialSpeedRange(shooterValue->getValue(),
@@ -513,7 +526,7 @@ void Particles::operator()(osg::Node* node, osg::NodeVisitor* nv)
     else if (counterCond)
         counter->setRateRange(counterStaticValue,
                               counterStaticValue + counterStaticExtraRange);
-    if (counterCond && !counterCond->test())
+    if (!GlobalParticleCallback::getEnabled() || (counterCond && !counterCond->test()))
         counter->setRateRange(0, 0);
     bool colorchange=false;
     for (int i = 0; i < 8; ++i) {
@@ -544,7 +557,7 @@ void Particles::operator()(osg::Node* node, osg::NodeVisitor* nv)
             if (displace * displace > 10000.0 * 10000.0) {
                 // Make new frame for particle system, coincident with
                 // the emitter frame, but oriented with local Z.
-                SGGeod geod = SGGeod::fromCart(SGVec3d(emitOrigin));
+                SGGeod geod = SGGeod::fromCart(toSG(emitOrigin));
                 Matrix newParticleMat = geod.makeZUpFrame();
                 Matrix changeParticleFrame
                     = particleMat * Matrix::inverse(newParticleMat);