diff options
author | Stijn Buys <ingar@osirion.org> | 2009-08-12 20:22:20 +0000 |
---|---|---|
committer | Stijn Buys <ingar@osirion.org> | 2009-08-12 20:22:20 +0000 |
commit | ea18c25aef4aa0104852f314dd76e4ce446673f3 (patch) | |
tree | 928d7ecef63acda7b32d5243ef5cf14760e555c9 /src/model/mapfile.cc | |
parent | 83b66522dfcad1b2428ce4fd81d83e39a051a4c5 (diff) |
triangle/quad code cleanup,corrects submodel origin, enable quad rendering again
Diffstat (limited to 'src/model/mapfile.cc')
-rw-r--r-- | src/model/mapfile.cc | 58 |
1 files changed, 29 insertions, 29 deletions
diff --git a/src/model/mapfile.cc b/src/model/mapfile.cc index 681a3be..385f986 100644 --- a/src/model/mapfile.cc +++ b/src/model/mapfile.cc @@ -582,7 +582,10 @@ void MapFile::make_brushface(Face *face) } } -/* + // 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 @@ -597,17 +600,22 @@ void MapFile::make_brushface(Face *face) ++vn2; ++vn2; - Vector3f n(face->normal()*-1); - n.normalize(); - - primitives->add_quad(*(*vn2), *(*vn1), *(*vn), *(*v0), n, face->detail()); + 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(); } #endif -*/ // split polygon into triangles while (vl.size() > 2) { std::vector<Vector3f *>::iterator v0 = vl.begin(); @@ -615,21 +623,14 @@ void MapFile::make_brushface(Face *face) std::vector<Vector3f *>::reverse_iterator vn1 = vl.rbegin(); ++vn1; - Vector3f n(face->normal()*-1); - n.normalize(); - - Triangle *triangle = primitives->add_triangle(*(*vn1) * SCALE, *(*vn) * SCALE, *(*v0) * SCALE, n, 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) { triangle->t0().assign(map_texture_coords(face, *(*vn1))); triangle->t1().assign(map_texture_coords(face, *(*vn))); triangle->t2().assign(map_texture_coords(face, *(*v0))); } - /* - triangle->t0().assign(0, 0); - triangle->t1().assign(0, 1); - triangle->t2().assign(1, 1); - */ delete(*vn); vl.pop_back(); } @@ -760,13 +761,12 @@ void MapFile::load_worldspawn(Model *model) return; // FIXME center in maps without brushes - map_center = (class_minbbox + class_maxbbox) / 2.0f; - + map_center = (class_minbbox + class_maxbbox) * 0.5f; + model->model_minbbox = class_minbbox - map_center; model->model_maxbbox = class_maxbbox - map_center; - - model->model_radius = model->model_maxbbox.length(); - + model->set_radius(model->model_maxbbox.length()); + model->set_origin(map_center); load_fragmentgroup(model, FragmentGroup::None); } @@ -850,10 +850,10 @@ void MapFile::load_fragmentgroup(Model *model, const FragmentGroup::Type class_t Quad *quad = (*quad_it); if (!quad->detail()) { size_t count = 0; - count += fragment->add_vertex(quad->v0()-group_center, quad->normal(), false); - count += fragment->add_vertex(quad->v1()-group_center, quad->normal(), false); - count += fragment->add_vertex(quad->v2()-group_center, quad->normal(), false); - count += fragment->add_vertex(quad->v3()-group_center, quad->normal(), 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++; } @@ -864,10 +864,10 @@ void MapFile::load_fragmentgroup(Model *model, const FragmentGroup::Type class_t Quad *quad = (*quad_it); if (quad->detail()) { size_t count = 0; - count += fragment->add_vertex(quad->v0()-group_center, quad->normal(), false); - count += fragment->add_vertex(quad->v1()-group_center, quad->normal(), false); - count += fragment->add_vertex(quad->v2()-group_center, quad->normal(), false); - count += fragment->add_vertex(quad->v3()-group_center, quad->normal(), 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++; @@ -1302,7 +1302,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(groupsrc->location() + submodel->location() - mapfile.map_center); + groupdst->set_location((submodel->location() - mapfile.map_center) + (submodel_model->origin() + groupsrc->location()) * submodel->scale() ); groupdst->set_axis(groupsrc->axis() * submodel->axis()); // copy fragments |