]> git.tdb.fi Git - libs/gl.git/blobdiff - source/render/scene.cpp
Move frustum culling from Scene to Camera
[libs/gl.git] / source / render / scene.cpp
index 0f7737227e8da37c4ba69e0260d99f4e893b87c0..a9cf8f96b326f76d388fed95187fbacd4dcdfa25 100644 (file)
@@ -15,64 +15,6 @@ using namespace std;
 namespace Msp {
 namespace GL {
 
-bool Scene::setup_frustum(const Renderer &renderer) const
-{
-       const Camera *camera = renderer.get_camera();
-       if(!camera)
-               return false;
-
-       culling_matrix = camera->get_view_matrix()*renderer.get_matrix();
-
-       if(camera->is_orthographic())
-       {
-               float h = camera->get_orthographic_height();
-               frustum_edges[0] = Vector4(0, 1, 0, -h);
-               frustum_edges[1] = Vector4(0, -1, 0, -h);
-
-               float w = camera->get_orthographic_width();
-               frustum_edges[2] = Vector4(1, 0, 0, -w);
-               frustum_edges[3] = Vector4(-1, 0, 0, -w);
-       }
-       else
-       {
-               float y = tan(camera->get_field_of_view()/2.0f);
-               float s = sqrt(y*y+1);
-               frustum_edges[0] = Vector4(0, 1/s, y/s, 0);
-               frustum_edges[1] = Vector4(0, -1/s, y/s, 0);
-
-               float x = y*camera->get_aspect_ratio();
-               s = sqrt(x*x+1);
-               frustum_edges[2] = Vector4(1/s, 0, x/s, 0);
-               frustum_edges[3] = Vector4(-1/s, 0, x/s, 0);
-       }
-
-       frustum_edges[4] = Vector4(0, 0, -1, -camera->get_far_clip());
-       frustum_edges[5] = Vector4(0, 0, 1, camera->get_near_clip());
-
-       return true;
-}
-
-bool Scene::frustum_cull(const Renderable &renderable) const
-{
-       const Matrix *matrix = renderable.get_matrix();
-       const Geometry::BoundingSphere<float, 3> *bsphere = renderable.get_bounding_sphere();
-       if(!matrix || !bsphere)
-               return false;
-
-       Vector4 center = culling_matrix*(*matrix*compose(bsphere->get_center(), 1.0f));
-       Vector3 x_axis = (matrix->column(0)*bsphere->get_radius()).slice<3>(0);
-       float radius_sq = inner_product(x_axis, x_axis);
-
-       for(unsigned i=0; i<6; ++i)
-       {
-               float distance = inner_product(center, frustum_edges[i]);
-               if(distance>0 && distance*distance>radius_sq)
-                       return true;
-       }
-
-       return false;
-}
-
 Scene::GenericLoader::TypeRegistry &Scene::get_scene_registry()
 {
        static Scene::GenericLoader::TypeRegistry registry;