library: use beevee's Intersected trait

This commit is contained in:
Bruno BELANYI 2020-03-24 21:37:00 +01:00
parent 21c7aea1c0
commit 6df2d857d4
3 changed files with 19 additions and 4 deletions

View file

@ -4,7 +4,11 @@ use crate::material::MaterialEnum;
use crate::shape::{Shape, ShapeEnum};
use crate::texture::TextureEnum;
use crate::Point;
use beevee::aabb::{Bounded, AABB};
use beevee::{
aabb::{Bounded, AABB},
bvh::Intersected,
ray::Ray,
};
use serde::Deserialize;
/// An object being rendered in the scene.
@ -66,6 +70,12 @@ impl Bounded for Object {
}
}
impl Intersected for Object {
fn intersect(&self, ray: &Ray) -> Option<f32> {
self.shape.intersect(ray)
}
}
#[cfg(test)]
mod test {
use super::*;

View file

@ -149,9 +149,7 @@ impl Scene {
}
fn cast_ray(&self, ray: Ray) -> Option<(f32, &Object)> {
self.bvh
.walk(&ray, &self.objects)
.and_then(|o| o.shape.intersect(&ray).map(|t| (t, o)))
self.bvh.walk(&ray, &self.objects)
}
fn color_at(

View file

@ -3,6 +3,7 @@
use super::{Point, Point2D, Vector};
use beevee::{
aabb::{Bounded, AABB},
bvh::Intersected,
ray::Ray,
};
use nalgebra::Unit;
@ -44,6 +45,12 @@ impl Bounded for dyn Shape {
}
}
impl Intersected for dyn Shape {
fn intersect(&self, ray: &Ray) -> Option<f32> {
self.intersect(ray)
}
}
mod sphere;
pub use sphere::*;