diff options
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/Makefile.am | 4 | ||||
-rw-r--r-- | src/core/face.cc | 53 | ||||
-rw-r--r-- | src/core/face.h | 43 | ||||
-rw-r--r-- | src/core/gameinterface.cc | 12 | ||||
-rw-r--r-- | src/core/model.cc | 88 | ||||
-rw-r--r-- | src/core/model.h | 51 |
6 files changed, 87 insertions, 164 deletions
diff --git a/src/core/Makefile.am b/src/core/Makefile.am index 8a65e9a..6f78e6a 100644 --- a/src/core/Makefile.am +++ b/src/core/Makefile.am @@ -2,8 +2,8 @@ METASOURCES = AUTO INCLUDES = -I$(top_srcdir)/src libcore_la_SOURCES = application.cc commandbuffer.cc core.cc cvar.cc entity.cc \ - func.cc gameconnection.cc gameinterface.cc gameserver.cc module.cc netclient.cc \ - netconnection.cc netserver.cc player.cc + func.cc gameconnection.cc gameinterface.cc gameserver.cc model.cc module.cc \ + netclient.cc netconnection.cc netserver.cc player.cc libcore_la_LDFLAGS = -avoid-version -no-undefined libcore_la_LIBADD = $(top_builddir)/src/math/libmath.la \ $(top_builddir)/src/filesystem/libfilesystem.la $(top_builddir)/src/sys/libsys.la $(top_builddir)/src/net/libnet.la diff --git a/src/core/face.cc b/src/core/face.cc deleted file mode 100644 index 31b7fcc..0000000 --- a/src/core/face.cc +++ /dev/null @@ -1,53 +0,0 @@ -/* - render/face.cc - This file is part of the Osirion project and is distributed under - the terms of the GNU General Public License version 2 -*/ - -#include "render/face.h" -#include "render/gl.h" - -namespace render { - -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); -} - -void Face::draw() -{ - //gl::begin(gl::LineLoop); - gl::begin(gl::Polygon); - gl::normal(face_normal); // face_normal already has unit lenght - for (std::vector<math::Vector3f *>::iterator it = face_vertex.begin(); it != face_vertex.end(); it++) { - gl::vertex(*(*it)); - } - gl::end(); -} - -} diff --git a/src/core/face.h b/src/core/face.h deleted file mode 100644 index a0a4d5a..0000000 --- a/src/core/face.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - render/face.h - This file is part of the Osirion project and is distributed under - the terms of the GNU General Public License version 2 -*/ - -#ifndef __INCLUDED_RENDER_FACE_H__ -#define __INCLUDED_RENDER_FACE_H__ - -#include <vector> - -#include "math/mathlib.h" - -namespace render { - -/// one face (polygon) of a model -class Face { -public: - Face(math::Vector3f const & normal, math::Color const *color=0); - ~Face(); - - /// the normal of this face - inline math::Vector3f const & normal() const { return face_normal; }; - - /// the color of this face - inline math::Color const *color() const { return face_color; }; - - /// add a vertex to the face - void add_vertex(math::Vector3f const &vertex); - - /// draw the polygon - void draw(); - -private: - math::Vector3f face_normal; - math::Color *face_color; - std::vector<math::Vector3f *> face_vertex; -}; - -} - -#endif // __INCLUDED_RENDER_FACE_H__ - diff --git a/src/core/gameinterface.cc b/src/core/gameinterface.cc index 9aa50fc..1f8f265 100644 --- a/src/core/gameinterface.cc +++ b/src/core/gameinterface.cc @@ -12,11 +12,17 @@ #include "core/cvar.h" #include "core/func.h" #include "core/gameinterface.h" +#include "core/model.h" #include "core/player.h" namespace core { +void func_list_model(std::string const &args) +{ + Model::list(); +} + Player GameInterface::game_localplayer; EntityControlable *localcontrol() @@ -54,10 +60,13 @@ GameInterface::GameInterface() } + core::Func::add("list_model", (core::FuncPtr) func_list_model); } GameInterface::~GameInterface() { + core::Func::remove("list_model"); + clear(); } @@ -87,6 +96,9 @@ void GameInterface::clear() Cvar::registry.erase(it); } } + + // remove all models + Model::clear(); } 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); diff --git a/src/core/model.h b/src/core/model.h index eca896b..e22d87a 100644 --- a/src/core/model.h +++ b/src/core/model.h @@ -4,19 +4,44 @@ the terms of the GNU General Public License version 2 */ -#ifndef __INCLUDED_RENDER_MODEL_H__ -#define __INCLUDED_RENDER_MODEL_H__ +#ifndef __INCLUDED_CORE_MODEL_H__ +#define __INCLUDED_CORE_MODEL_H__ +#include <vector> #include <map> #include <list> +#include "math/mathlib.h" #include "math/plane3f.h" #include "core/entity.h" -#include "render/face.h" -namespace render +namespace core { +/// one face (polygon) of a model +class Face { +public: + Face(math::Vector3f const & normal, math::Color const *color=0); + ~Face(); + + /// the normal of this face + inline math::Vector3f const & normal() const { return face_normal; }; + + /// the color of this face + inline math::Color const *color() const { return face_color; }; + + /// add a vertex to the face + void add_vertex(math::Vector3f const &vertex); + + /// face vertexes + std::vector<math::Vector3f *> face_vertex; + +private: + math::Vector3f face_normal; + math::Color *face_color; + +}; + /// a spacecraft engine class Engine { @@ -50,16 +75,6 @@ public: /// the Model registry static std::map<std::string, Model*> registry; - /// draw the model for an entity - /** This will not draw attached engines, turrents and cannons - */ - void draw(core::Entity const * entity, math::Vector3f const & eye); - - /// draw the model for a controlable enity - /** This will draw all attached engines, turrents and cannons - */ - void draw(core::EntityControlable const * entity, math::Vector3f const & eye); - /* ---- static functions for the Model registry -------------------- */ /// get name model, returns 0 if not found @@ -73,14 +88,18 @@ public: /// list the content of the model registry static void list(); + + /// list of Faces + std::list<Face *> model_face; + + /// list of Engines + std::list<Engine *> model_engine; private: void make_face(math::Plane3f *face, std::vector<math::Plane3f *> & planes); void add_engine(Engine *engine); void add_face(Face *face); - std::list<Face *> model_face; - std::list<Engine *> model_engine; std::string model_name; float model_scale; |