|
想在ocean的基础上添加粒子系统 实现几朵云的效果,但是现在初步尝试加了一个简单的粒子系统运行时无法看到效果,请问是怎么回事
//++++++++++++++++
osg::Group* CreateMyParticleScene()
{
osg::Group* cloud = new osg::Group() ;
//创建粒子系统模板
osgParticle:article ptemplate;
//设置生命周期
ptemplate.setLifeTime(-1);
//设置粒子大小变化范围
ptemplate.setSizeRange(osgParticle::rangef(0.75f, 3.0f));
//设置例子Alpha变化范围
ptemplate.setAlphaRange(osgParticle::rangef(0.0f, 1.0f));
//设置粒子颜色变化范围
ptemplate.setColorRange(osgParticle::rangev4(
osg::Vec4(1.0f, 0.5f, 0.3f, 1.0f),
osg::Vec4(0.0f, 0.7f, 1.0f, 0.0f)));
//设置半径
ptemplate.setRadius(0.5f);
//设置重量
ptemplate.setMass(0.5f);
//创建粒子系统
osgParticle::ParticleSystem *ps = new osgParticle::ParticleSystem();
//设置材质,是否放射例子,是否添加光照
ps->setDefaultAttributes("Images/smoke.rgb", false, false);
//加入模板
ps->setDefaultParticleTemplate(ptemplate);
//创建粒子放射器(包括计数器,放置器,发射器)
osgParticle::ModularEmitter *emitter = new osgParticle::ModularEmitter();
//关联粒子系统
emitter->setParticleSystem(ps);
//创建发射器计数器,调整每一帧增加的粒子的数目
osgParticle::RandomRateCounter *counter = new osgParticle::RandomRateCounter();
//设置每秒添加的粒子的个数
counter->setRateRange(100.0f, 100.0f);
//关联计数器
emitter->setCounter(counter);
//设置一个点放置器
osgParticle::PointPlacer *placer = new osgParticle::PointPlacer();
//设置位置
placer->setCenter(osg::Vec3(-40.0f,100.0f,10.0f));
//关联点放置器
emitter->setPlacer(placer);
//创建弧度发射器
osgParticle::RadialShooter *shooter = new osgParticle::RadialShooter();
//设置发射器速度变化范围
shooter->setInitialSpeedRange(100, 0);
//关联发射器
emitter->setShooter(shooter);
//加入到场景中
cloud->addChild(emitter);
//创建标准编程器对象,控制粒子在生命周期中的更新
osgParticle::ModularProgram *program = new osgParticle::ModularProgram();
//关联粒子系统
program->setParticleSystem(ps);
//创建重力模拟对象
osgParticle::AccelOperator *ap = new osgParticle::AccelOperator();
//设置重力加速度,默认为9.80665f
ap->setToGravity(-1.0f);
//关联重力
program->addOperator(ap);
//创建空气阻力模拟
osgParticle::FluidFrictionOperator* ffo = new osgParticle::FluidFrictionOperator();
//设置空气属性
//FluidViscosity为1.8e-5f FluidDensity为1.2929f
ffo->setFluidToAir();
//关联空气阻力
program->addOperator(ffo);
//添加到场景
cloud->addChild(program);
//添加更新器,实现每帧粒子的管理
osgParticle::ParticleSystemUpdater* psu = new osgParticle::ParticleSystemUpdater();
//关联粒子系统
psu->addParticleSystem(ps);
//加入场景
osg::Geode *geode = new osg::Geode;
geode->addDrawable(ps);
cloud->addChild(geode);
cloud->addChild(psu);
return cloud ;
}
main 里面添加
//自定义粒子系统加入场景
scene->getOceanScene()->addChild(CreateMyParticleScene()); |
|