diff options
Diffstat (limited to 'src/render/particles.cc')
-rw-r--r-- | src/render/particles.cc | 214 |
1 files changed, 208 insertions, 6 deletions
diff --git a/src/render/particles.cc b/src/render/particles.cc index c232ca1..f9271ab 100644 --- a/src/render/particles.cc +++ b/src/render/particles.cc @@ -112,6 +112,9 @@ void ParticleScript::init() continue; } else if (inifile.got_key_float("speed", script->particles_speed)) { continue; + } else if (inifile.got_key_float("offset", script->particles_offset)) { + math::clamp(script->particles_offset, 0.0f, 1.0f); + continue; } else if (inifile.got_key_float("alpha", script->particles_alpha)) { continue; } else if (inifile.got_key_float("radius", script->particles_radius)) { @@ -159,6 +162,8 @@ ParticleScript::ParticleScript() particles_timeout = 2.0f; particles_eject = 0.25f; + particles_offset = 0.1f; + particles_color.assign(1.0f, 1.0f); } @@ -168,8 +173,7 @@ ParticleScript::~ParticleScript() /* ---- class ParticleSystem --------------------------------------- */ -ParticleSystem::ParticleSystem(ParticleScript *script, core::Entity *entity, const math::Vector3f &location) : - particlesystem_location(location) +ParticleSystem::ParticleSystem(ParticleScript *script, core::Entity *entity, model::Particles *modelclass) { particlesystem_entity = entity; particlesystem_last_eject = 0; // timestamp of the last eject @@ -177,10 +181,24 @@ ParticleSystem::ParticleSystem(ParticleScript *script, core::Entity *entity, con particlesystem_script = script; particlesystem_texture = 0; + particlesystem_modelclass = modelclass; + if (particlesystem_script) { particlesystem_texture = Textures::load("textures/" + particlesystem_script->texture()); + + radius = particlesystem_script->radius(); color.assign(particlesystem_script->color()); } + + if (particlesystem_modelclass) { + particlesystem_location.assign(modelclass->location()); + if (modelclass->entity()) { + color.assign(entity->color()); + } + if (modelclass->engine()) { + color.assign(entity->model()->enginecolor()); + } + } } ParticleSystem::~ParticleSystem() @@ -249,8 +267,8 @@ void ParticleSystem::draw(float elapsed) /* ---- class Jet -------------------------------------------------- */ -Jet::Jet(ParticleScript *script, core::Entity *entity, const math::Vector3f &location) : - ParticleSystem(script, entity, location) { +Jet::Jet(ParticleScript *script, core::Entity *entity, model::Particles *modelclass) : + ParticleSystem(script, entity, modelclass) { } Jet::~Jet() @@ -309,8 +327,8 @@ void Jet::draw(float elapsed) { /* ---- class Trail ------------------------------------------------ */ -Trail::Trail(ParticleScript *script, core::Entity *entity, const math::Vector3f &location) : - ParticleSystem(script, entity, location) { +Trail::Trail(ParticleScript *script, core::Entity *entity, model::Particles *modelclass) : + ParticleSystem(script, entity, modelclass) { } Trail::~Trail() @@ -340,6 +358,7 @@ void Trail::draw(float elapsed) { fp = tp / (0.9f * particlesystem_script->timeout()); fp = 1.0 - fp; } + tp = (now - (*first)->time()) / particlesystem_script->timeout(); if (tp > 0) { color.a = 0.0f; @@ -373,6 +392,7 @@ void Trail::draw(float elapsed) { f = t / (0.9f * particlesystem_script->timeout()); f = 1.0 - f; } + t = (now - (*next)->time()) / particlesystem_script->timeout(); color.a = fp * particlesystem_script->alpha(); gl::color(color); @@ -402,4 +422,186 @@ void Trail::draw(float elapsed) { } } +/* ---- class Flame ------------------------------------------------ */ + +Flame::Flame(ParticleScript *script, core::Entity *entity, model::Particles *modelclass) : + ParticleSystem(script, entity, modelclass) { +} + +Flame::~Flame() +{} + +void Flame::draw(float elapsed) { + + if (!particlesystem_script) + return; + + ParticleSystem::draw(elapsed); + + if (particlesystem_stream.size() > 1) { + + Textures::bind(particlesystem_texture); + gl::begin(gl::Quads); + + Stream::iterator first = particlesystem_stream.begin(); + + float tp = now - (*first)->time(); + float fp = 0; + + if (tp < particlesystem_script->timeout() * particlesystem_script->offset()) { + fp = tp / (particlesystem_script->offset() * particlesystem_script->timeout()); + } else { + tp = tp - particlesystem_script->timeout() * particlesystem_script->offset(); + fp = tp / ((1.0f - particlesystem_script->offset()) * particlesystem_script->timeout()); + fp = 1.0 - fp; + } + tp = (now - (*first)->time()) / particlesystem_script->timeout(); + + Stream::iterator next = first; + if (tp > 0) { + color.a = 0; + gl::color(color); + glTexCoord2f(1,0); + gl::vertex(ejector_location); + glTexCoord2f(0,0); + gl::vertex(ejector_location); + + color.a = fp * particlesystem_script->alpha(); + gl::color(color); + glTexCoord2f(0,tp); + gl::vertex((*next)->location() + (*next)->axis().left() * particlesystem_script->radius() * fp); + glTexCoord2f(1,tp); + gl::vertex((*next)->location() + (*next)->axis().up() * particlesystem_script->radius() * fp); + Stats::quads++; + + color.a = 0; + gl::color(color); + glTexCoord2f(1,0); + gl::vertex(ejector_location); + glTexCoord2f(0,0); + gl::vertex(ejector_location); + + color.a = fp * particlesystem_script->alpha(); + gl::color(color); + glTexCoord2f(0,tp); + gl::vertex((*next)->location() + (*next)->axis().up() * particlesystem_script->radius() * fp); + glTexCoord2f(1,tp); + gl::vertex((*next)->location() - (*next)->axis().left() * particlesystem_script->radius() * fp); + Stats::quads++; + + color.a = 0; + gl::color(color); + glTexCoord2f(1,0); + gl::vertex(ejector_location); + glTexCoord2f(0,0); + gl::vertex(ejector_location); + + color.a = fp * particlesystem_script->alpha(); + gl::color(color); + glTexCoord2f(0,tp); + gl::vertex((*next)->location() + (*next)->axis().left() * particlesystem_script->radius() * fp); + glTexCoord2f(1,tp); + gl::vertex((*next)->location() - (*next)->axis().up() * particlesystem_script->radius() * fp); + Stats::quads++; + + color.a = 0; + gl::color(color); + glTexCoord2f(1,0); + gl::vertex(ejector_location); + glTexCoord2f(0,0); + gl::vertex(ejector_location); + + color.a = fp * particlesystem_script->alpha(); + gl::color(color); + glTexCoord2f(0,tp); + gl::vertex((*next)->location() - (*next)->axis().up() * particlesystem_script->radius() * fp); + glTexCoord2f(1,tp); + gl::vertex((*next)->location() - (*next)->axis().left() * particlesystem_script->radius() * fp); + Stats::quads++; + } + + for (next++; next != particlesystem_stream.end(); next++) { + + float t = now - (*next)->time(); + float f = 0; + + if (t < particlesystem_script->timeout() * particlesystem_script->offset()) { + f = t / (particlesystem_script->offset() * particlesystem_script->timeout()); + } else { + t = t - particlesystem_script->timeout() * particlesystem_script->offset(); + f = t / ((1.0f - particlesystem_script->offset()) * particlesystem_script->timeout()); + f = 1.0 - f; + } + t = (now - (*next)->time()) / particlesystem_script->timeout(); + + color.a = fp * particlesystem_script->alpha(); + gl::color(color); + glTexCoord2f(1,tp); + gl::vertex((*first)->location() + (*first)->axis().up() * particlesystem_script->radius() * fp); + glTexCoord2f(0,tp); + gl::vertex((*first)->location() + (*first)->axis().left() * particlesystem_script->radius() * fp); + + color.a = f * particlesystem_script->alpha(); + gl::color(color); + glTexCoord2f(0,t); + gl::vertex((*next)->location() + (*next)->axis().left() * particlesystem_script->radius() * f); + glTexCoord2f(1,t); + gl::vertex((*next)->location() + (*next)->axis().up() * particlesystem_script->radius() * f); + Stats::quads++; + + color.a = fp * particlesystem_script->alpha(); + gl::color(color); + glTexCoord2f(1,tp); + gl::vertex((*first)->location() - (*first)->axis().left() * particlesystem_script->radius() * fp); + glTexCoord2f(0,tp); + gl::vertex((*first)->location() + (*first)->axis().up() * particlesystem_script->radius() * fp); + + color.a = f * particlesystem_script->alpha(); + gl::color(color); + glTexCoord2f(0,t); + gl::vertex((*next)->location() + (*next)->axis().up() * particlesystem_script->radius() * f); + glTexCoord2f(1,t); + gl::vertex((*next)->location() - (*next)->axis().left() * particlesystem_script->radius() * f); + Stats::quads++; + + color.a = fp * particlesystem_script->alpha(); + gl::color(color); + glTexCoord2f(1,tp); + gl::vertex((*first)->location() - (*first)->axis().up() * particlesystem_script->radius() * fp); + glTexCoord2f(0,tp); + gl::vertex((*first)->location() + (*first)->axis().left() * particlesystem_script->radius() * fp); + + color.a = f * particlesystem_script->alpha(); + gl::color(color); + glTexCoord2f(0,t); + gl::vertex((*next)->location() + (*next)->axis().left() * particlesystem_script->radius() * f); + glTexCoord2f(1,t); + gl::vertex((*next)->location() - (*next)->axis().up() * particlesystem_script->radius() * f); + Stats::quads++; + + color.a = fp * particlesystem_script->alpha(); + gl::color(color); + glTexCoord2f(1,tp); + gl::vertex((*first)->location() - (*first)->axis().left() * particlesystem_script->radius() * fp); + glTexCoord2f(0,tp); + gl::vertex((*first)->location() - (*first)->axis().up() * particlesystem_script->radius() * fp); + + color.a = f * particlesystem_script->alpha(); + gl::color(color); + glTexCoord2f(0,t); + gl::vertex((*next)->location() - (*next)->axis().up() * particlesystem_script->radius() * f); + glTexCoord2f(1,t); + gl::vertex((*next)->location() - (*next)->axis().left() * particlesystem_script->radius() * f); + Stats::quads++; + + first = next; + fp = f; + tp = t; + } + + + gl::end(); + } +} + } // namespace render |