From f030154fe727e25a2afe1f78b3998c2d2dba95e4 Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Tue, 18 Aug 2009 09:24:15 +0000 Subject: astyle cleanup, corrects not loading of material textures --- src/model/mapfile.cc | 438 +++++++++++++++++++++++++-------------------------- 1 file changed, 219 insertions(+), 219 deletions(-) (limited to 'src/model/mapfile.cc') 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::iterator face = planes.begin(); face != planes.end(); face++) { make_brushface((*face)); } - + // clean planes for (std::vector::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 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::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::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::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::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::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::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::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::reverse_iterator vn = vl.rbegin(); std::vector::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::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; -- cgit v1.2.3