|
大家好,我用粒子系统做导弹尾焰时遇到一个问题,当导弹禁止时,效果还过得去
,但是当导弹动起来后,后面的尾焰就分叉了!如图
下面是做尾焰的代码
std::string textureFile("../data/model/image/fire3.png");
osg::ref_ptr<osgParticle:articleSystem> ps = new osgParticle::ParticleSystem;
ps->getDefaultParticleTemplate().setLifeTime(0.2);
ps->getDefaultParticleTemplate().setShape( osgParticle::Particle::POINT );
ps->setParticleScaleReferenceFrame(osgParticle::ParticleSystem:OCAL_COORDINATES);
//ps->setDefaultAttributes( textureFile, false, false, 0 );
ps->setDefaultAttributes( textureFile, true, false, 0 );
stateset = ps->getOrCreateStateSet();
stateset->setAttribute( new osg::Point(pointSize) );
stateset->setTextureAttributeAndModes( 0, new osg::PointSprite, osg::StateAttribute::ON );
emitter = new osgParticle::ModularEmitter;
emitter->setReferenceFrame(osgParticle::ParticleProcessor::RELATIVE_RF);
emitter->setParticleSystem( ps.get() );
osg::ref_ptr<osgParticle::ModularProgram> program = new osgParticle::ModularProgram;
program->setReferenceFrame(osgParticle::ParticleProcessor::RELATIVE_RF);
program->setParticleSystem( ps.get() );
// Emit specific number of particles every frame
osg::ref_ptr<osgParticle::RandomRateCounter> rrc = new osgParticle::RandomRateCounter;
rrc->setRateRange( 1000, 1000 );
osgParticle::RadialShooter *shooter = new osgParticle::RadialShooter;
shooter->setInitialSpeedRange(-10, -10);
shooter->setThetaRange(0, 0); // radians, relative to Z axis.
emitter->setShooter(shooter);
// Accelerate particles in the given gravity direction.
osg::ref_ptr<osgParticle::AccelOperator> accel = new osgParticle::AccelOperator;
accel->setToGravity(-1);
emitter->setCounter( rrc.get() );
program->addOperator(accel);
emitterAndprogram= new osg::MatrixTransform;
emitterAndprogram->setMatrix(osg::Matrix::rotate(-osg::PI_2,1,0,0)*osg::Matrix::translate(0,-4,0));
emitterAndprogram->addChild( emitter.get() );
emitterAndprogram->addChild( program.get() );
updater = new osgParticle::ParticleSystemUpdater;
updater->addParticleSystem( ps.get() );
psGeode = new osg::Geode;
psGeode->addDrawable( ps.get() );
这下面是放置尾焰的代码
//尾焰节点放在这里
MissleTrail missleTrail;
mPlume = new osg::MatrixTransform();
mPlume->addChild(missleTrail.getEmitterAndProgram());
mPlume->addChild( missleTrail.getUpdater());
mPlume->addChild( missleTrail.getParticleSystemGeode() );
大家帮忙看看,什么地方有问题,谢谢! |
|