pub fn view(&self, x: f32, y: f32, rng: &mut dyn RngCore) -> Ray {
        let base = self.normal.base + (x - 0.5) * self.x + (y - 0.5) * self.y;
        let direction = base - self.normal.at(-self.distance);
        let ray = Ray::new(base, direction);
        if let Some(lens) = &self.lens {
            let focal_point = ray.at(lens.focus_distance / (direction * self.normal.direction));
            let mut x = 1.0;
            let mut y = 1.0;
            let dist = rand::distributions::Uniform::new_inclusive(-1.0, 1.0);
            while x * x + y * y > 1.0 {
                x = rng.sample(dist);
                y = rng.sample(dist);
            }
            x *= lens.aperture;
            y *= lens.aperture;
            let direction = focal_point - (base + x * self.x + y * self.y);
            Ray::new(base, direction)
        } else {
            ray
        }
    }
/// Returns a ray for a given point of the screen
///
/// # Arguments
///
/// * `x` - the fractional position along the screen width
/// * `y` - the fractional position along the screen height
/// * `rng` - the random number generator to use
Returns a ray for a given point of the screen
Returns a ray for a given point of the screen
pub fn view(&self, x: f32, y: f32, rng: &mut dyn RngCore) -> Ray {
        let base = self.normal.base + (x - 0.5) * self.x + (y - 0.5) * self.y;
        let direction = base - self.normal.at(-self.distance);
        let ray = Ray::new(base, direction);
        if let Some(lens) = &self.lens {
            let focal_point = ray.at(lens.focus_distance / (direction * self.normal.direction));
            let mut x = 1.0;
            let mut y = 1.0;
            let dist = rand::distributions::Uniform::new_inclusive(-1.0, 1.0);
            while x * x + y * y > 1.0 {
                x = rng.sample(dist);
                y = rng.sample(dist);
            }
            x *= lens.aperture;
            y *= lens.aperture;
            let direction = focal_point - (base + x * self.x + y * self.y);
            Ray::new(base, direction)
        } else {
            ray
        }
    }
pub fn view ( & self , x : f32 , y : f32 , rng : & mut dyn RngCore ) -> Ray { let base = self . normal . base + ( x - 0.5 ) * self . x + ( y - 0.5 ) * self . y ; let direction = base - self . normal . at ( - self . distance ) ; let ray = Ray :: new ( base , direction ) ; if let Some ( lens ) = & self . lens { let focal_point = ray . at ( lens . focus_distance / ( direction * self . normal . direction ) ) ; let mut x = 1.0 ; let mut y = 1.0 ; let dist = rand :: distributions :: Uniform :: new_inclusive ( - 1.0 , 1.0 ) ; while x * x + y * y > 1.0 { x = rng . sample ( dist ) ; y = rng . sample ( dist ) ; } x *= lens . aperture ; y *= lens . aperture ; let direction = focal_point - ( base + x * self . x + y * self . y ) ; Ray :: new ( base , direction ) } else { ray } }
Returns a ray for a given point of the screen
Returns a ray for a given point of the screen
&self
x
f32
y
f32
rng
&mut dyn RngCore
&self
x
f32
y
f32
rng
&mut dyn RngCore