From: Mikko Rasa Date: Mon, 28 Nov 2016 00:20:20 +0000 (+0200) Subject: Properly scale the the bounding sphere for frustum culling X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=commitdiff_plain;h=380e636ddeb5811cb5d87800c445638246269b62;hp=d1e3975c163694d7bca6417463462be950019e5e Properly scale the the bounding sphere for frustum culling The original radius must be squared too. Also, negative distances mean the sphere is inside the frustum and should not be culled. --- diff --git a/source/scene.cpp b/source/scene.cpp index 6c3d2910..b8a74b59 100644 --- a/source/scene.cpp +++ b/source/scene.cpp @@ -66,13 +66,13 @@ bool Scene::frustum_cull(const Renderable &renderable) const return false; Vector4 center = culling_matrix*(*matrix*compose(bsphere->get_center(), 1.0f)); - 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); + Vector4 x_axis = *matrix*Vector4(bsphere->get_radius(), 0.0f, 0.0f, 0.0f); + 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*distance>radius_sq) + if(distance>0 && distance*distance>radius_sq) return true; }