From df61a28d708c30e3e77d1f739dfb4561c042c89c Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Thu, 6 Mar 2008 22:59:40 +0000 Subject: moved render::Model to core::Model --- src/core/model.cc | 88 ++++++++++++++++++++++++------------------------------- 1 file changed, 38 insertions(+), 50 deletions(-) (limited to 'src/core/model.cc') diff --git a/src/core/model.cc b/src/core/model.cc index ae34270..3b1cabd 100644 --- a/src/core/model.cc +++ b/src/core/model.cc @@ -12,16 +12,17 @@ #include #include -#include "render/model.h" -#include "render/gl.h" +#include "core/model.h" #include "filesystem/filesystem.h" -namespace render +namespace core { const float MAX_BOUNDS = 8192; const float delta = 10e-10; +/* ---------- core::Engine ------------------------------------------ */ + Engine::Engine(math::Vector3f const & location) : engine_location(location) {} @@ -29,6 +30,40 @@ Engine::Engine(math::Vector3f const & location) : Engine::~Engine() {} +/* ---------- core::Face ------------------------------------------ */ + +Face::Face(math::Vector3f const & normal, math::Color const *color) : + face_normal(normal) +{ + face_normal.normalize(); + + if (color) + face_color = new math::Color(*color); + else + face_color = 0; +} + +Face::~Face() +{ + for (std::vector::iterator it = face_vertex.begin(); it != face_vertex.end(); it++) { + delete (*it); + } + + face_vertex.clear(); + + if (face_color) + delete face_color; +} + +void Face::add_vertex(math::Vector3f const & vertex) +{ + math::Vector3f *v = new math::Vector3f(vertex); + + face_vertex.push_back(v); +} + +/* ---------- core::Model ------------------------------------------ */ + std::map Model::registry; Model::Model(std::string const & name) : @@ -446,53 +481,6 @@ void Model::add_engine(Engine *engine) model_engine.push_back(engine); } -void Model::draw(core::Entity const * entity, math::Vector3f const & eye) -{ - //gl::scale(model_scale, model_scale, model_scale); - - // calculate a normal from eye to entity location - math::Vector3f n = entity->location() - eye; - n.normalize(); - - // draw all faces - for (std::list::iterator fit = model_face.begin(); fit != model_face.end(); fit++) { - // poor man's lighting - // set the face color depending on the viewing direction - //float d = fabsf(math::dotproduct(n, (*fit)->normal())); - - //if (d > 1) - // d = 1; - //d = 0.5f + d/2; - - if ((*fit)->color()) { - render::gl::color(*(*fit)->color()); - } else { - render::gl::color(entity->color()); - } - (*fit)->draw(); - } -} - -void Model::draw(core::EntityControlable const * entity, math::Vector3f const & eye) -{ - // draw the model - draw((core::Entity *) entity, eye); - - // draw engines - // all engines are assumed to point to the rear - if (model_engine.size() && entity->thrust()) { - gl::color(1.0f,0 ,0); - gl::begin(gl::Lines); - - for (std::list::iterator eit = model_engine.begin(); eit != model_engine.end(); eit++) { - math::Vector3f const & v = (*eit)->location(); - gl::vertex(v); - gl::vertex(v.x - 0.0625f*entity->thrust(), v.y, v.z); - } - gl::end(); - } -} - Model *Model::find(std::string const & name) { std::map::iterator it = registry.find(name); -- cgit v1.2.3