X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fscene.cpp;h=6c3d2910706db98d6f2ecd7ed67b3dd771c372e8;hb=7503b8514cfcc9861c74cfebb0c60db3f72fa29b;hp=ad9dcd151110724a62581f1a7190de332b3ea86e;hpb=0a20dd14a0d1fd027a7d411b4d427bd4252342cc;p=libs%2Fgl.git diff --git a/source/scene.cpp b/source/scene.cpp index ad9dcd15..6c3d2910 100644 --- a/source/scene.cpp +++ b/source/scene.cpp @@ -29,15 +29,28 @@ bool Scene::setup_frustum(const Renderer &renderer) const culling_matrix = renderer.get_matrix(); - 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); + 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()); @@ -53,11 +66,15 @@ bool Scene::frustum_cull(const Renderable &renderable) const return false; Vector4 center = culling_matrix*(*matrix*compose(bsphere->get_center(), 1.0f)); - float radius = bsphere->get_radius(); + Vector4 x_axis = *matrix*Vector4(1.0f, 0.0f, 0.0f, 0.0f); + float radius_sq = bsphere->get_radius()*inner_product(x_axis, x_axis); for(unsigned i=0; i<6; ++i) - if(inner_product(center, frustum_edges[i])>radius) + { + float distance = inner_product(center, frustum_edges[i]); + if(distance*distance>radius_sq) return true; + } return false; }