pub fn render(self, filename: String) {
        let mut img: image::RgbImage = self.camera.imagebuffer();
        if self.objects.is_empty() {
            panic!("Please specify objects for rendering.");
        }
        for (x, y, pixel) in img.enumerate_pixels_mut() {
            *pixel = self.apply_ambient(self.default_color);
            let pixel_ray = Ray::new(
                self.camera.position,
                Vector3::new(
                    2.0 - (4.0 * (f64::from(x) / (self.camera.dimensions.0 as f64))),
                    0.0,
                    2.0 - (4.0 * (f64::from(y) / (self.camera.dimensions.1 as f64))),
                ) + self.camera.eye.dir,
            );
            let mut closest = Viewport::draw_ray(&pixel_ray, &self.objects[0]);
            for object in &self.objects {
                let res = Viewport::draw_ray(&pixel_ray, &object);
                if let Some((distance, color)) = res {
                    // This unwrap() is okay because we check for None -- if it's None, we know
                    // that we have to replace it as it's the furthest thing away. We saw
                    // nothing with the last ray we drew with the first object.
                    if closest == None || (distance < closest.unwrap().0) {
                        *pixel = self.apply_ambient(color);
                        closest = Some((distance, color));
                    } else {
                        *pixel = closest.unwrap().1;
                    }
                }
                // Viewport::light_ray(&pixel_ray, &self.objects, &self.objects[0], &self.lights[0]);
            }
        }
        img.save(filename).unwrap();
    }
/// Renders the full image to an output file.
///
/// # Warning
/// This may take awhile depending on how large of an image you specify in the camera.
///
/// # Note
/// Currently, the camera's shape (and size, fov) cannot be meaningfully set,
/// but this would be a good feature to add!
Renders the full image to an output file.
Renders the full image to an output file .
pub fn render(self, filename: String) {
        let mut img: image::RgbImage = self.camera.imagebuffer();
        if self.objects.is_empty() {
            panic!("Please specify objects for rendering.");
        }
        for (x, y, pixel) in img.enumerate_pixels_mut() {
            *pixel = self.apply_ambient(self.default_color);
            let pixel_ray = Ray::new(
                self.camera.position,
                Vector3::new(
                    2.0 - (4.0 * (f64::from(x) / (self.camera.dimensions.0 as f64))),
                    0.0,
                    2.0 - (4.0 * (f64::from(y) / (self.camera.dimensions.1 as f64))),
                ) + self.camera.eye.dir,
            );
            let mut closest = Viewport::draw_ray(&pixel_ray, &self.objects[0]);
            for object in &self.objects {
                let res = Viewport::draw_ray(&pixel_ray, &object);
                if let Some((distance, color)) = res {
                    // This unwrap() is okay because we check for None -- if it's None, we know
                    // that we have to replace it as it's the furthest thing away. We saw
                    // nothing with the last ray we drew with the first object.
                    if closest == None || (distance < closest.unwrap().0) {
                        *pixel = self.apply_ambient(color);
                        closest = Some((distance, color));
                    } else {
                        *pixel = closest.unwrap().1;
                    }
                }
                // Viewport::light_ray(&pixel_ray, &self.objects, &self.objects[0], &self.lights[0]);
            }
        }
        img.save(filename).unwrap();
    }
pub fn render ( self , filename : String ) { let mut img : image :: RgbImage = self . camera . imagebuffer ( ) ; if self . objects . is_empty ( ) { panic ! ( " " ) ; } for ( x , y , pixel ) in img . enumerate_pixels_mut ( ) { * pixel = self . apply_ambient ( self . default_color ) ; let pixel_ray = Ray :: new ( self . camera . position , Vector3 :: new ( 2.0 - ( 4.0 * ( f64 :: from ( x ) / ( self . camera . dimensions . 0 as f64 ) ) ) , 0.0 , 2.0 - ( 4.0 * ( f64 :: from ( y ) / ( self . camera . dimensions . 1 as f64 ) ) ) , ) + self . camera . eye . dir , ) ; let mut closest = Viewport :: draw_ray ( & pixel_ray , & self . objects [ 0 ] ) ; for object in & self . objects { let res = Viewport :: draw_ray ( & pixel_ray , & object ) ; if let Some ( ( distance , color ) ) = res { // This unwrap() is okay because we check for None -- if it's None, we know // that we have to replace it as it's the furthest thing away. We saw // nothing with the last ray we drew with the first object. if closest == None || ( distance < closest . unwrap ( ) . 0 ) { * pixel = self . apply_ambient ( color ) ; closest = Some ( ( distance , color ) ) ; } else { * pixel = closest . unwrap ( ) . 1 ; } } // Viewport::light_ray(&pixel_ray, &self.objects, &self.objects[0], &self.lights[0]); } } img . save ( filename ) . unwrap ( ) ; }
Renders the full image to an output file.
Renders the full image to an output file .
self
filename
String
warning
This may take awhile depending on how large of an image you specify in the camera.
This may take awhile depending on how large of an image you specify in the camera .
note
Currently, the camera's shape (and size, fov) cannot be meaningfully set,
but this would be a good feature to add!
Currently the camera ' s shape ( and size fov ) cannot be meaningfully set but this would be a good feature to add!