Correctly render multiple objects instead of just rendeing one

This commit is contained in:
Matthew Gordon 2019-11-12 17:25:10 -05:00
parent 99c79ea31b
commit 4f60719523
1 changed files with 15 additions and 7 deletions

View File

@ -68,15 +68,23 @@ pub fn render_scene<T: RealField>(output_image: &mut OutputImage, scene: &Scene<
for column in 0..output_image.get_width() { for column in 0..output_image.get_width() {
for row in 0..output_image.get_height() { for row in 0..output_image.get_height() {
let ray = image_sampler.ray_for_pixel(row, column); let ray = image_sampler.ray_for_pixel(row, column);
for object in scene.objects.iter() { let hit = scene
let gray = match object.intersect(&ray) { .objects
.iter()
.flat_map(|object| object.intersect(&ray))
.min_by(
|a, b| match PartialOrd::partial_cmp(&a.distance, &b.distance) {
None => std::cmp::Ordering::Less,
Some(ordering) => ordering,
},
);
let gray = match hit {
None => 0, None => 0,
Some(_) => 255, Some(_) => 255,
}; };
output_image.set_color(row, column, gray, gray, gray); output_image.set_color(row, column, gray, gray, gray);
} }
} }
}
} }
#[cfg(test)] #[cfg(test)]