From bcb6e31c4b2ef7956dead53ff3da9c0fedb2b094 Mon Sep 17 00:00:00 2001 From: Dooho Yi Date: Sat, 12 Oct 2024 19:16:25 +0900 Subject: [PATCH] a bugfix gps location algorithm.. --- index.html | 2 ++ js/classes.js | 4 ++-- js/util.js | 4 ++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/index.html b/index.html index 887c04b..62d3878 100644 --- a/index.html +++ b/index.html @@ -157,6 +157,8 @@ fill('white'); translate(30, 200, 0); Textline.restart(); + Textline.put('heading'); + Textline.put(heading); Textline.put('ang'); Textline.put(target.ang); Textline.put('angerr'); diff --git a/js/classes.js b/js/classes.js index ee7aca2..acd18ce 100644 --- a/js/classes.js +++ b/js/classes.js @@ -26,7 +26,7 @@ class Sounder { // // this.ang = getBearing(latitude, longitude, this.latitude, this.longitude); (deg) this.ang = getBearing(latitude, longitude, this.latitude, this.longitude); // (deg) - this.angerr = (((this.ang - heading + 360) % 360) + 180) % 360 - 180; + this.angerr = (heading - this.ang + 360) % 360; this.dist = getDistance(latitude, longitude, this.latitude, this.longitude); // (km) // this.distvol = map(this.dist, this.distmap[0], this.distmap[1], this.distmap[2], this.distmap[3], true); //(dB) @@ -106,7 +106,7 @@ class Compass { circle(0, 0, 0.9); // fill(this.colors[1]); - rotate(this.heading); + rotate(this.heading * -1); quad(0.1, 0.2, 0, -0.4, -0.1, 0.2, 0, 0.1); // fill(this.colors[2]); diff --git a/js/util.js b/js/util.js index d1c121b..87f585d 100644 --- a/js/util.js +++ b/js/util.js @@ -8,7 +8,7 @@ if (navigator.userAgent.match(/(iPod|iPhone|iPad)/)) { if (response == 'granted') { window.addEventListener("deviceorientation", (event) => { if (event.webkitCompassHeading) { - heading = event.webkitCompassHeading; + heading = (event.webkitCompassHeading + 180) % 360 - 180; // EAST == +90, WEST == -90 } }, true); } @@ -17,7 +17,7 @@ if (navigator.userAgent.match(/(iPod|iPhone|iPad)/)) { } } else { window.addEventListener("deviceorientationabsolute", (event) => { - heading = event.alpha * -1; + heading = ((360 - event.alpha) + 180) % 360 - 180; // EAST == +90, WEST == -90 }, true); }