From a7ed5812046b72bb6f8d2002781571c05eb8b4a4 Mon Sep 17 00:00:00 2001 From: Alex Szpakowski Date: Tue, 28 Jan 2014 03:20:08 -0400 Subject: [PATCH] =?UTF-8?q?Reverted=20ParticleSystem:setPosition=E2=80=99s?= =?UTF-8?q?=20functionality=20to=200.9.0=E2=80=99s=20beheaviour,=20added?= =?UTF-8?q?=20ParticleSystem:moveTo=20which=20has=20the=20new=20behaviour?= =?UTF-8?q?=20(new=20particles=20spawn=20in=20a=20line=20between=20the=20o?= =?UTF-8?q?ld=20position=20and=20where=20the=20emitter=20was=20moved=20to.?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/graphics/opengl/ParticleSystem.cpp | 6 ++++++ src/modules/graphics/opengl/ParticleSystem.h | 9 +++++++++ src/modules/graphics/opengl/wrap_ParticleSystem.cpp | 10 ++++++++++ src/modules/graphics/opengl/wrap_ParticleSystem.h | 1 + 4 files changed, 26 insertions(+) diff --git a/src/modules/graphics/opengl/ParticleSystem.cpp b/src/modules/graphics/opengl/ParticleSystem.cpp index cf613da04..d5d52da2b 100644 --- a/src/modules/graphics/opengl/ParticleSystem.cpp +++ b/src/modules/graphics/opengl/ParticleSystem.cpp @@ -474,6 +474,7 @@ void ParticleSystem::getParticleLifetime(float *min, float *max) const void ParticleSystem::setPosition(float x, float y) { position = love::Vector(x, y); + prevPosition = position; } const love::Vector &ParticleSystem::getPosition() const @@ -481,6 +482,11 @@ const love::Vector &ParticleSystem::getPosition() const return position; } +void ParticleSystem::moveTo(float x, float y) +{ + position = love::Vector(x, y); +} + void ParticleSystem::setAreaSpread(AreaSpreadDistribution distribution, float x, float y) { areaSpread = love::Vector(x, y); diff --git a/src/modules/graphics/opengl/ParticleSystem.h b/src/modules/graphics/opengl/ParticleSystem.h index 8180f52df..8ebdf1d8e 100644 --- a/src/modules/graphics/opengl/ParticleSystem.h +++ b/src/modules/graphics/opengl/ParticleSystem.h @@ -176,6 +176,15 @@ public: **/ const love::Vector &getPosition() const; + /** + * Moves the position of the center of the emitter. + * When update is called, newly spawned particles will appear in a line + * between the old emitter position and where the emitter was moved to, + * resulting in a smoother-feeling particle system if moveTo is called + * repeatedly. + **/ + void moveTo(float x, float y); + /** * Sets the emission area spread parameters and distribution type. The interpretation of * the parameters depends on the distribution type: diff --git a/src/modules/graphics/opengl/wrap_ParticleSystem.cpp b/src/modules/graphics/opengl/wrap_ParticleSystem.cpp index 8f38aa70d..6e875b645 100644 --- a/src/modules/graphics/opengl/wrap_ParticleSystem.cpp +++ b/src/modules/graphics/opengl/wrap_ParticleSystem.cpp @@ -191,6 +191,15 @@ int w_ParticleSystem_getPosition(lua_State *L) return 2; } +int w_ParticleSystem_moveTo(lua_State *L) +{ + ParticleSystem *t = luax_checkparticlesystem(L, 1); + float arg1 = (float)luaL_checknumber(L, 2); + float arg2 = (float)luaL_checknumber(L, 3); + t->moveTo(arg1, arg2); + return 0; +} + int w_ParticleSystem_setAreaSpread(lua_State *L) { ParticleSystem *t = luax_checkparticlesystem(L, 1); @@ -649,6 +658,7 @@ static const luaL_Reg functions[] = { "getParticleLifetime", w_ParticleSystem_getParticleLifetime }, { "setPosition", w_ParticleSystem_setPosition }, { "getPosition", w_ParticleSystem_getPosition }, + { "moveTo", w_ParticleSystem_moveTo }, { "setAreaSpread", w_ParticleSystem_setAreaSpread }, { "getAreaSpread", w_ParticleSystem_getAreaSpread }, { "setDirection", w_ParticleSystem_setDirection }, diff --git a/src/modules/graphics/opengl/wrap_ParticleSystem.h b/src/modules/graphics/opengl/wrap_ParticleSystem.h index 849374745..08948c386 100644 --- a/src/modules/graphics/opengl/wrap_ParticleSystem.h +++ b/src/modules/graphics/opengl/wrap_ParticleSystem.h @@ -48,6 +48,7 @@ int w_ParticleSystem_setParticleLifetime(lua_State *L); int w_ParticleSystem_getParticleLifetime(lua_State *L); int w_ParticleSystem_setPosition(lua_State *L); int w_ParticleSystem_getPosition(lua_State *L); +int w_ParticleSystem_moveTo(lua_State *L); int w_ParticleSystem_setAreaSpread(lua_State *L); int w_ParticleSystem_getAreaSpread(lua_State *L); int w_ParticleSystem_setDirection(lua_State *L);