Added extra controls for ParticleEffects.

This commit is contained in:
Robert Osfield
2005-03-23 17:05:21 +00:00
parent 60597f4bbb
commit aee1e88f15
10 changed files with 239 additions and 139 deletions

View File

@@ -27,9 +27,15 @@
using namespace osgParticle;
ExplosionEffect::ExplosionEffect()
ExplosionEffect::ExplosionEffect(const osg::Vec3& position, float scale, float intensity)
{
setDefaults();
_position = position;
_scale = scale;
_intensity = intensity;
buildEffect();
}
ExplosionEffect::ExplosionEffect(const ExplosionEffect& copy, const osg::CopyOp& copyop):
@@ -38,6 +44,11 @@ ExplosionEffect::ExplosionEffect(const ExplosionEffect& copy, const osg::CopyOp&
}
void ExplosionEffect::setDefaults()
{
ParticleEffect::setDefaults();
}
void ExplosionEffect::setUpEmitterAndProgram()
{
osgParticle::ParticleSystem *ps = new osgParticle::ParticleSystem;
ps->setDefaultAttributes("Images/particle.rgb", false, false);
@@ -64,28 +75,28 @@ void ExplosionEffect::setDefaults()
osg::Vec4(0.5, 0.5f, 0.0f, 0.0f)));
// these are physical properties of the particle
ptemplate.setRadius(0.1f); // 5 cm wide particles
ptemplate.setMass(1.0f); // 1kg heavy
ptemplate.setRadius(0.1f*_scale); // 5 cm wide particles
ptemplate.setMass(1.0f*_scale); // 1kg heavy
// assign the particle template to the system.
ps->setDefaultParticleTemplate(ptemplate);
//osgParticle::LimitedDurationRandomRateCounter* counter = new osgParticle::LimitedDurationRandomRateCounter;
osgParticle::RandomRateCounter* counter = new osgParticle::RandomRateCounter;
counter->setRateRange(2000,2000); // generate 1000 particles per second
counter->setRateRange(2000*_intensity,2000*_intensity); // generate 1000 particles per second
emitter->setCounter(counter);
osgParticle::SectorPlacer* placer = new osgParticle::SectorPlacer;
placer->setCenter(osg::Vec3(0.0,0.0,0.0));
placer->setRadiusRange(0.0f,1.0f);
placer->setCenter(_position);
placer->setRadiusRange(0.0f,1.0f*_scale);
emitter->setPlacer(placer);
osgParticle::RadialShooter* shooter = new osgParticle::RadialShooter;
shooter->setThetaRange(0.0f, osg::PI_2);
shooter->setInitialSpeedRange(5.0f,30.0f);
shooter->setInitialSpeedRange(5.0f*_scale,30.0f*_scale);
emitter->setShooter(shooter);
emitter->setStartTime(0.0f);
emitter->setStartTime(_startTime);
emitter->setResetTime(5.0f);
emitter->setLifeTime(0.1f);
emitter->setEndless(false);
@@ -113,29 +124,5 @@ void ExplosionEffect::setDefaults()
}
buildEffect();
}
void ExplosionEffect::buildEffect()
{
// clear the children.
removeChild(0,getNumChildren());
if (!_emitter || !_particleSystem || !_program) return;
// add the emitter
addChild(_emitter.get());
// add the program to update the particles
addChild(_program.get());
// add the particle system updater.
osgParticle::ParticleSystemUpdater *psu = new osgParticle::ParticleSystemUpdater;
psu->addParticleSystem(_particleSystem.get());
addChild(psu);
// add the geode to the scene graph
osg::Geode *geode = new osg::Geode;
geode->addDrawable(_particleSystem.get());
addChild(geode);
}

View File

@@ -26,9 +26,15 @@
using namespace osgParticle;
FireEffect::FireEffect()
FireEffect::FireEffect(const osg::Vec3& position, float scale, float intensity)
{
setDefaults();
_position = position;
_scale = scale;
_intensity = intensity;
buildEffect();
}
FireEffect::FireEffect(const FireEffect& copy, const osg::CopyOp& copyop):
@@ -37,6 +43,11 @@ FireEffect::FireEffect(const FireEffect& copy, const osg::CopyOp& copyop):
}
void FireEffect::setDefaults()
{
ParticleEffect::setDefaults();
}
void FireEffect::setUpEmitterAndProgram()
{
osgParticle::ParticleSystem *ps = new osgParticle::ParticleSystem;
ps->setDefaultAttributes("Images/smoke.rgb", true, false);
@@ -64,27 +75,27 @@ void FireEffect::setDefaults()
osg::Vec4(1, 0.0f, 0.f, 0.0f)));
// these are physical properties of the particle
ptemplate.setRadius(0.05f); // 5 cm wide particles
ptemplate.setMass(0.01f); // 10g heavy
ptemplate.setRadius(0.05f*_scale); // 5 cm wide particles
ptemplate.setMass(0.01f*_scale); // 10g heavy
// assign the particle template to the system.
ps->setDefaultParticleTemplate(ptemplate);
osgParticle::RandomRateCounter* counter = new osgParticle::RandomRateCounter;
counter->setRateRange(1,10); // generate 1000 particles per second
counter->setRateRange(1*_intensity*_scale,10*_intensity*_scale); // generate 1000 particles per second
emitter->setCounter(counter);
osgParticle::SectorPlacer* placer = new osgParticle::SectorPlacer;
placer->setCenter(osg::Vec3(0.0,0.0,0.0));
placer->setRadiusRange(0.0f,0.25f);
placer->setCenter(_position);
placer->setRadiusRange(0.0f*_scale,0.25f*_scale);
emitter->setPlacer(placer);
osgParticle::RadialShooter* shooter = new osgParticle::RadialShooter;
shooter->setThetaRange(0.0f, osg::PI_4);
shooter->setInitialSpeedRange(0.0f,0.0f);
shooter->setInitialSpeedRange(0.0f*_scale,0.0f*_scale);
emitter->setShooter(shooter);
emitter->setStartTime(0.0f);
emitter->setStartTime(_startTime);
_emitter = emitter;
}
@@ -108,31 +119,4 @@ void FireEffect::setDefaults()
// add the program to the scene graph
_program = program;
}
buildEffect();
}
void FireEffect::buildEffect()
{
// clear the children.
removeChild(0,getNumChildren());
if (!_emitter || !_particleSystem || !_program) return;
// add the emitter
addChild(_emitter.get());
// add the program to update the particles
addChild(_program.get());
// add the particle system updater.
osgParticle::ParticleSystemUpdater *psu = new osgParticle::ParticleSystemUpdater;
psu->addParticleSystem(_particleSystem.get());
addChild(psu);
// add the geode to the scene graph
osg::Geode *geode = new osg::Geode;
geode->addDrawable(_particleSystem.get());
addChild(geode);
}

View File

@@ -12,13 +12,80 @@
*/
#include <osgParticle/ParticleEffect>
#include <osgParticle/ParticleSystemUpdater>
#include <osg/Geode>
using namespace osgParticle;
ParticleEffect::ParticleEffect(const ParticleEffect& copy, const osg::CopyOp& copyop):
osg::Group(copy,copyop)/*,
_emitter(),
_program(),
_particleSystem(copy._particleSystem.valid()?copy._particleSystem->clone():0)*/
{
}
void ParticleEffect::setPosition(const osg::Vec3& position)
{
_position = position;
}
void ParticleEffect::setScale(float scale)
{
_scale = scale;
}
void ParticleEffect::setIntensity(float intensity)
{
_intensity = intensity;
}
void ParticleEffect::setStartTime(double startTime)
{
_startTime = startTime;
}
void ParticleEffect::setDuration(double duration)
{
_duration = duration;
}
void ParticleEffect::setDefaults()
{
_scale = 1.0f;
_intensity = 1.0f;
_startTime = 0.0;
_duration = 1.0;
_direction.set(0.0f,0.0f,1.0f);
}
void ParticleEffect::buildEffect()
{
setUpEmitterAndProgram();
Emitter* emitter = getEmitter();
Program* program = getProgram();
ParticleSystem* particleSystem = getParticleSystem();
if (!emitter || !particleSystem || !program) return;
// clear the children.
removeChild(0,getNumChildren());
// add the emitter
addChild(emitter);
// add the program to update the particles
addChild(program);
// add the particle system updater.
osgParticle::ParticleSystemUpdater *psu = new osgParticle::ParticleSystemUpdater;
psu->addParticleSystem(particleSystem);
addChild(psu);
// add the geode to the scene graph
osg::Geode *geode = new osg::Geode;
geode->addDrawable(particleSystem);
addChild(geode);
}

View File

@@ -13,8 +13,6 @@
#include <osgParticle/SmokeEffect>
#include <osgParticle/ModularEmitter>
#include <osgParticle/ModularProgram>
#include <osgParticle/RandomRateCounter>
#include <osgParticle/RadialShooter>
#include <osgParticle/AccelOperator>
@@ -26,9 +24,15 @@
using namespace osgParticle;
SmokeEffect::SmokeEffect()
SmokeEffect::SmokeEffect(const osg::Vec3& position, float scale, float intensity)
{
setDefaults();
_position = position;
_scale = scale;
_intensity = intensity;
buildEffect();
}
SmokeEffect::SmokeEffect(const SmokeEffect& copy, const osg::CopyOp& copyop):
@@ -37,6 +41,11 @@ SmokeEffect::SmokeEffect(const SmokeEffect& copy, const osg::CopyOp& copyop):
}
void SmokeEffect::setDefaults()
{
ParticleEffect::setDefaults();
}
void SmokeEffect::setUpEmitterAndProgram()
{
osgParticle::ParticleSystem *ps = new osgParticle::ParticleSystem;
@@ -54,35 +63,35 @@ void SmokeEffect::setDefaults()
osgParticle::Particle ptemplate;
ptemplate.setLifeTime(10); // 3 seconds of life
ptemplate.setLifeTime(10*_scale);
// the following ranges set the envelope of the respective
// graphical properties in time.
ptemplate.setSizeRange(osgParticle::rangef(0.75f, 3.0f));
ptemplate.setAlphaRange(osgParticle::rangef(0.0f, 1.0f));
ptemplate.setAlphaRange(osgParticle::rangef(0.1f, 1.0f));
ptemplate.setColorRange(osgParticle::rangev4(
osg::Vec4(1, 1.0f, 1.0f, 1.0f),
osg::Vec4(1, 1.0f, 1.f, 0.0f)));
// these are physical properties of the particle
ptemplate.setRadius(0.05f); // 5 cm wide particles
ptemplate.setMass(0.01f); // 10g heavy
ptemplate.setRadius(0.05f*_scale); // 5 cm wide particles
ptemplate.setMass(0.01f*_scale); // 10g heavy
// assign the particle template to the system.
ps->setDefaultParticleTemplate(ptemplate);
osgParticle::RandomRateCounter* counter = new osgParticle::RandomRateCounter;
counter->setRateRange(1,2); // generate 1000 particles per second
counter->setRateRange(1*_intensity*_scale,2*_intensity*_scale); // generate 1000 particles per second
emitter->setCounter(counter);
osgParticle::SectorPlacer* placer = new osgParticle::SectorPlacer;
placer->setCenter(osg::Vec3(0.0,0.0,0.0));
placer->setRadiusRange(0.0f,0.5f);
placer->setCenter(_position);
placer->setRadiusRange(0.0f*_scale,0.25f*_scale);
emitter->setPlacer(placer);
osgParticle::RadialShooter* shooter = new osgParticle::RadialShooter;
shooter->setThetaRange(0.0f, osg::PI_4);
shooter->setInitialSpeedRange(0.0f,0.0f);
shooter->setInitialSpeedRange(0.0f*_scale,0.0f*_scale);
emitter->setShooter(shooter);
emitter->setStartTime(0.0f);
@@ -108,30 +117,4 @@ void SmokeEffect::setDefaults()
_program = program;
}
buildEffect();
}
void SmokeEffect::buildEffect()
{
// clear the children.
removeChild(0,getNumChildren());
if (!_emitter || !_particleSystem || !_program) return;
// add the emitter
addChild(_emitter.get());
// add the program to update the particles
addChild(_program.get());
// add the particle system updater.
osgParticle::ParticleSystemUpdater *psu = new osgParticle::ParticleSystemUpdater;
psu->addParticleSystem(_particleSystem.get());
addChild(psu);
// add the geode to the scene graph
osg::Geode *geode = new osg::Geode;
geode->addDrawable(_particleSystem.get());
addChild(geode);
}