From ca65416c738a0b49ebb939d46d0e85a00809a051 Mon Sep 17 00:00:00 2001 From: hheik <4469778+hheik@users.noreply.github.com> Date: Sat, 2 Dec 2023 17:21:11 +0200 Subject: [PATCH] Added small optimisation and comments --- src/game/darkness.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/game/darkness.rs b/src/game/darkness.rs index d0ed28b..2b0c36c 100644 --- a/src/game/darkness.rs +++ b/src/game/darkness.rs @@ -318,6 +318,8 @@ fn get_light_geometry( true }); + // FIXME: light source may not always be at bounding box center + // for example: optimal spot light bounding box let center = aabb.center(); points.sort_unstable_by(|a, b| { f32::atan2(a.y - center.y, a.x - center.x) @@ -328,12 +330,14 @@ fn get_light_geometry( // Build visibility polygon let mut polygon: Vec<_> = vec![]; for point in points.drain(..) { - // We shoot 2 rays offset by this angle from the point. + /// We shoot 2 rays offset by this angle from the edge to catch what is beyond it. const ANGLE_OFFSET: f32 = 0.0001; + /// Multiplier for hypotenuse when the other two sides are the same length. Or sqrt(2). + const HYPOTENUSE_MULT: f32 = 1.4142135623730951; offset_cast( aabb.center(), (point - aabb.center()).normalize_or_zero(), - aabb.size().max_element(), + aabb.half_size().max_element() * HYPOTENUSE_MULT, true, filter, ANGLE_OFFSET,