diff options
author | Stijn Buys <ingar@osirion.org> | 2008-07-29 23:00:48 +0000 |
---|---|---|
committer | Stijn Buys <ingar@osirion.org> | 2008-07-29 23:00:48 +0000 |
commit | ad436de3a520fb2469dafe23afe03dd0afe8d189 (patch) | |
tree | 5cf3a4a46d1b173ca1116cfe167ad4b9a824ef96 /src | |
parent | c706b919da0df4599aeda811255fb9f50a03ee69 (diff) |
reorganise some variables (lights/engine trails heisenbugs)
Diffstat (limited to 'src')
-rw-r--r-- | src/render/draw.cc | 81 |
1 files changed, 42 insertions, 39 deletions
diff --git a/src/render/draw.cc b/src/render/draw.cc index b552361..ee42bb6 100644 --- a/src/render/draw.cc +++ b/src/render/draw.cc @@ -606,14 +606,22 @@ void draw_pass_model_fragments() /* draw model lights and engines */ void draw_pass_model_fx(float elapsed) { - float t; - + const size_t count = 8; // number of engine trail particles + + float t = 0.0f; + float u = 0.0f; + float a = 0.0f; + float light_size = 0.0f; + float engine_size = 0.0f; + float trail_size = 0.0f; + + math::Vector3f quad[4]; + math::Color color; + size_t circle_texture = Textures::load("bitmaps/fx/circle00"); - size_t flare_texture = Textures::bind("bitmaps/fx/flare00"); gl::enable(GL_TEXTURE_2D); - gl::begin(gl::Quads); for (core::Zone::Content::iterator it = zone->content().begin(); it != zone->content().end(); it++) { @@ -623,17 +631,16 @@ void draw_pass_model_fx(float elapsed) // draw model lights for (model::Model::Lights::iterator lit = entity->model()->lights().begin(); lit != entity->model()->lights().end(); lit++) { - + model::Light *light = (*lit); + // strobe frequency t = 1.0f; - if ((*lit)->strobe()) - t = (core::application()->time() + entity->state()->fuzz() - (*lit)->offset()) * (*lit)->frequency(); - - if (!(*lit)->strobe() || (( t - floorf(t)) <= (*lit)->time())) { - model::Light *light = (*lit); + if (light->strobe()) + t = (core::application()->time() + entity->state()->fuzz() - light->offset()) * light->frequency(); + if (!light->strobe() || (( t - floorf(t)) <= light->time())) { math::Vector3f location = entity->state()->location() + (entity->state()->axis() * light->location()); - float light_size = 0.0625 * (*lit)->radius(); + light_size = 0.0625 * light->radius(); if (flare_texture != light->texture()) { gl::end(); @@ -641,7 +648,7 @@ void draw_pass_model_fx(float elapsed) gl::begin(gl::Quads); } - math::Color color; + if (light->entity()) { color.assign(entity->color()); } else { @@ -680,7 +687,7 @@ void draw_pass_model_fx(float elapsed) flare_axis.change_direction(flare->angle()); math::Vector3f location = entity->state()->location() + (entity->state()->axis() * flare->location()); - float light_size = 0.0625 * flare->radius(); + light_size = 0.0625 * flare->radius(); if (flare_texture != flare->texture()) { gl::end(); @@ -688,14 +695,13 @@ void draw_pass_model_fx(float elapsed) gl::begin(gl::Quads); } - math::Color color; if (flare->entity()) { color.assign(entity->color()); } else { color.assign(flare->color()); } - float a = dotproduct(flare_axis.forward(), Camera::axis().forward()); + a = dotproduct(flare_axis.forward(), Camera::axis().forward()); if (a < -0.1f) { color.a = -a - 0.1f; gl::color(color); @@ -716,26 +722,26 @@ void draw_pass_model_fx(float elapsed) } // draw model engines for Controlable entities - if (entity->type() == core::Entity::Controlable && entity->model()->engines().size()) { + if ((entity->type() == core::Entity::Controlable) && entity->model()->engines().size()) { - float u = static_cast<core::EntityControlable *>(entity)->thrust(); + u = static_cast<core::EntityControlable *>(entity)->thrust(); if (u > 0) { - float fraction = entity->state()->state_engine_trail_offset; - fraction += elapsed * 4.0f * u; + t = entity->state()->state_engine_trail_offset; + t += elapsed * 4.0f * u; - if (fraction > 1.0f) - fraction -= 1.0f; - math::clamp(fraction, 0.0f, 1.0f); + if (t > 1.0f) + t -= 1.0f; + math::clamp(t, 0.0f, 1.0f); - entity->state()->state_engine_trail_offset = fraction; + entity->state()->state_engine_trail_offset = t; for(model::Model::Engines::iterator eit = entity->model()->engines().begin(); eit != entity->model()->engines().end(); eit++) { model::Engine *engine = (*eit); math::Vector3f location = entity->state()->location() + (entity->state()->axis() * engine->location()); - float engine_size = 0.0625 * engine->radius(); + engine_size = 0.0625 * engine->radius(); math::Color color(engine->color()); color.a = 0.9f * u; @@ -745,8 +751,6 @@ void draw_pass_model_fx(float elapsed) gl::begin(gl::Quads); } - math::Vector3f quad[4]; - quad[0].assign(entity->state()->axis().up() - entity->state()->axis().left()); quad[1].assign(entity->state()->axis().up() + entity->state()->axis().left()); quad[2].assign(entity->state()->axis().up() * -1 + entity->state()->axis().left()); @@ -772,34 +776,33 @@ void draw_pass_model_fx(float elapsed) color.assign(1.0f, 1.0f); math::Vector3f offset = entity->state()->axis().forward() * engine_size; - if (fraction) - location -= offset * fraction; + if (t) + location -= offset * t; - const size_t count = 8; for (size_t i = count; i > 0; i--) { - float size = engine_size * 0.8f * (0.4f + ((-fraction + (float) i) / (float) count) * 0.6f); - color.a = (0.1f + ((-fraction + (float) i) / (float) count) * 0.7f) * u; + trail_size = engine_size * 0.8f * (0.4f + ((-t + (float) i) / (float) count) * 0.6f); + color.a = (0.1f + ((-t + (float) i) / (float) count) * 0.7f) * u; gl::color(color); glTexCoord2f(0,1); - gl::vertex(location + quad[0] * size); + gl::vertex(location + quad[0] * trail_size); glTexCoord2f(0,0); - gl::vertex(location + quad[1] * size); + gl::vertex(location + quad[1] * trail_size); glTexCoord2f(1,0); - gl::vertex(location + quad[2] * size); + gl::vertex(location + quad[2] * trail_size); glTexCoord2f(1,1); - gl::vertex(location + quad[3] * size); + gl::vertex(location + quad[3] * trail_size); Stats::quads++; gl::color(color); glTexCoord2f(1,1); - gl::vertex(location + quad[3] * size); + gl::vertex(location + quad[3] * trail_size); glTexCoord2f(1,0); - gl::vertex(location + quad[2] * size); + gl::vertex(location + quad[2] * trail_size); glTexCoord2f(0,0); - gl::vertex(location + quad[1] * size); + gl::vertex(location + quad[1] * trail_size); glTexCoord2f(0,1); - gl::vertex(location + quad[0] * size); + gl::vertex(location + quad[0] * trail_size); Stats::quads++; location -= offset; |