Correctly render multiple objects instead of just rendeing one
This commit is contained in:
parent
99c79ea31b
commit
4f60719523
|
|
@ -68,8 +68,17 @@ pub fn render_scene<T: RealField>(output_image: &mut OutputImage, scene: &Scene<
|
|||
for column in 0..output_image.get_width() {
|
||||
for row in 0..output_image.get_height() {
|
||||
let ray = image_sampler.ray_for_pixel(row, column);
|
||||
for object in scene.objects.iter() {
|
||||
let gray = match object.intersect(&ray) {
|
||||
let hit = scene
|
||||
.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,
|
||||
Some(_) => 255,
|
||||
};
|
||||
|
|
@ -77,7 +86,6 @@ pub fn render_scene<T: RealField>(output_image: &mut OutputImage, scene: &Scene<
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
|
|
|
|||
Loading…
Reference in New Issue