From Tom Jolly. a couple of small changes to osgParticle.

"The first is with
Particle.cpp.  I made a change so that when the lifetime is 0 (lasts
forever) the sizeRange, colorRange, and alphaRange are used to create
a random size, color, and alpha."

"The second change is with range and SectorPlacer.  The distribution of
particles across the sector was not uniform.  I added get_random_sqrtf()
function where it is used in SectorPlacer::Place().  This seems to make
the distribution uniform (at least when minimum radius is 0)."
This commit is contained in:
Robert Osfield
2004-08-02 07:25:28 +00:00
parent e9a3420fa9
commit e122b34858
3 changed files with 18 additions and 4 deletions

View File

@@ -116,7 +116,7 @@ namespace osgParticle
inline void SectorPlacer::place(Particle *P) const
{
float rad = rad_range_.get_random();
float rad = rad_range_.get_random_sqrtf();
float phi = phi_range_.get_random();
osg::Vec3 pos(

View File

@@ -64,6 +64,12 @@ namespace osgParticle
return minimum + (maximum - minimum) * rand() / RAND_MAX;
}
/// Get a random square root value between min and max.
T_ get_random_sqrtf() const
{
return minimum + (maximum - minimum) * sqrtf( static_cast<float>(rand()) / static_cast<float>(RAND_MAX) );
}
};
/// Range of floats.

View File

@@ -86,9 +86,17 @@ bool osgParticle::Particle::update(double dt)
}
// compute the current values for size, alpha and color.
current_size_ = si_.get()->interpolate(x, sr_);
current_alpha_ = ai_.get()->interpolate(x, ar_);
current_color_ = ci_.get()->interpolate(x, cr_);
if (lifetime_ <= 0) {
if (dt == t0_) {
current_size_ = sr_.get_random();
current_alpha_ = ar_.get_random();
current_color_ = cr_.get_random();
}
} else {
current_size_ = si_.get()->interpolate(x, sr_);
current_alpha_ = ai_.get()->interpolate(x, ar_);
current_color_ = ci_.get()->interpolate(x, cr_);
}
// update position
prev_pos_ = position_;