From 7543e775e5cca09663c13b697418f4728ec13750 Mon Sep 17 00:00:00 2001 From: Daniel Barlow Date: Tue, 10 Jun 2025 13:12:19 +0100 Subject: [PATCH] repaint on orientation changes, rotate road names this is still not correct, but it's closer --- pkgs/maps/main.fnl | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/pkgs/maps/main.fnl b/pkgs/maps/main.fnl index 2a1183f..c725ee6 100644 --- a/pkgs/maps/main.fnl +++ b/pkgs/maps/main.fnl @@ -66,7 +66,7 @@ label.readout { :lon 0 :zoom 17 :course 0 ; direction of travel - :orientation 0 ; map rotation angle from north + :orientation {:target 0 :actual 0} ; map rotation angle from north :tiles {} } ) @@ -186,8 +186,10 @@ label.readout { (set biggest-n (- i 1))))) (let [[x y] (. points biggest-n) [nx ny] (. points (+ 1 biggest-n)) - angle (math.atan (- ny y) (- nx x))] - (if (> nx x) + angle (math.atan (- ny y) (- nx x)) + screen-angle (- angle + (/ (* app-state.orientation.target math.pi) 180))] + (if (< (math.abs screen-angle) (/ math.pi 2)) (values (* tile-size (- x bounds.min.x)) (* tile-size (- y bounds.min.y)) @@ -271,7 +273,7 @@ label.readout { (draw-onto-map-surface bounds app-state.zoom))))) (g:translate (+ (/ viewport-width 2)) (+ (/ viewport-height 2))) - (g:rotate (* (/ (- 360 app-state.orientation) 180) math.pi)) + (g:rotate (* (/ (- 360 app-state.orientation.actual) 180) math.pi)) (g:translate (- (/ viewport-width 2)) (- (/ viewport-height 2))) (g:set_source_surface map-surface (- offset-x) (- offset-y)) @@ -322,9 +324,15 @@ label.readout { (when (not (bounds= old-bounds bounds)) (fetch-tiles bounds app-state.tiles app-state.zoom) (set map-surface nil))) - (set app-state.orientation - (+ app-state.orientation - (* 0.05 (- app-state.course app-state.orientation)))) + (when (> (math.abs (- app-state.orientation.target app-state.course)) 20) + (set app-state.orientation.target app-state.course) + (set map-surface nil)) + + (when (not (= app-state.orientation.target app-state.orientation.actual)) + (set app-state.orientation.actual + (+ app-state.orientation.actual + (* 0.05 (- app-state.orientation.target app-state.orientation.actual))))) + (each [name widget (pairs state-widgets)] (case name :speed (widget:set_label @@ -359,7 +367,7 @@ label.readout { (fn [self g] (g:set_source_rgb 0.4 0.0 0.1) (g:translate (// height 2) (// height 2)) - (g:rotate (* (/ (- app-state.course app-state.orientation) + (g:rotate (* (/ (- app-state.course app-state.orientation.actual) 180) math.pi)) (g:translate (// height -2) (// height -2)) (g:set_line_width 4)