From 380e636ddeb5811cb5d87800c445638246269b62 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Mon, 28 Nov 2016 02:20:20 +0200 Subject: [PATCH] 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. --- source/scene.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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; } -- 2.45.2