]> git.tdb.fi Git - libs/gl.git/blobdiff - source/scene.cpp
Add a less-than operator to Version
[libs/gl.git] / source / scene.cpp
index 7d3c167975e7a3c548de29cc5aff782439e46a3a..1625ca32c7c74052cdec47cdf10f741d26115f12 100644 (file)
@@ -27,26 +27,33 @@ bool Scene::setup_frustum(const Renderer &renderer) const
        if(!camera)
                return false;
 
-       const Matrix &matrix = camera->get_object_matrix();
-
-       float y = tan(camera->get_field_of_view()/2.0f);
-       float s = sqrt(y*y+1);
-       frustum_edges[0] = matrix*Vector4(0, 1/s, y/s, 0);
-       frustum_edges[1] = matrix*Vector4(0, -1/s, y/s, 0);
-
-       float x = y*camera->get_aspect();
-       s = sqrt(x*x+1);
-       frustum_edges[2] = matrix*Vector4(1/s, 0, x/s, 0);
-       frustum_edges[3] = matrix*Vector4(-1/s, 0, x/s, 0);
-
-       const Vector3 &camera_pos = camera->get_position();
-       Vector4 pos4 = compose(camera_pos, 0.0f);
-       for(unsigned i=0; i<4; ++i)
-               frustum_edges[i].w = -inner_product(frustum_edges[i], pos4);
-
-       const Vector3 &look_dir = camera->get_look_direction();
-       frustum_edges[4] = compose(look_dir, -dot(camera_pos, look_dir)-camera->get_far_clip());
-       frustum_edges[5] = compose(-look_dir, dot(camera_pos, look_dir)+camera->get_near_clip());
+       culling_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();
+               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;
 }
@@ -58,7 +65,7 @@ bool Scene::frustum_cull(const Renderable &renderable) const
        if(!matrix || !bsphere)
                return false;
 
-       Vector4 center = *matrix*compose(bsphere->get_center(), 1.0f);
+       Vector4 center = culling_matrix*(*matrix*compose(bsphere->get_center(), 1.0f));
        float radius = bsphere->get_radius();
 
        for(unsigned i=0; i<6; ++i)