diff --git a/src/bin/flat/main.rs b/src/bin/flat/main.rs index b8832ff..cffb8b9 100644 --- a/src/bin/flat/main.rs +++ b/src/bin/flat/main.rs @@ -238,7 +238,6 @@ impl Space { } fn list_objects_inner(&self) -> Vec { - let cell = RectInside { rect: self.rect }; self.objs.iter().map(|&obj| { match self.which_subspace(obj.loc.pos) { Inner | Outer => { @@ -247,7 +246,7 @@ impl Space { Object { id: obj.id, loc: Location { - pos: cell.pos_to_local(obj.loc.pos), // в плоской СК для Inner или её продолжении на Outer + pos: vec2(obj.loc.pos.x, self.rect.u(obj.loc.pos.y)), // в плоской СК для Inner или её продолжении на Outer rot: m * obj.loc.rot, }, r: obj.r, @@ -273,9 +272,8 @@ impl Space { .filter(|&(_, t)| t >= 0.0 && t < limit) .map(|(obj, t)| { let pos = ray.forward(t).pos; - let rel = obj.loc.rot.inverse() * (pos - obj.loc.pos); - let dir = obj.loc.rot.inverse() * ray.dir; - Hit { id: obj.id, distance: t, pos: globalize(pos), rel: Ray { pos: rel, dir } } + let rel = obj.loc.rot.inverse() * Ray { pos: pos - obj.loc.pos, dir: ray.dir }; + Hit { id: obj.id, distance: t, pos: globalize(pos), rel } }) .collect() } @@ -452,6 +450,14 @@ impl Ray { } } +impl std::ops::Mul for Mat2 { + type Output = Ray; + + fn mul(self, rhs: Ray) -> Self::Output { + Ray { pos: self * rhs.pos, dir: self * rhs.dir } + } +} + mod basic_shapes { use glam::{Vec2, vec2}; use crate::Ray;