diff --git a/flockompass.kv b/flockompass.kv index 2bdca28..fbf016d 100644 --- a/flockompass.kv +++ b/flockompass.kv @@ -73,3 +73,14 @@ origin: self.center canvas.after: PopMatrix + Image: + id: to_flock + source: 'needle_to_flock.png' + canvas.before: + PushMatrix + Rotate: + angle: app.fbearing + axis: 0, 0, 1 + origin: self.center + canvas.after: + PopMatrix diff --git a/main.py b/main.py index f981d89..409d273 100644 --- a/main.py +++ b/main.py @@ -10,7 +10,7 @@ from kivy.uix.screenmanager import ScreenManager, Screen, RiseInTransition from kivy.vector import Vector from kivy.animation import Animation -from math import floor +from math import atan2, sin, cos, degrees, floor class MapScreen(Screen): @@ -26,6 +26,7 @@ class FlockompassApp(App): gps_data = DictProperty() session_data = DictProperty() needle_angle = NumericProperty(0) + fbearing = NumericProperty(0) def dump(self, dt): print(dt, self.gps_data, self.session_data) @@ -68,6 +69,18 @@ class FlockompassApp(App): self.ms.ids.mapview.center_on(self.session_data['dest_lat'], self.session_data['dest_lon']) + else: + lat1 = self.gps_data['lat'] + lon1 = self.gps_data['lon'] + + lat2 = self.session_data['dest_lat'] + lon2 = self.session_data['dest_lon'] + + self.fbearing = atan2(sin(lon2 - lon1) * cos(lat2), + cos(lat1) * sin(lat2) + - sin(lat1) * cos(lat2) * cos(lon2-lon1)) + self.fbearing = self.needle_angle + degrees(self.fbearing) + self.fbearing = (self.fbearing + 360) % 360 def get_field(self, dt): needle_angle = 7 @@ -88,7 +101,9 @@ class FlockompassApp(App): # animate the needle if self.cs._anim: self.cs._anim.stop(self) - self.cs._anim = Animation(needle_angle=needle_angle, d=.2, t='out_quad') + self.cs._anim = Animation(needle_angle=needle_angle, + d=0.2, + t='out_quad') self.cs._anim.start(self) def compass_enable(self): diff --git a/needle_to_flock.png b/needle_to_flock.png new file mode 100644 index 0000000..4c6d47d Binary files /dev/null and b/needle_to_flock.png differ