diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/model/asefile.cc | 1 | ||||
-rw-r--r-- | src/model/fragment.cc | 1 | ||||
-rw-r--r-- | src/model/fragment.h | 19 | ||||
-rw-r--r-- | src/model/mapfile.cc | 52 | ||||
-rw-r--r-- | src/render/draw.cc | 40 |
5 files changed, 58 insertions, 55 deletions
diff --git a/src/model/asefile.cc b/src/model/asefile.cc index 74076c1..ad62029 100644 --- a/src/model/asefile.cc +++ b/src/model/asefile.cc @@ -677,7 +677,6 @@ Model *ASEFile::load(const std::string &name) model->set_radius(model->box().max().length()); model->set_origin(ase_center * -1.0f); - asefile.fragmentgroup()->set_transform(true); asefile.fragmentgroup()->set_location(ase_center * -1.0f); for (FragmentGroup::Fragments::const_iterator fit = asefile.fragmentgroup()->fragments().begin(); fit != asefile.fragmentgroup()->fragments().end(); fit++) { diff --git a/src/model/fragment.cc b/src/model/fragment.cc index 0e0fd00..54ffad9 100644 --- a/src/model/fragment.cc +++ b/src/model/fragment.cc @@ -63,7 +63,6 @@ FragmentGroup::FragmentGroup() { group_type = None; group_scale = 1.0f; - group_transform = false; group_speed = 0.0f; group_engine = false; diff --git a/src/model/fragment.h b/src/model/fragment.h index 58ff4bb..db5f569 100644 --- a/src/model/fragment.h +++ b/src/model/fragment.h @@ -98,6 +98,10 @@ public: return group_location; } + inline const math::Vector3f &movement() const { + return group_movement; + } + inline const math::Axis & axis() const { return group_axis; } @@ -114,10 +118,6 @@ public: return group_scale; } - inline const bool transform() const { - return group_transform; - } - inline const bool engine() const { return group_engine; } @@ -143,6 +143,11 @@ public: inline void set_location(const math::Vector3f &location) { group_location.assign(location); } + + inline void set_movement(const math::Vector3f &movement) { + group_movement.assign(movement); + } + /** * @brief rotation axis @@ -171,10 +176,6 @@ public: group_scale = scale; } - inline void set_transform(const bool transform) { - group_transform = transform; - } - inline void add_fragment(Fragment *fragment) { group_fragments.push_back(fragment); } @@ -191,8 +192,8 @@ private: float group_scale; float group_distance; - bool group_transform; bool group_engine; + math::Vector3f group_movement; }; } diff --git a/src/model/mapfile.cc b/src/model/mapfile.cc index 698a0f6..8f8e87c 100644 --- a/src/model/mapfile.cc +++ b/src/model/mapfile.cc @@ -1160,34 +1160,45 @@ void MapFile::load_fragmentgroup(Model *model, const FragmentGroup::Type class_t { if (!map_materials.size()) return; - - FragmentGroup *group = new FragmentGroup(); - - if (class_type == FragmentGroup::Rotate) { - if (class_speed == 0) { - // default rotation speed 45 degrees per second - class_speed = 45.0f; - } - group->set_speed(class_speed); - group->set_engine(class_engine); - } else if (class_type == FragmentGroup::Move) { - group->set_speed(class_speed); - group->set_distance(class_distance); - group->set_engine(class_engine); - } - // expand bounding box map_box.expand(class_box); // special groups like func_door and func_group are re-centered math::Vector3f translation((class_box.min() + class_box.max()) * 0.5f); - group->set_transform(true); + FragmentGroup *group = new FragmentGroup(); group->set_location(translation); group->set_type(class_type); - group->set_axis(class_axis); - group->set_speed(class_speed); + + // these fragmentgroups are on the same level as worldspawn (no submodels) + // their axis is always the default + + switch (class_type) { + case FragmentGroup::None: + break; + + case FragmentGroup::Rotate: + if (class_speed == 0) { + // default rotation speed 45 degrees per second + class_speed = 45.0f; + } + group->set_speed(class_speed); + group->set_engine(class_engine); + group->set_movement(class_axis.forward()); + break; + + case FragmentGroup::Move: + group->set_speed(class_speed); + group->set_distance(class_distance); + group->set_engine(class_engine); + group->set_movement(class_axis.forward()); + break; + + case FragmentGroup::Door: + group->set_speed(class_speed); + break; + } for (Materials::iterator mit = map_materials.begin(); mit != map_materials.end(); mit++) { // split the Primitives with this material into fragments @@ -1795,7 +1806,7 @@ Model * MapFile::load(std::string const &name) FragmentGroup *groupsrc = (*git); FragmentGroup *groupdst = new FragmentGroup(); - groupdst->set_transform(true); + groupdst->set_movement(groupsrc->movement()); groupdst->set_type(groupsrc->type()); groupdst->set_scale(groupsrc->scale() * tag_submodel->scale()); groupdst->set_engine(groupsrc->engine()); @@ -1881,7 +1892,6 @@ Model * MapFile::load(std::string const &name) // translate transformed vertex groups for (Model::Groups::iterator git = model->groups().begin(); git != model->groups().end(); git++) { FragmentGroup *fragmentgroup = (*git); - fragmentgroup->set_transform(true); fragmentgroup->set_location(fragmentgroup->location() - map_center); } diff --git a/src/render/draw.cc b/src/render/draw.cc index 48e53a2..ecabe21 100644 --- a/src/render/draw.cc +++ b/src/render/draw.cc @@ -662,30 +662,26 @@ void draw_model_fragments(model::Model *model, for (model::Model::Groups::const_iterator git = model->groups().begin(); git != model->groups().end(); git++) { const model::FragmentGroup *group = (*git); + gl::push(); - if (group->transform()) { - gl::push(); - - gl::translate(group->location()); - - if (group->type() == model::FragmentGroup::Rotate) { - const float rotation_angle = math::degrees360f((group->engine() ? enginetime : core::application()->time()) * group->speed()); - gl::rotate(-rotation_angle, group->axis().forward()); - - } else if (group->type() == model::FragmentGroup::Move ) { - const float speed = group->distance() / group->speed(); // units per second - math::Vector3f translation(group->axis().forward() * group->distance()); - translation *= sinf((group->engine() ? enginetime : core::application()->time()) * M_PI * speed) * 0.5f + 0.5f; - gl::translate(translation); - } else { - gl::multmatrix(group->axis()); - } + gl::translate(group->location()); + gl::multmatrix(group->axis()); + const float s = group->scale(); + if (s) + gl::scale(s, s, s); + + if (group->type() == model::FragmentGroup::Rotate) { + const float rotation_angle = math::degrees360f((group->engine() ? enginetime : core::game()->time()) * group->speed()); + gl::rotate(-rotation_angle, group->movement()); - const float s = group->scale(); - if (s) - gl::scale(s, s, s); + } else if (group->type() == model::FragmentGroup::Move ) { + const float speed = group->distance() / group->speed(); // units per second + math::Vector3f translation(group->movement() * group->distance()); + translation *= sinf((group->engine() ? enginetime : core::application()->time()) * M_PI * speed) * 0.5f + 0.5f; + gl::translate(translation); } + for (model::FragmentGroup::Fragments::const_iterator fit = group->fragments().begin(); fit != group->fragments().end(); fit++) { const model::Fragment *fragment = (*fit); @@ -861,9 +857,7 @@ void draw_model_fragments(model::Model *model, } } - if (group->transform()) { - gl::pop(); - } + gl::pop(); } if (!use_light) { |