From 1207c2c55c772155d02a148d76616881f3f6c125 Mon Sep 17 00:00:00 2001 From: Rosyid Haryadi Date: Sun, 2 Mar 2025 00:25:53 +0700 Subject: upd: anti aliasing --- src/calculus.rs | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) (limited to 'src/calculus.rs') 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 -- cgit v1.2.3-70-g09d2