From b7dc0938eb7d59f928bbcf2a3a4877a6f60940e5 Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Mon, 8 Nov 2010 14:34:44 +0000 Subject: moved clear() from game::Game~ to core::GameServer~ (solves FIXME), unified bounding box code into math::BoundingBox3f class --- src/model/mapfile.cc | 83 ++++++++++++++++------------------------------------ 1 file changed, 25 insertions(+), 58 deletions(-) (limited to 'src/model/mapfile.cc') diff --git a/src/model/mapfile.cc b/src/model/mapfile.cc index 9fbcbc5..2eac688 100644 --- a/src/model/mapfile.cc +++ b/src/model/mapfile.cc @@ -152,14 +152,10 @@ MapFile::MapFile() warning_q2brush = false; class_engine = false; class_speed = 0; - - for (size_t i = 0; i < 3; i++) { - class_minbbox[i] = MAX_BOUNDS; - class_maxbbox[i] = -MAX_BOUNDS; - - map_minbbox[i] = MAX_BOUNDS; - map_maxbbox[i] = -MAX_BOUNDS; - } + + // the initial bounding box value is invalid: max and min are switched + class_box.assign(MAX_BOUNDS, -MAX_BOUNDS); + map_box.assign(MAX_BOUNDS, -MAX_BOUNDS); } MapFile::~MapFile() @@ -452,8 +448,6 @@ void MapFile::make_brushface(Face *face) // 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()))) { @@ -639,24 +633,13 @@ void MapFile::make_brushface(Face *face) // 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++) { - 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; - } + class_box.expand(*(*it) * SCALE); } // the actual polygon normal is on the other side Vector3f face_normal(face->normal()* -1); face_normal.normalize(); -//#ifndef HAVE_BULLET - - // Quads are disable to use model data for bullet physics - // split polygon into quads while (vl.size() > 3) { std::vector::iterator v0 = vl.begin(); @@ -682,7 +665,7 @@ void MapFile::make_brushface(Face *face) vl.pop_back(); vl.pop_back(); } -//#endif + // split polygon into triangles while (vl.size() > 2) { std::vector::iterator v0 = vl.begin(); @@ -813,11 +796,7 @@ void MapFile::close() void MapFile::clear_bbox() { - for (int i = 0; i < 3; i++) { - class_minbbox[i] = MAX_BOUNDS; - class_maxbbox[i] = -MAX_BOUNDS; - } - + class_box.assign(MAX_BOUNDS, -MAX_BOUNDS); class_axis.clear(); class_speed = 0; class_engine = false; @@ -838,20 +817,14 @@ void MapFile::load_fragmentgroup(Model *model, const FragmentGroup::Type class_t // default rotation speed 45 degrees per second class_speed = 45.0f; } -// group->set_engine(class_engine); + //group->set_engine(class_engine); } - // calculate map bbox - for (size_t i = 0; i < 3 ; i++) { - if (class_minbbox[i] < map_minbbox[i]) - map_minbbox[i] = class_minbbox[i]; - - if (class_maxbbox[i] > map_maxbbox[i]) - map_maxbbox[i] = class_maxbbox[i]; - } + // expand bounding box + map_box.expand(class_box); // special groups like func_door and func_group are re-centered - math::Vector3f translation((class_minbbox + class_maxbbox) * 0.5f); + math::Vector3f translation((class_box.min() + class_box.max()) * 0.5f); group->set_transform(true); group->set_location(translation); @@ -1459,21 +1432,12 @@ Model * MapFile::load(std::string const &name) } } - // recalculate bbox - for (size_t i = 0; i < 3; i ++) { - float c; - c = tag_submodel->location()[i] + submodel_model->model_maxbbox[i] * tag_submodel->scale(); - if (c > mapfile.map_maxbbox[i]) { - mapfile.map_maxbbox[i] = c; - } - - c = tag_submodel->location()[i] + submodel_model->model_minbbox[i] * tag_submodel->scale(); - if (c < mapfile.map_minbbox[i]) { - mapfile.map_minbbox[i] = c; - } - - } - + // add the scaled submodel bounding box to the map bounding box + mapfile.map_box.expand( + tag_submodel->location() + submodel_model->model_box.min() * tag_submodel->scale(), + tag_submodel->location() + submodel_model->model_box.max() * tag_submodel->scale() + ); + // copy light tags for (Model::Lights::const_iterator lit = submodel_model->lights().begin(); lit != submodel_model->lights().end(); lit++) { tag_light = new Light(*(*lit)); @@ -1514,11 +1478,14 @@ Model * MapFile::load(std::string const &name) delete tag_submodel; } - // center model around (0,0,0) - math::Vector3f map_center = (mapfile.map_minbbox + mapfile.map_maxbbox) * 0.5f; - model->model_minbbox.assign(mapfile.map_minbbox - map_center); - model->model_maxbbox.assign(mapfile.map_maxbbox - map_center); - model->set_radius(model->model_maxbbox.length()); + // center model around (0,0,0) and set the bounding box + math::Vector3f map_center = (mapfile.box().min() + mapfile.box().max()) * 0.5f; + model->model_box.assign( + mapfile.box().min() - map_center, + mapfile.box().max() - map_center + ); + + model->set_radius(model->box().max().length()); model->set_origin(map_center); // translate transformed vertex groups -- cgit v1.2.3