From d008ea7224710e154a004df59752948fb4eae650 Mon Sep 17 00:00:00 2001 From: ztimson Date: Tue, 9 Jul 2019 16:59:24 -0400 Subject: [PATCH] fixed physics service --- src/app/physics/physics.service.ts | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/app/physics/physics.service.ts b/src/app/physics/physics.service.ts index e1298cc..9d328ed 100644 --- a/src/app/physics/physics.service.ts +++ b/src/app/physics/physics.service.ts @@ -24,7 +24,7 @@ export class PhysicsService { if (!this.motionTimestamp) return this.motionTimestamp = new Date().getTime(); let currentTime = new Date().getTime(); - let {speedX, speedY, speedZ} = this.speed.value; + let {speedX, speedY, speedZ} = this.speed.value || {speedX: 0, speedY: 0, speedZ: 0}; this.speed.next({ speedX: speedX + event.acceleration.x / 1000 * ((currentTime - this.motionTimestamp) / 1000) / 3600, speedY: speedY + event.acceleration.y / 1000 * ((currentTime - this.motionTimestamp) / 1000) / 3600, @@ -35,15 +35,22 @@ export class PhysicsService { // Combine data into one nice package combineLatest(this.position, this.orientation, this.speed).subscribe(data => { - this.info.next({ + if(!data[0]) return; + + let info = { accuracy: data[0].accuracy, altitude: data[0].altitude, altitudeAccuracy: data[0].altitudeAccuracy, - heading: data[0].heading || data[1].alpha, + heading: data[0].heading, latitude: data[0].latitude, longitude: data[0].longitude, - speed: data[0].speed || Math.sqrt(data[2].x**2 + data[2].y**2 + data[2].z**2), - }); + speed: data[0].speed + }; + + if(info.heading == null && !!data[1]) info.heading = data[1].alpha; + if(info.speed == null && !!data[2]) info.speed = Math.sqrt(data[2].x**2 + data[2].y**2 + data[2].z**2); + + this.info.next(info); }) } }