1 #include <msp/datafile/collection.h>
2 #include "animatedobject.h"
14 for(list<Renderable *>::iterator i=owned_data.begin(); i!=owned_data.end(); ++i)
18 void Scene::render(const Tag &tag) const
21 render(renderer, tag);
24 bool Scene::setup_frustum(const Renderer &renderer) const
26 const Camera *camera = renderer.get_camera();
30 const Matrix &matrix = camera->get_object_matrix();
32 float y = tan(camera->get_field_of_view()/2.0f);
33 float s = sqrt(y*y+1);
34 frustum_edges[0] = matrix*Vector4(0, 1/s, y/s, 0);
35 frustum_edges[1] = matrix*Vector4(0, -1/s, y/s, 0);
37 float x = y*camera->get_aspect();
39 frustum_edges[2] = matrix*Vector4(1/s, 0, x/s, 0);
40 frustum_edges[3] = matrix*Vector4(-1/s, 0, x/s, 0);
42 const Vector3 &camera_pos = camera->get_position();
43 Vector4 pos4 = compose(camera_pos, 0.0f);
44 for(unsigned i=0; i<4; ++i)
45 frustum_edges[i].w = -inner_product(frustum_edges[i], pos4);
47 const Vector3 &look_dir = camera->get_look_direction();
48 frustum_edges[4] = compose(look_dir, -dot(camera_pos, look_dir)-camera->get_far_clip());
49 frustum_edges[5] = compose(-look_dir, dot(camera_pos, look_dir)+camera->get_near_clip());
54 bool Scene::frustum_cull(const Renderable &renderable) const
56 const Matrix *matrix = renderable.get_matrix();
57 const Geometry::BoundingSphere<float, 3> *bsphere = renderable.get_bounding_sphere();
58 if(!matrix || !bsphere)
61 Vector4 center = *matrix*compose(bsphere->get_center(), 1.0f);
62 float radius = bsphere->get_radius();
64 for(unsigned i=0; i<6; ++i)
65 if(inner_product(center, frustum_edges[i])>radius)
72 Scene::Loader::Loader(Scene &s, Collection &c):
73 DataFile::CollectionObjectLoader<Scene>(s, &c)
75 add("object", &Loader::object);
78 void Scene::Loader::object(const string &n)
80 RefPtr<AnimatedObject> anob = new AnimatedObject(get_collection().get<GL::Object>(n));
83 obj.owned_data.push_back(anob.release());