diff options
Diffstat (limited to 'src/core/model.cc')
-rw-r--r-- | src/core/model.cc | 88 |
1 files changed, 38 insertions, 50 deletions
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 <vector> #include <list> -#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<math::Vector3f *>::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<std::string, Model*> 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<Face *>::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<Engine *>::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<std::string, Model*>::iterator it = registry.find(name); |