diff options
author | Stijn Buys <ingar@osirion.org> | 2009-08-18 09:24:15 +0000 |
---|---|---|
committer | Stijn Buys <ingar@osirion.org> | 2009-08-18 09:24:15 +0000 |
commit | f030154fe727e25a2afe1f78b3998c2d2dba95e4 (patch) | |
tree | cd92baf9e4fa8a136523b9eb570e9811846c9250 /src/model | |
parent | 5636fad174f0bcff857c357c394c4cc8d424b302 (diff) |
astyle cleanup, corrects not loading of material textures
Diffstat (limited to 'src/model')
-rw-r--r-- | src/model/asefile.cc | 86 | ||||
-rw-r--r-- | src/model/asefile.h | 7 | ||||
-rw-r--r-- | src/model/face.cc | 8 | ||||
-rw-r--r-- | src/model/face.h | 53 | ||||
-rw-r--r-- | src/model/fragment.cc | 5 | ||||
-rw-r--r-- | src/model/fragment.h | 105 | ||||
-rw-r--r-- | src/model/mapfile.cc | 438 | ||||
-rw-r--r-- | src/model/mapfile.h | 84 | ||||
-rw-r--r-- | src/model/material.cc | 53 | ||||
-rw-r--r-- | src/model/material.h | 38 | ||||
-rw-r--r-- | src/model/model.cc | 46 | ||||
-rw-r--r-- | src/model/model.h | 96 | ||||
-rw-r--r-- | src/model/parts.cc | 13 | ||||
-rw-r--r-- | src/model/parts.h | 226 | ||||
-rw-r--r-- | src/model/primitives.cc | 2 | ||||
-rw-r--r-- | src/model/primitives.h | 23 | ||||
-rw-r--r-- | src/model/quad.cc | 2 | ||||
-rw-r--r-- | src/model/quad.h | 49 | ||||
-rw-r--r-- | src/model/triangle.cc | 26 | ||||
-rw-r--r-- | src/model/triangle.h | 160 | ||||
-rw-r--r-- | src/model/vertexarray.cc | 90 | ||||
-rw-r--r-- | src/model/vertexarray.h | 47 |
22 files changed, 847 insertions, 810 deletions
diff --git a/src/model/asefile.cc b/src/model/asefile.cc index 6010947..3bf0d59 100644 --- a/src/model/asefile.cc +++ b/src/model/asefile.cc @@ -23,7 +23,7 @@ ASEFile::ASEFile(std::string const &name) asefile_ifs.open(asefile_name); - for (int i=0; i < 3; i++) { + for (int i = 0; i < 3; i++) { ase_minbbox[i] = MAX_BOUNDS; ase_maxbbox[i] = -MAX_BOUNDS; } @@ -33,17 +33,17 @@ ASEFile::ASEFile(std::string const &name) ASEFile::~ASEFile() { for (VertexList::iterator it = ase_tvertexlist.begin(); it != ase_tvertexlist.end(); it++) { - delete (*it).second; + delete(*it).second; } ase_tvertexlist.clear(); for (VertexList::iterator it = ase_vertexlist.begin(); it != ase_vertexlist.end(); it++) { - delete (*it).second; + delete(*it).second; } ase_vertexlist.clear(); for (FaceList::iterator it = ase_facelist.begin(); it != ase_facelist.end(); it++) { - delete (*it).second; + delete(*it).second; } ase_facelist.clear(); @@ -60,7 +60,7 @@ bool ASEFile::read_header(std::istream &is) char data[1024]; memset(data, 0, sizeof(data)); - if (!is.getline(data, sizeof(data) -1 )) { + if (!is.getline(data, sizeof(data) - 1)) { return false; } @@ -82,7 +82,7 @@ bool ASEFile::read_mesh_vertex_list(std::istream &is) char data[1024]; memset(data, 0, sizeof(data)); - while (is.getline(data, sizeof(data) -1 )) { + while (is.getline(data, sizeof(data) - 1)) { std::istringstream line(data); std::string firstword; @@ -93,7 +93,7 @@ bool ASEFile::read_mesh_vertex_list(std::istream &is) return true; - } else if ( firstword.compare("*MESH_VERTEX") == 0) { + } else if (firstword.compare("*MESH_VERTEX") == 0) { size_t index; float x, y, z; if (line >> index >> x >> y >> z) { @@ -123,7 +123,7 @@ bool ASEFile::read_mesh_face_list(std::istream &is) char data[1024]; memset(data, 0, sizeof(data)); - while (is.getline(data, sizeof(data) -1 )) { + while (is.getline(data, sizeof(data) - 1)) { std::istringstream line(data); std::string word; @@ -133,22 +133,22 @@ bool ASEFile::read_mesh_face_list(std::istream &is) //con_debug << " " << count << " mesh faces" << std::endl; return true; - } else if ( word.compare("*MESH_FACE") == 0) { + } else if (word.compare("*MESH_FACE") == 0) { std::string facestr; size_t a, b, c; - if ( (line >> facestr) && - (line >> word) && (line >> a) && - (line >> word) && (line >> b) && - (line >> word) && (line >> c)) { + if ((line >> facestr) && + (line >> word) && (line >> a) && + (line >> word) && (line >> b) && + (line >> word) && (line >> c)) { if (facestr.size() && facestr[facestr.size()-1] == ':') { - facestr.erase(facestr.size()-1); + facestr.erase(facestr.size() - 1); } size_t index; std::istringstream faceindexstr(facestr); faceindexstr >> index; - + Triangle *triangle = new Triangle(*ase_vertexlist[a], *ase_vertexlist[b], *ase_vertexlist[c]); ase_facelist[index] = triangle; } @@ -171,7 +171,7 @@ bool ASEFile::read_mesh_normals(std::istream &is) float x, y, z; FaceList::iterator it; - while (is.getline(data, sizeof(data) -1 )) { + while (is.getline(data, sizeof(data) - 1)) { std::istringstream line(data); std::string firstword; @@ -181,7 +181,7 @@ bool ASEFile::read_mesh_normals(std::istream &is) //con_debug << " " << count << " face normals" << std::endl; return true; - } else if ( firstword.compare("*MESH_FACENORMAL") == 0) { + } else if (firstword.compare("*MESH_FACENORMAL") == 0) { if (line >> index >> x >> y >> z) { it = ase_facelist.find(index); if (it != ase_facelist.end()) { @@ -194,10 +194,10 @@ bool ASEFile::read_mesh_normals(std::istream &is) } else { it = ase_facelist.end(); } - } else if ( firstword.compare("*MESH_VERTEXNORMAL") == 0) { + } else if (firstword.compare("*MESH_VERTEXNORMAL") == 0) { + + if ((it != ase_facelist.end()) && (line >> index >> x >> y >> z)) { - if ( (it != ase_facelist.end()) && (line >> index >> x >> y >> z)) { - if (vertindex == 0) { (*it).second->n0().assign(x, y, z); } else if (vertindex == 1) { @@ -220,7 +220,7 @@ bool ASEFile::read_mesh_tvertex_list(std::istream &is) char data[1024]; memset(data, 0, sizeof(data)); - while (is.getline(data, sizeof(data) -1 )) { + while (is.getline(data, sizeof(data) - 1)) { std::istringstream line(data); std::string firstword; @@ -230,7 +230,7 @@ bool ASEFile::read_mesh_tvertex_list(std::istream &is) //con_debug << " " << count << " texture vertices" << std::endl; return true; - } else if ( firstword.compare("*MESH_TVERT") == 0) { + } else if (firstword.compare("*MESH_TVERT") == 0) { size_t index; float x, y, z; if (line >> index >> x >> y >> z) { @@ -246,12 +246,12 @@ bool ASEFile::read_mesh_tvertex_list(std::istream &is) bool ASEFile::read_mesh_tface_list(std::istream &is) { -size_t count = 0; + size_t count = 0; char data[1024]; memset(data, 0, sizeof(data)); - while (is.getline(data, sizeof(data) -1 )) { + while (is.getline(data, sizeof(data) - 1)) { std::istringstream line(data); std::string firstword; @@ -261,7 +261,7 @@ size_t count = 0; //con_debug << " " << count << " face texture coordinates" << std::endl; return true; - } else if ( firstword.compare("*MESH_TFACE") == 0) { + } else if (firstword.compare("*MESH_TFACE") == 0) { size_t index, a, b, c; if (line >> index >> a >> b >> c) { Triangle *triangle = ase_facelist[index]; @@ -292,38 +292,38 @@ bool ASEFile::read_mesh(std::istream &is) ase_vertexlist.clear(); - while (is.getline(data, sizeof(data) -1 )) { + while (is.getline(data, sizeof(data) - 1)) { std::istringstream line(data); std::string word; line >> word; - if ((level == 1 ) && (word.compare("*MESH_VERTEX_LIST") == 0)) { + if ((level == 1) && (word.compare("*MESH_VERTEX_LIST") == 0)) { if ((line >> word) && (word.compare("{") == 0)) { //con_debug << " " << name() << " *MESH_VERTEX_LIST" << std::endl; read_mesh_vertex_list(is); } - } else if ((level == 1 ) && (word.compare("*MESH_FACE_LIST") == 0)) { + } else if ((level == 1) && (word.compare("*MESH_FACE_LIST") == 0)) { if ((line >> word) && (word.compare("{") == 0)) { //con_debug << " " << name() << " *MESH_FACE_LIST" << std::endl; read_mesh_face_list(is); } - } else if ((level == 1 ) && (word.compare("*MESH_NORMALS") == 0)) { + } else if ((level == 1) && (word.compare("*MESH_NORMALS") == 0)) { if ((line >> word) && (word.compare("{") == 0)) { //con_debug << " " << name() << " *MESH_NORMALS" << std::endl; read_mesh_normals(is); } - } else if ((level == 1 ) && (word.compare("*MESH_TVERTLIST") == 0)) { - if ((line >> word) && (word.compare("{") == 0)) { + } else if ((level == 1) && (word.compare("*MESH_TVERTLIST") == 0)) { + if ((line >> word) && (word.compare("{") == 0)) { //con_debug << " " << name() << " *MESH_TVERTLIST" << std::endl; read_mesh_tvertex_list(is); } - } else if ((level == 1 ) && (word.compare("*MESH_TFACELIST") == 0)) { - if ((line >> word) && (word.compare("{") == 0)) { + } else if ((level == 1) && (word.compare("*MESH_TFACELIST") == 0)) { + if ((line >> word) && (word.compare("{") == 0)) { //con_debug << " " << name() << " *MESH_TFACELIST" << std::endl; read_mesh_tface_list(is); } @@ -352,13 +352,13 @@ bool ASEFile::read_geom(std::istream &is) memset(data, 0, sizeof(data)); int level = 1; - while (is.getline(data, sizeof(data) -1 )) { + while (is.getline(data, sizeof(data) - 1)) { std::istringstream line(data); std::string word; line >> word; - if ((level == 1 ) && (word.compare("*MESH") == 0)) { + if ((level == 1) && (word.compare("*MESH") == 0)) { if ((line >> word) && (word.compare("{") == 0)) { //con_debug << " " << name() << " " << "*MESH" << std::endl; read_mesh(is); @@ -391,13 +391,13 @@ bool ASEFile::read() char data[1024]; memset(data, 0, sizeof(data)); - while (asefile_ifs.getline(data, sizeof(data) -1 )) { + while (asefile_ifs.getline(data, sizeof(data) - 1)) { std::istringstream line(data); std::string word; line >> word; - - if (word.compare("*GEOMOBJECT") == 0) { + + if (word.compare("*GEOMOBJECT") == 0) { if ((line >> word) && (word.compare("{") == 0)) { //con_debug << " " << name() << " " << "*GEOMOBJECT" << std::endl; @@ -429,9 +429,9 @@ Model * ASEFile::load(const std::string &name) // default material Material *material = Material::find(name); if (!material) { - material = new Material(name); + material = new Material(name); Material::add(material); - material->set_flags(Material::Texture); + //material->set_flags(Material::Texture); material->set_texture(material->name()); } @@ -449,7 +449,7 @@ Model * ASEFile::load(const std::string &name) // caculate bounding box model->model_minbbox = (asefile.ase_minbbox - center) * scale; - model->model_maxbbox = (asefile.ase_maxbbox - center) * scale; + model->model_maxbbox = (asefile.ase_maxbbox - center) * scale; model->set_radius(model->model_maxbbox.length()); model->set_origin(center * scale); @@ -460,14 +460,14 @@ Model * ASEFile::load(const std::string &name) fragment->add_vertex((triangle->v0() - center) * scale , triangle->n0(), triangle->t0(), false); fragment->add_vertex((triangle->v1() - center) * scale , triangle->n1(), triangle->t1(), false); fragment->add_vertex((triangle->v2() - center) * scale , triangle->n2(), triangle->t2(), false); - + model->model_tris_count++; } model->add_group(group); con_debug << " " << asefile.name() << " " << asefile.ase_vertexlist.size() << " vertices " << - model->model_tris_detail_count << "/" << model->model_tris_count << " detail/tris" << std::endl; + model->model_tris_detail_count << "/" << model->model_tris_count << " detail/tris" << std::endl; return model; } diff --git a/src/model/asefile.h b/src/model/asefile.h index c792a9d..e129ec0 100644 --- a/src/model/asefile.h +++ b/src/model/asefile.h @@ -84,10 +84,11 @@ private: */ bool read(); - inline const std::string &name() const { return asefile_name; } + inline const std::string &name() const { + return asefile_name; + } - inline bool is_open() - { + inline bool is_open() { return asefile_ifs.is_open(); } diff --git a/src/model/face.cc b/src/model/face.cc index 7626fac..b7d5e45 100644 --- a/src/model/face.cc +++ b/src/model/face.cc @@ -22,20 +22,20 @@ Face::Face(Vector3f const & point0, Vector3f const &point1, Vector3f const &poin face_detail = false; face_surface_flags = 0; face_material = 0; - + face_point[0] = point0; face_point[1] = point1; face_point[2] = point2; - + face_normal = crossproduct((face_point[1] - face_point[0]) , (face_point[2] - face_point[0])); pd = -1 * (face_normal.x() * face_point[0].x() + face_normal.y() * face_point[0].y() + face_normal.z() * face_point[0].z()); } Face::Face(Face const & other) { - for (size_t i=0; i < 3; i++) + for (size_t i = 0; i < 3; i++) this->face_point[i] = other.face_point[i]; - + face_normal = crossproduct((face_point[1] - face_point[0]) , (face_point[2] - face_point[0])); pd = -1 * (face_normal.x() * face_point[0].x() + face_normal.y() * face_point[0].y() + face_normal.z() * face_point[0].z()); } diff --git a/src/model/face.h b/src/model/face.h index 725f798..cbed101 100644 --- a/src/model/face.h +++ b/src/model/face.h @@ -28,59 +28,50 @@ public: /// copy constructor Face(Face const & other); - + /// normal of the plane, not normalized to lenght 1 - inline math::Vector3f const & normal() const - { + inline math::Vector3f const & normal() const { return face_normal; } /// the points defining the plane. /// @param index 0 <= i < 3 - inline math::Vector3f const & point(size_t index) const - { + inline math::Vector3f const & point(size_t index) const { return face_point[index]; } /// face material - inline Material *material() const - { + inline Material *material() const { return face_material; } /// first parameter of the general plane equation - inline float a() const - { + inline float a() const { return face_normal[0]; } /// second parameter of the general plane equation - inline float b() const - { + inline float b() const { return face_normal[1]; } /// third param of the general plane equation - inline float c() const - { + inline float c() const { return face_normal[2]; } /// fourth parameter of the general plane equation - inline float d() const - { + inline float d() const { return pd; } /// indidcates if this plane was generated from a detail brush - inline bool detail() const - { + inline bool detail() const { return face_detail; } /// surface flags - inline unsigned int surface_flags() const - { + inline unsigned int surface_flags() const { return face_surface_flags; } @@ -93,22 +84,34 @@ public: } /// return texture shift - inline const math::Vector2f &tex_shift() { return face_tex_shift; } + inline const math::Vector2f &tex_shift() { + return face_tex_shift; + } - inline void set_material(Material *material) { face_material = material; } + inline void set_material(Material *material) { + face_material = material; + } - inline void set_detail(const bool detail = true) { face_detail = detail; } + inline void set_detail(const bool detail = true) { + face_detail = detail; + } - inline void set_surface_flags(const unsigned int flags) { face_surface_flags = flags; } + inline void set_surface_flags(const unsigned int flags) { + face_surface_flags = flags; + } /** * @brief return texture transformation vectors * @param index 0 <= i < 2 */ - inline math::Vector3f &get_tex_vec(size_t index) { return face_tex_vec[index]; } + inline math::Vector3f &get_tex_vec(size_t index) { + return face_tex_vec[index]; + } /// return texture shift - inline math::Vector2f &get_tex_shift() { return face_tex_shift; } + inline math::Vector2f &get_tex_shift() { + return face_tex_shift; + } private: math::Vector3f face_normal; diff --git a/src/model/fragment.cc b/src/model/fragment.cc index ab0f9fa..8e6483f 100644 --- a/src/model/fragment.cc +++ b/src/model/fragment.cc @@ -19,7 +19,7 @@ namespace model Fragment::Fragment(const Fragment &other) { fragment_type = other.fragment_type; - fragment_index = other.fragment_index; + fragment_index = other.fragment_index; fragment_structural_size = other.fragment_structural_size; fragment_detail_size = other.fragment_detail_size; fragment_material = other.fragment_material; @@ -71,7 +71,8 @@ FragmentGroup::~FragmentGroup() clear(); } -void FragmentGroup::clear() { +void FragmentGroup::clear() +{ for (iterator it = group_fragments.begin(); it != group_fragments.end(); it++) { delete(*it); diff --git a/src/model/fragment.h b/src/model/fragment.h index 0a9ca6a..6d65f7a 100644 --- a/src/model/fragment.h +++ b/src/model/fragment.h @@ -23,7 +23,7 @@ class Fragment public: /// fragment primitive type: triangles or quads enum Type {Triangles, Quads}; - + /// create a new fragment Fragment(Type type, const Material *material); @@ -31,43 +31,38 @@ public: * @brief copy constructor */ Fragment(const Fragment &other); - + /// add a vertex to the fragment size_t add_vertex(math::Vector3f const & vertex, math::Vector3f const &normal, bool detail); /// add a vertex to the fragment size_t add_vertex(math::Vector3f const & vertex, math::Vector3f const &normal, math::Vector2f const &texcoord, bool detail); - + /// the type of primitives this fragment consists of - inline Type type() const - { + inline Type type() const { return fragment_type; } - + /// VertexArray index of the start of the fragment - inline size_t index() const - { + inline size_t index() const { return fragment_index; } - + /// number of structural vertices in the fragment - inline size_t structural_size() const - { + inline size_t structural_size() const { return fragment_structural_size; } - + /// number of detail vertices in the fragment - inline size_t detail_size() const - { + inline size_t detail_size() const { return fragment_detail_size; } - + /// material flags - inline const Material * material() const - { + inline const Material * material() const { return fragment_material; } - + private: Type fragment_type; size_t fragment_index; @@ -92,38 +87,70 @@ public: ~FragmentGroup(); - inline const Type type() const { return group_type; } + inline const Type type() const { + return group_type; + } - inline const math::Vector3f &location() const { return group_location; } + inline const math::Vector3f &location() const { + return group_location; + } - inline const math::Axis & axis() const { return group_axis; } + inline const math::Axis & axis() const { + return group_axis; + } - inline const float speed() const { return group_speed; } + inline const float speed() const { + return group_speed; + } - inline const float scale() const { return group_scale; } - - inline const bool transform() const { return group_transform; } + inline const float scale() const { + return group_scale; + } - - inline void set_type(const Type type) { group_type = type; } + inline const bool transform() const { + return group_transform; + } - inline void set_location(const math::Vector3f &location) { group_location.assign(location); } - inline void set_axis(const math::Axis &axis) { group_axis.assign(axis); } + inline void set_type(const Type type) { + group_type = type; + } - inline void set_speed(const float speed) { group_speed = speed; } + inline void set_location(const math::Vector3f &location) { + group_location.assign(location); + } + + inline void set_axis(const math::Axis &axis) { + group_axis.assign(axis); + } + + inline void set_speed(const float speed) { + group_speed = speed; + } + + inline void set_scale(const float scale) { + group_scale = scale; + } - inline void set_scale(const float scale) { group_scale = scale; } + inline void set_transform(const bool transform) { + group_transform = transform; + } + + inline iterator begin() { + return group_fragments.begin(); + } - inline void set_transform(const bool transform) { group_transform = transform; } - - inline iterator begin() { return group_fragments.begin(); } + inline iterator end() { + return group_fragments.end(); + } - inline iterator end() { return group_fragments.end(); } - - inline const size_t size() const { return group_fragments.size(); } - - inline void add_fragment(Fragment *fragment) { group_fragments.push_back(fragment); } + inline const size_t size() const { + return group_fragments.size(); + } + + inline void add_fragment(Fragment *fragment) { + group_fragments.push_back(fragment); + } void clear(); diff --git a/src/model/mapfile.cc b/src/model/mapfile.cc index d3d19f6..8dff219 100644 --- a/src/model/mapfile.cc +++ b/src/model/mapfile.cc @@ -26,15 +26,14 @@ const float MAX_BOUNDS = 16384; const float MIN_DELTA = 10e-10; // from radiant tools/quake3/q3map2/map.c -math::Vector3f texture_baseaxis[18] = -{ +math::Vector3f texture_baseaxis[18] = { // normal texture plane - math::Vector3f(0,0,1), math::Vector3f(1,0,0), math::Vector3f(0,-1,0), // floor - math::Vector3f(0,0,-1), math::Vector3f(1,0,0), math::Vector3f(0,-1,0), // ceiling - math::Vector3f(1,0,0), math::Vector3f(0,1,0), math::Vector3f(0,0,-1), // west wall - math::Vector3f(-1,0,0), math::Vector3f(0,1,0), math::Vector3f(0,0,-1), // east wall - math::Vector3f(0,1,0), math::Vector3f(1,0,0), math::Vector3f(0,0,-1), // south wall - math::Vector3f(0,-1,0), math::Vector3f(1,0,0), math::Vector3f(0,0,-1) // north wall + math::Vector3f(0, 0, 1), math::Vector3f(1, 0, 0), math::Vector3f(0, -1, 0), // floor + math::Vector3f(0, 0, -1), math::Vector3f(1, 0, 0), math::Vector3f(0, -1, 0), // ceiling + math::Vector3f(1, 0, 0), math::Vector3f(0, 1, 0), math::Vector3f(0, 0, -1), // west wall + math::Vector3f(-1, 0, 0), math::Vector3f(0, 1, 0), math::Vector3f(0, 0, -1), // east wall + math::Vector3f(0, 1, 0), math::Vector3f(1, 0, 0), math::Vector3f(0, 0, -1), // south wall + math::Vector3f(0, -1, 0), math::Vector3f(1, 0, 0), math::Vector3f(0, 0, -1) // north wall }; @@ -46,19 +45,17 @@ void texture_axis_from_plane(const Face &face, math::Vector3f &xv, math::Vector3 float dot = 0; float best = 0; - math::Vector3f n(face.normal()*-1); + math::Vector3f n(face.normal()* -1); n.normalize(); - - for (size_t i=0 ; i<6 ; i++) - { + + for (size_t i = 0 ; i < 6 ; i++) { dot = math::dotproduct(n, texture_baseaxis[i *3]); - if( dot > best + MIN_DELTA ) /* ydnar: bug 637 fix, suggested by jmonroe */ - { + if (dot > best + MIN_DELTA) { /* ydnar: bug 637 fix, suggested by jmonroe */ best = dot; best_axis = i; } } - + xv.assign(texture_baseaxis[best_axis*3+1]); yv.assign(texture_baseaxis[best_axis*3+2]); } @@ -74,25 +71,28 @@ void face_texture_verts(Face &face, const math::Vector2f &tex_shift, const float float ang, sinv, cosv; float ns, nt; int i, j; - + texture_axis_from_plane(face, vecs[0], vecs[1]); - + if (!scale[0]) scale[0] = 1; if (!scale[1]) scale[1] = 1; // rotate axis - if (tex_rotate == 0.0f) - { sinv = 0.0f ; cosv = 1.0f; } - else if (tex_rotate == 90.0f) - { sinv = 1.0f ; cosv = 0.0f; } - else if (tex_rotate == 180.0f) - { sinv = 0.0f; cosv = -1.0f; } - else if (tex_rotate == 270.0f) - { sinv = -1.0f ; cosv = 0.0f; } - else - { + if (tex_rotate == 0.0f) { + sinv = 0.0f ; + cosv = 1.0f; + } else if (tex_rotate == 90.0f) { + sinv = 1.0f ; + cosv = 0.0f; + } else if (tex_rotate == 180.0f) { + sinv = 0.0f; + cosv = -1.0f; + } else if (tex_rotate == 270.0f) { + sinv = -1.0f ; + cosv = 0.0f; + } else { ang = tex_rotate / 180.0f * M_PI; sinv = sinf(ang); cosv = cosf(ang); @@ -112,15 +112,15 @@ void face_texture_verts(Face &face, const math::Vector2f &tex_shift, const float else tv = 2; - for (i=0 ; i<2 ; i++) { + for (i = 0 ; i < 2 ; i++) { ns = cosv * vecs[i][sv] - sinv * vecs[i][tv]; nt = sinv * vecs[i][sv] + cosv * vecs[i][tv]; vecs[i][sv] = ns; vecs[i][tv] = nt; } - for (i=0 ; i<2 ; i++) - for (j=0 ; j<3 ; j++) + for (i = 0 ; i < 2 ; i++) + for (j = 0 ; j < 3 ; j++) face.get_tex_vec(i)[j] = vecs[i][j] / scale[i]; face.get_tex_shift().assign(tex_shift); @@ -130,10 +130,10 @@ void face_texture_verts(Face &face, const math::Vector2f &tex_shift, const float // project vertex into texture plane const math::Vector2f map_texture_coords(Face *face, const math::Vector3f &v) { - return math::Vector2f ( - (face->get_tex_shift().x() + math::dotproduct(face->tex_vec(0), v)) / face->material()->size().width(), - (face->get_tex_shift().y() + math::dotproduct(face->tex_vec(1), v)) / face->material()->size().height() - ); + return math::Vector2f( + (face->get_tex_shift().x() + math::dotproduct(face->tex_vec(0), v)) / face->material()->size().width(), + (face->get_tex_shift().y() + math::dotproduct(face->tex_vec(1), v)) / face->material()->size().height() + ); } // function to test spawnflags @@ -177,12 +177,12 @@ bool MapFile::open(std::string const & mapname) classname_current = ""; line_number = 0; parse_level = 0; - + clear_materials(); - + mapfile_name.append(mapname); mapfile_name.append(".map"); - + mapfile_ifs.open(mapfile_name); if (!mapfile_ifs.is_open()) { return false; @@ -217,7 +217,7 @@ bool MapFile::read_patchdef() return false; else line_number++; - + // second line: "( a b c d e )" if (!mapfile_ifs.getline(data, 1023)) return false; @@ -235,11 +235,11 @@ bool MapFile::read_patchdef() std::istringstream linestream(data); std::string firstword; - + if (linestream >> firstword) { if (firstword.compare(")") == 0) { //con_debug << " patchDef2 with " << count << " lines" << std::endl; - return true; + return true; } else { count ++; } @@ -252,32 +252,32 @@ bool MapFile::read_patchdef() bool MapFile::getline() { using math::Vector3f; - + last_read_was_classname = false; last_read_was_key = false; last_read_was_classend = false; - + key_current = ""; value_current = ""; - + if (!mapfile_ifs.is_open()) return false; char data[1024]; memset(data, 0, sizeof(data)); - + if (mapfile_ifs.getline(data, 1023)) { line_number++; std::istringstream linestream(data); std::string firstword; - + if (linestream >> firstword) { if (!firstword.size()) { return true; - + } else if (firstword == "//") { return true; - + } else if (firstword == "{") { parse_level++; @@ -286,7 +286,7 @@ bool MapFile::getline() con_warn << name() << " error reading patchDef2 at line " << line_number << std::endl; } } - + } else if (firstword == "}") { if ((parse_level == 3) && (in_patchdef)) { @@ -294,19 +294,19 @@ bool MapFile::getline() in_patchdef = false; } else if ((parse_level == 2) && (planes.size())) { - // end-of-brush + // end-of-brush // for every face for (std::vector<Face *>::iterator face = planes.begin(); face != planes.end(); face++) { make_brushface((*face)); } - + // clean planes for (std::vector<Face *>::iterator it = planes.begin(); it != planes.end(); it++) { delete(*it); } planes.clear(); - + map_brushes++; value_current.clear(); @@ -317,51 +317,51 @@ bool MapFile::getline() } parse_level--; - + } else if (parse_level == 1) { - + if (firstword.compare("\"classname\"") == 0) { classname_current.clear(); - + if (linestream >> classname_current) { if (classname_current.size() > 2) { - classname_current.erase(0,1); - classname_current.erase(classname_current.size()-1, 1); + classname_current.erase(0, 1); + classname_current.erase(classname_current.size() - 1, 1); last_read_was_classname = true; } else { classname_current.clear(); } } - + } else if ((firstword.size() > 2) && (firstword[0] == '\"') && (firstword[firstword.size()-1] == '\"')) { - + key_current.assign(firstword); - key_current.erase(0,1); - key_current.erase(key_current.size()-1, 1); - + key_current.erase(0, 1); + key_current.erase(key_current.size() - 1, 1); + value_current.clear(); char c; while ((linestream.get(c)) && (c != '"')); while ((linestream.get(c)) && (c != '"')) value_current += c; - + last_read_was_key = true; } - + } else if (parse_level == 2) { - + if (firstword.compare("(") == 0) { // brush plane - + Vector3f p1, p2, p3; std::string tmp; std::string texture; int n = 0; - + linestream >> p1; // first plane vertex x y z linestream >> tmp; // ) linestream >> tmp; // ( - linestream >> p2; // second plane vertex x y z + linestream >> p2; // second plane vertex x y z linestream >> tmp; // ) linestream >> tmp; // ( linestream >> p3; // third plane vertex x y z @@ -377,11 +377,11 @@ bool MapFile::getline() if (!material) { material = new Material("textures/" + texture); Material::add(material); - material->set_flags(Material::Texture); + //material->set_flags(Material::Texture); material->set_texture(material->name()); } face->set_material(material); - + // texture alignment float tx, ty, tr, tsx, tsy; linestream >> tx >> ty; // texture shift @@ -390,7 +390,7 @@ bool MapFile::getline() // store the texture transformation for this face face_texture_verts((*face), math::Vector2f(tx, ty), tr, math::Vector2f(tsx, tsy)); - + // content flags if (!(linestream >> n)) n = 0; @@ -405,7 +405,7 @@ bool MapFile::getline() face->set_surface_flags(n); planes.push_back(face); - + value_current.clear(); } else if (firstword.compare("patchDef2") == 0) { @@ -414,17 +414,17 @@ bool MapFile::getline() } } } else { - + return false; } - + return true; } void MapFile::make_brushface(Face *face) { using math::Vector3f; - + // ignore materials with the 'Ignore' flag set if ((face->material()->flags() & Material::Ignore) == Material::Ignore) { return; @@ -436,18 +436,18 @@ void MapFile::make_brushface(Face *face) if (face->detail()) { map_faces_detail++; } - + // using suggestions from // http://www.flipcode.com/archives/Level_Editing.shtml - + // vertex list std::vector<math::Vector3f *> vl; - + // calculate initial vertices on the bounding box - + // check if the face is x-axis oriented if ((fabsf(face->normal().x()) >= fabsf(face->normal().y())) && (fabsf(face->normal().x()) >= fabsf(face->normal().z()))) { - + if (face->normal().x() > MIN_DELTA) { vl.push_back(new math::Vector3f(0, -MAX_BOUNDS, -MAX_BOUNDS)); vl.push_back(new math::Vector3f(0, -MAX_BOUNDS, MAX_BOUNDS)); @@ -462,15 +462,15 @@ void MapFile::make_brushface(Face *face) // calculate the x coordinate of each face vertex for (std::vector<Vector3f *>::iterator it = vl.begin(); it != vl.end(); it++) { (*it)->get_x() = (-face->d() - - face->normal().z() * (*it)->z() - - face->normal().y() * (*it)->y()) / - face->normal().x(); + face->normal().z() * (*it)->z() - + face->normal().y() * (*it)->y()) / + face->normal().x(); } } - + // check if the face is y-axis oriented else if ((fabsf(face->normal().y()) >= fabsf(face->normal().x())) && (fabsf(face->normal().y()) >= fabsf(face->normal().z()))) { - + if (face->normal().y() > MIN_DELTA) { vl.push_back(new Vector3f(MAX_BOUNDS, 0, -MAX_BOUNDS)); vl.push_back(new Vector3f(MAX_BOUNDS, 0, MAX_BOUNDS)); @@ -482,19 +482,19 @@ void MapFile::make_brushface(Face *face) vl.push_back(new Vector3f(MAX_BOUNDS, 0, MAX_BOUNDS)); vl.push_back(new Vector3f(MAX_BOUNDS, 0, -MAX_BOUNDS)); } - + // calculate the x coordinate of each face vertex for (std::vector<Vector3f *>::iterator it = vl.begin(); it != vl.end(); it++) { (*it)->get_y() = (-face->d() - - face->normal().z() * (*it)->z() - - face->normal().x() * (*it)->x()) / - face->normal().y(); + face->normal().z() * (*it)->z() - + face->normal().x() * (*it)->x()) / + face->normal().y(); } } - + // face must be z-axis oriented else { - + if (face->normal().z() > MIN_DELTA) { vl.push_back(new Vector3f(-MAX_BOUNDS, -MAX_BOUNDS, 0)); vl.push_back(new Vector3f(-MAX_BOUNDS, MAX_BOUNDS, 0)); @@ -506,17 +506,17 @@ void MapFile::make_brushface(Face *face) vl.push_back(new Vector3f(-MAX_BOUNDS, MAX_BOUNDS, 0)); vl.push_back(new Vector3f(-MAX_BOUNDS, -MAX_BOUNDS, 0)); } - + // calculate the x coordinate of each face vertex for (std::vector<Vector3f *>::iterator it = vl.begin(); it != vl.end(); it++) { (*it)->get_z() = (-face->d() - - face->normal().x() * (*it)->x() - - face->normal().y() * (*it)->y()) / - face->normal().z(); + face->normal().x() * (*it)->x() - + face->normal().y() * (*it)->y()) / + face->normal().z(); } } - - + + // intersect the face with every plane for (std::vector<Face *>::iterator pit = planes.begin(); pit != planes.end(); pit++) { @@ -524,102 +524,102 @@ void MapFile::make_brushface(Face *face) if (plane == face) { continue; } - - Vector3f fn = crossproduct(face->point(1)-face->point(0), face->point(2)-face->point(0)); - Vector3f pn = crossproduct(plane->point(1)-plane->point(0), plane->point(2)-plane->point(0)); - + + Vector3f fn = crossproduct(face->point(1) - face->point(0), face->point(2) - face->point(0)); + Vector3f pn = crossproduct(plane->point(1) - plane->point(0), plane->point(2) - plane->point(0)); + Vector3f t = crossproduct(fn, pn); if ((t.x() == 0) && (t.y() == 0) && (t.z() == 0)) { continue; } - + // intersect face with plane - for (int i=0; vl.size() - i > 0; i++) { - + for (int i = 0; vl.size() - i > 0; i++) { + Vector3f v(*vl.at(i)); - + Vector3f next; if (vl.size() - i > 1) { - next = *vl.at(i+1); + next = *vl.at(i + 1); } else { next = *vl.front(); } - + Vector3f prev; if (i > 0) { - prev = *vl.at(i-1); + prev = *vl.at(i - 1); } else { prev = *vl.back(); } - + if ((v.x() * plane->normal().x() + v.y() * plane->normal().y() + v.z() * plane->normal().z() + plane->d()) < MIN_DELTA) { - + // find current std::vector<Vector3f *>::iterator vit = vl.begin(); while ((*vit) != vl.at(i)) { vit++; } - + // check if prev - v intersects with plane if ((prev.x() * plane->normal().x() + prev.y() * plane->normal().y() + prev.z() * plane->normal().z() + plane->d()) > MIN_DELTA) { - + // calculate intersection - float t1 = -plane->normal().x() * prev.x() - plane->normal().y() * prev.y() - plane->normal().z() * prev.z() -plane->d(); + float t1 = -plane->normal().x() * prev.x() - plane->normal().y() * prev.y() - plane->normal().z() * prev.z() - plane->d(); float t2 = (plane->normal().x() * v.x() - plane->normal().x() * prev.x() + plane->normal().y() * v.y() - plane->normal().y() * prev.y() + plane->normal().z() * v.z() - plane->normal().z() * prev.z()); Vector3f *s = new Vector3f; - + if (t2 == 0) { *s = v; } else { for (int j = 0; j < 3; j++) (*s)[j] = prev [j] + t1 * (v[j] - prev[j]) / t2; } - - vit = vl.insert(vit,s); + + vit = vl.insert(vit, s); vit++; i++; } - + // check if next - v intersects with plane if ((next.x() * plane->normal().x() + next.y() * plane->normal().y() + next.z() * plane->normal().z() + plane->d()) > MIN_DELTA) { - + // calculate intersection - float t1 = -plane->normal().x() * v.x() - plane->normal().y() * v.y() - plane->normal().z() * v.z() -plane->d(); + float t1 = -plane->normal().x() * v.x() - plane->normal().y() * v.y() - plane->normal().z() * v.z() - plane->d(); float t2 = (plane->normal().x() * next.x() - plane->normal().x() * v.x() + plane->normal().y() * next.y() - plane->normal().y() * v.y() + plane->normal().z() * next.z() - plane->normal().z() * v.z()); Vector3f *s = new Vector3f; - + if (t2 == 0) { *s = v; } else { for (int j = 0; j < 3; j++) (*s)[j] = v [j] + t1 * (next[j] - v[j]) / t2; } - - vit = vl.insert(vit,s); + + vit = vl.insert(vit, s); vit++; i++; } - + // erase delete *vit; vl.erase(vit); i--; } - + } } - + if (vl.size() > 2) { // find the list if primitives for the current material, allocate a new one if necessary Primitives *primitives = 0; - + Materials::iterator mit = map_materials.find(face->material()); if (mit == map_materials.end()) { primitives = new Primitives(face->material()); @@ -627,26 +627,26 @@ void MapFile::make_brushface(Face *face) } else { primitives = (*mit).second; } - + // scale vertices and calculate the bounding box for (std::vector<Vector3f *>::iterator it = vl.begin(); it != vl.end(); it++) { //*(*it) *= SCALE; - for (int i=0; i < 3; i++) { + for (int i = 0; i < 3; i++) { if (class_maxbbox[i] < (*(*it))[i] * SCALE) class_maxbbox[i] = (*(*it))[i] * SCALE; - + if (class_minbbox[i] > (*(*it))[i] * SCALE) class_minbbox[i] = (*(*it))[i] * SCALE; } } // the actual polygon normal is on the other side - Vector3f face_normal(face->normal()*-1); - face_normal.normalize(); + Vector3f face_normal(face->normal()* -1); + face_normal.normalize(); -#ifndef HAVE_BULLET +#ifndef HAVE_BULLET - // Quads are disable to use model data for bullet physics + // Quads are disable to use model data for bullet physics // split polygon into quads while (vl.size() > 3) { @@ -657,7 +657,7 @@ void MapFile::make_brushface(Face *face) std::vector<Vector3f *>::reverse_iterator vn2 = vl.rbegin(); ++vn2; ++vn2; - + Quad *quad = new Quad(*(*vn2) * SCALE, *(*vn1) * SCALE, *(*vn) * SCALE, *(*v0) * SCALE, face_normal, face->detail()); primitives->add_quad(quad); @@ -680,8 +680,8 @@ void MapFile::make_brushface(Face *face) std::vector<Vector3f *>::reverse_iterator vn = vl.rbegin(); std::vector<Vector3f *>::reverse_iterator vn1 = vl.rbegin(); ++vn1; - - Triangle * triangle = new Triangle (*(*vn1) * SCALE, *(*vn) * SCALE, *(*v0) * SCALE, face_normal, face->detail()); + + Triangle * triangle = new Triangle(*(*vn1) * SCALE, *(*vn) * SCALE, *(*v0) * SCALE, face_normal, face->detail()); primitives->add_triangle(triangle); if (face->material()->flags() & Material::Texture) { @@ -695,12 +695,12 @@ void MapFile::make_brushface(Face *face) } else { con_warn << name() << " unresolved face at line " << line() << std::endl; } - + // clean up the vertex list for (std::vector<Vector3f *>::iterator it = vl.begin(); it != vl.end(); it++) { delete(*it); } - + vl.clear(); } @@ -720,9 +720,9 @@ bool MapFile::got_key_vector3f(const char * keylabel, math::Vector3f & v) std::istringstream is(value_current); float x, y, z; if ((is >> x) && (is >> y) && (is >> z)) { - v = math::Vector3f(x,y,z); + v = math::Vector3f(x, y, z); } else { - v= math::Vector3f(); + v = math::Vector3f(); } return true; } else { @@ -804,7 +804,7 @@ void MapFile::close() void MapFile::clear_bbox() { - for (int i=0; i < 3; i++) { + for (int i = 0; i < 3; i++) { class_minbbox[i] = MAX_BOUNDS; class_maxbbox[i] = -MAX_BOUNDS; } @@ -814,7 +814,7 @@ void MapFile::clear_bbox() } void MapFile::load_worldspawn(Model *model) -{ +{ if (!map_materials.size()) return; @@ -832,12 +832,12 @@ void MapFile::load_fragmentgroup(Model *model, const FragmentGroup::Type class_t { if (!VertexArray::instance() || VertexArray::instance()->overflow()) return; - + if (!map_materials.size()) return; FragmentGroup *group = new FragmentGroup(); - + if (class_type == FragmentGroup::Rotate) { if (class_speed == 0) { // default rotation speed 45 degrees per second @@ -862,39 +862,39 @@ void MapFile::load_fragmentgroup(Model *model, const FragmentGroup::Type class_t for (Materials::iterator mit = map_materials.begin(); mit != map_materials.end(); mit++) { // split the Primitives with this material into fragments Primitives *primitives = (*mit).second; - + // store triangles if (primitives->triangles().size()) { Fragment *fragment = new Fragment(Fragment::Triangles, primitives->material()); - + // add structural triangles to the fragment for (Primitives::Triangles::iterator tris_it = primitives->triangles().begin(); tris_it != primitives->triangles().end(); tris_it++) { Triangle *triangle = (*tris_it); if (!triangle->detail()) { size_t count = 0; - count += fragment->add_vertex(triangle->v0()-group_center, triangle->normal(), triangle->t0(), false); - count += fragment->add_vertex(triangle->v1()-group_center, triangle->normal(), triangle->t1(), false); - count += fragment->add_vertex(triangle->v2()-group_center, triangle->normal(), triangle->t2(), false); + count += fragment->add_vertex(triangle->v0() - group_center, triangle->normal(), triangle->t0(), false); + count += fragment->add_vertex(triangle->v1() - group_center, triangle->normal(), triangle->t1(), false); + count += fragment->add_vertex(triangle->v2() - group_center, triangle->normal(), triangle->t2(), false); if (count == 3) model->model_tris_count++; } } - + // add detail triangles to the fragment for (Primitives::Triangles::iterator tris_it = primitives->triangles().begin(); tris_it != primitives->triangles().end(); tris_it++) { Triangle *triangle = (*tris_it); if (triangle->detail()) { size_t count = 0; - count += fragment->add_vertex(triangle->v0()-group_center, triangle->normal(), triangle->t0(), true); - count += fragment->add_vertex(triangle->v1()-group_center, triangle->normal(), triangle->t1(), true); - count += fragment->add_vertex(triangle->v2()-group_center, triangle->normal(), triangle->t2(), true); + count += fragment->add_vertex(triangle->v0() - group_center, triangle->normal(), triangle->t0(), true); + count += fragment->add_vertex(triangle->v1() - group_center, triangle->normal(), triangle->t1(), true); + count += fragment->add_vertex(triangle->v2() - group_center, triangle->normal(), triangle->t2(), true); if (count == 3) { model->model_tris_count++; model->model_tris_detail_count++; } } } - + // add the fragment to the group group->add_fragment(fragment); } @@ -902,41 +902,41 @@ void MapFile::load_fragmentgroup(Model *model, const FragmentGroup::Type class_t // store quads if (primitives->quads().size()) { Fragment *fragment = new Fragment(Fragment::Quads, primitives->material()); - + // add structural quads to the fragment for (Primitives::Quads::iterator quad_it = primitives->quads().begin(); quad_it != primitives->quads().end(); quad_it++) { Quad *quad = (*quad_it); if (!quad->detail()) { size_t count = 0; - count += fragment->add_vertex(quad->v0()-group_center, quad->normal(), quad->t0(), false); - count += fragment->add_vertex(quad->v1()-group_center, quad->normal(), quad->t1(), false); - count += fragment->add_vertex(quad->v2()-group_center, quad->normal(), quad->t2(), false); - count += fragment->add_vertex(quad->v3()-group_center, quad->normal(), quad->t3(), false); + count += fragment->add_vertex(quad->v0() - group_center, quad->normal(), quad->t0(), false); + count += fragment->add_vertex(quad->v1() - group_center, quad->normal(), quad->t1(), false); + count += fragment->add_vertex(quad->v2() - group_center, quad->normal(), quad->t2(), false); + count += fragment->add_vertex(quad->v3() - group_center, quad->normal(), quad->t3(), false); if (count == 4) model->model_quad_count++; } } - + // add detail quads to the fragment for (Primitives::Quads::iterator quad_it = primitives->quads().begin(); quad_it != primitives->quads().end(); quad_it++) { Quad *quad = (*quad_it); if (quad->detail()) { size_t count = 0; - count += fragment->add_vertex(quad->v0()-group_center, quad->normal(), quad->t0(), false); - count += fragment->add_vertex(quad->v1()-group_center, quad->normal(), quad->t1(), false); - count += fragment->add_vertex(quad->v2()-group_center, quad->normal(), quad->t2(), false); - count += fragment->add_vertex(quad->v3()-group_center, quad->normal(), quad->t3(), false); + count += fragment->add_vertex(quad->v0() - group_center, quad->normal(), quad->t0(), false); + count += fragment->add_vertex(quad->v1() - group_center, quad->normal(), quad->t1(), false); + count += fragment->add_vertex(quad->v2() - group_center, quad->normal(), quad->t2(), false); + count += fragment->add_vertex(quad->v3() - group_center, quad->normal(), quad->t3(), false); if (count == 4) { model->model_quad_count++; model->model_quad_detail_count++; } } } - + // add the fragment to the group group->add_fragment(fragment); } - + } // add the group to the model @@ -945,7 +945,7 @@ void MapFile::load_fragmentgroup(Model *model, const FragmentGroup::Type class_t void MapFile::unknown_value() const { - con_warn << name() << " unknown value '" << value() << "' for '" << classname() << ":" << key() << "' at line " << line() << std::endl; + con_warn << name() << " unknown value '" << value() << "' for '" << classname() << ":" << key() << "' at line " << line() << std::endl; } void MapFile::unknown_key() const @@ -962,14 +962,14 @@ Model * MapFile::load(std::string const &name) { // open the .map file MapFile mapfile; - + if (!mapfile.open(name)) { return 0; } - + Model *model = new Model(name); mapfile.clear_bbox(); - + Dock *dock = 0; Particles *particles = 0; Flare *flare = 0; @@ -989,16 +989,16 @@ Model * MapFile::load(std::string const &name) std::string str; while (mapfile.getline()) { - + if (mapfile.got_classname("worldspawn")) { mapfile.clear_bbox(); } else if (mapfile.got_classend("worldspawn")) { mapfile.load_worldspawn(model); mapfile.clear_materials(); - + } else if (mapfile.in_class("worldspawn")) { - + // worldspawn attributes if (mapfile.got_key("name")) { //con_debug << " model name '" << name << "'" << std::endl; @@ -1044,7 +1044,7 @@ Model * MapFile::load(std::string const &name) mapfile.clear_materials(); } else if (mapfile.in_class("func_rotate")) { - + if (mapfile.got_key_float("angle", angle)) { if (angle == ANGLEUP) { mapfile.class_axis.change_pitch(90.0f); @@ -1073,101 +1073,101 @@ Model * MapFile::load(std::string const &name) mapfile.clear_materials(); } else if (mapfile.got_classname("light")) { - + // new light light = new Light(); model->add_light(light); continue; - + } else if (mapfile.classname().compare("light") == 0) { - + // light attributes if (mapfile.got_key_vector3f("origin", location)) { light->get_location().assign(location * SCALE); continue; - + } else if (mapfile.got_key_color("_color", color)) { light->get_color().assign(color); continue; - + } else if (mapfile.got_key_int("spawnflags", u)) { light->set_strobe(spawnflag_isset(u, 1)); light->set_entity(spawnflag_isset(u, 2)); light->set_engine(spawnflag_isset(u, 4)); continue; - + } else if (mapfile.got_key_float("light", r)) { - light->set_radius( r * LIGHTSCALE); + light->set_radius(r * LIGHTSCALE); continue; - + } else if (mapfile.got_key_float("radius", r)) { - light->set_radius( r * LIGHTSCALE); + light->set_radius(r * LIGHTSCALE); continue; } else if (mapfile.got_key_float("frequency", r)) { light->set_frequency(r); continue; - + } else if (mapfile.got_key_float("offset", r)) { light->set_offset(r); continue; - + } else if (mapfile.got_key_float("time", r)) { light->set_time(r); continue; - + } else if (mapfile.got_key_int("flare", u)) { light->set_flare(u); continue; - + } else if (mapfile.got_key()) { mapfile.unknown_key(); continue; - + } } else if (mapfile.got_classname("fx_flare")) { - + // new flare flare = new Flare(); model->add_flare(flare); } else if (mapfile.classname().compare("fx_flare") == 0) { - + // flare attributes if (mapfile.got_key_vector3f("origin", location)) { flare->get_location().assign(location * SCALE); continue; - + } else if (mapfile.got_key_color("_color", color)) { flare->get_color().assign(color); continue; - + } else if (mapfile.got_key_int("spawnflags", u)) { flare->set_strobe(spawnflag_isset(u, 1)); flare->set_entity(spawnflag_isset(u, 2)); flare->set_engine(spawnflag_isset(u, 4)); - + } else if (mapfile.got_key_float("light", r)) { - flare->set_radius( r * LIGHTSCALE); + flare->set_radius(r * LIGHTSCALE); continue; } else if (mapfile.got_key_float("radius", r)) { - flare->set_radius( r * LIGHTSCALE); + flare->set_radius(r * LIGHTSCALE); continue; } else if (mapfile.got_key_float("frequency", r)) { flare->set_frequency(r); continue; - + } else if (mapfile.got_key_float("offset", r)) { flare->set_offset(r); continue; - + } else if (mapfile.got_key_float("time", r)) { flare->set_time(r); continue; - + } else if (mapfile.got_key_int("flare", u)) { flare->set_flare(u); continue; @@ -1188,7 +1188,7 @@ Model * MapFile::load(std::string const &name) } else if (mapfile.got_key_float("roll", angle)) { flare->get_axis().change_roll(angle); - + } else if (mapfile.got_key_string("cull", str)) { aux::to_lowercase(str); @@ -1201,7 +1201,7 @@ Model * MapFile::load(std::string const &name) } else { mapfile.unknown_value(); } - + } else if (mapfile.got_key()) { mapfile.unknown_key(); } @@ -1211,7 +1211,7 @@ Model * MapFile::load(std::string const &name) // new particle system particles = new Particles(); model->add_particles(particles); - + } else if (mapfile.classname().compare("fx_particles") == 0) { // particle system attributes @@ -1246,7 +1246,7 @@ Model * MapFile::load(std::string const &name) } else if (mapfile.got_key_float("radius", r)) { particles->set_radius(r * LIGHTSCALE); - + } else if (mapfile.got_key_string("cull", str)) { aux::to_lowercase(str); @@ -1269,7 +1269,7 @@ Model * MapFile::load(std::string const &name) // new submodel submodel = new SubModel(); submodel_list.push_back(submodel); - + } else if (mapfile.classname().compare("misc_model") == 0) { // submodel attributes @@ -1281,7 +1281,7 @@ Model * MapFile::load(std::string const &name) // remove extension if (modelname[modelname.size()-4] == '.') { - modelname.erase(modelname.size()-4); + modelname.erase(modelname.size() - 4); } submodel->set_name(modelname); @@ -1303,7 +1303,7 @@ Model * MapFile::load(std::string const &name) submodel->set_scale(1.0f); } } - + } else if (mapfile.got_classname("location_dock")) { // new docking location @@ -1316,18 +1316,18 @@ Model * MapFile::load(std::string const &name) if (mapfile.got_key_vector3f("origin", location)) { dock->get_location().assign(location * SCALE); continue; - + } else if (mapfile.got_key_float("radius", r)) { - dock->set_radius (r * SCALE); + dock->set_radius(r * SCALE); continue; - + } else if (mapfile.got_key("angle")) { // TODO continue; } else if (mapfile.got_key()) { mapfile.unknown_key(); - + } } else if (mapfile.got_classname("location_cannon")) { @@ -1356,21 +1356,21 @@ Model * MapFile::load(std::string const &name) } else if (mapfile.got_classname()) { - mapfile.unknown_class(); + mapfile.unknown_class(); } } - + mapfile.close(); // reposition docks, lights, flares and particles according to the model center for (Model::Lights::iterator lit = model->lights().begin(); lit != model->lights().end(); lit++) { (*lit)->get_location() -= mapfile.map_center; } - + for (Model::Flares::iterator flit = model->flares().begin(); flit != model->flares().end(); flit++) { (*flit)->get_location() -= mapfile.map_center; } - + for (Model::ParticleSystems::iterator pit = model->particles().begin(); pit != model->particles().end(); pit++) { (*pit)->get_location() -= mapfile.map_center; } @@ -1399,7 +1399,7 @@ Model * MapFile::load(std::string const &name) groupdst->set_type(groupsrc->type()); groupdst->set_scale(groupsrc->scale() * submodel->scale()); groupdst->set_speed(groupsrc->speed()); - groupdst->set_location(submodel->location() + (submodel_model->origin() + groupsrc->location()) * submodel->scale() ); + groupdst->set_location(submodel->location() + (submodel_model->origin() + groupsrc->location()) * submodel->scale()); groupdst->set_axis(groupsrc->axis() * submodel->axis()); // copy fragments @@ -1416,7 +1416,7 @@ Model * MapFile::load(std::string const &name) } // recalculate bbox - for (size_t i =0; i < 3; i ++) { + for (size_t i = 0; i < 3; i ++) { float c; c = submodel->location()[i] + (submodel_model->origin()[i] + submodel_model->model_maxbbox[i]) * submodel->scale(); if (c > model->model_maxbbox[i]) { @@ -1438,14 +1438,14 @@ Model * MapFile::load(std::string const &name) light->set_radius(light->radius() * submodel->scale()); model->add_light(light); } - + for (Model::Flares::const_iterator flit = submodel_model->flares().begin(); flit != submodel_model->flares().end(); flit++) { flare = new Flare(*(*flit)); flare->get_location().assign(submodel->location() + (submodel_model->origin() + flare->location()) * submodel->scale()); flare->set_radius(flare->radius() * submodel->scale()); model->add_flare(flare); } - + for (Model::ParticleSystems::const_iterator pit = submodel_model->particles().begin(); pit != submodel_model->particles().end(); pit++) { particles = new Particles(*(*pit)); particles->get_location().assign(submodel->location() + (submodel_model->origin() + particles->location()) * submodel->scale()); @@ -1453,7 +1453,7 @@ Model * MapFile::load(std::string const &name) model->add_particles(particles); } - + //con_debug << " imported submodel '" << submodel->name() << "'" << std::endl; } @@ -1465,8 +1465,8 @@ Model * MapFile::load(std::string const &name) con_warn << mapfile.name() << " quake2 style brushes detected" << std::endl; con_debug << " " << mapfile.name() << " " << mapfile.map_brushes << " brushes " << - model->model_tris_detail_count << "/" << model->model_tris_count << " detail/tris " << - model->model_quad_detail_count << "/" << model->model_quad_count << " detail/quads" << std::endl; + model->model_tris_detail_count << "/" << model->model_tris_count << " detail/tris " << + model->model_quad_detail_count << "/" << model->model_quad_count << " detail/quads" << std::endl; return model; diff --git a/src/model/mapfile.h b/src/model/mapfile.h index 0cf66a5..be1e789 100644 --- a/src/model/mapfile.h +++ b/src/model/mapfile.h @@ -30,42 +30,39 @@ public: * If the file can not be read, load() returns the NULL-pointer */ static Model *load(std::string const &name); - + private: MapFile(); ~MapFile(); - + /// tpye definition for a per-material list of Primitives typedef std::map<Material *, Primitives *> Materials; - + /// open the file for reading /** the filename will get the "maps/" prefix and ".map" suffix */ bool open(std::string const & name); - + /// parse one line, returns false on end-of-file bool getline(); bool read_patchdef(); - + /// current classname - inline std::string classname() const - { + inline std::string classname() const { return classname_current; } - + /// current key - inline std::string key() const - { + inline std::string key() const { return key_current; } - + /// current value - inline std::string value() const - { + inline std::string value() const { return value_current; } - + /// true if the last read line contained a new classname bool got_classname() const; @@ -75,67 +72,62 @@ private: } /// true if the last read line contained a class closing bracket - inline bool got_classend() const - { + inline bool got_classend() const { return last_read_was_classend; } - + /// true if the last read line contained the closing bracket for the requested class bool got_classend(const char*) const; /// true if the last read line contained a new classname bool got_classname(const char*) const; - + /// true if the last read statement was a key=value pair - inline bool got_key() const - { + inline bool got_key() const { return last_read_was_key; } - + bool got_key(const char * keylabel); - + /// check if the last read key=value pair matches keylabel and store the value in valuestring bool got_key_string(const char * keylabel, std::string & valuestring); - + /// check if the last read key=value pair matches keylabel and store the value in color bool got_key_color(const char * keylabel, math::Color & color); - + /// check if the last read key=value pair matches keylabel and store the value in f bool got_key_float(const char * keylabel, float & f); - + /// check if the last read key=value pair matches keylabel and store the value in f bool got_key_int(const char * keylabel, unsigned int & u); - + /// check if the last read key=value pair matches keylabel and store the value in valuestring bool got_key_angle(const char * keylabel, float & f); - + bool got_key_vector3f(const char * keylabel, math::Vector3f & v); - - + + /// return the number of lines read so far - inline unsigned int line() const - { + inline unsigned int line() const { return line_number; } - + /// return true of the map file is open for reading - inline bool is_open() - { + inline bool is_open() { return mapfile_ifs.is_open(); } - + /// current filename - inline std::string const & name() const - { + inline std::string const & name() const { return mapfile_name; } - + /// close the file void close(); - + /// generate triangles for one plane in the plane list void make_brushface(Face *face); - + /// load parsed primitives into model worldspawn void load_worldspawn(Model *model); @@ -153,28 +145,28 @@ private: void unknown_key() const; void unknown_value() const; - + /// list of planes for the current brush std::vector<Face *> planes; - + std::string classname_current; std::string key_current; std::string value_current; - + bool last_read_was_key; bool last_read_was_classname; bool last_read_was_classend; - + unsigned int map_brushes; unsigned int map_faces; unsigned int map_faces_detail; - + unsigned int parse_level; unsigned int line_number; filesystem::IFileStream mapfile_ifs; std::string mapfile_name; - + math::Vector3f class_maxbbox; math::Vector3f class_minbbox; math::Axis class_axis; diff --git a/src/model/material.cc b/src/model/material.cc index 416e491..6baf4f9 100644 --- a/src/model/material.cc +++ b/src/model/material.cc @@ -19,9 +19,9 @@ Material::LoaderFuncPtr Material::material_loaderfunc = 0; Material::Registry Material::material_registry; Material::Material(const std::string &name) : - material_name(name), - material_color(1.0f) , - material_size(64.0f, 64.0f) + material_name(name), + material_color(1.0f) , + material_size(64.0f, 64.0f) { aux::to_lowercase(material_name); material_flags = 0; @@ -41,11 +41,16 @@ void Material::set_color(const math::Color &color) void Material::set_texture(const std::string &texture) { - material_texture.assign(texture); - - if (material_loaderfunc) { - material_loaderfunc(this); - //con_debug << " material " << name() << " " << size().width() << "x" << size().height() << std::endl; + if (texture.size()) { + set_flags(Texture); + material_texture.assign(texture); + if (material_loaderfunc) { + material_loaderfunc(this); + } + } else { + unset_flags(Texture); + material_texture.clear(); + material_texture_id = 0; } } @@ -80,8 +85,8 @@ void Material::init() while (shaderlist.getline(line, 1023)) { if ((line[0] == 0) || (line[0] == '#') || (line[0] == ';')) { continue; - if ((line[0] == '/') && (line[1] == '/')) - continue; + if ((line[0] == '/') && (line[1] == '/')) + continue; } else { std::string s(line); aux::trim(s); @@ -115,7 +120,7 @@ void Material::load_shader(const std::string &shadername) unsigned int linenumber = 0; char line[1024]; unsigned int count = 0; - float r,g,b; + float r, g, b; Material *material = 0; while (shaderfile.getline(line, 1023)) { @@ -130,12 +135,12 @@ void Material::load_shader(const std::string &shadername) continue; // skip comments - if ((s[0] == '#') || (s[0] == ';') || ((s[0] == '/') && (s[1] == '/'))) + if ((s[0] == '#') || (s[0] == ';') || ((s[0] == '/') && (s[1] == '/'))) continue; - + std::istringstream linestream(s); std::string firstword; - + if (linestream >> firstword) { if (firstword.compare("//") == 0) { continue; @@ -146,7 +151,7 @@ void Material::load_shader(const std::string &shadername) } else if (firstword.compare("{") == 0) { parselevel++; - } else if ((firstword.size()) && (parselevel == 0) ) { + } else if ((firstword.size()) && (parselevel == 0)) { material = find(firstword); if (material) { @@ -163,8 +168,10 @@ void Material::load_shader(const std::string &shadername) if (firstword.compare("color") == 0) { if (linestream >> r >> g >> b) { if (math::max(r, math::max(g, b)) > 1.0f) { - r /= 255.0f; g /= 255.0f; b /= 255.0f; - } + r /= 255.0f; + g /= 255.0f; + b /= 255.0f; + } material->set_color(math::Color(r, g, b, 1.0f)); } } else if (firstword.compare("engine") == 0) { @@ -178,7 +185,7 @@ void Material::load_shader(const std::string &shadername) } else if (firstword.compare("entitysecond") == 0) { material->set_flags(Secondary); } else if (firstword.compare("entitythird") == 0) { - material->set_flags(Tertiary); + material->set_flags(Tertiary); } else if (firstword.compare("ignore") == 0) { material->set_flags(Ignore); } else if (firstword.compare("qer_editorimage") == 0) { @@ -189,19 +196,19 @@ void Material::load_shader(const std::string &shadername) // texture name should not contain spaces if (linestream >> firstword) { + // remove extension if (firstword[firstword.size()-4] == '.') { - firstword.erase(firstword.size()-4); + firstword.erase(firstword.size() - 4); } material->set_texture(firstword); - material->set_flags(Material::Texture); } else { con_warn << shaderfile.name() << " texture key without filename at line " << linenumber << std::endl; } } else { - con_warn << shaderfile.name() << " unknown key '" << firstword - << "' at line " << linenumber << std::endl; + con_warn << shaderfile.name() << " unknown key '" << firstword + << "' at line " << linenumber << std::endl; } } } @@ -222,7 +229,7 @@ void Material::clear() con_print << "^BClearing materials..." << std::endl; for (Registry::iterator i = material_registry.begin(); i != material_registry.end(); ++i) { - delete (*i).second; + delete(*i).second; } material_registry.clear(); diff --git a/src/model/material.h b/src/model/material.h index 9185fd2..44470e5 100644 --- a/src/model/material.h +++ b/src/model/material.h @@ -24,7 +24,7 @@ public: typedef void(* LoaderFuncPtr)(Material *); /// surface flags - enum SurfaceFlags { None=0, Primary=1, Secondary=2, Tertiary=3, Bright=4, Engine=8, Environment=16, Texture=32, Ignore=64}; + enum SurfaceFlags { None = 0, Primary = 1, Secondary = 2, Tertiary = 3, Bright = 4, Engine = 8, Environment = 16, Texture = 32, Ignore = 64}; /// type definition for the material registry typedef std::map<std::string, Material *> Registry; @@ -35,20 +35,32 @@ public: /* ---- inspectors ----------------------------------------- */ - inline const std::string &name() const { return material_name; } + inline const std::string &name() const { + return material_name; + } - inline const math::Color &color() const { return material_color; } + inline const math::Color &color() const { + return material_color; + } - inline const unsigned int flags() const { return material_flags; } + inline const unsigned int flags() const { + return material_flags; + } - inline const std::string &texture() const { return material_texture; } + inline const std::string &texture() const { + return material_texture; + } - inline const size_t texture_id() const { return material_texture_id; } + inline const size_t texture_id() const { + return material_texture_id; + } /** * @brief returns the material texture size */ - inline const math::Vector2f & size() const { return material_size; } + inline const math::Vector2f & size() const { + return material_size; + } /* ---- mutators ------------------------------------------- */ @@ -74,16 +86,14 @@ public: */ void set_size(const math::Vector2f &size); - inline void set_flags(SurfaceFlags flags) - { + inline void set_flags(SurfaceFlags flags) { material_flags |= flags; } - inline void unset_flags(SurfaceFlags flags) - { + inline void unset_flags(SurfaceFlags flags) { material_flags &= ~flags; } - + /* ---- static ----------------------------------------------------- */ /** @@ -92,12 +102,12 @@ public: */ static void init(); - /** + /** * @brief shutdown material registry */ static void shutdown(); - /** + /** * @brief clear material registry */ static void clear(); diff --git a/src/model/model.cc b/src/model/model.cc index 2b3ec7a..85bf609 100644 --- a/src/model/model.cc +++ b/src/model/model.cc @@ -17,14 +17,14 @@ namespace model Model::Registry Model::model_registry; Model::Model(const std::string & name) : - model_enginecolor(1.0f, 0.0f, 0.0f), - model_name(name) - + model_enginecolor(1.0f, 0.0f, 0.0f), + model_name(name) + { model_radius = 0.5f; model_enginesound = 0; model_impulsesound = 0; - + model_tris_detail_count = 0; model_tris_count = 0; model_quad_detail_count = 0; @@ -35,28 +35,28 @@ Model::~Model() { // delete all fragment groups for (Groups::iterator git = model_groups.begin(); git != model_groups.end(); git++) { - delete (*git); + delete(*git); } model_groups.clear(); - + // delete all docks for (Docks::iterator dit = model_docks.begin(); dit != model_docks.end(); dit++) { - delete (*dit); + delete(*dit); } model_docks.clear(); // delete all particle systems for (Model::ParticleSystems::iterator pit = model_particles.begin(); pit != model_particles.end(); pit++) { - delete (*pit); + delete(*pit); } model_particles.clear(); - + // delete all lights for (Lights::iterator lit = model_lights.begin(); lit != model_lights.end(); lit++) { delete(*lit); } model_lights.clear(); - + // delete all flares for (Flares::iterator flit = model_flares.begin(); flit != model_flares.end(); flit++) { delete(*flit); @@ -115,18 +115,18 @@ Model *Model::load(const std::string & name) // try loading the .map model model = MapFile::load(name); } - + if (!model) { // if it can't be found, try the ase model model = ASEFile::load(name); } - - if (!model) { + + if (!model) { con_warn << "Could not open model " << name << std::endl; } else { model_registry[model->name()] = model; } - + return model; } @@ -137,7 +137,7 @@ void Model::clear() delete(*mit).second; } model_registry.clear(); - + // clear the vertex array if (VertexArray::instance()) VertexArray::instance()->clear(); @@ -159,18 +159,18 @@ void Model::list() { for (Registry::iterator mit = model_registry.begin(); mit != model_registry.end(); mit++) { list_model((*mit).second); - + } - + con_print << model_registry.size() << " registered models" << std::endl; if (VertexArray::instance()) { - + con_print << "vertex array " - << VertexArray::instance()->index() * 3 * sizeof(float) / (1024*1024) << "/" - << VertexArray::instance()->size() * 3 * sizeof(float) / (1024*1024) << "Mb " - << VertexArray::instance()->index() / 3 << "/" << VertexArray::instance()->size() / 3 << " verts " - << (VertexArray::instance()->index() * 100 / VertexArray::instance()->size())<< "% used" - << std::endl; + << VertexArray::instance()->index() * 3 * sizeof(float) / (1024*1024) << "/" + << VertexArray::instance()->size() * 3 * sizeof(float) / (1024*1024) << "Mb " + << VertexArray::instance()->index() / 3 << "/" << VertexArray::instance()->size() / 3 << " verts " + << (VertexArray::instance()->index() * 100 / VertexArray::instance()->size()) << "% used" + << std::endl; } } diff --git a/src/model/model.h b/src/model/model.h index af3b1dc..30714d4 100644 --- a/src/model/model.h +++ b/src/model/model.h @@ -32,16 +32,16 @@ class Model public: /// type definition for the model registry typedef std::map<std::string, Model*> Registry; - + /// type definition for a list of model fragments typedef std::list<Fragment *> Fragments; - + /// type definition for a list of model lights typedef std::list<Light *> Lights; - + /// type definition for a list of model flares typedef std::list<Flare *> Flares; - + /// type definition for a lost of dockable locations typedef std::list<Dock *> Docks; @@ -50,97 +50,84 @@ public: /// type definition for a list of FragmentGroups typedef std::list<FragmentGroup *> Groups; - + /// create a model with a name Model(const std::string & name); - + /// delete the model, and all fragments, lights, etc ~Model(); - + /// the name of the model - inline const std::string & name() const - { + inline const std::string & name() const { return model_name; } - + /// radius - inline float radius() const - { + inline float radius() const { return model_radius; } - + /// additional model fragment groups - inline Groups & groups() - { + inline Groups & groups() { return model_groups; } /// list of lights - inline Lights & lights() - { + inline Lights & lights() { return model_lights; } /// list of dockable locations - inline Docks & docks() - { + inline Docks & docks() { return model_docks; } - + /// list of flares - inline Flares & flares() - { + inline Flares & flares() { return model_flares; } - + /// list of engines - inline ParticleSystems & particles() - { + inline ParticleSystems & particles() { return model_particles; } - + /// maximum values of the bounding box - inline const math::Vector3f & maxbbox() const - { + inline const math::Vector3f & maxbbox() const { return model_maxbbox; } - + /// minimum values of the bounding box - inline const math::Vector3f & minbbox() const - { + inline const math::Vector3f & minbbox() const { return model_minbbox; } - + /// engine sound loop for this model - inline unsigned int enginesound() const - { + inline unsigned int enginesound() const { return model_enginesound; } /// impulse sound set for this model - inline unsigned int impulsesound() const - { + inline unsigned int impulsesound() const { return model_impulsesound; } /// engine color for this model - inline const math::Color & enginecolor() const - { + inline const math::Color & enginecolor() const { return model_enginecolor; } /// original origin - inline const math::Vector3f & origin() const - { + inline const math::Vector3f & origin() const { return model_origin; } - + /// add a light to the model void add_light(Light *light); - + /// add a particle system to the model void add_particles(Particles *particles); - + /// add a flare to the model void add_flare(Flare *flare); @@ -153,15 +140,15 @@ public: void set_radius(const float radius); void set_origin(const math::Vector3f &origin); - + math::Vector3f model_maxbbox; math::Vector3f model_minbbox; - + unsigned int model_enginesound; unsigned int model_impulsesound; math::Color model_enginecolor; - + /// total number of triangles size_t model_tris_count; /// number of detail triangles @@ -172,29 +159,28 @@ public: size_t model_quad_detail_count; /* ---- static functions for the Model registry -------------------- */ - + /// the model registry - static inline Registry & registry() - { + static inline Registry & registry() { return model_registry; } - + /// get name model, returns 0 if not found static Model *find(const std::string & name); - + /// get named model from the registry and load it if necessary static Model *load(const std::string & name); - + /// clear the model registry static void clear(); - + /// list the content of the model registry static void list(); - + /// list one model static void list_model(Model *model); - + private: std::string model_name; diff --git a/src/model/parts.cc b/src/model/parts.cc index ac54410..e71ad16 100644 --- a/src/model/parts.cc +++ b/src/model/parts.cc @@ -6,7 +6,8 @@ #include "model/parts.h" -namespace model { +namespace model +{ /* ---- class Light ------------------------------------------------ */ @@ -24,12 +25,12 @@ Light::Light() : light_time = 0.5f; light_flare = 0; - + light_texture = 0; } Light::Light(const Light& other) : Part(other), - light_color(other.color()) + light_color(other.color()) { light_entity = other.entity(); light_engine = other.engine(); @@ -41,7 +42,7 @@ Light::Light(const Light& other) : Part(other), light_time = other.time(); light_flare = other.flare(); - + light_texture = other.texture(); } Light::~Light() @@ -105,8 +106,8 @@ SubModel::SubModel() : Part() } SubModel::SubModel(const SubModel& other) : Part(other), - submodel_name(other.name()), - submodel_axis(other.axis()) + submodel_name(other.name()), + submodel_axis(other.axis()) { submodel_scale = other.scale(); } diff --git a/src/model/parts.h b/src/model/parts.h index 210a225..4df4672 100644 --- a/src/model/parts.h +++ b/src/model/parts.h @@ -24,7 +24,7 @@ namespace model * Culling is a paremeter used by flares and particles to indicate * with side of the polygons should be culled during rendering */ -enum Cull { CullNone=0, CullBack=1, CullFront=2 }; +enum Cull { CullNone = 0, CullBack = 1, CullFront = 2 }; /* ---- class Part ------------------------------------------------- */ @@ -37,23 +37,20 @@ public: /** * @brief default constructor */ - inline Part() : part_location() - { + inline Part() : part_location() { } /** * @brief copy constructor */ - inline Part(const Part& other) : part_location(other.location()) - { + inline Part(const Part& other) : part_location(other.location()) { } /** * @brief constructor with location * @param location location of this part within the parent model */ - inline Part(const math::Vector3f& location) : part_location(location) - { + inline Part(const math::Vector3f& location) : part_location(location) { } /* ---- inspectors ----------------------------------------- */ @@ -61,8 +58,7 @@ public: /** * @brief location of this part within the parent model */ - inline const math::Vector3f& location() const - { + inline const math::Vector3f& location() const { return part_location; } @@ -70,22 +66,25 @@ public: /** * @brief set the location within the parent model */ - inline void set_location(const math::Vector3f& location) { part_location.assign(location); } + inline void set_location(const math::Vector3f& location) { + part_location.assign(location); + } /** * @brief set the location within the parent model */ - inline void set_location(const float x, const float y, const float z) { part_location.assign(x, y, z); } + inline void set_location(const float x, const float y, const float z) { + part_location.assign(x, y, z); + } /* ---- actors --------------------------------------------- */ /** * @brief mutable reference to the location of this part within the parent model */ - inline math::Vector3f& get_location() - { + inline math::Vector3f& get_location() { return part_location; - } + } private: math::Vector3f part_location; @@ -111,66 +110,56 @@ public: * @brief destructor */ ~Light(); - + /* ---- inspectors ----------------------------------------- */ /// light color - inline const math::Color& color() const - { + inline const math::Color& color() const { return light_color; }; - + /// true if this is a strobe light - inline bool strobe() const - { + inline bool strobe() const { return light_strobe; } - + /// true if this light has entity color - inline bool entity() const - { + inline bool entity() const { return light_entity; } /// true if this light has engine activation - inline bool engine() const - { + inline bool engine() const { return light_engine; } - + /// size of the light, default is 1.0f - inline float radius() const - { + inline float radius() const { return light_radius; } - + /// strobe time offset, in seconds - inline float offset() const - { + inline float offset() const { return light_offset; } - + /// strobe frequency in strobes per second, default is 1.0f - inline float frequency() const - { + inline float frequency() const { return light_frequency; } - + /// fraction a strobe light will be on, default is 0.5f - inline float time() const - { + inline float time() const { return light_time; } - + /// flare texture number - inline unsigned int flare() const - { + inline unsigned int flare() const { return light_flare; } - + /// render texture id - inline size_t texture() const - { + inline size_t texture() const { return light_texture; } /* ---- mutators ------------------------------------------- */ @@ -178,53 +167,73 @@ public: /** * @brief set strobe color on or off */ - inline void set_strobe(const bool strobe) { light_strobe = strobe; } + inline void set_strobe(const bool strobe) { + light_strobe = strobe; + } /** * @brief set entity color on or off */ - inline void set_entity(const bool entity) { light_entity = entity; } + inline void set_entity(const bool entity) { + light_entity = entity; + } /** * @brief set engine activation on or off */ - inline void set_engine(const bool engine) { light_engine = engine; } + inline void set_engine(const bool engine) { + light_engine = engine; + } /** * @brief set the light radius */ - inline void set_radius(const float radius) { light_radius = radius; } + inline void set_radius(const float radius) { + light_radius = radius; + } /** * @brief set the light strobe frequency, in strobes per second */ - inline void set_frequency(const float frequency) { light_frequency = frequency; } + inline void set_frequency(const float frequency) { + light_frequency = frequency; + } /** * @brief set the light on time, from 0.0 (always off) to 1.0 (always on) */ - inline void set_time(const float time) { light_radius = time; } + inline void set_time(const float time) { + light_radius = time; + } /** * @brief set the light strobe time offset, in seconds */ - inline void set_offset(const float offset) { light_offset = offset; } + inline void set_offset(const float offset) { + light_offset = offset; + } /** * @brief set the flare texture number */ - inline void set_flare(unsigned int flare) { light_flare = flare; } + inline void set_flare(unsigned int flare) { + light_flare = flare; + } /** * @brief set the render texture id */ - inline void set_texture(size_t texture) { light_texture = texture; } + inline void set_texture(size_t texture) { + light_texture = texture; + } /** * @brief mutable reference to the color */ - inline math::Color& get_color() { return light_color; } - + inline math::Color& get_color() { + return light_color; + } + private: bool light_strobe; bool light_engine; @@ -256,29 +265,31 @@ public: Flare(const Flare& other); ~Flare(); - + /* ---- inspectors ----------------------------------------- */ - inline const math::Axis &axis() const - { + inline const math::Axis &axis() const { return flare_axis; } - - inline Cull cull() const - { + + inline Cull cull() const { return flare_cull; } /* ---- mutators ------------------------------------------- */ - - inline void set_cull(const Cull cull) { flare_cull = cull; } + + inline void set_cull(const Cull cull) { + flare_cull = cull; + } /* ---- actors --------------------------------------------- */ /** * @brief mutable reference to the axis */ - inline math::Axis& get_axis() { return flare_axis; } + inline math::Axis& get_axis() { + return flare_axis; + } private: Cull flare_cull; @@ -296,34 +307,28 @@ public: Particles(const math::Vector3f & location); ~Particles(); - - inline const math::Axis &axis() const - { + + inline const math::Axis &axis() const { return particles_axis; } - - inline const std::string& script() const - { + + inline const std::string& script() const { return particles_script; } - inline bool entity() const - { + inline bool entity() const { return particles_entity; } - inline bool engine() const - { + inline bool engine() const { return particles_engine; } - - inline float radius() const - { + + inline float radius() const { return particles_radius; } - inline Cull cull() const - { + inline Cull cull() const { return particles_cull; } @@ -332,25 +337,37 @@ public: /** * @brief set entity color on or off */ - inline void set_entity(const bool entity) { particles_entity = entity; } + inline void set_entity(const bool entity) { + particles_entity = entity; + } /** * @brief set engine activation on or off */ - inline void set_engine(const bool engine) { particles_engine = engine; } + inline void set_engine(const bool engine) { + particles_engine = engine; + } - inline void set_radius(const float radius) { particles_radius = radius; } + inline void set_radius(const float radius) { + particles_radius = radius; + } - inline void set_cull(const Cull cull) { particles_cull = cull; } + inline void set_cull(const Cull cull) { + particles_cull = cull; + } - inline void set_script(const std::string& script) { particles_script.assign(script); } + inline void set_script(const std::string& script) { + particles_script.assign(script); + } /* ---- actors --------------------------------------------- */ /** * @brief mutable reference to the axis */ - inline math::Axis& get_axis() { return particles_axis; } + inline math::Axis& get_axis() { + return particles_axis; + } private: bool particles_entity; @@ -360,7 +377,7 @@ private: float particles_radius; - math::Axis particles_axis; + math::Axis particles_axis; std::string particles_script; }; @@ -378,15 +395,16 @@ public: Dock(const Dock& other); ~Dock(); - + /// dock radius, default is 0.01f - inline float radius() const - { + inline float radius() const { return dock_radius; } - /// set dock radius - inline void set_radius(const float radius) { dock_radius = radius; } + /// set dock radius + inline void set_radius(const float radius) { + dock_radius = radius; + } private: float dock_radius; @@ -404,25 +422,39 @@ public: ~SubModel(); - inline const std::string& name() const { return submodel_name; } + inline const std::string& name() const { + return submodel_name; + } - inline const math::Axis& axis() const { return submodel_axis; } + inline const math::Axis& axis() const { + return submodel_axis; + } - inline float scale() const { return submodel_scale; } + inline float scale() const { + return submodel_scale; + } - inline void set_scale(const float scale) { submodel_scale = scale; } + inline void set_scale(const float scale) { + submodel_scale = scale; + } - inline void set_name(const std::string& name) { submodel_name.assign(name); } + inline void set_name(const std::string& name) { + submodel_name.assign(name); + } - inline void set_axis(const math::Axis& axis) { submodel_axis.assign(axis); } + inline void set_axis(const math::Axis& axis) { + submodel_axis.assign(axis); + } /* ---- actors --------------------------------------------- */ /** * @brief mutable reference to the axis */ - inline math::Axis& get_axis() { return submodel_axis; } + inline math::Axis& get_axis() { + return submodel_axis; + } private: float submodel_scale; diff --git a/src/model/primitives.cc b/src/model/primitives.cc index f21a6d5..85b07ee 100644 --- a/src/model/primitives.cc +++ b/src/model/primitives.cc @@ -20,7 +20,7 @@ Primitives::~Primitives() for (std::list<Triangle *>::iterator tris_it = primitives_triangles.begin(); tris_it != primitives_triangles.end(); tris_it++) delete(*tris_it); primitives_triangles.clear(); - + // clear list of quads for (std::list<Quad *>::iterator quad_it = primitives_quads.begin(); quad_it != primitives_quads.end(); quad_it++) delete(*quad_it); diff --git a/src/model/primitives.h b/src/model/primitives.h index 84c3f9b..43fd380 100644 --- a/src/model/primitives.h +++ b/src/model/primitives.h @@ -23,31 +23,28 @@ class Primitives public: /// type definition for a list of triangles typedef std::list<Triangle *> Triangles; - + /// type definition for a list of quads typedef std::list<Quad *> Quads; - + Primitives(Material *material); ~Primitives(); - + /// the material to be used for these primitives - inline const Material *material() const - { + inline const Material *material() const { return primitives_material; } - + /// list of triangles - inline Triangles & triangles() - { + inline Triangles & triangles() { return primitives_triangles; } - + /// list of quads - inline Quads & quads() - { + inline Quads & quads() { return primitives_quads; } - + /// add a Triangle primitive void add_triangle(Triangle *triangle); @@ -57,7 +54,7 @@ public: private: Triangles primitives_triangles; Quads primitives_quads; - + Material * primitives_material; }; diff --git a/src/model/quad.cc b/src/model/quad.cc index c012bf0..0830fe7 100644 --- a/src/model/quad.cc +++ b/src/model/quad.cc @@ -9,7 +9,7 @@ namespace model { -Quad::Quad(const math::Vector3f &v0,const math::Vector3f &v1, const math::Vector3f &v2, const math::Vector3f &v3, const math::Vector3f &normal, const bool detail) : +Quad::Quad(const math::Vector3f &v0, const math::Vector3f &v1, const math::Vector3f &v2, const math::Vector3f &v3, const math::Vector3f &normal, const bool detail) : quad_v0(v0), quad_n0(normal), quad_v1(v1), diff --git a/src/model/quad.h b/src/model/quad.h index 4728866..b7dd7af 100644 --- a/src/model/quad.h +++ b/src/model/quad.h @@ -21,85 +21,72 @@ public: * @brief a new quad with 4 vertices * this constructor assigns the face normal to every vertex normal */ - Quad(const math::Vector3f &v0,const math::Vector3f &v1, const math::Vector3f &v2, const math::Vector3f &v3, const math::Vector3f &normal, const bool detail = false); + Quad(const math::Vector3f &v0, const math::Vector3f &v1, const math::Vector3f &v2, const math::Vector3f &v3, const math::Vector3f &normal, const bool detail = false); /// delete quad ~Quad(); - + /// quad vertex 0 - inline math::Vector3f & v0() - { + inline math::Vector3f & v0() { return quad_v0; } - + /// quad vertex 0 normal - inline math::Vector3f & n0() - { + inline math::Vector3f & n0() { return quad_n0; } /// quad vertex 0 texture coordinates - inline math::Vector2f & t0() - { + inline math::Vector2f & t0() { return quad_t0; } /// quad vertex 1 - inline math::Vector3f & v1() - { + inline math::Vector3f & v1() { return quad_v1; } /// quad vertex 1 normal - inline math::Vector3f & n1() - { + inline math::Vector3f & n1() { return quad_n1; } /// quad vertex 1 texture coordinates - inline math::Vector2f & t1() - { + inline math::Vector2f & t1() { return quad_t1; } - + /// quad vertex 2 - inline math::Vector3f & v2() - { + inline math::Vector3f & v2() { return quad_v2; } /// quad vertex 2 normal - inline math::Vector3f & n2() - { + inline math::Vector3f & n2() { return quad_n2; } /// quad vertex 2 texture coordinates - inline math::Vector2f & t2() - { + inline math::Vector2f & t2() { return quad_t2; } /// quad vertex 3 - inline math::Vector3f & v3() - { + inline math::Vector3f & v3() { return quad_v3; } /// quad vertex 3 normal - inline math::Vector3f & n3() - { + inline math::Vector3f & n3() { return quad_n3; } /// quad vertex 3 texture coordinates - inline math::Vector2f & t3() - { + inline math::Vector2f & t3() { return quad_t3; } /// indidcates if this quad was generated from a detail brush - inline bool detail() const - { + inline bool detail() const { return quad_detail; } @@ -125,7 +112,7 @@ private: math::Vector3f quad_v3; math::Vector3f quad_n3; math::Vector2f quad_t3; - + math::Vector3f quad_normal; bool quad_detail; }; diff --git a/src/model/triangle.cc b/src/model/triangle.cc index 40c34a3..0fb7224 100644 --- a/src/model/triangle.cc +++ b/src/model/triangle.cc @@ -10,23 +10,23 @@ namespace model { Triangle::Triangle(const math::Vector3f &v0, const math::Vector3f &v1, const math::Vector3f &v2) : - triangle_v0(v0), - triangle_v1(v1), - triangle_v2(v2) + triangle_v0(v0), + triangle_v1(v1), + triangle_v2(v2) { - triangle_detail = false; + triangle_detail = false; } -Triangle::Triangle(const math::Vector3f &v0,const math::Vector3f &v1, const math::Vector3f &v2, const math::Vector3f &normal, const bool detail) : - triangle_v0(v0), - triangle_n0(normal), - triangle_v1(v1), - triangle_n1(normal), - triangle_v2(v2), - triangle_n2(normal), - triangle_normal(normal) +Triangle::Triangle(const math::Vector3f &v0, const math::Vector3f &v1, const math::Vector3f &v2, const math::Vector3f &normal, const bool detail) : + triangle_v0(v0), + triangle_n0(normal), + triangle_v1(v1), + triangle_n1(normal), + triangle_v2(v2), + triangle_n2(normal), + triangle_normal(normal) { - triangle_detail = detail; + triangle_detail = detail; } Triangle::~Triangle() diff --git a/src/model/triangle.h b/src/model/triangle.h index 8e8d1e2..06a8810 100644 --- a/src/model/triangle.h +++ b/src/model/triangle.h @@ -17,92 +17,92 @@ namespace model class Triangle { public: - /** - * @brief a new triangle with 3 vertices - * this constructor is used by the ASE reader sets the detail flag to false - */ - Triangle(const math::Vector3f &v0, const math::Vector3f &v1, const math::Vector3f &v2); - - /** - * @brief a new triangle with 3 vertices - * this constructor is used by the MAP reader and assigns the face normal to every vertex normal - */ - Triangle(const math::Vector3f &v0,const math::Vector3f &v1, const math::Vector3f &v2, const math::Vector3f &normal, const bool detail = false); - - /// delete triangle - ~Triangle(); - - /// triangle vertex 0 - inline math::Vector3f & v0() { - return triangle_v0; - } - - /// triangle vertex 0 normal - inline math::Vector3f & n0() { - return triangle_n0; - } - - /// triangle vertex 0 texture coordinates - inline math::Vector2f & t0() { - return triangle_t0; - } - - /// triangle vertex 1 - inline math::Vector3f & v1() { - return triangle_v1; - } - - /// triangle vertex 1 normal - inline math::Vector3f & n1() { - return triangle_n1; - } - - /// triangle vertex 1 texture coordinates - inline math::Vector2f & t1() { - return triangle_t1; - } - - /// triangle vertex 2 - inline math::Vector3f & v2() { - return triangle_v2; - } - - /// triangle vertex 2 normal - inline math::Vector3f & n2() { - return triangle_n2; - } - - /// triangle vertex 2 texture coordinates - inline math::Vector2f & t2() { - return triangle_t2; - } - - /// indidcates if this triangle was generated from a detail brush - inline bool detail() const { - return triangle_detail; - } - - /// face normal - inline math::Vector3f &normal() { - return triangle_normal; - } + /** + * @brief a new triangle with 3 vertices + * this constructor is used by the ASE reader sets the detail flag to false + */ + Triangle(const math::Vector3f &v0, const math::Vector3f &v1, const math::Vector3f &v2); + + /** + * @brief a new triangle with 3 vertices + * this constructor is used by the MAP reader and assigns the face normal to every vertex normal + */ + Triangle(const math::Vector3f &v0, const math::Vector3f &v1, const math::Vector3f &v2, const math::Vector3f &normal, const bool detail = false); + + /// delete triangle + ~Triangle(); + + /// triangle vertex 0 + inline math::Vector3f & v0() { + return triangle_v0; + } + + /// triangle vertex 0 normal + inline math::Vector3f & n0() { + return triangle_n0; + } + + /// triangle vertex 0 texture coordinates + inline math::Vector2f & t0() { + return triangle_t0; + } + + /// triangle vertex 1 + inline math::Vector3f & v1() { + return triangle_v1; + } + + /// triangle vertex 1 normal + inline math::Vector3f & n1() { + return triangle_n1; + } + + /// triangle vertex 1 texture coordinates + inline math::Vector2f & t1() { + return triangle_t1; + } + + /// triangle vertex 2 + inline math::Vector3f & v2() { + return triangle_v2; + } + + /// triangle vertex 2 normal + inline math::Vector3f & n2() { + return triangle_n2; + } + + /// triangle vertex 2 texture coordinates + inline math::Vector2f & t2() { + return triangle_t2; + } + + /// indidcates if this triangle was generated from a detail brush + inline bool detail() const { + return triangle_detail; + } + + /// face normal + inline math::Vector3f &normal() { + return triangle_normal; + } private: - math::Vector3f triangle_v0; - math::Vector3f triangle_n0; - math::Vector2f triangle_t0; + math::Vector3f triangle_v0; + math::Vector3f triangle_n0; + math::Vector2f triangle_t0; - math::Vector3f triangle_v1; - math::Vector3f triangle_n1; - math::Vector2f triangle_t1; + math::Vector3f triangle_v1; + math::Vector3f triangle_n1; + math::Vector2f triangle_t1; - math::Vector3f triangle_v2; - math::Vector3f triangle_n2; - math::Vector2f triangle_t2; + math::Vector3f triangle_v2; + math::Vector3f triangle_n2; + math::Vector2f triangle_t2; - math::Vector3f triangle_normal; - bool triangle_detail; + math::Vector3f triangle_normal; + bool triangle_detail; }; } diff --git a/src/model/vertexarray.cc b/src/model/vertexarray.cc index 8509dc6..057b80d 100644 --- a/src/model/vertexarray.cc +++ b/src/model/vertexarray.cc @@ -19,17 +19,17 @@ VertexArray *VertexArray::vertex_instance = 0 ; VertexArray::VertexArray(size_t size) { vertex_instance = this; - vertex_size = size * 1024*1024; // megabytes + vertex_size = size * 1024 * 1024; // megabytes vertex_size = vertex_size / sizeof(float); // sizeof float vertex_size = vertex_size / 3; // 3 arrays - + vertex_vertex = (float *) malloc(vertex_size * sizeof(float)); vertex_normal = (float *) malloc(vertex_size * sizeof(float)); vertex_texture = (float *) malloc(vertex_size * sizeof(float)); - + con_print << "^BInitializing vertex array..." << std::endl; con_print << " " << size << " Mb allocated" << std::endl; - + clear(); } @@ -38,7 +38,7 @@ VertexArray::~VertexArray() free(vertex_vertex); free(vertex_normal); free(vertex_texture); - + vertex_instance = 0 ; } @@ -46,90 +46,90 @@ void VertexArray::clear() { vertex_index = 0; vertex_overflow = false; - + memset(vertex_vertex, 0, sizeof(vertex_vertex)); memset(vertex_normal, 0, sizeof(vertex_normal)); memset(vertex_texture, 0, sizeof(vertex_texture)); - + add_sphere(); } void VertexArray::add_sphere() { // load sphere vertices into the VertexArray - + // build sin/cos table float *sintable; float *costable; - + sintable = new float[SPHERESEGMENTS]; costable = new float[SPHERESEGMENTS]; - float d = 2 * M_PI / (SPHERESEGMENTS-1); - - for (int i=0; i < SPHERESEGMENTS; i++) { + float d = 2 * M_PI / (SPHERESEGMENTS - 1); + + for (int i = 0; i < SPHERESEGMENTS; i++) { sintable[i] = sin(d * (float) i); costable[i] = cos(d * (float) i); } - + // draw body math::Vector3f v; math::Vector3f n; float texx, texy; - + int quad_count = 0; - + // add sphere - for (int j=0; j < (SPHERESEGMENTS-1) / 2; j++) { - + for (int j = 0; j < (SPHERESEGMENTS - 1) / 2; j++) { + float r = sintable[j]; float r1 = sintable[j+1]; - + for (int i = 0; i < SPHERESEGMENTS; i++) { - v = math::Vector3f(r*costable[i], r*sintable[i], costable[j]); + v = math::Vector3f(r * costable[i], r * sintable[i], costable[j]); n = v; n.normalize(); - texx = (float)i/(float)(SPHERESEGMENTS-1); - texy = -costable[j]/2 + 0.5f; + texx = (float)i / (float)(SPHERESEGMENTS - 1); + texy = -costable[j] / 2 + 0.5f; add_vertex(v, n, texx, texy); - - v = math::Vector3f(r1*costable[i], r1*sintable[i], costable[j+1]); + + v = math::Vector3f(r1 * costable[i], r1 * sintable[i], costable[j+1]); n = v; n.normalize(); - texx = (float)i/(float)(SPHERESEGMENTS-1); - texy = -costable[j+1]/2 + 0.5f; + texx = (float)i / (float)(SPHERESEGMENTS - 1); + texy = -costable[j+1] / 2 + 0.5f; add_vertex(v, n, texx, texy); - + quad_count++; } quad_count--; } - - + + // add inside-out sphere - for (int j=0; j < (SPHERESEGMENTS-1) / 2; j++) { - + for (int j = 0; j < (SPHERESEGMENTS - 1) / 2; j++) { + float r = sintable[j]; float r1 = sintable[j+1]; - - - for (int i = SPHERESEGMENTS -1 ; i >= 0; i--) { - v = math::Vector3f(r*costable[i], r*sintable[i], costable[j]); + + + for (int i = SPHERESEGMENTS - 1 ; i >= 0; i--) { + v = math::Vector3f(r * costable[i], r * sintable[i], costable[j]); n = v; n.normalize(); - texx = 1-(float)i/(float)(SPHERESEGMENTS-1); - texy = -costable[j]/2 + 0.5f; + texx = 1 - (float)i / (float)(SPHERESEGMENTS - 1); + texy = -costable[j] / 2 + 0.5f; add_vertex(v, n, texx, texy); - - v = math::Vector3f(r1*costable[i], r1*sintable[i], costable[j+1]); + + v = math::Vector3f(r1 * costable[i], r1 * sintable[i], costable[j+1]); n = v; n.normalize(); - texx = 1-(float)i/(float)(SPHERESEGMENTS-1); - texy = -costable[j+1]/2 + 0.5f; + texx = 1 - (float)i / (float)(SPHERESEGMENTS - 1); + texy = -costable[j+1] / 2 + 0.5f; add_vertex(v, n, texx, texy); } - + } - + delete[] sintable; delete[] costable; } @@ -143,7 +143,7 @@ size_t VertexArray::add_vertex(math::Vector3f const &v, math::Vector3f const &n, } return 0; } - + for (int i = 0; i < 3; i ++) { vertex_vertex[vertex_index+i] = v[i]; vertex_normal[vertex_index+i] = n[i]; @@ -152,9 +152,9 @@ size_t VertexArray::add_vertex(math::Vector3f const &v, math::Vector3f const &n, vertex_texture[vertex_index] = tex_x; vertex_texture[vertex_index+1] = tex_y; vertex_texture[vertex_index+2] = 0; - + vertex_index += 3; - + return 1; } diff --git a/src/model/vertexarray.h b/src/model/vertexarray.h index 4277442..4377f67 100644 --- a/src/model/vertexarray.h +++ b/src/model/vertexarray.h @@ -24,61 +24,54 @@ public: /// create a new VertexArray with size in Mb VertexArray(size_t size); ~VertexArray(); - + void clear(); - - size_t add_vertex(math::Vector3f const &v, math::Vector3f const &n, float tex_x=0.0f, float tex_y=0.0f); - - inline float *vertex() - { + + size_t add_vertex(math::Vector3f const &v, math::Vector3f const &n, float tex_x = 0.0f, float tex_y = 0.0f); + + inline float *vertex() { return vertex_vertex; } - inline float *normal() - { + inline float *normal() { return vertex_normal; } - inline float *texture() - { + inline float *texture() { return vertex_texture; } - - inline bool overflow() const - { + + inline bool overflow() const { return vertex_overflow; } - + /// size of the vertex array in number of floats (for a single array) - inline size_t size() const - { + inline size_t size() const { return vertex_size; } - + /// number of allocated floats - inline size_t index() const - { + inline size_t index() const { return vertex_index; } - - static inline VertexArray *instance() - { + + static inline VertexArray *instance() { return vertex_instance; } - + private: /// model vertices float *vertex_vertex; float *vertex_normal; float *vertex_texture; - + size_t vertex_index; size_t vertex_size; - + void add_sphere(); - + static VertexArray *vertex_instance; - + bool vertex_overflow; }; |