diff --git a/src/lib.rs b/src/lib.rs index e2bb071..13e9be9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -25,7 +25,7 @@ pub fn disable_mouse_trap(mut windows: ResMut) { window.set_cursor_visibility(true); } -pub fn random_sphere_vec(r: &mut impl rand::prelude::Rng) -> Vec3 { +pub fn random_unit_vec(r: &mut impl rand::prelude::Rng) -> Vec3 { // https://mathworld.wolfram.com/SpherePointPicking.html // Marsaglia (1972) for picking x1 and x2 from (-1, 1) and generating surface // points directly if their sum is less than 1. @@ -38,7 +38,7 @@ pub fn random_sphere_vec(r: &mut impl rand::prelude::Rng) -> Vec3 { x2 = r.gen_range(-1.0..=1.0); ssum = x1.powi(2) + x2.powi(2); } - let sqrt = (1.0 - x1.powi(2) - x2.powi(2)).sqrt(); + let sqrt = (1.0 - ssum).sqrt(); let x = 2.0 * x1 * sqrt; let y = 2.0 * x2 * sqrt; let z = 1.0 - 2.0 * ssum; diff --git a/src/lights.rs b/src/lights.rs index f6001e7..216d0a4 100644 --- a/src/lights.rs +++ b/src/lights.rs @@ -25,7 +25,7 @@ fn spawn_moving_lights( // spawn 200 orbiting bisexual lights for _ in 0..255 { // mechanics - let axis = crate::random_sphere_vec(rng); + let axis = crate::random_unit_vec(rng); let angle = rng.gen_range(0.0..TAU); let rate: f32 = rng.gen_range(7.0..10.0); let rate = rate.to_radians();