1 #include <msp/datafile/collection.h>
2 #include "animatedobject.h"
14 for(vector<Renderable *>::iterator i=owned_data.begin(); i!=owned_data.end(); ++i)
18 bool Scene::setup_frustum(const Renderer &renderer) const
20 const Camera *camera = renderer.get_camera();
24 culling_matrix = renderer.get_matrix();
26 if(camera->is_orthographic())
28 float h = camera->get_orthographic_height();
29 frustum_edges[0] = Vector4(0, 1, 0, -h);
30 frustum_edges[1] = Vector4(0, -1, 0, -h);
32 float w = camera->get_orthographic_width();
33 frustum_edges[2] = Vector4(1, 0, 0, -w);
34 frustum_edges[3] = Vector4(-1, 0, 0, -w);
38 float y = tan(camera->get_field_of_view()/2.0f);
39 float s = sqrt(y*y+1);
40 frustum_edges[0] = Vector4(0, 1/s, y/s, 0);
41 frustum_edges[1] = Vector4(0, -1/s, y/s, 0);
43 float x = y*camera->get_aspect_ratio();
45 frustum_edges[2] = Vector4(1/s, 0, x/s, 0);
46 frustum_edges[3] = Vector4(-1/s, 0, x/s, 0);
49 frustum_edges[4] = Vector4(0, 0, -1, -camera->get_far_clip());
50 frustum_edges[5] = Vector4(0, 0, 1, camera->get_near_clip());
55 bool Scene::frustum_cull(const Renderable &renderable) const
57 const Matrix *matrix = renderable.get_matrix();
58 const Geometry::BoundingSphere<float, 3> *bsphere = renderable.get_bounding_sphere();
59 if(!matrix || !bsphere)
62 Vector4 center = culling_matrix*(*matrix*compose(bsphere->get_center(), 1.0f));
63 Vector3 x_axis = (matrix->column(0)*bsphere->get_radius()).slice<3>(0);
64 float radius_sq = inner_product(x_axis, x_axis);
66 for(unsigned i=0; i<6; ++i)
68 float distance = inner_product(center, frustum_edges[i]);
69 if(distance>0 && distance*distance>radius_sq)
77 Scene::Loader::Loader(Scene &s, Collection &c):
78 DataFile::CollectionObjectLoader<Scene>(s, &c),
84 Scene::Loader::Loader(Scene &s, Collection &c, ContentMap &m):
85 DataFile::CollectionObjectLoader<Scene>(s, &c),
91 void Scene::Loader::init()
93 add("object", &Loader::object);
94 add("object", &Loader::object_tagged);
97 void Scene::Loader::object(const string &n)
99 object_tagged(n, string());
102 void Scene::Loader::object_tagged(const string &n, const string &t)
104 RefPtr<AnimatedObject> anob = new AnimatedObject(get_collection().get<GL::Object>(n));
107 if(content && !t.empty())
108 (*content)[t] = anob.get();
109 obj.owned_data.push_back(anob.release());