Added support for setting the texture filename and more fine control over

the particle template used in ParticleEffects
This commit is contained in:
Robert Osfield
2005-05-11 15:26:16 +00:00
parent 4c613896ff
commit 52666a6dee
6 changed files with 112 additions and 54 deletions

View File

@@ -36,7 +36,6 @@ ExplosionEffect::ExplosionEffect(const osg::Vec3& position, float scale, float i
_intensity = intensity;
_emitterDuration = 1.0;
_particleDuration = 0.5+0.1*_scale;
buildEffect();
}
@@ -50,8 +49,19 @@ void ExplosionEffect::setDefaults()
{
ParticleEffect::setDefaults();
_textureFileName = "Images/smoke.rgb";
_emitterDuration = 1.0;
_particleDuration = 0.5+0.1*_scale;
// set up unit particle.
_defaultParticleTemplate.setLifeTime(0.5+0.1*_scale);
_defaultParticleTemplate.setRadius(1.0f);
_defaultParticleTemplate.setMass(osg::PI*4.0f/3.0f);
_defaultParticleTemplate.setSizeRange(osgParticle::rangef(0.75f, 3.0f));
_defaultParticleTemplate.setAlphaRange(osgParticle::rangef(0.1f, 1.0f));
_defaultParticleTemplate.setColorRange(osgParticle::rangev4(
osg::Vec4(1.0f, 0.8f, 0.2f, 1.0f),
osg::Vec4(1.0f, 0.4f, 0.1f, 0.0f)));
}
@@ -65,26 +75,26 @@ void ExplosionEffect::setUpEmitterAndProgram()
if (_particleSystem.valid())
{
_particleSystem->setDefaultAttributes("Images/smoke.rgb", false, false);
_particleSystem->setDefaultAttributes(_textureFileName, false, false);
osgParticle::Particle& ptemplate = _particleSystem->getDefaultParticleTemplate();
ptemplate.setLifeTime(_particleDuration);
float radius = 0.4f*_scale;
float density = 1.2f; // 1.0kg/m^3
ptemplate.setLifeTime(_defaultParticleTemplate.getLifeTime());
// the following ranges set the envelope of the respective
// graphical properties in time.
ptemplate.setSizeRange(osgParticle::rangef(radius*0.75f, radius*3.0f));
ptemplate.setAlphaRange(osgParticle::rangef(0.1f, 1.0f));
ptemplate.setColorRange(osgParticle::rangev4(
osg::Vec4(1.0f, 0.8f, 0.2f, 1.0f),
osg::Vec4(1.0f, 0.4f, 0.1f, 0.0f)));
ptemplate.setSizeRange(osgParticle::rangef(radius*_defaultParticleTemplate.getSizeRange().minimum,
radius*_defaultParticleTemplate.getSizeRange().maximum));
ptemplate.setAlphaRange(_defaultParticleTemplate.getAlphaRange());
ptemplate.setColorRange(_defaultParticleTemplate.getColorRange());
// these are physical properties of the particle
ptemplate.setRadius(radius); // 5 cm wide particles
ptemplate.setMass(density*osg::PI*4.0f*radius*radius*radius/3.0f);
float r = _defaultParticleTemplate.getRadius()*radius;
ptemplate.setRadius(r);
ptemplate.setMass(density*r*r*r*_defaultParticleTemplate.getMass());
}