diff --git a/include/osgParticle/SectorPlacer b/include/osgParticle/SectorPlacer index 9d31357cd..5e79516f2 100644 --- a/include/osgParticle/SectorPlacer +++ b/include/osgParticle/SectorPlacer @@ -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( diff --git a/include/osgParticle/range b/include/osgParticle/range index 03f5c0255..f48087afb 100644 --- a/include/osgParticle/range +++ b/include/osgParticle/range @@ -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(rand()) / static_cast(RAND_MAX) ); + } + }; /// Range of floats. diff --git a/src/osgParticle/Particle.cpp b/src/osgParticle/Particle.cpp index 06307aa88..3ad314505 100644 --- a/src/osgParticle/Particle.cpp +++ b/src/osgParticle/Particle.cpp @@ -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_;