Hi,

Hi I´m trying to change my particle systems life time in run-time. To do that, 
I started making a function setUp called once and a function update called 
every frame. Inside the setUp function I create the particle system: I set  the 
shape, life time, size, mass, initial speed and so on. 



Code:

void setUp(osg::Group *pRoot)
{
   m_ParticleSystem = new osgParticle::ParticleSystem;
   m_ParticleSystem->setDefaultAttributes("Fire.dds", false, false);

   m_Geode = new osg::Geode;
   m_Geode->addDrawable(m_ParticleSystem.get());
   mRoot->addChild(m_Geode.get());

   m_pSystemUpdater = new osgParticle::ParticleSystemUpdater;
   m_pSystemUpdater->addParticleSystem(m_ParticleSystem.get());
   mRoot->addChild(m_SystemUpdater.get());


        m_myParticle = new osgParticle::Particle;

   m_myParticle->setShape(osgParticle::Particle::QUAD);
   m_myParticle->setSizeRange(osgParticle::rangef(0.2,0.2));
   m_myParticle->setLifeTime(4);
   m_myParticle->setMass(0.1);


   m_ParticleSystem->setDefaultParticleTemplate(*m_myParticle);


   m_Emitter = new osgParticle::ModularEmitter;
   m_Emitter->setParticleSystem(m_ParticleSystem.get());

   osg::ref_ptr<osgParticle::PointPlacer> mPlacer = new 
osgParticle::PointPlacer();
   mPlacer->setCenter(osg::Vec3(0.0,0.0,0.0));
   m_Emitter->setPlacer(mPlacer.get()); 
 
   m_Program = new osgParticle::ModularProgram;
   m_Program->setParticleSystem(m_ParticleSystem.get());

 
   Root->addChild(m_Program.get());
}






Then in the Update function for each frame I want to change the life time, 
random rate counter and initial speed. The problem is that I can change the 
random rate counter and initial speed but I can´t change the life time because 
the particle disappear (whatever the value I set). Below you can find my code 
snipet



Code:


void Update(float speed, float count, float life)
{
        
        osg::ref_ptr<osgParticle::RadialShooter> pShooter = 
(osgParticle::RadialShooter *)_pEmitter->getShooter();
        pShooter->setInitialSpeedRange(speed*0.5,speed*0.9);

        osg::ref_ptr<osgParticle::RandomRateCounter> pRate = 
static_cast<osgParticle::RandomRateCounter *> (_pEmitter->getCounter());
        pRate->setRateRange(count*1.0,count*1.5);
  

        //osgParticle::Particle myParticle = 
_pParticleSystem->getDefaultParticleTemplate(); //This don't work if there are 
several particle systems

        //if I remove the following instruction, the system works properly but 
without the lifetime functionality.
        m_myParticle->setLifeTime(life);
}





Thanks in advance for your help

cheers,

     Iban

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=12605#12605





_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to