diff options
author | Stijn Buys <ingar@osirion.org> | 2008-11-15 19:24:55 +0000 |
---|---|---|
committer | Stijn Buys <ingar@osirion.org> | 2008-11-15 19:24:55 +0000 |
commit | 28ba97bdd8fb6ca352dc49dba01a66bd155ad523 (patch) | |
tree | eb4abd0505eb842e15201783529814bda1ae6e76 /src/render/renderext.cc | |
parent | 1f0dbeeabdffff096908473168898c5fa63bcff0 (diff) |
entity extensions
Diffstat (limited to 'src/render/renderext.cc')
-rw-r--r-- | src/render/renderext.cc | 114 |
1 files changed, 114 insertions, 0 deletions
diff --git a/src/render/renderext.cc b/src/render/renderext.cc new file mode 100644 index 0000000..ffe462f --- /dev/null +++ b/src/render/renderext.cc @@ -0,0 +1,114 @@ +/* + render/renderext.cc + This file is part of the Osirion project and is distributed under + the terms of the GNU General Public License version 2 +*/ + +#include <sstream> +#include <iomanip> + +#include "math/functions.h" +#include "core/range.h" +#include "model/model.h" +#include "render/renderext.h" +#include "render/render.h" +#include "render/textures.h" + +namespace render +{ + +RenderExt::RenderExt(core::Entity *entity) : core::Extension(core::Extension::Render, entity) +{ + state_visible = false; + state_detailvisible = false; + state_fuzz = math::randomf(); + + state_engine_trail_offset = 0; + + using namespace model; + + if (entity->model()) { + model::Model *model = entity->model(); + + for (Model::Lights::iterator lit = model->lights().begin(); lit != model->lights().end(); lit++) { + Light *light = (*lit); + + // load light texture + std::stringstream flarename; + flarename << "bitmaps/fx/flare" << std::setfill('0') << std::setw(2) << light->flare(); + light->render_texture = Textures::load(flarename.str()); + } + + for(Model::Engines::iterator eit = model->engines().begin(); eit != model->engines().end(); eit++) { + Engine *engine = (*eit); + + if (!engine->flare()) engine->engine_flare = 1; + + // load engine texture + std::stringstream flarename; + flarename << "bitmaps/fx/flare" << std::setfill('0') << std::setw(2) << engine->flare(); + engine->render_texture = Textures::load(flarename.str()); + } + + for (Model::Flares::iterator flit = model->flares().begin(); flit != model->flares().end(); flit++) { + Flare *flare = (*flit); + + // load flare texture + std::stringstream flarename; + flarename << "bitmaps/fx/flare" << std::setfill('0') << std::setw(2) << flare->flare(); + flare->render_texture = Textures::load(flarename.str()); + } + } else if (entity->type() == core::Entity::Globe) { + core::EntityGlobe *globe = static_cast<core::EntityGlobe *>(entity); + + // load globe textures + if (!globe->render_texture && globe->texture().size()) { + std::stringstream texname; + texname << "textures/" << globe->texture(); + globe->render_texture = Textures::load(texname.str()); + if (!globe->render_texture) + globe->entity_texture.clear(); + } + } +} + +RenderExt::~RenderExt() +{ +} + +void RenderExt::frame(float elapsed) +{ + state_distance = math::distance(Camera::eye(), entity()->location()); + + state_visible = entity()->visible(); + state_detailvisible = false; + + if ((entity()->type() == core::Entity::Controlable)) { + if (static_cast<core::EntityDynamic *>(entity())->eventstate() == core::Entity::Docked) { + state_visible = false; + } + } + + if (state_visible && entity()->model()) { + float r = entity()->model()->radius(); + math::clamp(r, 1.0f, farplane / drawfxdistance); + if (distance() < drawfxdistance * r) { + // entity within detail range + state_visible = true; + state_detailvisible = true; + } else if ((distance() < drawdistance * r) && (distance() < core::range::max)) { + // entity within drawing distance, outside detail range + state_visible = true; + state_detailvisible = false; + } else { + // entity out of range + state_visible = false; + state_detailvisible = false; + } + } + +} + +} // namespace render + + |