diff options
author | Stijn Buys <ingar@osirion.org> | 2012-10-14 10:10:55 +0000 |
---|---|---|
committer | Stijn Buys <ingar@osirion.org> | 2012-10-14 10:10:55 +0000 |
commit | 5227a260a893c0562f93f994f6b94b310ddc4f73 (patch) | |
tree | 3ab36e2a36d1ea6715c43653ad8ad3f85f9b4409 /src/render/particles.cc | |
parent | 97d79a827ef4978df15fa117e013817dbcde1d09 (diff) |
Render a generic explosion effect for destroyed entities.
Diffstat (limited to 'src/render/particles.cc')
-rw-r--r-- | src/render/particles.cc | 129 |
1 files changed, 66 insertions, 63 deletions
diff --git a/src/render/particles.cc b/src/render/particles.cc index 40b79ad..2cc1b1a 100644 --- a/src/render/particles.cc +++ b/src/render/particles.cc @@ -135,6 +135,8 @@ ParticleScript *ParticleScript::load(const std::string &label) script->particlescript_type = ParticleScript::Jet; } else if (strval.compare("trail") == 0) { script->particlescript_type = ParticleScript::Trail; + } else if (strval.compare("spray") == 0) { + script->particlescript_type = ParticleScript::Spray; } else { inifile.unknown_value(); } @@ -387,7 +389,16 @@ void ParticleSystem::draw(const float elapsed) // add new particles if (ejector_active && (particlesystem_last_eject + particlesystem_script->eject() <= now)) { - particlesystem_stream.push_front(new Particle(ejector_location, particlesystem_entity->axis() * particlesystem_axis, now)); + math::Axis particle_axis(particlesystem_entity->axis() * particlesystem_axis); + math::Vector3f particle_location(ejector_location); + + if (particlesystem_script->type() == ParticleScript::Spray) { + particle_axis.change_direction(math::randomf(180)); + particle_axis.change_pitch(math::randomf(180)); + particle_axis.change_roll(math::randomf(180)); + particle_location += particle_axis.forward() * particlesystem_entity->radius() * 0.5f; + } + particlesystem_stream.push_front(new Particle(particle_location, particle_axis, now)); particlesystem_last_eject = now; } } @@ -453,68 +464,6 @@ void Jet::draw(const float elapsed) gl::end(); } } -/* ---- class Spray ------------------------------------------------ */ - -Spray::Spray(const ParticleScript *script, const core::Entity *entity, const model::Particles *modelclass) : - ParticleSystem(script, entity, modelclass) -{ -} - -Spray::~Spray() -{} - -void Spray::draw(const float elapsed) -{ - if (!particlesystem_script) - return; - - ParticleSystem::draw(elapsed); - - math::Vector3f quad[4]; - - if (particlesystem_stream.size()) { - Textures::bind(particlesystem_texture); - gl::begin(gl::Quads); - - for (Stream::iterator it = particlesystem_stream.begin(); it != particlesystem_stream.end(); it++) { - Particle *particle = (*it); - - quad[0].assign(Camera::axis().up() - Camera::axis().left()); - quad[1].assign(Camera::axis().up() + Camera::axis().left()); - quad[2].assign(Camera::axis().up() * -1 + Camera::axis().left()); - quad[3].assign(Camera::axis().up() * -1 - Camera::axis().left()); - - float t = now - particle->time(); - float f = 0; - - if (t < particlesystem_script->timeout() * 0.1f) { - f = t / (0.1f * particlesystem_script->timeout()); - } else { - t = t - particlesystem_script->timeout() * 0.1f; - f = t / (0.9f * particlesystem_script->timeout()); - f = 1.0 - f; - } - - f *= f; - float radius = particlesystem_radius * f; - particlesystem_color.a = f * particlesystem_script->alpha(); - gl::color(particlesystem_color); - - glTexCoord2f(0, 1); - gl::vertex(particle->location() + quad[0] * radius); - glTexCoord2f(0, 0); - gl::vertex(particle->location() + quad[1] * radius); - glTexCoord2f(1, 0); - gl::vertex(particle->location() + quad[2] * radius); - glTexCoord2f(1, 1); - gl::vertex(particle->location() + quad[3] * radius); - Stats::quads++; - } - - gl::end(); - } -} - /* ---- class Trail ------------------------------------------------ */ @@ -799,4 +748,58 @@ void Flame::draw(const float elapsed) } } +/* ---- class Spray ------------------------------------------------ */ + +Spray::Spray(const ParticleScript *script, const core::Entity *entity, const model::Particles *modelclass) : + ParticleSystem(script, entity, modelclass) +{ +} + +Spray::~Spray() +{ +} + +void Spray::draw(const float elapsed) +{ + if (!particlesystem_script) + return; + + ParticleSystem::draw(elapsed); + + math::Vector3f quad[4]; + + if (particlesystem_stream.size()) { + Textures::bind(particlesystem_texture); + gl::begin(gl::Quads); + + quad[0].assign((Camera::axis().up() - Camera::axis().left())); + quad[1].assign((Camera::axis().up() + Camera::axis().left())); + quad[2].assign((Camera::axis().up() * -1 + Camera::axis().left())); + quad[3].assign((Camera::axis().up() * -1 - Camera::axis().left())); + + for (Stream::iterator it = particlesystem_stream.begin(); it != particlesystem_stream.end(); it++) { + Particle *particle = (*it); + + const float t = now - particle->time(); + const float f = t / particlesystem_script->timeout(); + const float radius = particlesystem_radius * f; + + particlesystem_color.a = (1.0f - f) * particlesystem_script->alpha(); + gl::color(particlesystem_color); + + glTexCoord2f(0, 1); + gl::vertex(particle->location() + quad[0] * radius); + glTexCoord2f(0, 0); + gl::vertex(particle->location() + quad[1] * radius); + glTexCoord2f(1, 0); + gl::vertex(particle->location() + quad[2] * radius); + glTexCoord2f(1, 1); + gl::vertex(particle->location() + quad[3] * radius); + Stats::quads++; + } + + gl::end(); + } +} + } // namespace render |