wip: fix intersect_aabb
This commit is contained in:
parent
f770f5ac7b
commit
74eefcb78f
@ -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=>{
|
||||
|
Loading…
x
Reference in New Issue
Block a user