Added small optimisation and comments
parent
ddce5075ce
commit
ca65416c73
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Reference in New Issue