diff options
-rw-r--r-- | src/render/particleejector.cc | 77 | ||||
-rw-r--r-- | src/render/particleejector.h | 12 | ||||
-rw-r--r-- | src/render/particleejectorscript.cc | 3 | ||||
-rw-r--r-- | src/render/particleejectorscript.h | 34 | ||||
-rw-r--r-- | src/render/particlesystem.cc | 12 | ||||
-rw-r--r-- | src/render/particlesystemscript.cc | 25 |
6 files changed, 155 insertions, 8 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 diff --git a/src/render/particleejector.h b/src/render/particleejector.h index 17e4688..743e370 100644 --- a/src/render/particleejector.h +++ b/src/render/particleejector.h @@ -112,6 +112,18 @@ protected: virtual void draw(const math::Vector3f & ps_location, const math::Axis & ps_axis); }; +/** + * @brief Streak particles + * */ +class ParticleEjectorStreak : public ParticleEjector { +public: + ParticleEjectorStreak(const ParticleEjectorScript &script); + virtual ~ParticleEjectorStreak(); + +protected: + virtual void draw(const math::Vector3f & ps_location, const math::Axis & ps_axis); +}; + } // namespace render #endif // __INCLUDED_RENDER_PARTICLEEJECTOR_H__ diff --git a/src/render/particleejectorscript.cc b/src/render/particleejectorscript.cc index 1eb1eff..2b6f8ce 100644 --- a/src/render/particleejectorscript.cc +++ b/src/render/particleejectorscript.cc @@ -26,6 +26,7 @@ ParticleEjectorScript::ParticleEjectorScript() script_cull = model::CullNone; script_spawn_radius = 0.0f; script_attached = false; + script_scaled = false; } ParticleEjectorScript::ParticleEjectorScript(const ParticleEjectorScript &other) @@ -44,12 +45,14 @@ ParticleEjectorScript::ParticleEjectorScript(const ParticleEjectorScript &other) script_thrust = other.thrust(); script_cull = other.cull(); script_attached = other.attached(); + script_scaled = other.scaled(); script_texture.assign(other.texture()); script_axis.assign(other.axis()); script_radius_vec.assign(other.radius_vec()); script_alpha_vec.assign(other.alpha_vec()); script_speed_vec.assign(other.speed_vec()); + script_tailspeed_vec.assign(other.tailspeed_vec()); script_color.assign(other.color()); } diff --git a/src/render/particleejectorscript.h b/src/render/particleejectorscript.h index 731dbe2..4ba8dea 100644 --- a/src/render/particleejectorscript.h +++ b/src/render/particleejectorscript.h @@ -119,6 +119,15 @@ public: { return script_attached; } + + /** + * @brief ejector particles and speed are scaled according to modelscale + * */ + inline const bool scaled() const + { + return script_scaled; + } + /** * @brief name of the texture used to render ejected particles @@ -168,6 +177,14 @@ public: } /** + * @brief minimum and maximum tail speed of ejected particles, in gameunits per second + * */ + inline const math::Vector2f & tailspeed_vec() const + { + return script_tailspeed_vec; + } + + /** * @brief acceleration of ejected particles, in gameunits per second squared * */ inline const float acceleration() const @@ -219,6 +236,14 @@ public: } /** + * @brief return a reference to the tail speed vector + * */ + inline math::Vector2f &get_tailspeed_vec() + { + return script_tailspeed_vec; + } + + /** * @brief return a reference to particle color * */ inline math::Color &get_color() @@ -370,6 +395,11 @@ public: script_attached = attached; } + inline void set_scaled(const bool scaled) + { + script_scaled = scaled; + } + /** * @brief set the particle color * */ @@ -398,6 +428,8 @@ private: /// minimum and maximum speed of ejected particles, in gameunits per second math::Vector2f script_speed_vec; + /// minimum and maximum speed of ejected tail particles, in gameunits per second + math::Vector2f script_tailspeed_vec; /// acceleration of ejected particles, in gameunits per second squared float script_acceleration; /// spawn radius @@ -418,6 +450,8 @@ private: bool script_impulse; /// ejector is attached to entity coordinates bool script_attached; + /// ejector particles and speed are scaled according to modelscale + bool script_scaled; /// texture to render particles with std::string script_texture; diff --git a/src/render/particlesystem.cc b/src/render/particlesystem.cc index 518a5f7..9cc2fca 100644 --- a/src/render/particlesystem.cc +++ b/src/render/particlesystem.cc @@ -43,6 +43,11 @@ ParticleSystem::ParticleSystem(const ParticleSystemScript *script, const core::E case ParticleEjector::Trail: ejector = new ParticleEjectorTrail(*(*it)); break; + + case ParticleEjector::Streak: + ejector = new ParticleEjectorStreak(*(*it)); + break; + default: break; } @@ -96,6 +101,13 @@ ParticleSystem::ParticleSystem(const ParticleSystemScript *script, const core::E } } } + + if (ejector->scaled()) { + ejector->get_speed_vec() *= particlesystem_modelscale; + ejector->get_tailspeed_vec() *= particlesystem_modelscale; + ejector->get_radius_vec() *= particlesystem_modelscale; + ejector->set_acceleration(ejector->acceleration() * particlesystem_modelscale); + } } } } diff --git a/src/render/particlesystemscript.cc b/src/render/particlesystemscript.cc index 2f90f1b..0fad772 100644 --- a/src/render/particlesystemscript.cc +++ b/src/render/particlesystemscript.cc @@ -27,10 +27,10 @@ void ParticleSystemScript::list() switch (ejector->type()) { case ParticleEjectorScript::Sprite: - strval.append(" sprite"); + strval.append(" sprites"); break; case ParticleEjectorScript::Flare: - strval.append(" flare"); + strval.append(" flares"); break; case ParticleEjectorScript::Trail: strval.append(" trail"); @@ -39,7 +39,7 @@ void ParticleSystemScript::list() strval.append(" flame"); break; case ParticleEjectorScript::Streak: - strval.append(" streak"); + strval.append(" streaks"); break; } } @@ -128,7 +128,7 @@ ParticleSystemScript *ParticleSystemScript::load(const std::string &label) } else { inifile.unknown_error("ejector section without particles section"); } - } else if (inifile.got_section("streak")) { + } else if (inifile.got_section("streaks")) { if (script) { ejector = script->add_ejector(); ejector->set_type(ParticleEjectorScript::Streak); @@ -146,7 +146,7 @@ ParticleSystemScript *ParticleSystemScript::load(const std::string &label) } else if (script) { - if (inifile.in_section("sprites") || inifile.in_section("flares") || inifile.in_section("trail") || inifile.in_section("flame") || inifile.in_section("streak")) { + if (inifile.in_section("sprites") || inifile.in_section("flares") || inifile.in_section("trail") || inifile.in_section("flame") || inifile.in_section("streaks")) { if (inifile.got_key_string("cull", strval)) { aux::to_label(strval); @@ -171,6 +171,11 @@ ParticleSystemScript *ParticleSystemScript::load(const std::string &label) ejector->get_speed_vec() *= 0.01f; continue; + } else if (inifile.got_key_vector2f_opt("tailspeed", ejector->get_tailspeed_vec())) { + // convert tail speed from meters/second to game units/second + ejector->get_tailspeed_vec() *= 0.01f; + continue; + } else if (inifile.got_key_float("acceleration", f)) { // convert speed from meters/second to game units/second ejector->set_acceleration(f * 0.01f); @@ -241,6 +246,10 @@ ParticleSystemScript *ParticleSystemScript::load(const std::string &label) ejector->set_attached(b); continue; + } else if (inifile.got_key_bool("scaled", b)) { + ejector->set_scaled(b); + continue; + } else if (inifile.got_key_float("angle", yaw)) { if (yaw == model::ANGLEUP) { @@ -292,10 +301,10 @@ ParticleSystemScript *ParticleSystemScript::load(const std::string &label) switch (ejector->type()) { case ParticleEjectorScript::Sprite: - strval.append(" sprite"); + strval.append(" sprites"); break; case ParticleEjectorScript::Flare: - strval.append(" flare"); + strval.append(" flares"); break; case ParticleEjectorScript::Trail: strval.append(" trail"); @@ -304,7 +313,7 @@ ParticleSystemScript *ParticleSystemScript::load(const std::string &label) strval.append(" flame"); break; case ParticleEjectorScript::Streak: - strval.append(" streak"); + strval.append(" streaks"); break; } } |