flock bearing on compass
This commit is contained in:
parent
82be1ba9e0
commit
ab5a918f2c
@ -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
|
||||
|
||||
19
main.py
19
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):
|
||||
|
||||
BIN
needle_to_flock.png
Normal file
BIN
needle_to_flock.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 3.8 KiB |
Loading…
Reference in New Issue
Block a user