From 9ec5f17754921a5c32556edd176034ee6c421796 Mon Sep 17 00:00:00 2001 From: numzero Date: Mon, 10 Jun 2024 19:50:39 +0300 Subject: [PATCH] Hit objects from different space regions --- src/bin/flat/main.rs | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/src/bin/flat/main.rs b/src/bin/flat/main.rs index ec693b2..dd87c4d 100644 --- a/src/bin/flat/main.rs +++ b/src/bin/flat/main.rs @@ -192,7 +192,7 @@ impl Space { fn trace_outer(&self, ray: Ray) -> FlatTraceResult { assert_eq!(self.which_subspace(ray.pos), Outer); let cell = basic_shapes::Rect { size: vec2(self.rect.outer_radius, self.rect.external_halflength) }; - let objs = Self::trace_to_objects(self.list_objects_outer(), ray); + let objs = Self::trace_to_objects(self.list_objects_outer().as_slice(), ray); if let Some(dist) = cell.trace_into(ray) { FlatTraceResult { end: Some(ray.forward(dist)), @@ -213,8 +213,25 @@ impl Space { .expect("Can't get outta the wall!") } - fn list_objects_outer(&self) -> &[Object] { - self.objs.as_slice() + fn list_objects_outer(&self) -> Vec { + self.objs.iter().map(|&obj| { + match self.which_subspace(obj.loc.pos) { + Outer => obj, + Inner => { + let Vec2 { x, y } = obj.loc.pos; // в основной СК + let y = self.rect.u(y) + y.signum() * (self.rect.external_halflength - self.rect.internal_halflength); + Object { + id: obj.id, + loc: Location { + pos: vec2(x, y), // в плоском продолжении СК Outer на область Inner + rot: obj.loc.rot, + }, + r: obj.r, + } + } + Boundary => panic!("Object {} was destroyed by the space curvature", obj.id), + } + }).collect() } fn trace_to_objects(objs: &[Object], ray: Ray) -> Vec {