Add Light trait and PointLight instance

This commit is contained in:
bijan2005 2021-01-23 22:52:50 -05:00
parent 53f5c8bac5
commit ed6e84a240
10 changed files with 123 additions and 48 deletions

25
src/render.rs Normal file
View file

@ -0,0 +1,25 @@
extern crate nalgebra as na;
use std::cmp::Ordering;
use na::*;
use na::geometry::Point3;
use crate::types::*;
use crate::object::*;
fn trace(ray: Ray, objects: &Vec<Object>) -> Option<(&Object, f32)> {
objects.iter()
.filter_map(|obj| obj.intersect(ray)
.map(|x| (obj, x)))
.min_by(|a, b| a.1.partial_cmp(&b.1).unwrap_or(Ordering::Equal))
}
pub fn cast_ray(ray: Ray, scene: &Scene) -> Color {
if let Some((obj, dist)) = trace(ray, &scene.objects) {
let point = ray.project(dist);
obj.getcolor(point)
}
else { scene.background }
}