Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStijn Buys <ingar@osirion.org>2011-11-20 16:37:19 +0000
committerStijn Buys <ingar@osirion.org>2011-11-20 16:37:19 +0000
commite9cc1520bfbc28c1c62a14d1f0e625ca8549d9d4 (patch)
tree6e29ecf9fee2fffb256f7bf9a3a08ac5e3007e17
parent01b98a40b9c6d8ace96538342ccdd6ac46fbbbe7 (diff)
Added origin brush support for func_rotate.
-rw-r--r--src/model/mapfile.cc106
-rw-r--r--src/model/material.cc5
2 files changed, 69 insertions, 42 deletions
diff --git a/src/model/mapfile.cc b/src/model/mapfile.cc
index 2cbee2b..7020d47 100644
--- a/src/model/mapfile.cc
+++ b/src/model/mapfile.cc
@@ -948,64 +948,74 @@ void MapFile::make_brushface(Face *face)
primitives = (*mit).second;
}
- // add vertices to the bounding box
- for (std::vector<Vector3f *>::iterator it = vl.begin(); it != vl.end(); it++) {
- class_box.expand(*(*it) * SCALE);
- }
+ if ((face->material()->flags() & Material::Origin)) {
+ // add vertices to the origin list
+ for (std::vector<Vector3f *>::iterator it = vl.begin(); it != vl.end(); it++) {
+ class_origin_vertices.push_back(new math::Vector3f((*(*it) * SCALE)));
+ }
+
+ } else {
+
+ // add vertices to the bounding box
+ for (std::vector<Vector3f *>::iterator it = vl.begin(); it != vl.end(); it++) {
+ class_box.expand(*(*it) * SCALE);
+ }
- // the actual polygon normal is on the other side
- Vector3f face_normal(face->normal()* -1);
- face_normal.normalize();
+ // the actual polygon normal is on the other side
+ Vector3f face_normal(face->normal()* -1);
+ face_normal.normalize();
- // clip faces have to be triangulated and can not be split into quads
- if (!(face->material()->flags() & Material::Clip)) {
+ // clip faces have to be triangulated and can not be split into quads
+ if (!(face->material()->flags() & Material::Clip)) {
+
+ // split polygon into quads
+ while (vl.size() > 3) {
+ std::vector<Vector3f *>::iterator v0 = vl.begin();
+ std::vector<Vector3f *>::reverse_iterator vn = vl.rbegin();
+ std::vector<Vector3f *>::reverse_iterator vn1 = vl.rbegin();
+ ++vn1;
+ 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);
+
+ if (face->material()->flags() & Material::Texture) {
+ quad->t0().assign(map_texture_coords(face, *(*vn2)));
+ quad->t1().assign(map_texture_coords(face, *(*vn1)));
+ quad->t2().assign(map_texture_coords(face, *(*vn)));
+ quad->t3().assign(map_texture_coords(face, *(*v0)));
+ }
+
+ delete(*vn);
+ delete(*vn1);
+ vl.pop_back();
+ vl.pop_back();
+ }
+ }
- // split polygon into quads
- while (vl.size() > 3) {
+ // split polygon into triangles
+ while (vl.size() > 2) {
std::vector<Vector3f *>::iterator v0 = vl.begin();
std::vector<Vector3f *>::reverse_iterator vn = vl.rbegin();
std::vector<Vector3f *>::reverse_iterator vn1 = vl.rbegin();
++vn1;
- 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);
+ Triangle * triangle = new Triangle(*(*vn1) * SCALE, *(*vn) * SCALE, *(*v0) * SCALE, face_normal, face->detail());
+ primitives->add_triangle(triangle);
if (face->material()->flags() & Material::Texture) {
- quad->t0().assign(map_texture_coords(face, *(*vn2)));
- quad->t1().assign(map_texture_coords(face, *(*vn1)));
- quad->t2().assign(map_texture_coords(face, *(*vn)));
- quad->t3().assign(map_texture_coords(face, *(*v0)));
+ triangle->t0().assign(map_texture_coords(face, *(*vn1)));
+ triangle->t1().assign(map_texture_coords(face, *(*vn)));
+ triangle->t2().assign(map_texture_coords(face, *(*v0)));
}
-
+
delete(*vn);
- delete(*vn1);
- vl.pop_back();
vl.pop_back();
}
}
- // split polygon into triangles
- while (vl.size() > 2) {
- std::vector<Vector3f *>::iterator v0 = vl.begin();
- 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());
- primitives->add_triangle(triangle);
-
- if (face->material()->flags() & Material::Texture) {
- triangle->t0().assign(map_texture_coords(face, *(*vn1)));
- triangle->t1().assign(map_texture_coords(face, *(*vn)));
- triangle->t2().assign(map_texture_coords(face, *(*v0)));
- }
-
- delete(*vn);
- vl.pop_back();
- }
} else {
con_warn << name() << " unresolved brush face at line " << line() << std::endl;
}
@@ -1196,6 +1206,18 @@ void MapFile::load_fragmentgroup(Model *model, const FragmentGroup::Type class_t
group->set_speed(class_speed);
group->set_engine(class_engine);
group->set_movement(class_axis.forward());
+
+ // origin bruhes override group center
+ if (class_origin_vertices.size()) {
+ math::Vector3f v;
+ for (std::vector<math::Vector3f *>::iterator i = class_origin_vertices.begin(); i != class_origin_vertices.end(); i++) {
+ v += *(*i);
+ }
+
+ v /= (float) class_origin_vertices.size();
+ translation.assign(v);
+ group->set_location(translation);
+ }
break;
case FragmentGroup::Move:
diff --git a/src/model/material.cc b/src/model/material.cc
index 2f32f6c..56bb3fc 100644
--- a/src/model/material.cc
+++ b/src/model/material.cc
@@ -68,6 +68,9 @@ void Material::print()
}
if (flags() & Clip) {
con_print << "clip ";
+ }
+ if (flags() & Origin) {
+ con_print << "origin ";
}
}
con_print << std::endl;
@@ -238,6 +241,8 @@ void Material::load_shader(const std::string &shadername)
material->set_flags(Ignore);
} else if (firstword.compare("clip") == 0) {
material->set_flags(Clip);
+ } else if (firstword.compare("origin") == 0) {
+ material->set_flags(Origin);
} else if (firstword.compare("qer_editorimage") == 0) {
// keyword qer_editorimage is ignored
continue;