diff options
author | Stijn Buys <ingar@osirion.org> | 2009-08-15 13:25:37 +0000 |
---|---|---|
committer | Stijn Buys <ingar@osirion.org> | 2009-08-15 13:25:37 +0000 |
commit | a3cfb9c4634e3ce7e052e72ce564d25e5367a430 (patch) | |
tree | d0efd558c108b674fbfd367bdc1f2fc68682c04a /src/model | |
parent | 4ca453e2272beed121b957244408a61b0b0d8b9b (diff) |
API cleanups, const optimizations, submodel lights/flares/particles import
Diffstat (limited to 'src/model')
-rw-r--r-- | src/model/mapfile.cc | 52 | ||||
-rw-r--r-- | src/model/parts.cc | 42 | ||||
-rw-r--r-- | src/model/parts.h | 64 |
3 files changed, 130 insertions, 28 deletions
diff --git a/src/model/mapfile.cc b/src/model/mapfile.cc index a86e06e..9c9048b 100644 --- a/src/model/mapfile.cc +++ b/src/model/mapfile.cc @@ -1211,7 +1211,7 @@ Model * MapFile::load(std::string const &name) // submodel attributes if (mapfile.got_key_vector3f("origin", location)) { - submodel->set_location(location * SCALE); + submodel->get_location().assign(location * SCALE); continue; } else if (mapfile.got_key_string("model", modelname)) { @@ -1226,11 +1226,11 @@ Model * MapFile::load(std::string const &name) } else if (mapfile.got_key_float("angle", angle)) { if (angle == ANGLEUP) { - submodel->axis().change_pitch(90.0f); + submodel->get_axis().change_pitch(90.0f); } else if (angle == ANGLEDOWN) { - submodel->axis().change_pitch(-90.0f); + submodel->get_axis().change_pitch(-90.0f); } else { - submodel->axis().change_direction(angle); + submodel->get_axis().change_direction(angle); } } else if (mapfile.got_key_float("modelscale", s)) { @@ -1316,7 +1316,6 @@ Model * MapFile::load(std::string const &name) (*dit)->get_location() -= mapfile.map_center; } - // FIXME this will go wrong if a Rotate group is imported as submodel for (SubModelList::iterator smit = submodel_list.begin(); smit != submodel_list.end(); smit++) { submodel = (*smit); Model *submodel_model = 0; @@ -1326,6 +1325,8 @@ Model * MapFile::load(std::string const &name) } if (submodel_model) { + submodel->get_location() -= mapfile.map_center; + // copy fragmentgroups for (Model::Groups::iterator git = submodel_model->groups().begin(); git != submodel_model->groups().end(); git++) { FragmentGroup *groupsrc = (*git); @@ -1335,7 +1336,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((submodel->location() - mapfile.map_center) + (submodel_model->origin() + groupsrc->location()) * submodel->scale() ); + groupdst->set_location(submodel->location() + (submodel_model->origin() + groupsrc->location()) * submodel->scale() ); groupdst->set_axis(groupsrc->axis() * submodel->axis()); // copy fragments @@ -1351,6 +1352,45 @@ Model * MapFile::load(std::string const &name) } } + // recalculate bbox + for (size_t i =0; i < 3; i ++) { + float c; + c = submodel->location()[i] + (submodel_model->origin()[i] + submodel_model->model_maxbbox[i]) * submodel->scale(); + if (c > model->model_maxbbox[i]) { + model->model_maxbbox[i] = c; + } + + c = submodel->location()[i] + (submodel_model->origin()[i] + submodel_model->model_minbbox[i]) * submodel->scale(); + if (c < model->model_minbbox[i]) { + model->model_minbbox[i] = c; + } + + } + model->set_radius(sqrtf(math::max(model->model_maxbbox.lengthsquared(), model->model_minbbox.lengthsquared()))); + + // copy lights, flares and particle systems + for (Model::Lights::const_iterator lit = submodel_model->lights().begin(); lit != submodel_model->lights().end(); lit++) { + light = new Light(*(*lit)); + light->get_location().assign(submodel->location() + (submodel_model->origin() + light->location()) * submodel->scale()); + light->set_radius(light->radius() * submodel->scale()); + model->add_light(light); + } + + for (Model::Flares::const_iterator flit = submodel_model->flares().begin(); flit != submodel_model->flares().end(); flit++) { + flare = new Flare(*(*flit)); + flare->get_location().assign(submodel->location() + (submodel_model->origin() + flare->location()) * submodel->scale()); + flare->set_radius(flare->radius() * submodel->scale()); + model->add_flare(flare); + } + + for (Model::ParticleSystems::const_iterator pit = submodel_model->particles().begin(); pit != submodel_model->particles().end(); pit++) { + particles = new Particles(*(*pit)); + particles->get_location().assign(submodel->location() + (submodel_model->origin() + particles->location()) * submodel->scale()); + particles->set_radius(particles->radius() * submodel->scale()); + model->add_particles(particles); + } + + con_debug << " imported submodel '" << submodel->name() << "'" << std::endl; } diff --git a/src/model/parts.cc b/src/model/parts.cc index eabc108..ac54410 100644 --- a/src/model/parts.cc +++ b/src/model/parts.cc @@ -28,6 +28,22 @@ Light::Light() : light_texture = 0; } +Light::Light(const Light& other) : Part(other), + light_color(other.color()) +{ + light_entity = other.entity(); + light_engine = other.engine(); + light_strobe = other.strobe(); + + light_radius = other.radius(); + light_frequency = other.frequency(); + light_offset = other.offset(); + light_time = other.time(); + + light_flare = other.flare(); + + light_texture = other.texture(); +} Light::~Light() {} @@ -38,13 +54,17 @@ Flare::Flare() : Light() flare_cull = CullBack; } +Flare::Flare(const Flare& other) : Light(other) +{ + flare_cull = other.cull(); +} + Flare::~Flare() {} /* ---- class Particles -------------------------------------------- */ -Particles::Particles() : - Part() +Particles::Particles() : Part() { particles_entity = false; particles_engine = false; @@ -52,7 +72,7 @@ Particles::Particles() : particles_cull = CullNone; } -Particles::Particles(math::Vector3f const & location) : +Particles::Particles(const math::Vector3f& location) : Part(location) { } @@ -63,22 +83,34 @@ Particles::~Particles() /* ---- class Dock ------------------------------------------------- */ -Dock::Dock() +Dock::Dock() : Part() { dock_radius = 0.01f; } +Dock::Dock(const Dock& other) : Part(other) +{ + dock_radius = other.radius(); +} + Dock::~Dock() { } /* ---- class SubModel---------------------------------------------- */ -SubModel::SubModel() +SubModel::SubModel() : Part() { submodel_scale = 1.0f; } +SubModel::SubModel(const SubModel& other) : Part(other), + submodel_name(other.name()), + submodel_axis(other.axis()) +{ + submodel_scale = other.scale(); +} + SubModel::~SubModel() { } diff --git a/src/model/parts.h b/src/model/parts.h index c3a0401..5c90efb 100644 --- a/src/model/parts.h +++ b/src/model/parts.h @@ -42,9 +42,17 @@ public: } /** + * @brief copy constructor + */ + inline Part(const Part& other) : part_location(other.location()) + { + } + + /** * @brief constructor with location + * @param location location of this part within the parent model */ - inline Part(const math::Vector3f &location) : part_location(location) + inline Part(const math::Vector3f& location) : part_location(location) { } @@ -53,7 +61,7 @@ public: /** * @brief location of this part within the parent model */ - inline const math::Vector3f &location() const + inline const math::Vector3f& location() const { return part_location; } @@ -62,7 +70,7 @@ public: /** * @brief set the location within the parent model */ - inline void set_location(const math::Vector3f location) { part_location.assign(location); } + inline void set_location(const math::Vector3f& location) { part_location.assign(location); } /** * @brief set the location within the parent model @@ -74,7 +82,7 @@ public: /** * @brief mutable reference to the location of this part within the parent model */ - inline math::Vector3f &get_location() + inline math::Vector3f& get_location() { return part_location; } @@ -95,6 +103,11 @@ public: Light(); /** + * @brief copy constructor + */ + Light(const Light& other); + + /** * @brief destructor */ ~Light(); @@ -102,7 +115,7 @@ public: /* ---- inspectors ----------------------------------------- */ /// light color - inline const math::Color & color() const + inline const math::Color& color() const { return light_color; }; @@ -237,6 +250,11 @@ class Flare : public Light public: Flare(); + /** + * @brief copy constructor + */ + Flare(const Flare& other); + ~Flare(); /* ---- inspectors ----------------------------------------- */ @@ -282,7 +300,7 @@ public: return particles_axis; } - inline const std::string & script() const + inline const std::string& script() const { return particles_script; } @@ -323,14 +341,14 @@ public: inline void set_cull(const Cull cull) { particles_cull = cull; } - inline void set_script(const std::string &script) { particles_script.assign(script); } + inline void set_script(const std::string& script) { particles_script.assign(script); } /* ---- actors --------------------------------------------- */ /** * @brief mutable reference to the axis */ - inline math::Axis &get_axis() { return particles_axis; } + inline math::Axis& get_axis() { return particles_axis; } private: bool particles_entity; @@ -351,6 +369,12 @@ class Dock : public Part { public: Dock(); + + /** + * @brief copy constructor + */ + Dock(const Dock& other); + ~Dock(); /// dock radius, default is 0.01f @@ -369,32 +393,38 @@ private: /* ---- class SubModel --------------------------------------------- */ /// a submodel -class SubModel +class SubModel : public Part { public: SubModel(); + + SubModel(const SubModel& other); + ~SubModel(); - inline const std::string &name() const { return submodel_name; } + inline const std::string& name() const { return submodel_name; } inline const float scale() const { return submodel_scale; } - inline const math::Vector3f &location() const { return submodel_location; } + inline const math::Axis& axis() const { return submodel_axis; } - inline math::Axis &axis() { return submodel_axis; } inline void set_scale(const float scale) { submodel_scale = scale; } - inline void set_name(const std::string &name) { submodel_name.assign(name); } + inline void set_name(const std::string& name) { submodel_name.assign(name); } + + inline void set_axis(const math::Axis& axis) { submodel_axis.assign(axis); } - inline void set_location(const math::Vector3f &location) { submodel_location.assign(location); } + /* ---- actors --------------------------------------------- */ - inline void set_axis(const math::Axis &axis) { submodel_axis.assign(axis); } + /** + * @brief mutable reference to the axis + */ + inline math::Axis& get_axis() { return submodel_axis; } private: - std::string submodel_name; float submodel_scale; - math::Vector3f submodel_location; + std::string submodel_name; math::Axis submodel_axis; }; |