From 3da609588ad6fe7eb0581e4678a2ec8c6c1c4a18 Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Thu, 31 Jul 2008 12:43:43 +0000 Subject: more heisenbugs fixes --- src/render/draw.cc | 76 ++++++++++++++++++------------------------------------ 1 file changed, 25 insertions(+), 51 deletions(-) (limited to 'src/render/draw.cc') diff --git a/src/render/draw.cc b/src/render/draw.cc index 13f9ee6..c575f20 100644 --- a/src/render/draw.cc +++ b/src/render/draw.cc @@ -43,10 +43,8 @@ const float drawdistance = 128.0f; const float drawfxdistance = 64.0f; core::Zone *zone = 0; -float angle = 0; - // function to test flags -inline bool flag_is_set(unsigned int spawnflags, unsigned int flag) { +inline bool flag_is_set(unsigned int const spawnflags, unsigned int const flag) { return ((spawnflags & flag) == flag); } @@ -497,24 +495,6 @@ void pass_prepare(float seconds) } } } - - /* - // calculate screen position - if (entity->state()->visible()) { - GLdouble x = 0; - GLdouble y = 0; - GLdouble z = 0; - - math::Vector3f const & pos = entity->state()->location(); - if (gluProject((GLdouble) pos.x , (GLdouble)pos.y, (GLdouble)pos.z, gl_model_matrix, gl_projection_matrix, gl_viewport, &x, &y, &z) == GL_TRUE) { - entity->state()->state_screenlocation[0] = x; - entity->state()->state_screenlocation[1] = y; - entity->state()->state_screenlocation[2] = z; - entity->state()->state_targetable = true; - } - } - */ - } } @@ -639,9 +619,14 @@ void draw_pass_model_fx(float elapsed) math::Vector3f offset; math::Color color; - + model::Light *light; + model::Flare *flare; + model::Engine *engine; + + math::Axis flare_axis; + size_t circle_texture = Textures::load("bitmaps/fx/circle00"); - size_t flare_texture = Textures::bind("bitmaps/fx/flare00"); + size_t current_texture = Textures::bind("bitmaps/fx/flare00"); gl::enable(GL_TEXTURE_2D); gl::begin(gl::Quads); @@ -649,28 +634,26 @@ void draw_pass_model_fx(float elapsed) for (core::Zone::Content::iterator it = zone->content().begin(); it != zone->content().end(); it++) { core::Entity *entity = (*it); - if (entity->model() && entity->state()->detailvisible()) { + if (entity->model() && entity->state() && entity->state()->detailvisible()) { // draw model lights for (model::Model::Lights::iterator lit = entity->model()->lights().begin(); lit != entity->model()->lights().end(); lit++) { - model::Light *light = (*lit); + light = (*lit); // strobe frequency t = 1.0f; if (light->strobe()) - t = (core::application()->time() + entity->state()->fuzz() - light->offset()) * light->frequency(); - + t = (core::application()->time() - light->offset() - entity->state()->fuzz()) * light->frequency(); if ((!light->strobe()) || (( t - floorf(t)) <= light->time())) { location.assign(entity->state()->location() - Camera::eye() + (entity->state()->axis() * light->location())); light_size = 0.0625 * light->radius(); - if (flare_texture != light->texture()) { + if (current_texture != light->texture()) { gl::end(); - flare_texture = Textures::bind(light->texture()); + current_texture = Textures::bind(light->texture()); gl::begin(gl::Quads); } - if (light->entity()) { color.assign(entity->color()); } else { @@ -687,16 +670,13 @@ void draw_pass_model_fx(float elapsed) gl::vertex(location + (Camera::axis().up() * -1 + Camera::axis().left()) * light_size); glTexCoord2f(1,1); gl::vertex(location + (Camera::axis().up() * -1 - Camera::axis().left()) * light_size); - Stats::quads++; - } } // draw flares - for (model::Model::Flares::iterator flit = entity->model()->flares().begin(); flit != entity->model()->flares().end(); flit++) { - - model::Flare *flare = (*flit); + for (model::Model::Flares::iterator flit = entity->model()->flares().begin(); flit != entity->model()->flares().end(); flit++) { + flare = (*flit); // strobe frequency t = 1.0f; @@ -704,16 +684,16 @@ void draw_pass_model_fx(float elapsed) 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()); + flare_axis.assign(entity->state()->axis()); if (flare->angle()) flare_axis.change_direction(flare->angle()); location.assign(entity->state()->location() - Camera::eye() + (entity->state()->axis() * flare->location())); light_size = 0.0625 * flare->radius(); - if (flare_texture != flare->texture()) { + if (current_texture != flare->texture()) { gl::end(); - flare_texture = Textures::bind(flare->texture()); + current_texture = Textures::bind(flare->texture()); gl::begin(gl::Quads); } @@ -723,6 +703,7 @@ void draw_pass_model_fx(float elapsed) color.assign(flare->color()); } + // FIXME Camera::axis().forward() should be the vector flare_location - camera_eye a = dotproduct(flare_axis.forward(), Camera::axis().forward()); if (a < -0.1f) { color.a = -a - 0.1f; @@ -755,21 +736,20 @@ void draw_pass_model_fx(float elapsed) if (t > 1.0f) t -= 1.0f; math::clamp(t, 0.0f, 1.0f); - 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); + engine = (*eit); location.assign(entity->state()->location() - Camera::eye() + (entity->state()->axis() * engine->location())); engine_size = 0.0625 * engine->radius(); color.assign(engine->color()); color.a = 0.9f * u; - if (flare_texture != engine->texture() ) { + if (current_texture != engine->texture() ) { gl::end(); - flare_texture = Textures::bind(engine->texture()); + current_texture = Textures::bind(engine->texture()); gl::begin(gl::Quads); } @@ -790,15 +770,15 @@ void draw_pass_model_fx(float elapsed) Stats::quads++; // draw the engine trail - if (flare_texture != circle_texture) { + if (current_texture != circle_texture) { gl::end(); - flare_texture = Textures::bind(circle_texture); + current_texture = Textures::bind(circle_texture); gl::begin(gl::Quads); } color.assign(1.0f, 1.0f); offset.assign(entity->state()->axis().forward() * engine_size); - if (t) + if (t > 0) location -= offset * t; for (size_t i = count; i > 0; i--) { @@ -937,12 +917,6 @@ void draw(float seconds) zone = core::localplayer()->zone(); if (!zone) return; - - // used for animations - angle += 180.0f * seconds; - if( angle > 360.0f ) { - angle -= 360.0f; - } Camera::frame(seconds); Camera::draw(); // draw the current camera transformation -- cgit v1.2.3