Browse Source

The default offset for particles in a ParticleSystem is now updated when ParticleSystem:setQuads or ParticleSystem:setTexture is used (resolves issue #998.)

Alex Szpakowski 10 years ago
parent
commit
4263de89ab

+ 1 - 1
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.
 

+ 25 - 8
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<Quad *> &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

+ 6 - 2
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<Colorf> colors;
@@ -664,6 +666,8 @@ protected:
 
 	bool relativeRotation;
 
+	void resetOffset();
+
 	void createBuffers(size_t size);
 	void deleteBuffers();