diff options
author | Stijn Buys <ingar@osirion.org> | 2013-01-27 15:19:14 +0000 |
---|---|---|
committer | Stijn Buys <ingar@osirion.org> | 2013-01-27 15:19:14 +0000 |
commit | fd6663f0d3a4e860c14a0f3279fcce06d27fa283 (patch) | |
tree | 4b5b1a2cb65f634096fd14983ba8a68c383c7a1c /src/render/particleejector.cc | |
parent | f096586dac6e6c0e083e23afafc99731bf2ba642 (diff) |
ADded support for streak style particles.
Diffstat (limited to 'src/render/particleejector.cc')
-rw-r--r-- | src/render/particleejector.cc | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/src/render/particleejector.cc b/src/render/particleejector.cc index 9ee9cc8..acec84f 100644 --- a/src/render/particleejector.cc +++ b/src/render/particleejector.cc @@ -4,6 +4,8 @@ the terms of the GNU General Public License version 2 */ +#include <cassert> + #include "core/application.h" #include "render/particleejector.h" #include "render/camera.h" @@ -76,6 +78,16 @@ void ParticleEjector::frame(const float seconds, const math::Vector3f & ps_locat particle->set_rotation(math::randomf(2.0f * M_PI)); particle->set_speed(math::randomf(speed_vec()[0], speed_vec()[1])); particles().push_front(particle); + + if (type() == Streak) { + Particle *tail = new Particle(particle_location, particle_axis, now); + tail->set_radius(radius_vec()[0]); + tail->set_alpha(alpha_vec()[0]); + tail->set_rotation(particle->rotation()); + tail->set_speed(math::randomf(tailspeed_vec()[0], tailspeed_vec()[1])); + particles().push_front(tail); + } + ejector_last_eject -= interval(); } } else { @@ -305,5 +317,70 @@ void ParticleEjectorTrail::draw(const math::Vector3f & ps_location, const math:: gl::end(); } +/* ---- class ParticleEjectorStreak --------------------------------- */ + +ParticleEjectorStreak::ParticleEjectorStreak(const ParticleEjectorScript &script) : ParticleEjector(script) +{ + +} + +ParticleEjectorStreak::~ParticleEjectorStreak() +{ + +} + +void ParticleEjectorStreak::draw(const math::Vector3f & ps_location, const math::Axis & ps_axis) +{ + if (!particles().size()) { + return; + } + + assert( !(particles().size() % 2) ); + + Particles::iterator first = particles().begin(); + Particles::iterator next = first; + + math::Vector3f normal; + math::Color c(color()); + + Textures::bind(texture()); + gl::begin(gl::Quads); + + while (first != particles().end()) { + + next = first; + ++next; + + math::Vector3f first_location(attached() ? ps_location + ps_axis * (*first)->location() : (*first)->location()); + math::Vector3f next_location(attached() ? ps_location + ps_axis * (*next)->location() : (*next)->location()); + + normal.assign(math::crossproduct((first_location - Camera::eye()), (next_location - Camera::eye()))); + normal.normalize(); + + c.a = (*first)->alpha(); + gl::color(c); + + glTexCoord2f(1, 0); + gl::vertex(first_location - normal * (*first)->radius()); + glTexCoord2f(0, 0); + gl::vertex(first_location + normal * (*first)->radius()); + + c.a = (*next)->alpha(); + gl::color(c); + + glTexCoord2f(0, 1); + gl::vertex(next_location + normal * (*next)->radius()); + glTexCoord2f(1, 1); + gl::vertex(next_location - normal * (*next)->radius()); + + Stats::quads++; + + ++first; + ++first; + } + + gl::end(); +} + } // namespace render |