[osg-users] Creating a flame of rocket
Suraj Paul
suraj at isac.gov.in
Mon Sep 26 07:29:17 PDT 2016
Hi Jannik,
Here's my code i am using the create the particle system and emitter. I am creating two particle systems--one for each exhaust of the rocket.:--
int main()
{
osg::ref_ptr<osg::MatrixTransform> mt = new osg::MatrixTransform;
osg::ref_ptr<osg::MatrixTransform> mt_2 = new osg::MatrixTransform;
osg::ref_ptr<osg::MatrixTransform> trans= new osg::MatrixTransform;
osg::ref_ptr<osg::Node> lan = osgDB::readNodeFile("cessna.osg");
trans->setMatrix( osg::Matrix::translate(0.0f, 0.0f, 0.0f) );
trans->addChild(lan);
//create two particle systems at different locations
mt->setMatrix( osg::Matrix::translate(5.0f, -5.0f, 0.0f) );
osgParticle::ParticleSystem* ps = createParticleSystem( mt.get());
mt_2->setMatrix( osg::Matrix::translate(-5.0f, -5.0f, 0.0f) );
osgParticle::ParticleSystem* ps_2 = createParticleSystem( mt_2.get());
//attach the two Particle system to 'trans' node
trans->addChild(mt.get()); trans->addChild(mt_2.get());
//give motion to 'trans' using osg::AnimationPath::LOOP
trans->addUpdateCallback( createAnimationPathCallback(100.0f, 30.0) );
//add updater to each of the particle system
osg::ref_ptr<osgParticle::ParticleSystemUpdater> updater = new osgParticle::ParticleSystemUpdater;
updater->addParticleSystem( ps );
updater->addParticleSystem( ps_2 );
//add the trans and updater to a group node called root
osg::ref_ptr<osg::Group> root = new osg::Group;
root->addChild( updater.get() );
root->addChild(trans.get());
osgViewer::Viewer viewer;
viewer.setSceneData( root.get() );
return viewer.run();
} /*******end of main********/
/************createparticleSystem func ***********************/
osgParticle::ParticleSystem* createParticleSystem( osg::Group* parent )
{
osg::ref_ptr<osgParticle::ParticleSystem> ps = new osgParticle::ParticleSystem;
ps->getDefaultParticleTemplate().setShape( osgParticle::Particle::QUAD);
ps->getDefaultParticleTemplate().setLifeTime( 0.50f );
ps->getDefaultParticleTemplate().setSizeRange( osgParticle::rangef(0.5f, 0.1f) );
ps->getDefaultParticleTemplate().setAlphaRange( osgParticle::rangef(0.5f, 0.0f) );
ps->getDefaultParticleTemplate().setColorRange(osgParticle::rangev4(osg::Vec4(45.0/255.0f,179.0/255.0,217/255.0f,1.0f), osg::Vec4(172.0/255.0f,225.0/255.0f,240/255.0f,1.0f)) );
ps->setDefaultAttributes("smoke.rgb", true, false );
osg::ref_ptr<osgParticle::RandomRateCounter> rrc = new osgParticle::RandomRateCounter;
rrc->setRateRange( 100, 200 );
osg::ref_ptr<osgParticle::ModularEmitter> emitter = new osgParticle::ModularEmitter;
emitter->setParticleSystem( ps.get() );
emitter->setCounter( rrc.get() );
osg::ref_ptr<osgParticle::RadialShooter> shooter = new osgParticle::RadialShooter;
shooter->setThetaRange(osg::DegreesToRadians(-0.50), osg::DegreesToRadians(0.50) );
shooter->setInitialSpeedRange( 1.5f, 1.0f );
emitter->setShooter( shooter.get() );
ps->setUseShaders(true);
osg::ref_ptr<osgParticle::ModularProgram> program = new osgParticle::ModularProgram;
program->setParticleSystem( ps.get() );
osg::ref_ptr<osg::Geode> geode = new osg::Geode;
geode->addDrawable( ps.get() );
parent->addChild( emitter.get() );
parent->addChild( program.get() );
parent->addChild( geode.get() );
return ps.get();
}
...
Thank you!
Cheers,
Suraj
------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=68760#68760
More information about the osg-users
mailing list