From b887a9f9de76df999a40f2ae8994984723ac46bf Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Mon, 21 Jan 2013 20:13:08 +0000 Subject: Renamed particle ejector types, added random rotation to sprites. --- src/render/particle.h | 38 ++++++++++++++++++++++++++++++++++++- src/render/particleejector.cc | 23 ++++++++++++++-------- src/render/particleejector.h | 8 ++++---- src/render/particleejectorscript.cc | 2 +- src/render/particleejectorscript.h | 2 +- src/render/particlesystem.cc | 4 ++-- src/render/particlesystemscript.cc | 36 ++++++++++++++--------------------- 7 files changed, 74 insertions(+), 39 deletions(-) (limited to 'src/render') diff --git a/src/render/particle.h b/src/render/particle.h index f2b1788..0370660 100644 --- a/src/render/particle.h +++ b/src/render/particle.h @@ -23,9 +23,13 @@ class Particle public: Particle(const math::Vector3f &location, const unsigned long timestamp); Particle(const math::Vector3f &location, const math::Vector3f &velocity, const unsigned long timestamp); + + /* ---- inspectors ----------------------------------------- */ /** * @brief location of the particle + * Depending on the attached setting of the ejector + * location can be in world coordinates or in model coordinates, * */ inline const math::Vector3f &location() const { return particle_location; @@ -38,23 +42,39 @@ public: return particle_velocity; } + /** + * @brief radius of the particle + * */ const float radius() const { return particle_radius; } + /** + * @brief alpha value of the particle + * */ const float alpha() const { return particle_alpha; } + + /** + * @brief rotation of the particle, in radians + * */ + const float rotation() const + { + return particle_rotation; + } /** - * @brief creation timestamp + * @brief particle creation timestamp * */ inline const unsigned long timestamp() const { return particle_timestamp; } + /* ---- mutators ------------------------------------------- */ + /** * @brief reference to the location of the particle * */ @@ -85,21 +105,37 @@ public: particle_velocity.assign(velocity); } + /** + * @brief set the radius of the particle + * */ inline void set_radius(const float radius) { particle_radius = radius; } + /** + * @brief set the alpha value of the particle + * */ inline void set_alpha(const float alpha) { particle_alpha = alpha; } + + /** + * @brief set the rotation of the particle, in radians + * This value is used to rotate the texture when rendering the particle + * */ + inline void set_rotation(const float rotation) + { + particle_rotation = rotation; + } protected: math::Vector3f particle_location; math::Vector3f particle_velocity; float particle_radius; float particle_alpha; + float particle_rotation; unsigned long particle_timestamp; }; diff --git a/src/render/particleejector.cc b/src/render/particleejector.cc index 091743d..c697e8f 100644 --- a/src/render/particleejector.cc +++ b/src/render/particleejector.cc @@ -49,6 +49,9 @@ void ParticleEjector::frame(const float seconds, const math::Vector3f & ps_locat // add new particles if (ejector_enabled) { + // FIXME currently, only one particle per frame is ejected + // particle ejection rate should be independent of framerate, but we run into issues + // of the particle systems not rendered if (ejector_last_eject + interval() <= now) { math::Vector3f particle_location; math::Axis particle_axis; @@ -72,6 +75,7 @@ void ParticleEjector::frame(const float seconds, const math::Vector3f & ps_locat Particle *particle = new Particle(particle_location, particle_axis.forward() * speed(), now); particle->set_radius(radius_vec()[0]); particle->set_alpha(alpha_vec()[0]); + particle->set_rotation(math::randomf(2.0f * M_PI)); particles().push_front(particle); ejector_last_eject = now; @@ -131,19 +135,19 @@ void ParticleEjector::draw(const math::Vector3f & ps_location, const math::Axis } -/* ---- class ParticleEjectorSpray --------------------------------- */ +/* ---- class ParticleEjectorSprite --------------------------------- */ -ParticleEjectorSpray::ParticleEjectorSpray(const ParticleEjectorScript &script) : ParticleEjector(script) +ParticleEjectorSprite::ParticleEjectorSprite(const ParticleEjectorScript &script) : ParticleEjector(script) { } -ParticleEjectorSpray::~ParticleEjectorSpray() +ParticleEjectorSprite::~ParticleEjectorSprite() { } -void ParticleEjectorSpray::draw(const math::Vector3f & ps_location, const math::Axis & ps_axis) +void ParticleEjectorSprite::draw(const math::Vector3f & ps_location, const math::Axis & ps_axis) { math::Vector3f quad[4]; Textures::bind(texture()); @@ -159,6 +163,9 @@ void ParticleEjectorSpray::draw(const math::Vector3f & ps_location, const math:: for (Particles::iterator it = particles().begin(); it != particles().end(); it++) { Particle *particle = (*it); + math::Axis rotation; + rotation.rotate(Camera::axis().forward(), particle->rotation()); + math::Vector3f l(attached() ? ps_location + ps_axis * particle->location() : particle->location()); const float r = particle->radius(); @@ -166,13 +173,13 @@ void ParticleEjectorSpray::draw(const math::Vector3f & ps_location, const math:: gl::color(c); glTexCoord2f(0, 1); - gl::vertex(l + quad[0] * r); + gl::vertex(l + rotation * quad[0] * r); glTexCoord2f(0, 0); - gl::vertex(l + quad[1] * r); + gl::vertex(l + rotation * quad[1] * r); glTexCoord2f(1, 0); - gl::vertex(l + quad[2] * r); + gl::vertex(l + rotation * quad[2] * r); glTexCoord2f(1, 1); - gl::vertex(l + quad[3] * r); + gl::vertex(l + rotation * quad[3] * r); Stats::quads++; } gl::end(); diff --git a/src/render/particleejector.h b/src/render/particleejector.h index 9e090d9..4d3ace9 100644 --- a/src/render/particleejector.h +++ b/src/render/particleejector.h @@ -75,12 +75,12 @@ private: }; /** - * @brief Spray particles + * @brief Sprite particles * */ -class ParticleEjectorSpray : public ParticleEjector { +class ParticleEjectorSprite : public ParticleEjector { public: - ParticleEjectorSpray(const ParticleEjectorScript &script); - virtual ~ParticleEjectorSpray(); + ParticleEjectorSprite(const ParticleEjectorScript &script); + virtual ~ParticleEjectorSprite(); protected: virtual void draw(const math::Vector3f & ps_location, const math::Axis & ps_axis); diff --git a/src/render/particleejectorscript.cc b/src/render/particleejectorscript.cc index 3609b9e..1aabbe7 100644 --- a/src/render/particleejectorscript.cc +++ b/src/render/particleejectorscript.cc @@ -12,7 +12,7 @@ namespace render ParticleEjectorScript::ParticleEjectorScript() { - script_type = Spray; + script_type = Sprite; script_interval = 100; script_cone = 0.0f; script_offset = 0.5f; diff --git a/src/render/particleejectorscript.h b/src/render/particleejectorscript.h index 5a79cc8..03f7294 100644 --- a/src/render/particleejectorscript.h +++ b/src/render/particleejectorscript.h @@ -20,7 +20,7 @@ public: /** * @brief definition for type of ejector * */ - enum Type {Jet = 0, Trail = 1, Flame = 2, Spray = 3, Flare = 4 }; + enum Type { Sprite = 0, Flare = 1, Trail = 2, Flame = 3 }; ParticleEjectorScript(); ParticleEjectorScript(const ParticleEjectorScript & other); diff --git a/src/render/particlesystem.cc b/src/render/particlesystem.cc index 920d77c..e6f8ccc 100644 --- a/src/render/particlesystem.cc +++ b/src/render/particlesystem.cc @@ -32,8 +32,8 @@ ParticleSystem::ParticleSystem(const ParticleSystemScript *script, const core::E for (ParticleSystemScript::Ejectors::const_iterator it = script->ejectors().begin(); it != script->ejectors().end(); ++it) { ParticleEjector *ejector = 0; switch ((*it)->type()) { - case ParticleEjector::Spray: - ejector = new ParticleEjectorSpray(*(*it)); + case ParticleEjector::Sprite: + ejector = new ParticleEjectorSprite(*(*it)); break; case ParticleEjector::Trail: diff --git a/src/render/particlesystemscript.cc b/src/render/particlesystemscript.cc index 866fce1..ff75093 100644 --- a/src/render/particlesystemscript.cc +++ b/src/render/particlesystemscript.cc @@ -26,21 +26,18 @@ void ParticleSystemScript::list() const ParticleEjectorScript *ejector = (*eit); switch (ejector->type()) { - case ParticleEjectorScript::Flame: - strval.append(" flame"); + case ParticleEjectorScript::Sprite: + strval.append(" sprite"); break; case ParticleEjectorScript::Flare: strval.append(" flare"); break; - case ParticleEjectorScript::Jet: - strval.append(" jet"); - break; - case ParticleEjectorScript::Spray: - strval.append(" spray"); - break; case ParticleEjectorScript::Trail: strval.append(" trail"); break; + case ParticleEjectorScript::Flame: + strval.append(" flame"); + break; } } con_print << " " << script->label() << strval << " " << script->script_ejectors.size() << " " << aux::plural("ejector", script->script_ejectors.size()) << std::endl; @@ -119,16 +116,14 @@ ParticleSystemScript *ParticleSystemScript::load(const std::string &label) if (inifile.got_key_string("type", strval)) { aux::to_label(strval); - if (strval.compare("jet") == 0) { - ejector->set_type(ParticleEjectorScript::Jet); + if (strval.compare("sprite") == 0) { + ejector->set_type(ParticleEjectorScript::Sprite); + } else if (strval.compare("flare") == 0) { + ejector->set_type(ParticleEjectorScript::Flare); } else if (strval.compare("trail") == 0) { ejector->set_type(ParticleEjectorScript::Trail); } else if (strval.compare("flame") == 0) { ejector->set_type(ParticleEjectorScript::Flame); - } else if (strval.compare("spray") == 0) { - ejector->set_type(ParticleEjectorScript::Spray); - } else if (strval.compare("flare") == 0) { - ejector->set_type(ParticleEjectorScript::Flare); } else { inifile.unknown_value(); } @@ -271,21 +266,18 @@ ParticleSystemScript *ParticleSystemScript::load(const std::string &label) const ParticleEjectorScript *ejector = (*eit); switch (ejector->type()) { - case ParticleEjectorScript::Flame: - strval.append(" flame"); + case ParticleEjectorScript::Sprite: + strval.append(" sprite"); break; case ParticleEjectorScript::Flare: strval.append(" flare"); break; - case ParticleEjectorScript::Jet: - strval.append(" jet"); - break; - case ParticleEjectorScript::Spray: - strval.append(" spray"); - break; case ParticleEjectorScript::Trail: strval.append(" trail"); break; + case ParticleEjectorScript::Flame: + strval.append(" flame"); + break; } } con_debug << " " << script->label() << strval << " " << script->script_ejectors.size() << " " << aux::plural("ejector", script->script_ejectors.size()) << std::endl; -- cgit v1.2.3