|
楼主 |
发表于 2009-7-14 15:12:51
|
显示全部楼层
下面是我的代码,不知道如何设置????一直都对osg粒子系统比较模糊,希望能解决
osg::Group* pGroup = new osg::Group;
//创建粒子系统模板
osgParticle:article ptemplate;
//设置生命周期
ptemplate.setLifeTime(1);
//设置粒子大小变化范围
ptemplate.setSizeRange(osgParticle::rangef(0.01f, 0.03f));
//设置例子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.1f);
//设置重量
ptemplate.setMass(0.01f);
ptemplate.setShape(osgParticle::Particle:UAD);
//创建粒子系统
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);
emitter->setEndless(true);
//创建发射器计数器,调整每一帧增加的粒子的数目
m_pCounter = new osgParticle::RandomRateCounter();
//设置每秒添加的粒子的个数
m_pCounter->setRateRange(100.0f, 100.0f);
//关联计数器
emitter->setCounter(m_pCounter.get());
//设置一个点放置器
m_pPlacer = new osgParticle::PointPlacer();
//设置位置
m_pPlacer->setCenter(osg::Vec3(0.0f,0.0f,0.0f));
//关联点放置器
emitter->setPlacer(m_pPlacer.get());
//创建弧度发射器
m_pShooter = new osgParticle::RadialShooter();
//设置发射器速度变化范围
m_pShooter->setInitialSpeedRange(0.0001, 0.0001);
//m_pShooter->setThetaRange(osg::inDegrees(-90.f),osg::inDegrees(-90.f));
//m_pShooter->setPhiRange(osg::inDegrees(0.f),osg::inDegrees(360.f));
//关联发射器
emitter->setShooter(m_pShooter.get());
//加入到场景中
pGroup->addChild(emitter);
//创建标准编程器对象,控制粒子在生命周期中的更新
osgParticle::ModularProgram *program = new osgParticle::ModularProgram();
//关联粒子系统
program->setParticleSystem(ps);
//添加到场景
pGroup->addChild(program);
//添加更新器,实现每帧粒子的管理
osgParticle::ParticleSystemUpdater* psu = new osgParticle::ParticleSystemUpdater();
//关联粒子系统
psu->addParticleSystem(ps);
//加入场景
osg::Geode *geode = new osg::Geode;
geode->addDrawable(ps);
pGroup->addChild(psu); |
|