From 30ab817ee1fb815f3ce8ccc581fe0daa3a071d3d Mon Sep 17 00:00:00 2001 From: Mark Hu Date: Fri, 16 Apr 2021 11:25:16 +0800 Subject: [PATCH] Fix rotation when the sensor is not available --- lib/panorama.dart | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/lib/panorama.dart b/lib/panorama.dart index 512af8a..5678acc 100644 --- a/lib/panorama.dart +++ b/lib/panorama.dart @@ -270,15 +270,13 @@ class _PanoramaState extends State with SingleTickerProviderStateMixin case SensorControl.Orientation: motionSensors.orientationUpdateInterval = Duration.microsecondsPerSecond ~/ 60; _orientationSubscription = motionSensors.orientation.listen((OrientationEvent event) { - orientation.setFrom(Vector3(event.yaw, event.pitch, event.roll)); - _updateView(); + orientation.setValues(event.yaw, event.pitch, event.roll); }); break; case SensorControl.AbsoluteOrientation: motionSensors.absoluteOrientationUpdateInterval = Duration.microsecondsPerSecond ~/ 60; _orientationSubscription = motionSensors.absoluteOrientation.listen((AbsoluteOrientationEvent event) { - orientation.setFrom(Vector3(event.yaw, event.pitch, event.roll)); - _updateView(); + orientation.setValues(event.yaw, event.pitch, event.roll); }); break; default: @@ -319,7 +317,7 @@ class _PanoramaState extends State with SingleTickerProviderStateMixin surface = Object(name: 'surface', mesh: mesh, backfaceCulling: false); _loadTexture(widget.child!.image); scene.world.add(surface!); - WidgetsBinding.instance!.addPostFrameCallback((_) => _updateView()); + _updateView(); } } @@ -346,7 +344,7 @@ class _PanoramaState extends State with SingleTickerProviderStateMixin Vector3 positionFromLatLon(double lat, double lon) { // create projection matrix final Matrix4 m = scene!.camera.projectionMatrix * scene!.camera.lookAtMatrix * matrixFromLatLon(lat, lon); - // apply projection atrix + // apply projection matrix final Vector4 v = Vector4(0.0, 0.0, -_radius, 1.0)..applyMatrix4(m); // apply perspective division and transform NDC to the viewport coordinate return Vector3( @@ -394,7 +392,7 @@ class _PanoramaState extends State with SingleTickerProviderStateMixin _updateSensorControl(); _controller = AnimationController(duration: Duration(milliseconds: 60000), vsync: this)..addListener(_updateView); - if (widget.sensorControl == SensorControl.None && widget.animSpeed != 0) _controller.repeat(); + if (widget.sensorControl != SensorControl.None || widget.animSpeed != 0) _controller.repeat(); } @override