summaryrefslogtreecommitdiff
path: root/src/calculus.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/calculus.rs')
-rw-r--r--src/calculus.rs14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/calculus.rs b/src/calculus.rs
index e59ae56..62253cf 100644
--- a/src/calculus.rs
+++ b/src/calculus.rs
@@ -132,6 +132,20 @@ pub mod calculus {
let r_out_parallel = normal.scalar_mul(-1.0 * f);
r_out_perp.add(&r_out_parallel)
}
+
+ pub fn random_in_unit_disk() -> Self {
+ let mut rng = rand::rng();
+ loop {
+ let p = Vec3::new(
+ rng.random_range(-1.0..1.0),
+ rng.random_range(-1.0..1.0),
+ 0.0
+ );
+ if p.mag_sqr() < 1.0 {
+ return p;
+ }
+ }
+ }
}
pub struct Ray {