This can be used for various forms of culling.
meshes[i].keep();
}
+void Object::update_bounding_sphere()
+{
+ vector<Vector3> points;
+ 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);
+ if(offset<0)
+ {
+ // TODO Handle two-dimensional meshes
+ bounding_sphere = Geometry::BoundingSphere<float, 3>();
+ return;
+ }
+
+ unsigned n_vertices = vertices.size();
+ points.reserve(points.size()+n_vertices);
+ 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]));
+ }
+ }
+
+ bounding_sphere = Geometry::BoundingSphere<float, 3>::from_point_cloud(points.begin(), points.end());
+}
+
const Mesh *Object::get_mesh(unsigned i) const
{
if(i>=meshes.size())
add("lod_mesh", &Loader::mesh_lod);
}
+void Object::Loader::finish()
+{
+ obj.update_bounding_sphere();
+}
+
void Object::Loader::mesh_inline()
{
RefPtr<Mesh> msh = new Mesh;
Loader(Object &, Collection &);
private:
void init();
+ virtual void finish();
- private:
void mesh_inline();
void mesh_inline_lod(unsigned);
void mesh(const std::string &);
private:
std::vector<RefPtr<const Mesh> > meshes;
RefPtr<const Technique> technique;
+ Geometry::BoundingSphere<float, 3> bounding_sphere;
public:
Object();
void set_mesh(const Mesh *m) { set_mesh(0, m); }
void set_mesh(unsigned, const Mesh *);
+private:
+ void update_bounding_sphere();
+public:
const Mesh *get_mesh(unsigned = 0) const;
void set_technique(const Technique *);
const Technique *get_technique() const { return technique.get(); }
+ virtual const Geometry::BoundingSphere<float, 3> *get_bounding_sphere() const { return &bounding_sphere; }
+
virtual void render(const Tag &tag = Tag()) const;
virtual void render(Renderer &, const Tag & = Tag()) const;
-#include "object.h"
#include "objectinstance.h"
#include "renderer.h"
#define MSP_GL_OBJETCINSTANCE_H_
#include <string>
+#include "object.h"
#include "renderable.h"
namespace Msp {
namespace GL {
-class Object;
class ProgramData;
/**
const Object &get_object() const { return object; }
virtual long get_instance_key() const { return reinterpret_cast<long>(&object); }
+ virtual const Geometry::BoundingSphere<float, 3> *get_bounding_sphere() const { return object.get_bounding_sphere(); }
+
virtual void render(const Tag &tag = Tag()) const;
virtual void render(Renderer &, const Tag & = Tag()) const;
#define MSP_GL_RENDERABLE_H_
#include <string>
+#include <msp/geometry/boundingsphere.h>
#include "tag.h"
namespace Msp {
matrix exists. */
virtual const Matrix *get_matrix() const { return 0; }
+ /** Returns a bounding sphere that completely encloses the Renderable. The
+ bounding sphere is expressed in the renderable's coordinates. Null is
+ returned if the bounding sphere cannot be determined. */
+ virtual const Geometry::BoundingSphere<float, 3> *get_bounding_sphere() const { return 0; }
+
/** Called when starting to render a new frame. */
virtual void setup_frame() const { }