diff options
author | Rosyid Haryadi <rosyid_haryadi@protonmail.com> | 2025-03-02 00:25:53 +0700 |
---|---|---|
committer | Rosyid Haryadi <rosyid_haryadi@protonmail.com> | 2025-03-02 00:25:53 +0700 |
commit | 1207c2c55c772155d02a148d76616881f3f6c125 (patch) | |
tree | 9a504e189f88f0417adcc558c268b408701cad58 /src/calculus.rs | |
parent | 5fb34460b02b2b151dd775e43675bd4f09d2633a (diff) |
upd: anti aliasing
Diffstat (limited to 'src/calculus.rs')
-rw-r--r-- | src/calculus.rs | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/src/calculus.rs b/src/calculus.rs index c9b0574..a39c8a5 100644 --- a/src/calculus.rs +++ b/src/calculus.rs @@ -1,4 +1,6 @@ pub mod calculus { + use rand::Rng; + #[derive(Copy, Clone, Debug)] pub struct Vec3 { pub x: f32, @@ -68,12 +70,12 @@ pub mod calculus { } } - pub struct Ray<'a> { - pub origin: &'a Point3, - pub direction: &'a Vec3, + pub struct Ray { + pub origin: Point3, + pub direction: Vec3, } - impl<'a> Ray<'a> { + impl Ray { pub fn at(&self, t: f32) -> Point3 { // Get parametric location self.origin.add(&self.direction.scalar_mul(t)) @@ -84,4 +86,13 @@ pub mod calculus { deg * std::f32::consts::PI / 180.0 } + pub fn sample_square() -> Vec3 { + // Returns the vector to a random point in the [-.5,-.5]-[+.5,+.5] unit square. + let mut rng = rand::rng(); + Vec3::new( + rng.random_range(0.0..1.0) - 0.5, + rng.random_range(0.0..1.0) - 0.5, + 0.0) + } + }
\ No newline at end of file |