mirror of
https://github.com/love2d/love.git
synced 2026-08-15 15:51:12 +02:00
Added ParticleSystem:setLinearAcceleration(xmin, ymin, xmax, ymax) and removed ParticleSystem:setGravity (issue #599)
This commit is contained in:
@@ -82,8 +82,6 @@ ParticleSystem::ParticleSystem(Image *image, unsigned int buffer)
|
||||
, relative(false)
|
||||
, speedMin(0)
|
||||
, speedMax(0)
|
||||
, gravityMin(0)
|
||||
, gravityMax(0)
|
||||
, radialAccelerationMin(0)
|
||||
, radialAccelerationMax(0)
|
||||
, tangentialAccelerationMin(0)
|
||||
@@ -162,9 +160,8 @@ void ParticleSystem::add()
|
||||
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;
|
||||
@@ -355,23 +352,24 @@ void ParticleSystem::getSpeed(float *min, float *max) const
|
||||
*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)
|
||||
@@ -723,7 +721,7 @@ void ParticleSystem::update(float dt)
|
||||
{
|
||||
|
||||
// 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.
|
||||
@@ -745,7 +743,7 @@ void ParticleSystem::update(float dt)
|
||||
tangential *= p->tangentialAcceleration;
|
||||
|
||||
// Update position.
|
||||
p->speed += (radial+tangential+gravity)*dt;
|
||||
p->speed += (radial+tangential+p->linearAcceleration)*dt;
|
||||
|
||||
// Modify position.
|
||||
ppos += p->speed * dt;
|
||||
|
||||
@@ -51,7 +51,7 @@ struct particle
|
||||
love::Vector origin;
|
||||
|
||||
love::Vector speed;
|
||||
float gravity;
|
||||
love::Vector linearAcceleration;
|
||||
float radialAcceleration;
|
||||
float tangentialAcceleration;
|
||||
|
||||
@@ -256,24 +256,27 @@ public:
|
||||
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).
|
||||
@@ -564,9 +567,9 @@ protected:
|
||||
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;
|
||||
|
||||
@@ -247,23 +247,27 @@ int w_ParticleSystem_getSpeed(lua_State *L)
|
||||
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)
|
||||
@@ -676,8 +680,8 @@ static const luaL_Reg functions[] =
|
||||
{ "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 },
|
||||
|
||||
@@ -58,8 +58,8 @@ int w_ParticleSystem_setRelativeDirection(lua_State *L);
|
||||
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);
|
||||
|
||||
Reference in New Issue
Block a user