Skip to content

Commit

Permalink
feat(render): add OnOffRenderer
Browse files Browse the repository at this point in the history
the first render eq. solver, it only produces
black and white simple image

docs missing
  • Loading branch information
andros21 committed May 4, 2022
1 parent 9992184 commit bc22424
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
//! Provides different renderers that implement [`Solve`] trait.
use crate::color::Color;
use crate::ray::Ray;
use crate::world::World;

/// A trait for solving rendering equation.
///
Expand All @@ -11,3 +12,27 @@ use crate::ray::Ray;
pub trait Solve {
fn solve(&self, ray: Ray) -> Color;
}

pub struct OnOffRenderer<'a> {
world: &'a World,
background_color: Color,
color: Color,
}

impl<'a> OnOffRenderer<'a> {
pub fn new(world: &World, background_color: Color, color: Color) -> OnOffRenderer {
OnOffRenderer {
world,
background_color,
color,
}
}
}
impl<'a> Solve for OnOffRenderer<'a> {
fn solve(&self, ray: Ray) -> Color {
match self.world.ray_intersection(ray) {
Some(_hit) => self.color,
None => self.background_color,
}
}
}

0 comments on commit bc22424

Please sign in to comment.