From d8eed54c8b0abf1a331fb2ff27696cf19b71431d Mon Sep 17 00:00:00 2001 From: numzero Date: Sun, 15 Sep 2024 00:04:14 +0300 Subject: [PATCH] =?UTF-8?q?Extract=20camera=E2=86=92ray=20conversion?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/bin/flat/tube/mod.rs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/bin/flat/tube/mod.rs b/src/bin/flat/tube/mod.rs index 3c36a87..7b5ae03 100644 --- a/src/bin/flat/tube/mod.rs +++ b/src/bin/flat/tube/mod.rs @@ -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, 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, ray| { for ray in self.trace_iter(ray).skip(1) {