revamping fork math

This commit is contained in:
Dustin Carlino 2019-01-23 17:15:34 -08:00
parent a25f358295
commit 8d270574ec
4 changed files with 24 additions and 28 deletions

View File

@ -66,8 +66,7 @@
## Switch to OpenGL (for speed)
- no bugs
- forking is buggy (traffic signal diagram)
- arrows
- arrows... then debug legend
- top menu rectangles are slightly off; grab the " " glyph's width?
- some colors are wrong
- ContextBuilder has with_pixel_format and with_srgb

View File

@ -42,14 +42,8 @@ impl Plugin for Legend {
}
fn draw(&self, g: &mut GfxCtx, ctx: &Ctx) {
// TODO The negation and reasoning about the zoom is annoying. I want to say something like
// "Make top_left the origin, zoom 10."
let zoom = 10.0;
g.fork(
Pt2D::new(-self.top_left.x / zoom, -self.top_left.y / zoom),
zoom,
&ctx.canvas,
);
g.fork(Pt2D::new(0.0, 0.0), self.top_left, zoom, &ctx.canvas);
// Create a fake turn.
let mut turn = Turn {
@ -60,6 +54,8 @@ impl Plugin for Legend {
},
turn_type: TurnType::Straight,
lookup_idx: 0,
// TODO Do we need to zoom here at all? For the arrows, sadly. Annoying to express the
// fake geometry in terms of zoom, but oh well.
geom: PolyLine::new(vec![
Pt2D::new(10.0 / zoom, 10.0 / zoom),
Pt2D::new(10.0 / zoom, 100.0 / zoom),

View File

@ -353,27 +353,15 @@ pub fn draw_signal_diagram(
);
for (idx, (txt, cycle)) in labels.into_iter().zip(cycles.iter()).enumerate() {
// TODO API for "make this map pt be this screen pt"
g.fork(
Pt2D::new(
top_left.x() - (x1_screen / zoom),
top_left.y()
- (y1_screen / zoom)
- intersection_height * (idx as f64)
- padding * ((idx as f64) + 1.0),
),
zoom,
&ctx.canvas,
);
let y1 = y1_screen + (padding + intersection_height) * (idx as f64) * zoom;
g.fork(top_left, ScreenPt::new(x1_screen, y1), zoom, &ctx.canvas);
draw_signal_cycle(&cycle, g, ctx);
ctx.canvas.draw_text_at_screenspace_topleft(
g,
txt,
ScreenPt::new(
x1_screen + 10.0 + (intersection_width * zoom),
y1_screen + (padding + intersection_height) * (idx as f64) * zoom,
),
ScreenPt::new(x1_screen + 10.0 + (intersection_width * zoom), y1),
);
}

View File

@ -130,15 +130,28 @@ impl<'a> GfxCtx<'a> {
// Up to the caller to call unfork()!
// TODO Canvas doesn't understand this change, so things like text drawing that use
// map_to_screen will just be confusing.
pub fn fork(&mut self, top_left: Pt2D, zoom: f64, canvas: &Canvas) {
pub fn fork(
&mut self,
top_left_map: Pt2D,
top_left_screen: ScreenPt,
zoom: f64,
canvas: &Canvas,
) {
// map_to_screen of top_left_map should be top_left_screen
let cam_x = (top_left_map.x() * zoom) - top_left_screen.x;
let cam_y = (top_left_map.y() * zoom) - top_left_screen.y;
self.uniforms = uniform! {
transform: [top_left.x() as f32, top_left.y() as f32, zoom as f32],
transform: [cam_x as f32, cam_y as f32, zoom as f32],
window: [canvas.window_width as f32, canvas.window_height as f32],
};
}
pub fn fork_screenspace(&mut self, canvas: &Canvas) {
self.fork(Pt2D::new(0.0, 0.0), 1.0, canvas)
self.uniforms = uniform! {
transform: [0.0, 0.0, 1.0],
window: [canvas.window_width as f32, canvas.window_height as f32],
};
}
pub fn unfork(&mut self, canvas: &Canvas) {