Skip to content

Commit 43fcacc

Browse files
committed
Merged in nkorth/love (pull request #70)
Add 'ellipse' distribution to ParticleSystem
2 parents ba21512 + 53c528a commit 43fcacc

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

Diff for: src/modules/graphics/ParticleSystem.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@ void ParticleSystem::initParticle(Particle *p, float t)
242242

243243
p->position = pos;
244244

245+
float rand_x, rand_y;
245246
switch (areaSpreadDistribution)
246247
{
247248
case DISTRIBUTION_UNIFORM:
@@ -252,6 +253,12 @@ void ParticleSystem::initParticle(Particle *p, float t)
252253
p->position.x += (float) rng.randomNormal(areaSpread.getX());
253254
p->position.y += (float) rng.randomNormal(areaSpread.getY());
254255
break;
256+
case DISTRIBUTION_ELLIPSE:
257+
rand_x = (float) rng.random(-1, 1);
258+
rand_y = (float) rng.random(-1, 1);
259+
p->position.x += areaSpread.getX() * (rand_x * sqrt(1 - 0.5f*pow(rand_y, 2)));
260+
p->position.y += areaSpread.getY() * (rand_y * sqrt(1 - 0.5f*pow(rand_x, 2)));
261+
break;
255262
case DISTRIBUTION_NONE:
256263
default:
257264
break;
@@ -969,6 +976,7 @@ StringMap<ParticleSystem::AreaSpreadDistribution, ParticleSystem::DISTRIBUTION_M
969976
{ "none", DISTRIBUTION_NONE },
970977
{ "uniform", DISTRIBUTION_UNIFORM },
971978
{ "normal", DISTRIBUTION_NORMAL },
979+
{ "ellipse", DISTRIBUTION_ELLIPSE },
972980
};
973981

974982
StringMap<ParticleSystem::AreaSpreadDistribution, ParticleSystem::DISTRIBUTION_MAX_ENUM> ParticleSystem::distributions(ParticleSystem::distributionsEntries, sizeof(ParticleSystem::distributionsEntries));

Diff for: src/modules/graphics/ParticleSystem.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,14 @@ class ParticleSystem : public Drawable
4646
{
4747
public:
4848
/**
49-
* Type of distribution new particles are drawn from: None, uniform, normal.
49+
* Type of distribution new particles are drawn from: None, uniform, normal, ellipse.
5050
*/
5151
enum AreaSpreadDistribution
5252
{
5353
DISTRIBUTION_NONE,
5454
DISTRIBUTION_UNIFORM,
5555
DISTRIBUTION_NORMAL,
56+
DISTRIBUTION_ELLIPSE,
5657
DISTRIBUTION_MAX_ENUM
5758
};
5859

0 commit comments

Comments
 (0)