Use unified coordinate handling as unified
This commit is contained in:
parent
b9cf26701c
commit
08dba8e1dd
|
|
@ -60,12 +60,8 @@ impl Space {
|
||||||
let inner = Rect { size: vec2(self.tube.inner_radius, self.tube.internal_halflength) };
|
let inner = Rect { size: vec2(self.tube.inner_radius, self.tube.internal_halflength) };
|
||||||
let ray = cs.global_to_flat(ray);
|
let ray = cs.global_to_flat(ray);
|
||||||
assert!(inner.is_inside(ray.pos));
|
assert!(inner.is_inside(ray.pos));
|
||||||
let dist = inner.trace_out_of(ray).expect("Can't get outta here!");
|
let dist = inner.trace_out_of(ray);
|
||||||
let objs = self.list_objects(|loc| cs.global_to_flat(loc));
|
self.trace_flat(cs, ray, dist)
|
||||||
FlatTraceResult {
|
|
||||||
end: Some(cs.flat_to_global(ray.forward(dist))),
|
|
||||||
objects: Self::hit_objects(objs.as_slice(), ray, Some(dist), |pos| cs.flat_to_global(pos)),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn trace_outer(&self, ray: Ray) -> FlatTraceResult {
|
pub fn trace_outer(&self, ray: Ray) -> FlatTraceResult {
|
||||||
|
|
@ -73,10 +69,14 @@ impl Space {
|
||||||
let cs = OuterCS(self.tube);
|
let cs = OuterCS(self.tube);
|
||||||
let outer = Rect { size: vec2(self.tube.outer_radius, self.tube.external_halflength) };
|
let outer = Rect { size: vec2(self.tube.outer_radius, self.tube.external_halflength) };
|
||||||
let dist = outer.trace_into(ray);
|
let dist = outer.trace_into(ray);
|
||||||
|
self.trace_flat(cs, ray, dist)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn trace_flat(&self, cs: impl FlatCoordinateSystem<Vec2> + FlatCoordinateSystem<Ray> + FlatCoordinateSystem<Location>, ray: Ray, dist: Option<f32>) -> FlatTraceResult {
|
||||||
let objs = self.list_objects(|loc| cs.global_to_flat(loc));
|
let objs = self.list_objects(|loc| cs.global_to_flat(loc));
|
||||||
FlatTraceResult {
|
FlatTraceResult {
|
||||||
end: dist.map(|dist| ray.forward(dist)),
|
end: dist.map(|dist| cs.flat_to_global(ray.forward(dist))),
|
||||||
objects: Self::hit_objects(objs.as_slice(), ray, dist, |pos| pos),
|
objects: Self::hit_objects(objs.as_slice(), ray, dist, |pos| cs.flat_to_global(pos)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -196,8 +196,8 @@ mod coords {
|
||||||
use super::{Rect, Tube};
|
use super::{Rect, Tube};
|
||||||
|
|
||||||
pub trait FlatCoordinateSystem<T> {
|
pub trait FlatCoordinateSystem<T> {
|
||||||
fn flat_to_global(&self, v: T) -> T;
|
fn flat_to_global(&self, v: T) -> T { v }
|
||||||
fn global_to_flat(&self, v: T) -> T;
|
fn global_to_flat(&self, v: T) -> T { v }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct InnerCS(pub Tube);
|
pub struct InnerCS(pub Tube);
|
||||||
|
|
@ -243,6 +243,10 @@ mod coords {
|
||||||
|
|
||||||
pub struct OuterCS(pub Tube);
|
pub struct OuterCS(pub Tube);
|
||||||
|
|
||||||
|
impl FlatCoordinateSystem<Vec2> for OuterCS {}
|
||||||
|
|
||||||
|
impl FlatCoordinateSystem<Ray> for OuterCS {}
|
||||||
|
|
||||||
impl FlatCoordinateSystem<Location> for OuterCS {
|
impl FlatCoordinateSystem<Location> for OuterCS {
|
||||||
fn flat_to_global(&self, loc: Location) -> Location {
|
fn flat_to_global(&self, loc: Location) -> Location {
|
||||||
todo!()
|
todo!()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user