Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
path: root/src/model
diff options
context:
space:
mode:
Diffstat (limited to 'src/model')
-rw-r--r--src/model/asefile.cc34
-rw-r--r--src/model/asefile.h8
-rw-r--r--src/model/mapfile.cc83
-rw-r--r--src/model/mapfile.h10
-rw-r--r--src/model/model.h13
5 files changed, 50 insertions, 98 deletions
diff --git a/src/model/asefile.cc b/src/model/asefile.cc
index c9dfe1c..64b38d3 100644
--- a/src/model/asefile.cc
+++ b/src/model/asefile.cc
@@ -22,10 +22,7 @@ ASEFile::ASEFile(std::string const &name)
asefile_name.append(".ase");
asefile_ifs.open(asefile_name);
- for (int i = 0; i < 3; i++) {
- ase_minbbox[i] = 0;
- ase_maxbbox[i] = 0;
- }
+ ase_box.assign(MAX_BOUNDS, - MAX_BOUNDS);
// a single fragmentgroup wil contain all the model triangles
ase_fragmentgroup = new FragmentGroup();
@@ -263,15 +260,7 @@ bool ASEFile::read_mesh_vertex_list(std::istream &is)
if (line >> index >> x >> y >> z) {
math::Vector3f *v = new math::Vector3f(x, y, z);
ase_vertexlist[index] = v;
-
- for (size_t i = 0; i < 3; i++) {
- if ((*v)[i] > ase_maxbbox[i]) {
- ase_maxbbox[i] = (*v)[i];
- }
- if ((*v)[i] < ase_minbbox[i]) {
- ase_minbbox[i] = (*v)[i];
- }
- }
+ ase_box.expand(*v * SCALE);
ase_vertexcount++;
}
}
@@ -679,19 +668,18 @@ Model *ASEFile::load(const std::string &name)
// create a new model
Model *model = new Model(name);
- // set bounding box properties
- asefile.ase_minbbox *= SCALE;
- asefile.ase_maxbbox *= SCALE;
-
- math::Vector3f ase_center((asefile.ase_maxbbox + asefile.ase_minbbox) * 0.5f);
+ // center model around (0,0,0) and set the bounding box
+ math::Vector3f ase_center((asefile.box().min() + asefile.box().max()) * 0.5f);
+ model->model_box.assign(
+ asefile.box().min() - ase_center,
+ asefile.box().max() - ase_center
+ );
+ model->set_radius(model->box().max().length());
+ model->set_origin(ase_center);
+
asefile.fragmentgroup()->set_transform(true);
asefile.fragmentgroup()->set_location(ase_center * -1.0f);
- model->model_minbbox.assign(asefile.ase_minbbox - ase_center);
- model->model_maxbbox.assign(asefile.ase_maxbbox - ase_center);
- model->set_radius(asefile.ase_maxbbox.length());
- model->set_origin(ase_center);
-
for (FragmentGroup::Fragments::const_iterator fit = asefile.fragmentgroup()->fragments().begin(); fit != asefile.fragmentgroup()->fragments().end(); fit++) {
const Fragment *fragment = (*fit);
model->model_tris_count += (fragment->structural_size() + fragment->detail_size()) / 3;
diff --git a/src/model/asefile.h b/src/model/asefile.h
index 9e3fea6..c16bf5c 100644
--- a/src/model/asefile.h
+++ b/src/model/asefile.h
@@ -141,6 +141,10 @@ private:
inline FragmentGroup *fragmentgroup() {
return ase_fragmentgroup;
}
+
+ inline const math::BoundingBox3f & box() const {
+ return ase_box;
+ }
std::string asefile_name;
@@ -154,9 +158,7 @@ private:
MaterialList ase_materials;
- math::Vector3f ase_maxbbox;
-
- math::Vector3f ase_minbbox;
+ math::BoundingBox3f ase_box;
FragmentGroup *ase_fragmentgroup;
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<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()))) {
@@ -639,24 +633,13 @@ void MapFile::make_brushface(Face *face)
// 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++) {
- 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<Vector3f *>::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<Vector3f *>::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
diff --git a/src/model/mapfile.h b/src/model/mapfile.h
index fbb594c..4cea7f0 100644
--- a/src/model/mapfile.h
+++ b/src/model/mapfile.h
@@ -121,6 +121,10 @@ private:
inline std::string const & name() const {
return mapfile_name;
}
+
+ inline const math::BoundingBox3f & box() const {
+ return map_box;
+ }
/// close the file
void close();
@@ -164,11 +168,9 @@ private:
filesystem::IFileStream mapfile_ifs;
std::string mapfile_name;
- math::Vector3f map_minbbox;
- math::Vector3f map_maxbbox;
+ math::BoundingBox3f map_box;
- math::Vector3f class_minbbox;
- math::Vector3f class_maxbbox;
+ math::BoundingBox3f class_box;
math::Axis class_axis;
float class_speed;
bool class_engine;
diff --git a/src/model/model.h b/src/model/model.h
index 287b0cf..9495285 100644
--- a/src/model/model.h
+++ b/src/model/model.h
@@ -101,14 +101,8 @@ public:
return model_particles;
}
- /// maximum values of the bounding box
- inline const math::Vector3f & maxbbox() const {
- return model_maxbbox;
- }
-
- /// minimum values of the bounding box
- inline const math::Vector3f & minbbox() const {
- return model_minbbox;
+ inline const math::BoundingBox3f & box() const {
+ return model_box;
}
/// engine sound loop for this model
@@ -156,8 +150,7 @@ public:
void set_origin(const math::Vector3f &origin);
math::Vector3f model_origin;
- math::Vector3f model_maxbbox;
- math::Vector3f model_minbbox;
+ math::BoundingBox3f model_box;
unsigned int model_enginesound;
unsigned int model_impulsesound;