From 8ec64bb1b08fc33ebbaba41d391533d9ece56cef Mon Sep 17 00:00:00 2001 From: Daniel Barlow Date: Sun, 8 Jun 2025 17:59:46 +0100 Subject: [PATCH] rotate the map to face direction of travel there is a bit of smoothing so it does not instantly lurch to the new new course, as the visual effect was quite jarring --- pkgs/maps/main.fnl | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/pkgs/maps/main.fnl b/pkgs/maps/main.fnl index d4089bb..ad4598c 100644 --- a/pkgs/maps/main.fnl +++ b/pkgs/maps/main.fnl @@ -65,7 +65,8 @@ label.readout { :lat 49 :lon 0 :zoom 17 - :course 22 + :course 0 + :smooth-course 0 } ) @@ -253,6 +254,10 @@ label.readout { bounds.pixels.y) (draw-onto-map-surface bounds app-state.zoom))))) + (g:translate (+ (/ viewport-width 2)) (+ (/ viewport-height 2))) + (g:rotate (* (/ (- 360 app-state.smooth-course) 180) math.pi)) + (g:translate (- (/ viewport-width 2)) (- (/ viewport-height 2))) + (g:set_source_surface map-surface (- offset-x) (- offset-y)) (g:set_operator cairo.Operator.SOURCE) (g:rectangle 0 0 viewport-width viewport-height) @@ -293,9 +298,6 @@ label.readout { (expect= (hhmmss (+ 45 (* 60 12) (* 60 60 3))) "3:12:45") - - - (fn update-app-state [new-vals] (let [old-bounds (map-bounds app-state.lat app-state.lon app-state.zoom)] @@ -306,6 +308,9 @@ label.readout { (not (= old-bounds.min.x bounds.min.x)) (not (= old-bounds.min.y bounds.min.y))) (set map-surface nil))) + (set app-state.smooth-course + (+ app-state.smooth-course + (* 0.05 (- app-state.course app-state.smooth-course)))) (each [name widget (pairs state-widgets)] (case name :speed (widget:set_label @@ -340,7 +345,8 @@ 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 180) math.pi)) + (g:rotate (* (/ (- app-state.course app-state.smooth-course) + 180) math.pi)) (g:translate (// height -2) (// height -2)) (g:set_line_width 4) (g:move_to 10 height) @@ -393,7 +399,11 @@ label.readout { GLib.PRIORITY_DEFAULT 20 ; ms (fn [] + ;; run cqueues scheduler (cq:step 0) + ;; for smoother rotation when course changes, repaint more often than + ;; once per gnss message + (update-app-state {}) true) nil nil)