mirror of
https://github.com/love2d/love.git
synced 2026-08-12 08:30:56 +02:00
Added ParticleSystem:setLinearDamping and ParticleSystem:getLinearDamping (resolves issue #803.)
This commit is contained in:
@@ -86,6 +86,8 @@ ParticleSystem::ParticleSystem(Texture *texture, uint32 size)
|
||||
, radialAccelerationMax(0)
|
||||
, tangentialAccelerationMin(0)
|
||||
, tangentialAccelerationMax(0)
|
||||
, linearDampingMin(0.0f)
|
||||
, linearDampingMax(0.0f)
|
||||
, sizeVariation(0)
|
||||
, rotationMin(0)
|
||||
, rotationMax(0)
|
||||
@@ -135,6 +137,8 @@ ParticleSystem::ParticleSystem(const ParticleSystem &p)
|
||||
, radialAccelerationMax(p.radialAccelerationMax)
|
||||
, tangentialAccelerationMin(p.tangentialAccelerationMin)
|
||||
, tangentialAccelerationMax(p.tangentialAccelerationMax)
|
||||
, linearDampingMin(p.linearDampingMin)
|
||||
, linearDampingMax(p.linearDampingMax)
|
||||
, sizes(p.sizes)
|
||||
, sizeVariation(p.sizeVariation)
|
||||
, rotationMin(p.rotationMin)
|
||||
@@ -284,6 +288,10 @@ void ParticleSystem::initParticle(Particle *p, float t)
|
||||
max = tangentialAccelerationMax;
|
||||
p->tangentialAcceleration = (float) rng.random(min, max);
|
||||
|
||||
min = linearDampingMin;
|
||||
max = linearDampingMax;
|
||||
p->linearDamping = (float) rng.random(min, max);
|
||||
|
||||
p->sizeOffset = (float) rng.random(sizeVariation); // time offset for size change
|
||||
p->sizeIntervalSize = (1.0f - (float) rng.random(sizeVariation)) - p->sizeOffset;
|
||||
p->size = sizes[(size_t)(p->sizeOffset - .5f) * (sizes.size() - 1)];
|
||||
@@ -460,12 +468,10 @@ void ParticleSystem::setParticleLifetime(float min, float max)
|
||||
particleLifeMax = max;
|
||||
}
|
||||
|
||||
void ParticleSystem::getParticleLifetime(float *min, float *max) const
|
||||
void ParticleSystem::getParticleLifetime(float &min, float &max) const
|
||||
{
|
||||
if (min)
|
||||
*min = particleLifeMin;
|
||||
if (max)
|
||||
*max = particleLifeMax;
|
||||
min = particleLifeMin;
|
||||
max = particleLifeMax;
|
||||
}
|
||||
|
||||
void ParticleSystem::setPosition(float x, float y)
|
||||
@@ -531,12 +537,10 @@ void ParticleSystem::setSpeed(float min, float max)
|
||||
speedMax = max;
|
||||
}
|
||||
|
||||
void ParticleSystem::getSpeed(float *min, float *max) const
|
||||
void ParticleSystem::getSpeed(float &min, float &max) const
|
||||
{
|
||||
if (min)
|
||||
*min = speedMin;
|
||||
if (max)
|
||||
*max = speedMax;
|
||||
min = speedMin;
|
||||
max = speedMax;
|
||||
}
|
||||
|
||||
void ParticleSystem::setLinearAcceleration(float x, float y)
|
||||
@@ -551,12 +555,10 @@ void ParticleSystem::setLinearAcceleration(float xmin, float ymin, float xmax, f
|
||||
linearAccelerationMax = love::Vector(xmax, ymax);
|
||||
}
|
||||
|
||||
void ParticleSystem::getLinearAcceleration(love::Vector *min, love::Vector *max) const
|
||||
void ParticleSystem::getLinearAcceleration(love::Vector &min, love::Vector &max) const
|
||||
{
|
||||
if (min)
|
||||
*min = linearAccelerationMin;
|
||||
if (max)
|
||||
*max = linearAccelerationMax;
|
||||
min = linearAccelerationMin;
|
||||
max = linearAccelerationMax;
|
||||
}
|
||||
|
||||
void ParticleSystem::setRadialAcceleration(float acceleration)
|
||||
@@ -570,12 +572,10 @@ void ParticleSystem::setRadialAcceleration(float min, float max)
|
||||
radialAccelerationMax = max;
|
||||
}
|
||||
|
||||
void ParticleSystem::getRadialAcceleration(float *min, float *max) const
|
||||
void ParticleSystem::getRadialAcceleration(float &min, float &max) const
|
||||
{
|
||||
if (min)
|
||||
*min = radialAccelerationMin;
|
||||
if (max)
|
||||
*max = radialAccelerationMax;
|
||||
min = radialAccelerationMin;
|
||||
max = radialAccelerationMax;
|
||||
}
|
||||
|
||||
void ParticleSystem::setTangentialAcceleration(float acceleration)
|
||||
@@ -589,12 +589,22 @@ void ParticleSystem::setTangentialAcceleration(float min, float max)
|
||||
tangentialAccelerationMax = max;
|
||||
}
|
||||
|
||||
void ParticleSystem::getTangentialAcceleration(float *min, float *max) const
|
||||
void ParticleSystem::getTangentialAcceleration(float &min, float &max) const
|
||||
{
|
||||
if (min)
|
||||
*min = tangentialAccelerationMin;
|
||||
if (max)
|
||||
*max = tangentialAccelerationMax;
|
||||
min = tangentialAccelerationMin;
|
||||
max = tangentialAccelerationMax;
|
||||
}
|
||||
|
||||
void ParticleSystem::setLinearDamping(float min, float max)
|
||||
{
|
||||
linearDampingMin = min;
|
||||
linearDampingMax = max;
|
||||
}
|
||||
|
||||
void ParticleSystem::getLinearDamping(float &min, float &max) const
|
||||
{
|
||||
min = linearDampingMin;
|
||||
max = linearDampingMax;
|
||||
}
|
||||
|
||||
void ParticleSystem::setSize(float size)
|
||||
@@ -634,12 +644,10 @@ void ParticleSystem::setRotation(float min, float max)
|
||||
rotationMax = max;
|
||||
}
|
||||
|
||||
void ParticleSystem::getRotation(float *min, float *max) const
|
||||
void ParticleSystem::getRotation(float &min, float &max) const
|
||||
{
|
||||
if (min)
|
||||
*min = rotationMin;
|
||||
if (max)
|
||||
*max = rotationMax;
|
||||
min = rotationMin;
|
||||
max = rotationMax;
|
||||
}
|
||||
|
||||
void ParticleSystem::setSpin(float spin)
|
||||
@@ -654,12 +662,10 @@ void ParticleSystem::setSpin(float start, float end)
|
||||
spinEnd = end;
|
||||
}
|
||||
|
||||
void ParticleSystem::getSpin(float *start, float *end) const
|
||||
void ParticleSystem::getSpin(float &start, float &end) const
|
||||
{
|
||||
if (start)
|
||||
*start = spinStart;
|
||||
if (end)
|
||||
*end = spinEnd;
|
||||
start = spinStart;
|
||||
end = spinEnd;
|
||||
}
|
||||
|
||||
void ParticleSystem::setSpinVariation(float variation)
|
||||
@@ -931,6 +937,9 @@ void ParticleSystem::update(float dt)
|
||||
// Update velocity.
|
||||
p->velocity += (radial + tangential + p->linearAcceleration) * dt;
|
||||
|
||||
// Apply damping.
|
||||
p->velocity *= 1.0f / (1.0f + p->linearDamping * dt);
|
||||
|
||||
// Modify position.
|
||||
ppos += p->velocity * dt;
|
||||
|
||||
|
||||
@@ -162,7 +162,7 @@ public:
|
||||
* @param[out] min The minimum life.
|
||||
* @param[out] max The maximum life.
|
||||
**/
|
||||
void getParticleLifetime(float *min, float *max) const;
|
||||
void getParticleLifetime(float &min, float &max) const;
|
||||
|
||||
/**
|
||||
* Sets the position of the center of the emitter.
|
||||
@@ -249,7 +249,7 @@ public:
|
||||
* @param[out] min The minimum speed.
|
||||
* @param[out] max The maximum speed.
|
||||
**/
|
||||
void getSpeed(float *min, float *max) const;
|
||||
void getSpeed(float &min, float &max) const;
|
||||
|
||||
/**
|
||||
* Sets the linear acceleration (the acceleration along the x and y axes).
|
||||
@@ -272,7 +272,7 @@ public:
|
||||
* @param[out] min The minimum acceleration.
|
||||
* @param[out] max The maximum acceleration.
|
||||
**/
|
||||
void getLinearAcceleration(love::Vector *min, love::Vector *max) const;
|
||||
void getLinearAcceleration(love::Vector &min, love::Vector &max) const;
|
||||
|
||||
/**
|
||||
* Sets the radial acceleration (the acceleration towards the particle emitter).
|
||||
@@ -292,7 +292,7 @@ public:
|
||||
* @param[out] min The minimum amount of radial acceleration.
|
||||
* @param[out] max The maximum amount of radial acceleration.
|
||||
**/
|
||||
void getRadialAcceleration(float *min, float *max) const;
|
||||
void getRadialAcceleration(float &min, float &max) const;
|
||||
|
||||
/**
|
||||
* Sets the tangential acceleration (the acceleration perpendicular to the particle's direction).
|
||||
@@ -312,7 +312,18 @@ public:
|
||||
* @param[out] min The minimum tangential acceleration.
|
||||
* @param[out] max The maximum tangential acceleration.
|
||||
**/
|
||||
void getTangentialAcceleration(float *min, float *max) const;
|
||||
void getTangentialAcceleration(float &min, float &max) const;
|
||||
|
||||
/**
|
||||
* Sets the amount of linear damping. Damping reduces the velocity of
|
||||
* particles over time. A value of 0 corresponds to no damping.
|
||||
**/
|
||||
void setLinearDamping(float min, float max);
|
||||
|
||||
/**
|
||||
* Gets the current amount of linear damping.
|
||||
**/
|
||||
void getLinearDamping(float &min, float &max) const;
|
||||
|
||||
/**
|
||||
* Sets the size of the sprite (1.0 being the default size).
|
||||
@@ -360,7 +371,7 @@ public:
|
||||
* @param[out] min The minimum initial rotation.
|
||||
* @param[out] max The maximum initial rotation.
|
||||
**/
|
||||
void getRotation(float *min, float *max) const;
|
||||
void getRotation(float &min, float &max) const;
|
||||
|
||||
/**
|
||||
* Sets the spin of the sprite.
|
||||
@@ -380,7 +391,7 @@ public:
|
||||
* @param[out] start The initial spin, in radians / s.
|
||||
* @param[out] end The final spin, in radians / s.
|
||||
**/
|
||||
void getSpin(float *start, float *end) const;
|
||||
void getSpin(float &start, float &end) const;
|
||||
|
||||
/**
|
||||
* Sets the variation of the start spin (0 being no variation and 1 being a random spin between start and end).
|
||||
@@ -533,6 +544,8 @@ protected:
|
||||
float radialAcceleration;
|
||||
float tangentialAcceleration;
|
||||
|
||||
float linearDamping;
|
||||
|
||||
float size;
|
||||
float sizeOffset;
|
||||
float sizeIntervalSize;
|
||||
@@ -619,6 +632,9 @@ protected:
|
||||
float tangentialAccelerationMin;
|
||||
float tangentialAccelerationMax;
|
||||
|
||||
float linearDampingMin;
|
||||
float linearDampingMax;
|
||||
|
||||
// Size.
|
||||
std::vector<float> sizes;
|
||||
float sizeVariation;
|
||||
|
||||
@@ -164,7 +164,7 @@ int w_ParticleSystem_getParticleLifetime(lua_State *L)
|
||||
{
|
||||
ParticleSystem *t = luax_checkparticlesystem(L, 1);
|
||||
float min, max;
|
||||
t->getParticleLifetime(&min, &max);
|
||||
t->getParticleLifetime(min, max);
|
||||
lua_pushnumber(L, min);
|
||||
lua_pushnumber(L, max);
|
||||
return 2;
|
||||
@@ -278,7 +278,7 @@ int w_ParticleSystem_getSpeed(lua_State *L)
|
||||
{
|
||||
ParticleSystem *t = luax_checkparticlesystem(L, 1);
|
||||
float min, max;
|
||||
t->getSpeed(&min, &max);
|
||||
t->getSpeed(min, max);
|
||||
lua_pushnumber(L, min);
|
||||
lua_pushnumber(L, max);
|
||||
return 2;
|
||||
@@ -299,7 +299,7 @@ int w_ParticleSystem_getLinearAcceleration(lua_State *L)
|
||||
{
|
||||
ParticleSystem *t = luax_checkparticlesystem(L, 1);
|
||||
love::Vector min, max;
|
||||
t->getLinearAcceleration(&min, &max);
|
||||
t->getLinearAcceleration(min, max);
|
||||
lua_pushnumber(L, min.x);
|
||||
lua_pushnumber(L, min.y);
|
||||
lua_pushnumber(L, max.x);
|
||||
@@ -320,7 +320,7 @@ int w_ParticleSystem_getRadialAcceleration(lua_State *L)
|
||||
{
|
||||
ParticleSystem *t = luax_checkparticlesystem(L, 1);
|
||||
float min, max;
|
||||
t->getRadialAcceleration(&min, &max);
|
||||
t->getRadialAcceleration(min, max);
|
||||
lua_pushnumber(L, min);
|
||||
lua_pushnumber(L, max);
|
||||
return 2;
|
||||
@@ -339,7 +339,26 @@ int w_ParticleSystem_getTangentialAcceleration(lua_State *L)
|
||||
{
|
||||
ParticleSystem *t = luax_checkparticlesystem(L, 1);
|
||||
float min, max;
|
||||
t->getTangentialAcceleration(&min, &max);
|
||||
t->getTangentialAcceleration(min, max);
|
||||
lua_pushnumber(L, min);
|
||||
lua_pushnumber(L, max);
|
||||
return 2;
|
||||
}
|
||||
|
||||
int w_ParticleSystem_setLinearDamping(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->setLinearDamping(arg1, arg2);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_ParticleSystem_getLinearDamping(lua_State *L)
|
||||
{
|
||||
ParticleSystem *t = luax_checkparticlesystem(L, 1);
|
||||
float min, max;
|
||||
t->getLinearDamping(min, max);
|
||||
lua_pushnumber(L, min);
|
||||
lua_pushnumber(L, max);
|
||||
return 2;
|
||||
@@ -411,7 +430,7 @@ int w_ParticleSystem_getRotation(lua_State *L)
|
||||
{
|
||||
ParticleSystem *t = luax_checkparticlesystem(L, 1);
|
||||
float min, max;
|
||||
t->getRotation(&min, &max);
|
||||
t->getRotation(min, max);
|
||||
lua_pushnumber(L, min);
|
||||
lua_pushnumber(L, max);
|
||||
return 2;
|
||||
@@ -430,7 +449,7 @@ int w_ParticleSystem_getSpin(lua_State *L)
|
||||
{
|
||||
ParticleSystem *t = luax_checkparticlesystem(L, 1);
|
||||
float start, end;
|
||||
t->getSpin(&start, &end);
|
||||
t->getSpin(start, end);
|
||||
lua_pushnumber(L, start);
|
||||
lua_pushnumber(L, end);
|
||||
return 2;
|
||||
@@ -730,6 +749,8 @@ static const luaL_Reg functions[] =
|
||||
{ "getRadialAcceleration", w_ParticleSystem_getRadialAcceleration },
|
||||
{ "setTangentialAcceleration", w_ParticleSystem_setTangentialAcceleration },
|
||||
{ "getTangentialAcceleration", w_ParticleSystem_getTangentialAcceleration },
|
||||
{ "setLinearDamping", w_ParticleSystem_setLinearDamping },
|
||||
{ "getLinearDamping", w_ParticleSystem_getLinearDamping },
|
||||
{ "setSizes", w_ParticleSystem_setSizes },
|
||||
{ "getSizes", w_ParticleSystem_getSizes },
|
||||
{ "setSizeVariation", w_ParticleSystem_setSizeVariation },
|
||||
|
||||
@@ -63,6 +63,8 @@ int w_ParticleSystem_setRadialAcceleration(lua_State *L);
|
||||
int w_ParticleSystem_getRadialAcceleration(lua_State *L);
|
||||
int w_ParticleSystem_setTangentialAcceleration(lua_State *L);
|
||||
int w_ParticleSystem_getTangentialAcceleration(lua_State *L);
|
||||
int w_ParticleSystem_setLinearDamping(lua_State *L);
|
||||
int w_ParticleSystem_getLinearDamping(lua_State *L);
|
||||
int w_ParticleSystem_setSizes(lua_State *L);
|
||||
int w_ParticleSystem_getSizes(lua_State *L);
|
||||
int w_ParticleSystem_setSizeVariation(lua_State *L);
|
||||
|
||||
Reference in New Issue
Block a user