Hit objects from different space regions

This commit is contained in:
numzero 2024-06-10 19:50:39 +03:00
parent 11e48580b9
commit 9ec5f17754

View File

@ -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<Object> {
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<Hit> {