X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=blobdiff_plain;f=source%2Frender%2Fobject.cpp;h=65e9a7ef083fc52db1f899906b7febaed96264a5;hp=b63434742b7ef8a7305a2bbcaed7e3e85a9ba98b;hb=5871764de7aa23d2c40cac03ad9d07088fb57e06;hpb=c0b7d6ee4a7478f5aecb1504429ec1fc846d64ed diff --git a/source/render/object.cpp b/source/render/object.cpp index b6343474..65e9a7ef 100644 --- a/source/render/object.cpp +++ b/source/render/object.cpp @@ -17,19 +17,31 @@ namespace GL { const Matrix Object::identity_matrix; Object::Object(): - lods(1), - lod0_watched(false) + lods(1) { } Object::Object(const Mesh *m, const Technique *t): - lods(1), - lod0_watched(false) + Object() { set_mesh(m); set_technique(t); } -// TODO should have copy-c'tor to set watch on lod0 mesh if necessary +Object::Object(const Object &other): + lods(other.lods), + bounding_sphere(other.bounding_sphere) +{ + if(other.lod0_watched) + watch_lod0(); +} + +Object::Object(Object &&other): + lods(move(other.lods)), + bounding_sphere(move(other.bounding_sphere)) +{ + if(other.lod0_watched) + watch_lod0(); +} Object::~Object() { @@ -61,15 +73,20 @@ void Object::set_mesh(unsigned i, const Mesh *m) lod0_watched = false; if(i==0 && m) - if(ResourceManager *rm = m->get_manager()) - { - rm->observe_resource(*m, *this); - lod0_watched = true; - } + watch_lod0(); update_bounding_sphere(); } +void Object::watch_lod0() +{ + if(ResourceManager *rm = lods[0].mesh->get_manager()) + { + rm->observe_resource(*lods[0].mesh, *this); + lod0_watched = true; + } +} + void Object::update_bounding_sphere() { vector points; @@ -95,7 +112,7 @@ void Object::update_bounding_sphere() for(unsigned j=0; j(vertices[j]+offset); - points.push_back(Vector3(v[0], v[1], (three ? v[2] : 0.0f))); + points.emplace_back(v[0], v[1], (three ? v[2] : 0.0f)); } } @@ -188,7 +205,7 @@ void Object::resource_removed(Resource &res) } -Object::Loader::Loader(Object &o, Collection *c): +Object::Loader::Loader(Object &o, Collection &c): LodLoader(o, 0, c) { add("bounding_sphere_hint", &Loader::bounding_sphere_hint); @@ -207,13 +224,13 @@ void Object::Loader::bounding_sphere_hint(float x, float y, float z, float r) void Object::Loader::level_of_detail(unsigned i) { - LodLoader ldr(obj, i, coll); + LodLoader ldr(obj, i, get_collection()); load_sub_with(ldr); } -Object::LodLoader::LodLoader(Object &o, unsigned i, Collection *c): - DataFile::CollectionObjectLoader(o, c), +Object::LodLoader::LodLoader(Object &o, unsigned i, Collection &c): + DataFile::CollectionObjectLoader(o, &c), index(i), lod(obj.get_lod(index, "Object::LodLoader::LodLoader")) {