mirror of https://github.com/espruino/BangleApps
working on rotation
parent
1f76505f5f
commit
531d403ff3
|
@ -2,6 +2,9 @@
|
||||||
|
|
||||||
var lat = null;
|
var lat = null;
|
||||||
var lon = null;
|
var lon = null;
|
||||||
|
var direction = 0;
|
||||||
|
var cos_direction = Math.cos(direction);
|
||||||
|
var sin_direction = Math.sin(direction);
|
||||||
|
|
||||||
class Path {
|
class Path {
|
||||||
constructor(filename) {
|
constructor(filename) {
|
||||||
|
@ -63,11 +66,12 @@ class Point {
|
||||||
this.lon = lon;
|
this.lon = lon;
|
||||||
this.lat = lat;
|
this.lat = lat;
|
||||||
}
|
}
|
||||||
screen_x() {
|
coordinates() {
|
||||||
return 172/2 + Math.round((this.lon - lon) * 20000.0);
|
let x = (this.lon - lon) * 20000.0;
|
||||||
}
|
let y = (this.lat - lat) * 20000.0;
|
||||||
screen_y() {
|
let rotated_x = x*cos_direction - y*sin_direction;
|
||||||
return 172/2 + Math.round((this.lat - lat) * 20000.0);
|
let rotated_y = x*sin_direction + y*cos_direction;
|
||||||
|
return [g.getWidth()/2 + Math.round(rotated_x), g.getHeight()/2 + Math.round(rotated_y)];
|
||||||
}
|
}
|
||||||
minus(other_point) {
|
minus(other_point) {
|
||||||
let xdiff = this.lon - other_point.lon;
|
let xdiff = this.lon - other_point.lon;
|
||||||
|
@ -139,23 +143,20 @@ function display(path) {
|
||||||
let start = Math.max(current_segment - 5, 0);
|
let start = Math.max(current_segment - 5, 0);
|
||||||
let end = Math.min(current_segment + 7, path.len-1);
|
let end = Math.min(current_segment + 7, path.len-1);
|
||||||
path.on_segments(function(p1, p2, i) {
|
path.on_segments(function(p1, p2, i) {
|
||||||
let px = p2.screen_x();
|
let c2 = p2.coordinates();
|
||||||
let py = p2.screen_y();
|
|
||||||
if (i == current_segment + 1) {
|
if (i == current_segment + 1) {
|
||||||
g.setColor(0.0, 1.0, 0.0);
|
g.setColor(0.0, 1.0, 0.0);
|
||||||
} else {
|
} else {
|
||||||
g.setColor(1.0, 0.0, 0.0);
|
g.setColor(1.0, 0.0, 0.0);
|
||||||
}
|
}
|
||||||
|
let c1 = p1.coordinates();
|
||||||
g.drawLine(
|
g.drawLine(
|
||||||
p1.screen_x(),
|
c1[0], c1[1], c2[0], c2[1]
|
||||||
p1.screen_y(),
|
|
||||||
px,
|
|
||||||
py
|
|
||||||
);
|
);
|
||||||
g.setColor(g.theme.fg);
|
g.setColor(g.theme.fg);
|
||||||
g.fillCircle(px, py, 4);
|
g.fillCircle(c2[0], c2[1], 4);
|
||||||
g.setColor(g.theme.bg);
|
g.setColor(g.theme.bg);
|
||||||
g.fillCircle(px, py, 3);
|
g.fillCircle(c2[0], c2[1], 3);
|
||||||
}, 0, path.len-1);
|
}, 0, path.len-1);
|
||||||
|
|
||||||
g.setColor(g.theme.fgH);
|
g.setColor(g.theme.fgH);
|
||||||
|
@ -173,37 +174,43 @@ let path = new Path("test.gpc");
|
||||||
var current_segment = path.nearest_segment(new Point(lon, lat), 0, path.len-1);
|
var current_segment = path.nearest_segment(new Point(lon, lat), 0, path.len-1);
|
||||||
var remaining_distance = path.total_distance - path.segments_length(0, 1);
|
var remaining_distance = path.total_distance - path.segments_length(0, 1);
|
||||||
|
|
||||||
// let fake_gps_point = 0.0;
|
let fake_gps_point = 0.0;
|
||||||
// function simulate_gps(path) {
|
function simulate_gps(path) {
|
||||||
// let point_index = Math.floor(fake_gps_point);
|
let point_index = Math.floor(fake_gps_point);
|
||||||
// if (point_index >= path.len) {
|
if (point_index >= path.len) {
|
||||||
// return;
|
return;
|
||||||
|
}
|
||||||
|
let p1 = path.point(point_index);
|
||||||
|
let p2 = path.point(point_index+1);
|
||||||
|
let alpha = fake_gps_point - point_index;
|
||||||
|
|
||||||
|
let old_lon = lon;
|
||||||
|
let old_lat = lat;
|
||||||
|
lon = (1-alpha)*p1.lon + alpha*p2.lon;
|
||||||
|
lat = (1-alpha)*p1.lat + alpha*p2.lat;
|
||||||
|
fake_gps_point += 0.2;
|
||||||
|
direction = Math.atan2(lat-old_lat, lon-old_lon);
|
||||||
|
direction = 0.0;
|
||||||
|
cos_direction = Math.cos(direction);
|
||||||
|
sin_direction = Math.sin(direction);
|
||||||
|
display(path);
|
||||||
|
}
|
||||||
|
|
||||||
|
setInterval(simulate_gps, 500, path);
|
||||||
|
|
||||||
|
|
||||||
|
// function set_coordinates(data) {
|
||||||
|
// let old_lat = lat;
|
||||||
|
// if (!isNaN(data.lat)) {
|
||||||
|
// lat = data.lat;
|
||||||
// }
|
// }
|
||||||
// let p1 = path.point(point_index);
|
// let old_lon = lon;
|
||||||
// let p2 = path.point(point_index+1);
|
// if (!isNaN(data.lon)) {
|
||||||
// let alpha = fake_gps_point - point_index;
|
// lon = data.lon;
|
||||||
//
|
// }
|
||||||
// lon = (1-alpha)*p1.lon + alpha*p2.lon;
|
// if ((old_lat != lat)||(old_lon != lon)) {
|
||||||
// lat = (1-alpha)*p1.lat + alpha*p2.lat;
|
|
||||||
// fake_gps_point += 0.2;
|
|
||||||
// display(path);
|
// display(path);
|
||||||
// }
|
// }
|
||||||
//
|
// }
|
||||||
// setInterval(simulate_gps, 500, path);
|
// Bangle.setGPSPower(true, "gipy");
|
||||||
|
// Bangle.on('GPS', set_coordinates);
|
||||||
|
|
||||||
function set_coordinates(data) {
|
|
||||||
let old_lat = lat;
|
|
||||||
if (!isNaN(data.lat)) {
|
|
||||||
lat = data.lat;
|
|
||||||
}
|
|
||||||
let old_lon = lon;
|
|
||||||
if (!isNaN(data.lon)) {
|
|
||||||
lon = data.lon;
|
|
||||||
}
|
|
||||||
if ((old_lat != lat)||(old_lon != lon)) {
|
|
||||||
display(path);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Bangle.setGPSPower(true, "gipy");
|
|
||||||
Bangle.on('GPS', set_coordinates);
|
|
||||||
|
|
Loading…
Reference in New Issue