diff --git a/lib/common/src/bvh.rs b/lib/common/src/bvh.rs index bc10bf8..aaed42a 100644 --- a/lib/common/src/bvh.rs +++ b/lib/common/src/bvh.rs @@ -1,6 +1,9 @@ use std::cmp::Ordering; use std::collections::BTreeMap; +use fixed_wide::fixed::Fixed; +use linear_ops::types::Vector3; + use crate::aabb::Aabb; use crate::integer::{Ratio,Planar64,Planar64Vec3}; use crate::instruction::{InstructionCollector,TimedInstruction}; @@ -20,6 +23,10 @@ pub struct Ray{ pub direction:Planar64Vec3, } impl Ray{ + pub fn extrapolate(&self,t:Ratio<Planar64,Planar64>)->Ratio<Vector3<Fixed<2,64>>,Planar64>{ + // o+d*t + (self.origin*t.den+self.direction*t.num)/t.den + } pub fn intersect_aabb(&self,aabb:&Aabb)->Option<Ratio<Planar64,Planar64>>{ // n.(o+d*t)==n.p // n.o + n.d * t == n.p @@ -35,7 +42,11 @@ impl Ray{ match self.direction.z.cmp(&Planar64::ZERO){ Ordering::Less=>{ let t=(aabb.max().z-self.origin.z)/self.direction.z; - hit=Some(hit.map_or(t,|best_t|best_t.min(t))); + let p=self.extrapolate(t); + if aabb.min().x<p.x&&p.x<aabb.max().x + &&aabb.min().y<p.y&&p.y<aabb.max().y{ + hit=Some(hit.map_or(t,|best_t|best_t.min(t))); + } }, Ordering::Equal=>(), Ordering::Greater=>{