Commits

Alex Szpakowski committed b9c1c97

Added ParticleSystem:setLinearAcceleration(xmin, ymin, xmax, ymax) and removed ParticleSystem:setGravity (issue #599)

Comments (0)

Files changed (4)

src/modules/graphics/opengl/ParticleSystem.cpp

 	, relative(false)
 	, speedMin(0)
 	, speedMax(0)
-	, gravityMin(0)
-	, gravityMax(0)
 	, radialAccelerationMin(0)
 	, radialAccelerationMax(0)
 	, tangentialAccelerationMin(0)
 	pLast->speed = love::Vector(cos(pLast->direction), sin(pLast->direction));
 	pLast->speed *= speed;
 
-	min = gravityMin;
-	max = gravityMax;
-	pLast->gravity = rng.random(min, max);
+	pLast->linearAcceleration.x = rng.random(linearAccelerationMin.x, linearAccelerationMax.x);
+	pLast->linearAcceleration.y = rng.random(linearAccelerationMin.y, linearAccelerationMax.y);
 
 	min = radialAccelerationMin;
 	max = radialAccelerationMax;
 		*max = speedMax;
 }
 
-void ParticleSystem::setGravity(float gravity)
+void ParticleSystem::setLinearAcceleration(float x, float y)
 {
-	gravityMin = gravityMax = gravity;
+	linearAccelerationMin.x = linearAccelerationMax.x = x;
+	linearAccelerationMin.y = linearAccelerationMax.y = y;
 }
 
-void ParticleSystem::setGravity(float min, float max)
+void ParticleSystem::setLinearAcceleration(float xmin, float ymin, float xmax, float ymax)
 {
-	gravityMin = min;
-	gravityMax = max;
+	linearAccelerationMin = love::Vector(xmin, ymin);
+	linearAccelerationMax = love::Vector(xmax, ymax);
 }
 
-void ParticleSystem::getGravity(float *min, float *max) const
+void ParticleSystem::getLinearAcceleration(love::Vector *min, love::Vector *max) const
 {
 	if (min)
-		*min = gravityMin;
+		*min = linearAccelerationMin;
 	if (max)
-		*max = gravityMax;
+		*max = linearAccelerationMax;
 }
 
 void ParticleSystem::setRadialAcceleration(float acceleration)
 		{
 
 			// Temp variables.
-			love::Vector radial, tangential, gravity(0, p->gravity);
+			love::Vector radial, tangential;
 			love::Vector ppos(p->position[0], p->position[1]);
 
 			// Get vector from particle center to particle.
 			tangential *= p->tangentialAcceleration;
 
 			// Update position.
-			p->speed += (radial+tangential+gravity)*dt;
+			p->speed += (radial+tangential+p->linearAcceleration)*dt;
 
 			// Modify position.
 			ppos += p->speed * dt;

src/modules/graphics/opengl/ParticleSystem.h

 	love::Vector origin;
 
 	love::Vector speed;
-	float gravity;
+	love::Vector linearAcceleration;
 	float radialAcceleration;
 	float tangentialAcceleration;
 
 	void getSpeed(float *min, float *max) const;
 
 	/**
-	 * Sets the gravity of the particles (the acceleration along the y-axis).
-	 * @param gravity The amount of gravity.
+	 * Sets the linear acceleration (the acceleration along the x and y axes).
+	 * @param x The acceleration along the x-axis.
+	 * @param y The acceleration along the y-axis.
 	 **/
-	void setGravity(float gravity);
+	void setLinearAcceleration(float x, float y);
 
 	/**
-	 * Sets the gravity of the particles (the acceleration along the y-axis).
-	 * @param min The minimum gravity.
-	 * @param max The maximum gravity.
+	 * Sets the linear acceleration (the acceleration along the x and y axes).
+	 * @param xmin The minimum amount of acceleration along the x-axis.
+	 * @param ymin The minimum amount of acceleration along the y-axis.
+	 * @param xmax The maximum amount of acceleration along the x-axis.
+	 * @param ymax The maximum amount of acceleration along the y-axis.
 	 **/
-	void setGravity(float min, float max);
+	void setLinearAcceleration(float xmin, float ymin, float xmax, float ymax);
 
 	/**
-	 * Gets the gravity (y-axis acceleration) of the particles.
-	 * @param[out] min
-	 * @param[out] max
+	 * Gets the linear acceleration of the particles.
+	 * @param[out] min The minimum acceleration.
+	 * @param[out] max The maximum acceleration.
 	 **/
-	void getGravity(float *min, float *max) const;
+	void getLinearAcceleration(love::Vector *min, love::Vector *max) const;
 
 	/**
 	 * Sets the radial acceleration (the acceleration towards the particle emitter).
 	float speedMin;
 	float speedMax;
 
-	// Acceleration towards the bottom of the screen
-	float gravityMin;
-	float gravityMax;
+	// Acceleration along the x and y axes.
+	love::Vector linearAccelerationMin;
+	love::Vector linearAccelerationMax;
 
 	// Acceleration towards the emitter's center
 	float radialAccelerationMin;

src/modules/graphics/opengl/wrap_ParticleSystem.cpp

 	return 2;
 }
 
-int w_ParticleSystem_setGravity(lua_State *L)
+int w_ParticleSystem_setLinearAcceleration(lua_State *L)
 {
 	ParticleSystem *t = luax_checkparticlesystem(L, 1);
-	float arg1 = (float)luaL_checknumber(L, 2);
-	float arg2 = (float)luaL_optnumber(L, 3, arg1);
-	t->setGravity(arg1, arg2);
+	float xmin = (float) luaL_optnumber(L, 2, 0.0);
+	float ymin = (float) luaL_optnumber(L, 3, 0.0);
+	float xmax = (float) luaL_optnumber(L, 4, xmin);
+	float ymax = (float) luaL_optnumber(L, 5, ymin);
+	t->setLinearAcceleration(xmin, ymin, xmax, ymax);
 	return 0;
 }
 
-int w_ParticleSystem_getGravity(lua_State *L)
+int w_ParticleSystem_getLinearAcceleration(lua_State *L)
 {
 	ParticleSystem *t = luax_checkparticlesystem(L, 1);
-	float min, max;
-	t->getGravity(&min, &max);
-	lua_pushnumber(L, min);
-	lua_pushnumber(L, max);
-	return 2;
+	love::Vector min, max;
+	t->getLinearAcceleration(&min, &max);
+	lua_pushnumber(L, min.x);
+	lua_pushnumber(L, min.y);
+	lua_pushnumber(L, max.x);
+	lua_pushnumber(L, max.y);
+	return 4;
 }
 
 int w_ParticleSystem_setRadialAcceleration(lua_State *L)
 	{ "isRelativeDirection", w_ParticleSystem_isRelativeDirection },
 	{ "setSpeed", w_ParticleSystem_setSpeed },
 	{ "getSpeed", w_ParticleSystem_getSpeed },
-	{ "setGravity", w_ParticleSystem_setGravity },
-	{ "getGravity", w_ParticleSystem_getGravity },
+	{ "setLinearAcceleration", w_ParticleSystem_setLinearAcceleration },
+	{ "getLinearAcceleration", w_ParticleSystem_getLinearAcceleration },
 	{ "setRadialAcceleration", w_ParticleSystem_setRadialAcceleration },
 	{ "getRadialAcceleration", w_ParticleSystem_getRadialAcceleration },
 	{ "setTangentialAcceleration", w_ParticleSystem_setTangentialAcceleration },

src/modules/graphics/opengl/wrap_ParticleSystem.h

 int w_ParticleSystem_isRelativeDirection(lua_State *L);
 int w_ParticleSystem_setSpeed(lua_State *L);
 int w_ParticleSystem_getSpeed(lua_State *L);
-int w_ParticleSystem_setGravity(lua_State *L);
-int w_ParticleSystem_getGravity(lua_State *L);
+int w_ParticleSystem_setLinearAcceleration(lua_State *L);
+int w_ParticleSystem_getLinearAcceleration(lua_State *L);
 int w_ParticleSystem_setRadialAcceleration(lua_State *L);
 int w_ParticleSystem_getRadialAcceleration(lua_State *L);
 int w_ParticleSystem_setTangentialAcceleration(lua_State *L);