From 9a4b92160585657347a8f9a7fe96fff443714d58 Mon Sep 17 00:00:00 2001 From: rude Date: Sun, 24 Jul 2011 18:47:13 +0200 Subject: [PATCH] Particles now have fixed origin. (ParticleSystem::SetPosition will only affect new particles, and existing particles will not gravitate against the new point). This is another requirement to implement ParticleSystem in GLSL. --- src/modules/graphics/opengl/ParticleSystem.cpp | 4 +++- src/modules/graphics/opengl/ParticleSystem.h | 3 +++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/modules/graphics/opengl/ParticleSystem.cpp b/src/modules/graphics/opengl/ParticleSystem.cpp index 2d8a5fe6a..a5044d6c5 100644 --- a/src/modules/graphics/opengl/ParticleSystem.cpp +++ b/src/modules/graphics/opengl/ParticleSystem.cpp @@ -95,6 +95,8 @@ namespace opengl max = direction + spread/2.0f; pLast->direction = (rand() / (float(RAND_MAX)+1)) * (max - min) + min; + pLast->origin = position; + min = speedMin; max = speedMax; float speed = (rand() / (float(RAND_MAX)+1)) * (max - min) + min; @@ -447,7 +449,7 @@ namespace opengl love::Vector ppos(p->position[0], p->position[1]); // Get vector from particle center to particle. - radial = ppos - position; + radial = ppos - p->origin; radial.normalize(); tangential = radial; diff --git a/src/modules/graphics/opengl/ParticleSystem.h b/src/modules/graphics/opengl/ParticleSystem.h index 0af4f0bd6..6514d1568 100644 --- a/src/modules/graphics/opengl/ParticleSystem.h +++ b/src/modules/graphics/opengl/ParticleSystem.h @@ -46,6 +46,9 @@ namespace opengl float position[2]; float direction; + // Particles gravitate towards this point. + love::Vector origin; + love::Vector speed; float gravity; float radialAcceleration;