Extract camera→ray conversion

This commit is contained in:
numzero 2024-09-15 00:04:14 +03:00
parent e9993182bf
commit d8eed54c8b

View File

@ -153,6 +153,14 @@ impl Space {
Boundary => panic!("Can't draw a line here!"),
}
}
fn camera_ray_to_abs(&self, camera: Location, ray: Ray) -> Ray {
let pos = camera.pos;
let dir = camera.rot * ray.dir;
// TODO account for ray.pos
let dir = DT * self.tube.normalize_vec_at(pos, dir);
Ray { pos, dir }
}
}
impl Traceable for Space {
@ -165,11 +173,7 @@ impl DebugTraceable for Space {
fn trace_dbg(&self, camera: Location, ray: Ray) -> (Vec<Hit>, RayPath) {
let mut points = vec![];
let mut hits = vec![];
let mut ray = Ray {
pos: camera.pos,
dir: camera.rot * ray.dir,
}; // TODO account for ray.pos
ray.dir = self.tube.normalize_vec_at(ray.pos, ray.dir) * DT;
let mut ray = self.camera_ray_to_abs(camera, ray);
let trace_to_flat = |points: &mut Vec<Vec2>, ray| {
for ray in self.trace_iter(ray).skip(1) {