]> git.mxchange.org Git - simgear.git/blobdiff - simgear/scene/model/particles.hxx
Add preliminary spot light animation
[simgear.git] / simgear / scene / model / particles.hxx
index 5beb7fe8a6e93d9f815253ee0ca76f611912c493..cdbb1f21af317e456b1fa8d42ddc0fedc9673731 100644 (file)
 #define _SG_PARTICLES_HXX 1
 
 #include <osg/ref_ptr>
-#include <osg/Group>
-#include <osg/Node>
-#include <osg/NodeVisitor>
-#include <osg/Texture2D>
 #include <osgParticle/SmokeTrailEffect>
 #include <osgParticle/Particle>
 #include <osgParticle/ModularEmitter>
-#include <osgParticle/ParticleSystemUpdater>
-#include <osgParticle/ParticleSystem>
-#include <osg/MatrixTransform>
 #include <osgDB/ReaderWriter>
 #include <osgDB/FileNameUtils>
 #include <osgDB/FileUtils>
 #include <osg/Notify>
 #include <osg/Vec3>
 
+namespace osg
+{
+class Group;
+class MatrixTransform;
+class Node;
+class NodeVisitor;
+}
+
+namespace osgParticle
+{
+class ParticleSystem;
+class ParticleSystemUpdater;
+}
 
 #include <simgear/scene/util/SGNodeMasks.hxx>
 #include <simgear/props/props.hxx>
 #include <simgear/props/condition.hxx>
 #include <simgear/structure/SGExpression.hxx>
+#include <simgear/structure/SGSharedPtr.hxx>
 #include <simgear/math/SGQuat.hxx>
 #include <simgear/math/SGMatrix.hxx>
 
@@ -68,7 +75,7 @@ public:
     }
 
     virtual void operator()(osg::Node* node, osg::NodeVisitor* nv);
-    
+
     static const osg::Vec3 &getGravityVector()
     {
         return gravity;
@@ -79,12 +86,22 @@ public:
         return wind;
     }
 
+    static void setSwitch(const SGPropertyNode* n)
+    {
+        enabledNode = n;
+    }
+
+    static bool getEnabled()
+    {
+        return enabled;
+    }
 
+private:
     static osg::Vec3 gravity;
     static osg::Vec3 wind;
-private:
-
-    const SGPropertyNode* modelRoot;
+    SGConstPropertyNode_ptr modelRoot;
+    static SGConstPropertyNode_ptr enabledNode;
+    static bool enabled;
 };
 
 
@@ -92,22 +109,9 @@ private:
 class Particles : public osg::NodeCallback 
 {
 public:
-    Particles() : 
-        shooterValue(NULL),
-        counterValue(NULL),
-        startSizeValue(NULL),
-        endSizeValue(NULL),
-        lifeValue(NULL),
-        refFrame(NULL),
-        program(NULL),
-        useGravity(false),
-        useWind(false),
-        counterCond(NULL)
-    {
-        memset(colorComponents, 0, sizeof(colorComponents));
-    }
+    Particles();
 
-    static osg::Group * appendParticles(const SGPropertyNode* configNode, SGPropertyNode* modelRoot, const osgDB::ReaderWriter::Options* options);
+    static osg::Group * appendParticles(const SGPropertyNode* configNode, SGPropertyNode* modelRoot, const osgDB::Options* options);
 
     virtual void operator()(osg::Node* node, osg::NodeVisitor* nv);
 
@@ -233,19 +237,7 @@ public:
         staticColorComponents[7] = a2;
     }
 
-    static osg::Group * getCommonRoot()
-    {
-        if(!commonRoot.valid())
-        {
-            SG_LOG(SG_GENERAL, SG_DEBUG, "Particle common root called!\n");
-            commonRoot = new osg::Group;
-            commonRoot.get()->setName("common particle system root");
-            commonGeode.get()->setName("common particle system geode");
-            commonRoot.get()->addChild(commonGeode.get());
-            commonRoot.get()->addChild(psu.get());
-        }
-        return commonRoot.get();
-    }
+    static osg::Group * getCommonRoot();
 
     static osg::Geode * getCommonGeode()
     {
@@ -257,31 +249,50 @@ public:
         return psu.get();
     }
 
+    static void setFrozen(bool e) { _frozen = e; }
+
+    /**
+     *  Set and get the wind vector for particles in the
+     * atmosphere. This vector is in the Z-up Y-north frame, and the
+     * magnitude is the velocity in meters per second.
+     */
+    static void setWindVector(const osg::Vec3& wind) { _wind = wind; }
+    static void setWindFrom(const double from_deg, const double speed_kt) {
+       double map_rad = -from_deg * SG_DEGREES_TO_RADIANS;
+       double speed_mps = speed_kt * SG_KT_TO_MPS;
+       _wind[0] = cos(map_rad) * speed_mps;
+       _wind[1] = sin(map_rad) * speed_mps;
+       _wind[2] = 0.0;
+    }
+    static const osg::Vec3& getWindVector() { return _wind; }
 protected:
     float shooterExtraRange;
     float counterExtraRange;
-    SGExpressiond* shooterValue;
-    SGExpressiond* counterValue;
-    SGExpressiond* colorComponents[8];
-    SGExpressiond* startSizeValue;
-    SGExpressiond* endSizeValue;
-    SGExpressiond* lifeValue;
-    SGCondition* counterCond;
-    osg::MatrixTransform* refFrame;
+    SGSharedPtr<SGExpressiond> shooterValue;
+    SGSharedPtr<SGExpressiond> counterValue;
+    SGSharedPtr<SGExpressiond> colorComponents[8];
+    SGSharedPtr<SGExpressiond> startSizeValue;
+    SGSharedPtr<SGExpressiond> endSizeValue;
+    SGSharedPtr<SGExpressiond> lifeValue;
+    SGSharedPtr<SGCondition> counterCond;
     float staticColorComponents[8];
     float startSize;
     float endSize;
     float counterStaticValue;
     float counterStaticExtraRange;
-    osgParticle::RadialShooter* shooter;
-    osgParticle::RandomRateCounter* counter;
-    osgParticle::ParticleSystem* particleSys;
-    osgParticle::FluidProgram* program;
+    osg::ref_ptr<osgParticle::RadialShooter> shooter;
+    osg::ref_ptr<osgParticle::RandomRateCounter> counter;
+    osg::ref_ptr<osgParticle::ParticleSystem> particleSys;
+    osg::ref_ptr<osgParticle::FluidProgram> program;
+    osg::ref_ptr<osg::MatrixTransform> particleFrame;
+    
     bool useGravity;
     bool useWind;
+    static bool _frozen;
     static osg::ref_ptr<osgParticle::ParticleSystemUpdater> psu;
     static osg::ref_ptr<osg::Group> commonRoot;
     static osg::ref_ptr<osg::Geode> commonGeode;
+    static osg::Vec3 _wind;
 };
 }
 #endif