Added small optimisation and comments
parent
ddce5075ce
commit
ca65416c73
|
|
@ -318,6 +318,8 @@ fn get_light_geometry(
|
||||||
true
|
true
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// FIXME: light source may not always be at bounding box center
|
||||||
|
// for example: optimal spot light bounding box
|
||||||
let center = aabb.center();
|
let center = aabb.center();
|
||||||
points.sort_unstable_by(|a, b| {
|
points.sort_unstable_by(|a, b| {
|
||||||
f32::atan2(a.y - center.y, a.x - center.x)
|
f32::atan2(a.y - center.y, a.x - center.x)
|
||||||
|
|
@ -328,12 +330,14 @@ fn get_light_geometry(
|
||||||
// Build visibility polygon
|
// Build visibility polygon
|
||||||
let mut polygon: Vec<_> = vec![];
|
let mut polygon: Vec<_> = vec![];
|
||||||
for point in points.drain(..) {
|
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;
|
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(
|
offset_cast(
|
||||||
aabb.center(),
|
aabb.center(),
|
||||||
(point - aabb.center()).normalize_or_zero(),
|
(point - aabb.center()).normalize_or_zero(),
|
||||||
aabb.size().max_element(),
|
aabb.half_size().max_element() * HYPOTENUSE_MULT,
|
||||||
true,
|
true,
|
||||||
filter,
|
filter,
|
||||||
ANGLE_OFFSET,
|
ANGLE_OFFSET,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue