Updated to latest love-android code (b615972822cb)

This commit is contained in:
fysx
2015-08-13 17:21:53 +02:00
parent f3dd769e98
commit 9cbddc2f5e
50 changed files with 827 additions and 663 deletions
@@ -43,11 +43,6 @@ namespace
love::math::RandomGenerator rng;
Colorf colorToFloat(const Color &c)
{
return Colorf((float)c.r/255.0f, (float)c.g/255.0f, (float)c.b/255.0f, (float)c.a/255.0f);
}
float calculate_variation(float inner, float outer, float var)
{
float low = inner - (outer/2.0f)*var;
@@ -261,35 +256,34 @@ void ParticleSystem::initParticle(Particle *p, float t)
p->life = (float) rng.random(min, max);
p->lifetime = p->life;
p->position[0] = pos.x;
p->position[1] = pos.y;
p->position = pos;
switch (areaSpreadDistribution)
{
case DISTRIBUTION_UNIFORM:
p->position[0] += (float) rng.random(-areaSpread.getX(), areaSpread.getX());
p->position[1] += (float) rng.random(-areaSpread.getY(), areaSpread.getY());
p->position.x += (float) rng.random(-areaSpread.getX(), areaSpread.getX());
p->position.y += (float) rng.random(-areaSpread.getY(), areaSpread.getY());
break;
case DISTRIBUTION_NORMAL:
p->position[0] += (float) rng.randomNormal(areaSpread.getX());
p->position[1] += (float) rng.randomNormal(areaSpread.getY());
p->position.x += (float) rng.randomNormal(areaSpread.getX());
p->position.y += (float) rng.randomNormal(areaSpread.getY());
break;
case DISTRIBUTION_NONE:
default:
break;
}
min = direction - spread/2.0f;
max = direction + spread/2.0f;
p->direction = (float) rng.random(min, max);
p->origin = pos;
min = speedMin;
max = speedMax;
float speed = (float) rng.random(min, max);
p->velocity = love::Vector(cosf(p->direction), sinf(p->direction));
p->velocity *= speed;
min = direction - spread/2.0f;
max = direction + spread/2.0f;
float dir = (float) rng.random(min, max);
p->velocity = love::Vector(cosf(dir), sinf(dir)) * speed;
p->linearAcceleration.x = (float) rng.random(linearAccelerationMin.x, linearAccelerationMax.x);
p->linearAcceleration.y = (float) rng.random(linearAccelerationMin.y, linearAccelerationMax.y);
@@ -706,30 +700,31 @@ love::Vector ParticleSystem::getOffset() const
return offset;
}
void ParticleSystem::setColor(const Color &color)
void ParticleSystem::setColor(const std::vector<Colorf> &newColors)
{
colors.resize(1);
colors[0] = colorToFloat(color);
}
colors = newColors;
void ParticleSystem::setColor(const std::vector<Color> &newColors)
{
colors.resize(newColors.size());
for (size_t i = 0; i < newColors.size(); ++i)
colors[i] = colorToFloat(newColors[i]);
}
std::vector<Color> ParticleSystem::getColor() const
{
// The particle system stores colors as floats...
std::vector<Color> ncolors(colors.size());
for (size_t i = 0; i < colors.size(); ++i)
for (Colorf &c : colors)
{
ncolors[i].r = (unsigned char) (colors[i].r * 255);
ncolors[i].g = (unsigned char) (colors[i].g * 255);
ncolors[i].b = (unsigned char) (colors[i].b * 255);
ncolors[i].a = (unsigned char) (colors[i].a * 255);
// We want to store the colors as [0, 1], rather than [0, 255].
c.r /= 255.0f;
c.g /= 255.0f;
c.b /= 255.0f;
c.a /= 255.0f;
}
}
std::vector<Colorf> ParticleSystem::getColor() const
{
// The particle system stores colors in the range of [0, 1]...
std::vector<Colorf> ncolors(colors);
for (Colorf &c : ncolors)
{
c.r *= 255.0f;
c.g *= 255.0f;
c.b *= 255.0f;
c.a *= 255.0f;
}
return ncolors;
@@ -854,10 +849,8 @@ void ParticleSystem::draw(float x, float y, float angle, float sx, float sy, flo
OpenGL::TempDebugGroup debuggroup("ParticleSystem draw");
Matrix4 t(x, y, angle, sx, sy, ox, oy, kx, ky);
OpenGL::TempTransform transform(gl);
transform.get() *= t;
transform.get() *= Matrix4(x, y, angle, sx, sy, ox, oy, kx, ky);
const Vertex *textureVerts = texture->getVertices();
Vertex *pVerts = particleVerts;
@@ -865,14 +858,16 @@ void ParticleSystem::draw(float x, float y, float angle, float sx, float sy, flo
bool useQuads = !quads.empty();
Matrix3 t;
// set the vertex data for each particle (transformation, texcoords, color)
while (p)
{
if (useQuads)
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, offset.x, offset.y, 0.0f, 0.0f);
// particle vertices are image vertices transformed by particle info
t.setTransformation(p->position.x, p->position.y, 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
@@ -881,7 +876,8 @@ void ParticleSystem::draw(float x, float y, float angle, float sx, float sy, flo
pVerts[v].s = textureVerts[v].s;
pVerts[v].t = textureVerts[v].t;
// particle colors are stored as floats (0-1) but vertex colors are stored as unsigned bytes (0-255)
// Particle colors are stored as floats (0-1) but vertex colors are
// unsigned bytes (0-255).
pVerts[v].r = (unsigned char) (p->color.r*255);
pVerts[v].g = (unsigned char) (p->color.g*255);
pVerts[v].b = (unsigned char) (p->color.b*255);
@@ -927,7 +923,7 @@ void ParticleSystem::update(float dt)
{
// Temp variables.
love::Vector radial, tangential;
love::Vector ppos(p->position[0], p->position[1]);
love::Vector ppos = p->position;
// Get vector from particle center to particle.
radial = ppos - p->origin;
@@ -956,8 +952,7 @@ void ParticleSystem::update(float dt)
// Modify position.
ppos += p->velocity * dt;
p->position[0] = ppos.getX();
p->position[1] = ppos.getY();
p->position = ppos;
const float t = 1.0f - p->life / p->lifetime;