From f7283b2b9a9bf305ac110ef00cd5c21d5304bfbb Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Sun, 25 May 2008 16:44:37 +0000 Subject: target_flare --- src/render/draw.cc | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 65 insertions(+), 4 deletions(-) (limited to 'src/render/draw.cc') diff --git a/src/render/draw.cc b/src/render/draw.cc index f84abe7..351b1a6 100644 --- a/src/render/draw.cc +++ b/src/render/draw.cc @@ -239,6 +239,16 @@ void pass_prepare(float seconds) flarename << "bitmaps/fx/flare" << std::setfill('0') << std::setw(2) << light->flare(); light->render_texture = Textures::load(flarename.str()); } + + for (std::list::iterator flit = entity->model()->model_flare.begin(); flit != entity->model()->model_flare.end(); flit++) { + model::Flare *flare = (*flit); + + // load flare texture + // FIXME optimize + std::stringstream flarename; + flarename << "bitmaps/fx/flare" << std::setfill('0') << std::setw(2) << flare->flare(); + flare->render_texture = Textures::load(flarename.str()); + } } } @@ -487,6 +497,57 @@ void draw_pass_model_fx() } } + // draw flares + for (std::list::iterator flit = entity->model()->model_flare.begin(); flit != entity->model()->model_flare.end(); flit++) { + + model::Flare *flare = (*flit); + + // strobe frequency + t = 1.0f; + if (flare->strobe()) + t = (core::application()->time() + entity->state()->fuzz() - flare->offset()) * flare->frequency(); + + if (!flare->strobe() || (( t - floorf(t)) <= flare->time())) { + math::Axis flare_axis(entity->state()->axis()); + if (flare->angle()) + flare_axis.change_direction(flare->angle()); + + math::Vector3f location = entity->state()->location() + (entity->state()->axis() * flare->location()); + float light_size = 0.0625 * flare->radius(); + + if (flare->render_texture != flare_texture) { + gl::end(); + flare_texture = Textures::bind(flare->render_texture); + 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()); + if (a < -0.1f) { + color.a = -a - 0.1f; + gl::color(color); + + glTexCoord2f(0,1); + gl::vertex(location + (flare_axis.up() + flare_axis.left()) * light_size); + glTexCoord2f(0,0); + gl::vertex(location + (flare_axis.up() - flare_axis.left()) * light_size); + glTexCoord2f(1,0); + gl::vertex(location + (flare_axis.up() * -1 - flare_axis.left()) * light_size); + glTexCoord2f(1,1); + gl::vertex(location + (flare_axis.up() * -1 + flare_axis.left()) * light_size); + + Stats::quads++; + } + + } + } + // draw model engines for Controlable entities if (entity->type() == core::Entity::Controlable && entity->model()->model_engine.size()) { @@ -513,13 +574,13 @@ void draw_pass_model_fx() gl::color(color); glTexCoord2f(0,1); - gl::vertex(location + (camera_axis.up() - camera_axis.left()) * engine_size); + gl::vertex(location + (entity->state()->axis().up() - entity->state()->axis().left()) * engine_size); glTexCoord2f(0,0); - gl::vertex(location + (camera_axis.up() + camera_axis.left()) * engine_size); + gl::vertex(location + (entity->state()->axis().up() + entity->state()->axis().left()) * engine_size); glTexCoord2f(1,0); - gl::vertex(location + (camera_axis.up() * -1 + camera_axis.left()) * engine_size); + gl::vertex(location + (entity->state()->axis().up() * -1 + entity->state()->axis().left()) * engine_size); glTexCoord2f(1,1); - gl::vertex(location + (camera_axis.up() * -1 - camera_axis.left()) * engine_size); + gl::vertex(location + (entity->state()->axis().up() * -1 - entity->state()->axis().left()) * engine_size); Stats::quads++; } -- cgit v1.2.3