animate destination needle

This commit is contained in:
rgarcia-herrera 2020-08-11 20:37:56 -05:00
parent 3b62936b2a
commit f8f40bef55
4 changed files with 24 additions and 18 deletions

View File

@ -81,8 +81,8 @@
canvas.after:
PopMatrix
Image:
id: to_flock
source: 'needle_to_flock.png'
id: to_dest
source: 'needle_to_dest.png'
canvas.before:
PushMatrix
Rotate:

38
main.py
View File

@ -75,22 +75,9 @@ 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
self.dest_distance = "D: %0.1f km" % geodesic(
(self.gps_data['lat'], self.gps_data['lon']),
(self.session_data['dest_lat'], self.session_data['dest_lon'])).kilometers
print(self.dest_distance)
def center_map_on_gps(self):
self.ms.ids.mapview.center_on(self.gps_data['lat'],
@ -106,7 +93,7 @@ class FlockompassApp(App):
if self.cs.facade.field != (None, None, None):
x, y, z = self.cs.facade.field
smoothingFactor = 0.5
smoothingFactor = 0.88
angle = atan2(y, x)
self.last_angle = smoothingFactor * self.last_angle + (1 - smoothingFactor) * angle
@ -124,8 +111,26 @@ class FlockompassApp(App):
if self.cs._anim:
self.cs._anim.stop(self)
self.cs._anim = Animation(needle_angle=needle_angle,
d=0.2,
d=0.1,
t='out_quad')
lat1 = self.gps_data['lat']
lon1 = self.gps_data['lon']
lat2 = self.session_data['dest_lat']
lon2 = self.session_data['dest_lon']
fbearing = atan2(sin(lon2 - lon1) * cos(lat2),
cos(lat1) * sin(lat2)
- sin(lat1) * cos(lat2) * cos(lon2-lon1))
fbearing = self.needle_angle - degrees(fbearing)
fbearing = (fbearing + 360) % 360
self.cs._anim &= Animation(fbearing=fbearing,
d=0.1,
t='out_quad')
self.cs._anim.start(self)
def compass_enable(self):
@ -170,7 +175,8 @@ class FlockompassApp(App):
self.cs = CompassScreen(name='compass')
self.cs._anim = None
self.cs.p = None
self.cs._anim1 = None
screen_manager.add_widget(self.cs)
# smoothing vars for compass

View File

Before

Width:  |  Height:  |  Size: 3.6 KiB

After

Width:  |  Height:  |  Size: 3.6 KiB

View File

Before

Width:  |  Height:  |  Size: 7.4 KiB

After

Width:  |  Height:  |  Size: 7.4 KiB