osgParticle.ConnectedParticleSystem
是基于粒子系统的扩展类,它允许在粒子系统之间创建连接,使得它们可以相互影响,从而创建更复杂的粒子效果。
osgParticle.ParticleSystem
osgParticle.ConnectedParticleSystem
要创建连接,可以使用下面的代码:
osgParticle.ConnectedParticleSystem* system1 = new osgParticle.ConnectedParticleSystem;
osgParticle.ConnectedParticleSystem* system2 = new osgParticle.ConnectedParticleSystem;
// 创建直线连接
osgParticle.BasicLineSegmentEmitter* emitter1 = new osgParticle.BasicLineSegmentEmitter;
osgParticle.BasicLineSegmentEmitter* emitter2 = new osgParticle.BasicLineSegmentEmitter;
osgParticle.ParticleSystemUpdater* updater1 = new osgParticle.ParticleSystemUpdater;
osgParticle.ParticleSystemUpdater* updater2 = new osgParticle.ParticleSystemUpdater;
osgParticle.ParticleSystem::ParticlePair pair(system1, emitter1, updater1, system2, emitter2, updater2, false);
system1->addParticlePair(pair);
system2->addParticlePair(pair);
要设置连接的属性,可以使用osgParticle.ParticlePair
和osgParticle.ParticleConnector
类的方法。例如,要设置连接的距离和角度限制,可以使用以下代码:
osgParticle.ParticlePair pair;
osgParticle.ParticleConnector* connector = pair.getConnector();
connector->setSourceMinDistance(1.0f);
connector->setSourceMaxDistance(5.0f);
connector->setSourceMinAngle(0.0f);
connector->setSourceMaxAngle(180.0f);
system1->addParticlePair(pair);
system2->addParticlePair(pair);
要在连接的两端定义触发器,可以使用以下代码:
osgParticle.ParticlePair pair;
osgParticle.ParticleConnector* connector = pair.getConnector();
connector->setSourceTrigger(new osgParticle.RandomRateCounter(10.0f, 20.0f));
connector->setTargetTrigger(new osgParticle.RandomRateCounter(5.0f, 10.0f));
system1->addParticlePair(pair);
system2->addParticlePair(pair);
要在连接的两端定义生成器和转移器,可以使用以下代码:
osgParticle.ParticlePair pair;
osgParticle.ParticleConnector* connector = pair.getConnector();
osgParticle.ParticleEffect* effect1 = new osgParticle.ParticleEffect;
effect1->getDefaultParticleTemplate().setLifeTime(1.0f);
effect1->getDefaultParticleTemplate().setShape(osgParticle.Particle::QUAD);
effect1->getDefaultParticleTemplate().setSizeRange(osgParticle.Rangev2(1.0f, 2.0f));
effect1->getDefaultParticleTemplate().setColorRange(osgParticle.createRange(osg::Vec4(1.0f, 0.0f, 0.0f, 1.0f), osg::Vec4(0.0f, 0.0f, 1.0f, 0.0f)));
osgParticle.ParticleGenerator* generator1 = new osgParticle.ParticleGenerator(effect1);
generator1->setParticleSystem(system1);
osgParticle.ParticleEffect* effect2 = new osgParticle.ParticleEffect;
effect2->getDefaultParticleTemplate().setLifeTime(2.0f);
effect2->getDefaultParticleTemplate().setShape(osgParticle.Particle::HEXAGON);
effect2->getDefaultParticleTemplate().setSizeRange(osgParticle.Rangev2(2.0f, 4.0f));
effect2->getDefaultParticleTemplate().setColorRange(osgParticle.createRange(osg::Vec4(0.0f, 1.0f, 0.0f, 1.0f), osg::Vec4(1.0f, 1.0f, 1.0f, 0.0f)));
osgParticle.ParticleGenerator* generator2 = new osgParticle.ParticleGenerator(effect2);
generator2->setParticleSystem(system2);
osgParticle.ParticleTransfer* transfer1 = new osgParticle.ParticleTransfer(1.0f, osgParticle.ParticleTransfer::ADD_PARTICLE);
connector->setSourceGenerator(generator1);
connector->setTargetGenerator(generator2);
connector->setSourceTransfer(transfer1);
system1->addParticlePair(pair);
system2->addParticlePair(pair);
要在连接的两端定义管理器,可以使用以下代码:
osgParticle.ParticlePair pair;
osgParticle.ParticleConnector* connector = pair.getConnector();
osgParticle.ParticleEffect* effect1 = new osgParticle.ParticleEffect;
effect1->getDefaultParticleTemplate().setLifeTime(1.0f);
effect1->getDefaultParticleTemplate().setShape(osgParticle.Particle::QUAD);
effect1->getDefaultParticleTemplate().setSizeRange(osgParticle.Rangev2(1.0f, 2.0f));
effect1->getDefaultParticleTemplate().setColorRange(osgParticle.createRange(osg::Vec4(1.0f, 0.0f, 0.0f, 1.0f), osg::Vec4(0.0f, 0.0f, 1.0f, 0.0f)));
osgParticle.ParticleGenerator* generator1 = new osgParticle.ParticleGenerator(effect1);
generator1->setParticleSystem(system1);
osgParticle.ParticleEffect* effect2 = new osgParticle.ParticleEffect;
effect2->getDefaultParticleTemplate().setLifeTime(2.0f);
effect2->getDefaultParticleTemplate().setShape(osgParticle.Particle::HEXAGON);
effect2->getDefaultParticleTemplate().setSizeRange(osgParticle.Rangev2(2.0f, 4.0f));
effect2->getDefaultParticleTemplate().setColorRange(osgParticle.createRange(osg::Vec4(0.0f, 1.0f, 0.0f, 1.0f), osg::Vec4(1.0f, 1.0f, 1.0f, 0.0f)));
osgParticle.ParticleGenerator* generator2 = new osgParticle.ParticleGenerator(effect2);
generator2->setParticleSystem(system2);
osgParticle.ParticleTransfer* transfer1 = new osgParticle.ParticleTransfer(1.0f, osgParticle.ParticleTransfer::ADD_PARTICLE);
connector->setSourceGenerator(generator1);
connector->setTargetGenerator(generator2);
connector->setSourceTransfer(transfer1);
osgParticle.Counter* counter1 = new osgParticle.FrameCounter(200);
osgParticle.Counter* counter2 = new osgParticle.FrameCounter(100);
osgParticle.Collector* collector1 = new osgParticle.Collector;
osgParticle.Collector* collector2 = new osgParticle.Collector;
osgParticle.Sink* sink1 = new osgParticle.Sink;
osgParticle.Sink* sink2 = new osgParticle.Sink;
connector->setSourceManager(new osgParticle.ParticleManager(counter1, collector1, sink1));
connector->setTargetManager(new osgParticle.ParticleManager(counter2, collector2, sink2));
system1->addParticlePair(pair);
system2->addParticlePair(pair);