Pull the distance a level out

This commit is contained in:
numzero 2024-06-09 20:59:28 +03:00
parent 2c47c66b60
commit 978138c780

View File

@ -158,7 +158,8 @@ impl Space {
assert_eq!(self.which_subspace(ray.pos), Inner);
let cell = RectInside { rect: self.rect };
let ray = cell.ray_to_local(ray);
let ray = cell.to_boundary(ray).expect("Can't get outta here!");
let dist = cell.to_boundary(ray).expect("Can't get outta here!");
let ray = Ray { pos: ray.pos + ray.dir * dist, dir: ray.dir };
cell.ray_to_global(ray)
}
@ -412,7 +413,7 @@ trait FlatCell: std::fmt::Debug {
}
fn local_bounds(&self) -> (Vec2, Vec2);
fn to_boundary(&self, ray: Ray) -> Option<Ray> {
fn to_boundary(&self, ray: Ray) -> Option<f32> {
assert!(self.is_inside(ray.pos));
let sgn = ray.dir.signum();
let p = ray.pos * sgn;
@ -430,7 +431,7 @@ trait FlatCell: std::fmt::Debug {
(bnd.1.y - p.y) / v.y
};
if t <= 100000.0 {
Some(Ray { pos: sgn * (p + v * t), dir: sgn * v })
Some(t)
} else {
None
}