From 4263de89abe9d6faa0caebae117263d84d889ae7 Mon Sep 17 00:00:00 2001 From: Alex Szpakowski Date: Wed, 4 Mar 2015 03:57:41 -0400 Subject: [PATCH] The default offset for particles in a ParticleSystem is now updated when ParticleSystem:setQuads or ParticleSystem:setTexture is used (resolves issue #998.) --- readme.md | 2 +- .../graphics/opengl/ParticleSystem.cpp | 33 ++++++++++++++----- src/modules/graphics/opengl/ParticleSystem.h | 8 +++-- 3 files changed, 32 insertions(+), 11 deletions(-) diff --git a/readme.md b/readme.md index dbc8c171c..7349d8fd0 100644 --- a/readme.md +++ b/readme.md @@ -28,7 +28,7 @@ Then use the Xcode project found at `platform/xcode/love.xcodeproj` to build the Download the required libraries from [here][dependencies-ios] and place the `include` and `libraries` folders into the `platform/xcode/ios` folder. -Then use the Xcode project foind at `platform/xcode/love.xcodeproj` to build the `love-ios` target. +Then use the Xcode project found at `platform/xcode/love.xcodeproj` to build the `love-ios` target. Note that you must be registered in the [iOS Developer Program][iosdeveloper] in order to build for physical iOS devices. diff --git a/src/modules/graphics/opengl/ParticleSystem.cpp b/src/modules/graphics/opengl/ParticleSystem.cpp index 96ff9f1fa..ab2786b2b 100644 --- a/src/modules/graphics/opengl/ParticleSystem.cpp +++ b/src/modules/graphics/opengl/ParticleSystem.cpp @@ -95,8 +95,8 @@ ParticleSystem::ParticleSystem(Texture *texture, uint32 size) , spinStart(0) , spinEnd(0) , spinVariation(0) - , offsetX(float(texture->getWidth())*0.5f) - , offsetY(float(texture->getHeight())*0.5f) + , offset(float(texture->getWidth())*0.5f, float(texture->getHeight())*0.5f) + , defaultOffset(true) , relativeRotation(false) { if (size == 0 || size > MAX_PARTICLES) @@ -148,8 +148,8 @@ ParticleSystem::ParticleSystem(const ParticleSystem &p) , spinStart(p.spinStart) , spinEnd(p.spinEnd) , spinVariation(p.spinVariation) - , offsetX(p.offsetX) - , offsetY(p.offsetY) + , offset(p.offset) + , defaultOffset(p.defaultOffset) , colors(p.colors) , quads(p.quads) , relativeRotation(p.relativeRotation) @@ -167,6 +167,17 @@ ParticleSystem *ParticleSystem::clone() return new ParticleSystem(*this); } +void ParticleSystem::resetOffset() +{ + if (quads.empty()) + offset = love::Vector(float(texture->getWidth())*0.5f, float(texture->getHeight())*0.5f); + else + { + Quad::Viewport v = quads[0]->getViewport(); + offset = love::Vector(v.x*0.5f, v.y*0.5f); + } +} + void ParticleSystem::createBuffers(size_t size) { try @@ -423,6 +434,9 @@ ParticleSystem::Particle *ParticleSystem::removeParticle(Particle *p) void ParticleSystem::setTexture(Texture *tex) { texture.set(tex); + + if (defaultOffset) + resetOffset(); } Texture *ParticleSystem::getTexture() const @@ -683,13 +697,13 @@ float ParticleSystem::getSpinVariation() const void ParticleSystem::setOffset(float x, float y) { - offsetX = x; - offsetY = y; + offset = love::Vector(x, y); + defaultOffset = false; } love::Vector ParticleSystem::getOffset() const { - return love::Vector(offsetX, offsetY); + return offset; } void ParticleSystem::setColor(const Color &color) @@ -730,6 +744,9 @@ void ParticleSystem::setQuads(const std::vector &newQuads) quadlist.push_back(q); quads = quadlist; + + if (defaultOffset) + resetOffset(); } void ParticleSystem::setQuads() @@ -856,7 +873,7 @@ void ParticleSystem::draw(float x, float y, float angle, float sx, float sy, flo textureVerts = quads[p->quadIndex]->getVertices(); // particle vertices are image vertices transformed by particle information - t.setTransformation(p->position[0], p->position[1], p->angle, p->size, p->size, offsetX, offsetY, 0.0f, 0.0f); + t.setTransformation(p->position[0], p->position[1], p->angle, p->size, p->size, offset.x, offset.y, 0.0f, 0.0f); t.transform(pVerts, textureVerts, 4); // set the texture coordinate and color data for particle vertices diff --git a/src/modules/graphics/opengl/ParticleSystem.h b/src/modules/graphics/opengl/ParticleSystem.h index b5bd2c691..d9c497f6d 100644 --- a/src/modules/graphics/opengl/ParticleSystem.h +++ b/src/modules/graphics/opengl/ParticleSystem.h @@ -653,8 +653,10 @@ protected: float spinVariation; // Offsets - float offsetX; - float offsetY; + love::Vector offset; + + // Is the ParticleSystem using a default offset? + bool defaultOffset; // Color. std::vector colors; @@ -664,6 +666,8 @@ protected: bool relativeRotation; + void resetOffset(); + void createBuffers(size_t size); void deleteBuffers();