Skip to content

Commit

Permalink
Fix rotation when the sensor is not available
Browse files Browse the repository at this point in the history
  • Loading branch information
zesage committed Apr 16, 2021
1 parent a9a83f9 commit 30ab817
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions lib/panorama.dart
Original file line number Diff line number Diff line change
Expand Up @@ -270,15 +270,13 @@ class _PanoramaState extends State<Panorama> 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:
Expand Down Expand Up @@ -319,7 +317,7 @@ class _PanoramaState extends State<Panorama> with SingleTickerProviderStateMixin
surface = Object(name: 'surface', mesh: mesh, backfaceCulling: false);
_loadTexture(widget.child!.image);
scene.world.add(surface!);
WidgetsBinding.instance!.addPostFrameCallback((_) => _updateView());
_updateView();
}
}

Expand All @@ -346,7 +344,7 @@ class _PanoramaState extends State<Panorama> 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(
Expand Down Expand Up @@ -394,7 +392,7 @@ class _PanoramaState extends State<Panorama> 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
Expand Down

0 comments on commit 30ab817

Please sign in to comment.