/* render/model.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_CORE_MODEL_H__ #define __INCLUDED_CORE_MODEL_H__ #include #include #include #include "math/mathlib.h" #include "math/plane3f.h" #include "core/entity.h" namespace core { /// Global vertex array const size_t VERTEXARRAYSIZE=65536*512; class VertexArray { public: /// model vertices static float vertex[VERTEXARRAYSIZE]; static float vertex_color[VERTEXARRAYSIZE]; static float vertex_normal[VERTEXARRAYSIZE]; /// model vertices with entity color static float evertex[VERTEXARRAYSIZE]; static float evertex_normal[VERTEXARRAYSIZE]; static size_t vertex_index; static size_t evertex_index; static void clear(); static void add_vertex(math::Vector3f const &v, math::Vector3f const &n, math::Color const &color); static void add_evertex(math::Vector3f const &v, math::Vector3f const &n); }; /// a spacecraft engine class Engine { public: Engine(math::Vector3f const & location); ~Engine(); inline math::Vector3f const & location() const { return engine_location; } private: math::Vector3f engine_location; }; /// an exterior light class Light { public: Light(math::Vector3f const & location, math::Color const & color); ~Light(); inline math::Vector3f const & location() const { return light_location; } inline math::Color const & color() const { return light_color; }; private: math::Vector3f light_location; math::Color light_color; }; /// a 3D model contains a list of faces class Model { public: /// load a model from disk Model(std::string const & name); ~Model(); /// the name of the model inline std::string const & name() const { return model_name; } /// maximum values of the bounding box inline math::Vector3f const & maxbbox() const { return model_maxbbox; } /// minimum values of the bounding box inline math::Vector3f const & minbbox() const { return model_minbbox; } /// first vertex in the global VertexArray inline size_t first_vertex() const { return model_first_vertex; } /// number of vertexes in this model inline size_t vertex_count() const { return model_vertex_count; } /// first vertex in the global VertexArray inline size_t first_evertex() const { return model_first_evertex; } /// number of vertexes in this model inline size_t evertex_count() const { return model_evertex_count; } /// radius inline float radius() const { return model_radius; } /// the Model registry static std::map registry; /* ---- static functions for the Model registry -------------------- */ /// get name model, returns 0 if not found static Model *find(std::string const & name); /// get named model from the registry and load it if necessary static Model *get(std::string const & name); /// clear the model registry static void clear(); /// list the content of the model registry static void list(); /// list of Engines std::list model_engine; /// list of Lights std::list model_light; private: void make_face(math::Plane3f *face, std::vector & planes); void add_engine(Engine *engine); void add_light(Light *light); std::string model_name; float model_radius; float model_scale; bool model_valid; math::Vector3f model_maxbbox; math::Vector3f model_minbbox; size_t model_first_vertex; size_t model_vertex_count; size_t model_first_evertex; size_t model_evertex_count; }; } #endif // __INCLUDED_RENDER_MODEL_H__