Explorar o código

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.

rude %!s(int64=14) %!d(string=hai) anos
pai
achega
9a4b921605

+ 3 - 1
src/modules/graphics/opengl/ParticleSystem.cpp

@@ -95,6 +95,8 @@ namespace opengl
 		max = direction + spread/2.0f;
 		max = direction + spread/2.0f;
 		pLast->direction = (rand() / (float(RAND_MAX)+1)) * (max - min) + min;
 		pLast->direction = (rand() / (float(RAND_MAX)+1)) * (max - min) + min;
 
 
+		pLast->origin = position;
+
 		min = speedMin;
 		min = speedMin;
 		max = speedMax;
 		max = speedMax;
 		float speed = (rand() / (float(RAND_MAX)+1)) * (max - min) + min;
 		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]);
 				love::Vector ppos(p->position[0], p->position[1]);
 
 
 				// Get vector from particle center to particle.
 				// Get vector from particle center to particle.
-				radial = ppos - position;
+				radial = ppos - p->origin;
 				radial.normalize();
 				radial.normalize();
 				tangential = radial;
 				tangential = radial;
 
 

+ 3 - 0
src/modules/graphics/opengl/ParticleSystem.h

@@ -46,6 +46,9 @@ namespace opengl
 		float position[2];
 		float position[2];
 		float direction;
 		float direction;
 
 
+		// Particles gravitate towards this point.
+		love::Vector origin;
+
 		love::Vector speed;
 		love::Vector speed;
 		float gravity;
 		float gravity;
 		float radialAcceleration;
 		float radialAcceleration;