]> git.mxchange.org Git - simgear.git/blobdiff - simgear/scene/model/particles.cxx
Make return type from loadPagedModel explicit.
[simgear.git] / simgear / scene / model / particles.cxx
index 9f3aeb7d686414cbc4b57b67904e4cc7f205389e..a7fee2ded106e3dbb4c69bd8570bd6f930ddd6f6 100644 (file)
@@ -1,6 +1,6 @@
 // particles.cxx - classes to manage particles
-// started in 2008 by Tiago Gusmão, using animation.hxx as reference
-// Copyright (C) 2008 Tiago Gusmão
+// started in 2008 by Tiago Gusmo, using animation.hxx as reference
+// Copyright (C) 2008 Tiago Gusmo
 //
 // This program is free software; you can redistribute it and/or
 // modify it under the terms of the GNU General Public License as
 #  include <simgear_config.h>
 #endif
 
-#include <simgear/math/SGMath.hxx>
-#include <simgear/math/SGGeod.hxx>
 #include <simgear/misc/sg_path.hxx>
 #include <simgear/props/props.hxx>
 #include <simgear/props/props_io.hxx>
+#include <simgear/scene/util/OsgMath.hxx>
 #include <simgear/structure/OSGVersion.hxx>
 
 #include <osgParticle/SmokeTrailEffect>
 
 #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)
@@ -59,14 +54,16 @@ void GlobalParticleCallback::operator()(osg::Node* node, osg::NodeVisitor* nv)
     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]);
 }
 
 
@@ -78,8 +75,9 @@ 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::ref_ptr<osg::Geode> Particles::commonGeode = new osg::Geode;
 osg::Vec3 Particles::_wind;
+bool Particles::_frozen = false;
 
 Particles::Particles() : 
     useGravity(false),
@@ -112,6 +110,7 @@ osg::Group* Particles::getCommonRoot()
         commonGeode.get()->setName("common particle system geode");
         commonRoot.get()->addChild(commonGeode.get());
         commonRoot.get()->addChild(psu.get());
+        commonRoot->setNodeMask( ~simgear::MODELLIGHT_BIT );
     }
     return commonRoot.get();
 }
@@ -132,7 +131,7 @@ void transformParticles(osgParticle::ParticleSystem* particleSys,
 
 osg::Group * Particles::appendParticles(const SGPropertyNode* configNode,
                                           SGPropertyNode* modelRoot,
-                                          const osgDB::ReaderWriter::Options*
+                                          const osgDB::Options*
                                           options)
 {
     SG_LOG(SG_GENERAL, SG_DEBUG, "Setting up a particle system!\n");
@@ -189,19 +188,12 @@ osg::Group * Particles::appendParticles(const SGPropertyNode* configNode,
         osg::Geode* g = new osg::Geode;
         align->addChild(g);
         g->addDrawable(particleSys);
-#ifndef OSG_PARTICLE_FIX
-        emitter->setReferenceFrame(osgParticle::Emitter::ABSOLUTE_RF);
-#endif
     } else {
-#ifdef OSG_PARTICLE_FIX
         callback()->particleFrame = new osg::MatrixTransform();
         osg::Geode* g = new osg::Geode;
         g->addDrawable(particleSys);
         callback()->particleFrame->addChild(g);
         getCommonRoot()->addChild(callback()->particleFrame.get());
-#else
-        getCommonGeode()->addDrawable(particleSys);
-#endif
     }
     std::string textureFile;
     if (configNode->hasValue("texture")) {
@@ -474,14 +466,7 @@ osg::Group * Particles::appendParticles(const SGPropertyNode* configNode,
             program->setFluidToWater();
 
         if (programnode->getBoolValue("gravity", true)) {
-#ifdef OSG_PARTICLE_FIX
             program->setToGravity();
-#else
-            if (attach == "world")
-                callback()->setupProgramGravity(true);
-            else
-                program->setToGravity();
-#endif
         } else
             program->setAcceleration(osg::Vec3(0,0,0));
 
@@ -510,6 +495,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(),
@@ -540,7 +527,7 @@ void Particles::operator()(osg::Node* node, osg::NodeVisitor* nv)
         particleSys->getDefaultParticleTemplate().setSizeRange(osgParticle::rangef(startSize, endSize));
     if (lifeValue)
         particleSys->getDefaultParticleTemplate().setLifeTime(lifeValue->getValue());
-#ifdef OSG_PARTICLE_FIX
+
     if (particleFrame.valid()) {
         MatrixList mlist = node->getWorldMatrices();
         if (!mlist.empty()) {
@@ -552,8 +539,8 @@ 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));
-                Matrix newParticleMat = geod.makeZUpFrame();
+                SGGeod geod = SGGeod::fromCart(toSG(emitOrigin));
+                Matrix newParticleMat = makeZUpFrame(geod);
                 Matrix changeParticleFrame
                     = particleMat * Matrix::inverse(newParticleMat);
                 particleFrame->setMatrix(newParticleMat);
@@ -563,13 +550,5 @@ void Particles::operator()(osg::Node* node, osg::NodeVisitor* nv)
     }
     if (program.valid() && useWind)
         program->setWind(_wind);
-#else
-    if (program.valid()) {
-        if (useGravity)
-            program->setAcceleration(GlobalParticleCallback::getGravityVector());
-        if (useWind)
-            program->setWind(GlobalParticleCallback::getWindVector());
-    }
-#endif
 }
 } // namespace simgear