From f36ec64b08c791e7b907ed8efd9a2baa44e7f8fd Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Sat, 20 Dec 2008 14:54:17 +0000 Subject: initial support for func_rotate and friends --- src/model/map.cc | 65 +++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 46 insertions(+), 19 deletions(-) (limited to 'src/model/map.cc') diff --git a/src/model/map.cc b/src/model/map.cc index f2c519f..71b0dda 100644 --- a/src/model/map.cc +++ b/src/model/map.cc @@ -242,6 +242,14 @@ bool Map::getline() return true; } +void Map::clear_bbox() +{ + for (int i=0; i < 3; i++) { + class_minbbox[i] = MAX_BOUNDS; + class_maxbbox[i] = -MAX_BOUNDS; + } +} + void Map::make_brushface(Plane *face) { using math::Vector3f; @@ -445,7 +453,7 @@ void Map::make_brushface(Plane *face) // default material is none unsigned int material = 0; - // default color makrs unknown textures hot pink + // default color makes unknown textures hot pink math::Color color(1.0f, 0.0, 1.0f, 1.0f); // translate texture names to color and material @@ -516,9 +524,7 @@ void Map::make_brushface(Plane *face) // calculate 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]) class_maxbbox[i] = (*(*it))[i]; @@ -528,6 +534,7 @@ void Map::make_brushface(Plane *face) } } + // split polygon into quads while (vl.size() > 3) { std::vector::iterator v0 = vl.begin(); std::vector::reverse_iterator vn = vl.rbegin(); @@ -677,24 +684,28 @@ void Map::load_worldspawn(Model *model) return; // FIXME center in maps without brushes - map_center = (class_minbbox + class_maxbbox) / 2; + map_center = (class_minbbox + class_maxbbox) / 2.0f; model->model_minbbox = class_minbbox - map_center; model->model_maxbbox = class_maxbbox - map_center; model->model_radius = model->model_maxbbox.length(); - load_fragmentgroup(model, model->worldspawn()); + load_fragmentgroup(model, FragmentGroup::None); } -void Map::load_fragmentgroup(Model *model, FragmentGroup &group) +void Map::load_fragmentgroup(Model *model, const FragmentGroup::Type type) { if (!VertexArray::instance() || VertexArray::instance()->overflow()) return; if (!map_materials.size()) return; - + + FragmentGroup *group = new FragmentGroup(); + group->set_type(type); + group->set_location((class_minbbox + class_maxbbox) / 2.0f - map_center); + for (Materials::iterator mit = map_materials.begin(); mit != map_materials.end(); mit++) { // split the Primitives with this material into fragments Primitives *primitives = (*mit).second; @@ -731,8 +742,8 @@ void Map::load_fragmentgroup(Model *model, FragmentGroup &group) } } - // add the fragment to the fragment group - group.push_back(fragment); + // add the fragment to the group + group->push_back(fragment); } // store quads @@ -769,12 +780,14 @@ void Map::load_fragmentgroup(Model *model, FragmentGroup &group) } } - // add the fragment to the model - group.push_back(fragment); + // add the fragment to the group + group->push_back(fragment); } } - + + // add the group to the model + model->add_group(group); } Model * Map::load(std::string const &name) @@ -787,6 +800,7 @@ Model * Map::load(std::string const &name) } Model *model = new Model(name); + mapfile.clear_bbox(); Dock *dock = 0; Particles *particles = 0; @@ -799,13 +813,12 @@ Model * Map::load(std::string const &name) while (mapfile.getline()) { if (mapfile.got_classname("worldspawn")) { - // new wordspawn - - } else if (mapfile.got_classend("worldspawn")) { + mapfile.clear_bbox(); + } else if (mapfile.got_classend("worldspawn")) { mapfile.load_worldspawn(model); mapfile.clear_materials(); - + } else if (mapfile.classname().compare("worldspawn") == 0) { // worldspawn attributes @@ -827,14 +840,28 @@ Model * Map::load(std::string const &name) con_warn "Unknown key " << mapfile.classname() << ":" << mapfile.key() << std::endl; } + } else if (mapfile.got_classname("func_door")) { + mapfile.clear_bbox(); + + } else if (mapfile.got_classend("func_door")) { + mapfile.load_fragmentgroup(model, FragmentGroup::Door); + mapfile.clear_materials(); + + } else if (mapfile.got_classname("func_group")) { + mapfile.clear_bbox(); } else if (mapfile.got_classend("func_group")) { + mapfile.load_fragmentgroup(model, FragmentGroup::None); + mapfile.clear_materials(); - // func_group fragments are loaded into worldspawn - mapfile.load_fragmentgroup(model, model->worldspawn()); + } else if (mapfile.got_classname("func_rotate")) { + mapfile.clear_bbox(); - } else if (mapfile.got_classend()) { + } else if (mapfile.got_classend("func_rotate")) { + mapfile.load_fragmentgroup(model, FragmentGroup::Rotate); + mapfile.clear_materials(); + } else if (mapfile.got_classend()) { mapfile.clear_materials(); } else if (mapfile.got_classname("light")) { -- cgit v1.2.3