From: Mikko Rasa Date: Fri, 25 Nov 2016 21:19:08 +0000 (+0200) Subject: Account for scale when performing frustum culling X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=b6fd887102ab8e4109fa2edd40b9e51f80f88410;p=libs%2Fgl.git Account for scale when performing frustum culling It will still break with non-uniform scaling. --- diff --git a/source/scene.cpp b/source/scene.cpp index 1625ca32..6c3d2910 100644 --- a/source/scene.cpp +++ b/source/scene.cpp @@ -66,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; }