Add Light trait and PointLight instance
This commit is contained in:
parent
53f5c8bac5
commit
ed6e84a240
10 changed files with 123 additions and 48 deletions
25
src/render.rs
Normal file
25
src/render.rs
Normal 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 }
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue