diff options
Diffstat (limited to 'racer-tracer/src/util.rs')
| -rw-r--r-- | racer-tracer/src/util.rs | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/racer-tracer/src/util.rs b/racer-tracer/src/util.rs index 2f04567..5fb2d36 100644 --- a/racer-tracer/src/util.rs +++ b/racer-tracer/src/util.rs @@ -1,6 +1,7 @@ use rand::Rng; -// For later use +use crate::vec3::Vec3; + pub fn degrees_to_radians(degrees: f64) -> f64 { degrees * std::f64::consts::PI / 180.0 } @@ -10,8 +11,23 @@ pub fn random_double() -> f64 { rng.gen::<f64>() } -// For later use pub fn random_double_range(min: f64, max: f64) -> f64 { let mut rng = rand::thread_rng(); rng.gen_range(min..max) } + +pub fn random_in_unit_disk() -> Vec3 { + // TODO: This feels not nice + loop { + let p = Vec3::new( + random_double_range(-1.0, 1.0), + random_double_range(-1.0, 1.0), + 0.0, + ); + if p.length_squared() >= 1.0 { + continue; + } + + return p; + } +} |
