diff --git a/src/modules/graphics/ParticleSystem.cpp b/src/modules/graphics/ParticleSystem.cpp index 2a4f2accf..fdb445fc0 100644 --- a/src/modules/graphics/ParticleSystem.cpp +++ b/src/modules/graphics/ParticleSystem.cpp @@ -242,6 +242,7 @@ void ParticleSystem::initParticle(Particle *p, float t) p->position = pos; + float rand_x, rand_y; switch (areaSpreadDistribution) { case DISTRIBUTION_UNIFORM: @@ -252,6 +253,12 @@ void ParticleSystem::initParticle(Particle *p, float t) p->position.x += (float) rng.randomNormal(areaSpread.getX()); p->position.y += (float) rng.randomNormal(areaSpread.getY()); break; + case DISTRIBUTION_ELLIPSE: + rand_x = (float) rng.random(-1, 1); + rand_y = (float) rng.random(-1, 1); + p->position.x += areaSpread.getX() * (rand_x * sqrt(1 - 0.5f*pow(rand_y, 2))); + p->position.y += areaSpread.getY() * (rand_y * sqrt(1 - 0.5f*pow(rand_x, 2))); + break; case DISTRIBUTION_NONE: default: break; @@ -969,6 +976,7 @@ StringMap ParticleSystem::distributions(ParticleSystem::distributionsEntries, sizeof(ParticleSystem::distributionsEntries)); diff --git a/src/modules/graphics/ParticleSystem.h b/src/modules/graphics/ParticleSystem.h index cae0307d4..b95941c30 100644 --- a/src/modules/graphics/ParticleSystem.h +++ b/src/modules/graphics/ParticleSystem.h @@ -46,13 +46,14 @@ class ParticleSystem : public Drawable { public: /** - * Type of distribution new particles are drawn from: None, uniform, normal. + * Type of distribution new particles are drawn from: None, uniform, normal, ellipse. */ enum AreaSpreadDistribution { DISTRIBUTION_NONE, DISTRIBUTION_UNIFORM, DISTRIBUTION_NORMAL, + DISTRIBUTION_ELLIPSE, DISTRIBUTION_MAX_ENUM };