From be1c0d9dd0fe27079f7edd89c55f5eeeff0ae00c Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Tue, 22 Jan 2013 21:10:29 +0000 Subject: Implemented Flare particles. --- src/render/particleejector.cc | 53 +++++++++++++++++++++++++++++++++++++++---- 1 file changed, 48 insertions(+), 5 deletions(-) (limited to 'src/render/particleejector.cc') diff --git a/src/render/particleejector.cc b/src/render/particleejector.cc index c697e8f..92b8d8f 100644 --- a/src/render/particleejector.cc +++ b/src/render/particleejector.cc @@ -59,9 +59,8 @@ void ParticleEjector::frame(const float seconds, const math::Vector3f & ps_locat particle_location.assign(ps_location); particle_axis.assign(ps_axis); } - + particle_axis.change_roll(math::randomf(360.0f)); if (cone() > 0) { - particle_axis.change_roll(math::randomf(360.0f)); particle_axis.change_pitch(math::randomf(cone()) - (cone() * 0.5f) ); } if (spawn_radius() > 0) { @@ -72,11 +71,11 @@ void ParticleEjector::frame(const float seconds, const math::Vector3f & ps_locat particle_location += random_axis.forward() * spawn_radius(); } - Particle *particle = new Particle(particle_location, particle_axis.forward() * speed(), now); + Particle *particle = new Particle(particle_location, particle_axis, now); particle->set_radius(radius_vec()[0]); particle->set_alpha(alpha_vec()[0]); particle->set_rotation(math::randomf(2.0f * M_PI)); - + particle->set_speed(speed()); particles().push_front(particle); ejector_last_eject = now; } @@ -87,8 +86,12 @@ void ParticleEjector::frame(const float seconds, const math::Vector3f & ps_locat for (Particles::iterator it = particles().begin(); it != particles().end(); ++it) { Particle *particle = (*it); if (particle->timestamp() < now) { + // apply acceleration + if (acceleration()) { + particle->set_speed(particle->speed() + acceleration() * seconds); + } // apply velocity - particle->get_location() += (particle->velocity() * seconds); + particle->get_location() += (particle->axis().forward() * particle->speed() * seconds); // set particle radius_vec and alpha_vec const float age = (float) (now - particle->timestamp()); @@ -185,6 +188,46 @@ void ParticleEjectorSprite::draw(const math::Vector3f & ps_location, const math: gl::end(); } +/* ---- class ParticleEjectorFlare --------------------------------- */ + +ParticleEjectorFlare::ParticleEjectorFlare(const ParticleEjectorScript &script) : ParticleEjector(script) +{ + +} + +ParticleEjectorFlare::~ParticleEjectorFlare() +{ + +} + +void ParticleEjectorFlare::draw(const math::Vector3f & ps_location, const math::Axis & ps_axis) +{ + Textures::bind(texture()); + gl::begin(gl::Quads); + math::Color c(color()); + for (Particles::iterator it = particles().begin(); it != particles().end(); it++) { + Particle *particle = (*it); + + math::Vector3f particle_location(attached() ? ps_location + ps_axis * particle->location() : particle->location()); + math::Axis particle_axis(attached() ? ps_axis * particle->axis() : particle->axis()); + const float r = particle->radius(); + + c.a = particle->alpha(); + gl::color(c); + + glTexCoord2f(0, 1); + gl::vertex(particle_location + (particle_axis.up() - particle_axis.left()) * r); + glTexCoord2f(0, 0); + gl::vertex(particle_location + (particle_axis.up() + particle_axis.left()) * r); + glTexCoord2f(1, 0); + gl::vertex(particle_location + (particle_axis.up() * -1 + particle_axis.left()) * r); + glTexCoord2f(1, 1); + gl::vertex(particle_location + (particle_axis.up() * -1 - particle_axis.left()) * r); + Stats::quads++; + } + gl::end(); +} + /* ---- class ParticleEjectorTrail --------------------------------- */ ParticleEjectorTrail::ParticleEjectorTrail(const ParticleEjectorScript &script) : ParticleEjector(script) -- cgit v1.2.3