-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed: Random issues for spot lights.
- Loading branch information
Showing
5 changed files
with
40 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,35 @@ | ||
#define_import_path bevy_incandescent::math | ||
|
||
const PI: f32 = 3.14159265358979323846; | ||
const TAU: f32 = 6.28318530717958647692; | ||
const FRAC_PI_2: f32 = 1.57079632679489661923; | ||
|
||
// https://www.cnblogs.com/miloyip/archive/2013/04/19/3029852.html | ||
fn is_point_inside_sector( | ||
point: vec2f, | ||
center: vec2f, | ||
radius: f32, | ||
angles: array<f32, 2>, | ||
) -> bool { | ||
if angles[1] >= TAU { | ||
return true; | ||
} | ||
|
||
let p0 = point - center; | ||
let sqr_dist = p0.x * p0.x + p0.y * p0.y; | ||
if sqr_dist > radius * radius { | ||
return false; | ||
} | ||
var pol = atan(p0.y / p0.x); | ||
if p0.x < 0.0 { | ||
pol += PI; | ||
|
||
let ctr = vec2f(cos(angles[0]), sin(angles[0])); | ||
let cos_ext = cos(angles[1]); | ||
let d = dot(p0, ctr); | ||
|
||
if d >= 0. && cos_ext >= 0. { | ||
return d * d > sqr_dist * cos_ext * cos_ext; | ||
} else if d < 0. && cos_ext < 0. { | ||
return d * d < sqr_dist * cos_ext * cos_ext; | ||
} else { | ||
return d >= 0.; | ||
} | ||
return pol > angles[0] && pol < angles[1]; | ||
} |