From 74eefcb78f491d9ffb39c10b7b94d6a6362aaa0b Mon Sep 17 00:00:00 2001 From: Quaternions <krakow20@gmail.com> Date: Fri, 7 Feb 2025 14:48:55 -0800 Subject: [PATCH] wip: fix intersect_aabb --- lib/common/src/bvh.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) 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=>{