]> git.tdb.fi Git - libs/gl.git/commitdiff
Improve bounding sphere handling in Object
authorMikko Rasa <tdb@tdb.fi>
Wed, 24 Sep 2014 17:36:33 +0000 (20:36 +0300)
committerMikko Rasa <tdb@tdb.fi>
Fri, 26 Sep 2014 10:24:20 +0000 (13:24 +0300)
source/object.cpp

index efd84db89168b85598b278f79147b70214eee493..9aba5466e3e1cf548674b61f2a4b70f156eb8a93 100644 (file)
@@ -53,6 +53,8 @@ void Object::set_mesh(unsigned i, const Mesh *m)
        if(i==0 && m)
                if(ResourceManager *rm = m->get_manager())
                        rm->watch_resource(*m, *this);
+
+       update_bounding_sphere();
 }
 
 void Object::update_bounding_sphere()
@@ -61,12 +63,15 @@ void Object::update_bounding_sphere()
        for(vector<RefPtr<const Mesh> >::const_iterator i=meshes.begin(); i!=meshes.end(); ++i)
        {
                const VertexArray &vertices = (*i)->get_vertices();
+
                int offset = vertices.get_format().offset(VERTEX3);
+               bool three = true;
                if(offset<0)
                {
-                       // TODO Handle two-dimensional meshes
-                       bounding_sphere = Geometry::BoundingSphere<float, 3>();
-                       return;
+                       offset = vertices.get_format().offset(VERTEX2);
+                       three = false;
+                       if(offset<0)
+                               continue;
                }
 
                unsigned n_vertices = vertices.size();
@@ -74,7 +79,7 @@ void Object::update_bounding_sphere()
                for(unsigned j=0; j<n_vertices; ++j)
                {
                        const float *v = vertices[j];
-                       points.push_back(Vector3(v[offset], v[offset+1], v[offset+2]));
+                       points.push_back(Vector3(v[offset], v[offset+1], (three ? v[offset+2] : 0.0f)));
                }
        }