Use the fancy functions

It is not as beautiful as it could be but... looks OK for now
This commit is contained in:
numzero 2024-05-27 19:44:28 +03:00
parent 355416764f
commit 6fd15f9422

View File

@ -130,15 +130,14 @@ fn draw_ray_2(gc: &mut Vec<Draw>, space: &Space, base: Vec2, dir: Vec2) {
let dir = space.rect.globalize(base, dir); let dir = space.rect.globalize(base, dir);
gc.new_path(); gc.new_path();
gc.move_to(base.x, base.y); gc.move_to(base.x, base.y);
let mut p = base; let mut ray = Ray { pos: base, dir: space.rect.normalize_vec_at(base, dir) * DT };
let mut v = space.rect.normalize_vec_at(base, dir) * DT;
for _ in 0..10000 { for _ in 0..10000 {
Ray { pos: p, dir: v } = space.trace_step(Ray { pos: p, dir: v }); ray = space.trace_step(ray);
gc.line_to(p.x, p.y); gc.line_to(ray.pos.x, ray.pos.y);
if p.abs().cmpgt(Vec2::splat(1000.0)).any() { if ray.pos.abs().cmpgt(Vec2::splat(1000.0)).any() {
break; break;
} }
let sub = space.which_subspace(p); let sub = space.which_subspace(ray.pos);
if sub == Boundary { if sub == Boundary {
continue; continue;
} }
@ -146,31 +145,29 @@ fn draw_ray_2(gc: &mut Vec<Draw>, space: &Space, base: Vec2, dir: Vec2) {
gc.new_dash_pattern(); gc.new_dash_pattern();
gc.dash_length(6.0); gc.dash_length(6.0);
gc.new_path(); gc.new_path();
gc.move_to(p.x, p.y); gc.move_to(ray.pos.x, ray.pos.y);
match sub { match sub {
Inner => { Inner => {
let cell = RectInside { rect: space.rect }; ray = space.trace_inner(ray);
let ray = cell.ray_to_local(Ray { pos: p, dir: v });
let ray = cell.to_boundary(ray).expect("Can't get outta here!");
Ray { pos: p, dir: v } = cell.ray_to_global(ray);
} }
Outer => { Outer => {
let cell = basic_shapes::Rect { size: vec2(space.rect.outer_radius, space.rect.external_halflength) }; ray = match space.trace_outer(ray) {
let Some(dist) = cell.trace_into(Ray { pos: p, dir: v }) else { Some(r) => r,
p += v * (1000.0 / DT); None => {
gc.line_to(p.x, p.y); ray.pos += ray.dir * (1000.0 / DT);
gc.stroke(); gc.line_to(ray.pos.x, ray.pos.y);
break; gc.stroke();
break;
}
}; };
p += v * dist;
} }
Boundary => panic!(), Boundary => panic!(),
} }
gc.line_to(p.x, p.y); gc.line_to(ray.pos.x, ray.pos.y);
gc.stroke(); gc.stroke();
gc.new_dash_pattern(); gc.new_dash_pattern();
gc.new_path(); gc.new_path();
gc.move_to(p.x, p.y); gc.move_to(ray.pos.x, ray.pos.y);
} }
gc.stroke(); gc.stroke();
gc.new_dash_pattern(); gc.new_dash_pattern();