Fix rotation when the sensor is not available

This commit is contained in:
Mark Hu 2021-04-16 11:25:16 +08:00
parent a9a83f91ae
commit 30ab817ee1

View file

@ -270,15 +270,13 @@ class _PanoramaState extends State<Panorama> with SingleTickerProviderStateMixin
case SensorControl.Orientation: case SensorControl.Orientation:
motionSensors.orientationUpdateInterval = Duration.microsecondsPerSecond ~/ 60; motionSensors.orientationUpdateInterval = Duration.microsecondsPerSecond ~/ 60;
_orientationSubscription = motionSensors.orientation.listen((OrientationEvent event) { _orientationSubscription = motionSensors.orientation.listen((OrientationEvent event) {
orientation.setFrom(Vector3(event.yaw, event.pitch, event.roll)); orientation.setValues(event.yaw, event.pitch, event.roll);
_updateView();
}); });
break; break;
case SensorControl.AbsoluteOrientation: case SensorControl.AbsoluteOrientation:
motionSensors.absoluteOrientationUpdateInterval = Duration.microsecondsPerSecond ~/ 60; motionSensors.absoluteOrientationUpdateInterval = Duration.microsecondsPerSecond ~/ 60;
_orientationSubscription = motionSensors.absoluteOrientation.listen((AbsoluteOrientationEvent event) { _orientationSubscription = motionSensors.absoluteOrientation.listen((AbsoluteOrientationEvent event) {
orientation.setFrom(Vector3(event.yaw, event.pitch, event.roll)); orientation.setValues(event.yaw, event.pitch, event.roll);
_updateView();
}); });
break; break;
default: default:
@ -319,7 +317,7 @@ class _PanoramaState extends State<Panorama> with SingleTickerProviderStateMixin
surface = Object(name: 'surface', mesh: mesh, backfaceCulling: false); surface = Object(name: 'surface', mesh: mesh, backfaceCulling: false);
_loadTexture(widget.child!.image); _loadTexture(widget.child!.image);
scene.world.add(surface!); scene.world.add(surface!);
WidgetsBinding.instance!.addPostFrameCallback((_) => _updateView()); _updateView();
} }
} }
@ -346,7 +344,7 @@ class _PanoramaState extends State<Panorama> with SingleTickerProviderStateMixin
Vector3 positionFromLatLon(double lat, double lon) { Vector3 positionFromLatLon(double lat, double lon) {
// create projection matrix // create projection matrix
final Matrix4 m = scene!.camera.projectionMatrix * scene!.camera.lookAtMatrix * matrixFromLatLon(lat, lon); 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); final Vector4 v = Vector4(0.0, 0.0, -_radius, 1.0)..applyMatrix4(m);
// apply perspective division and transform NDC to the viewport coordinate // apply perspective division and transform NDC to the viewport coordinate
return Vector3( return Vector3(
@ -394,7 +392,7 @@ class _PanoramaState extends State<Panorama> with SingleTickerProviderStateMixin
_updateSensorControl(); _updateSensorControl();
_controller = AnimationController(duration: Duration(milliseconds: 60000), vsync: this)..addListener(_updateView); _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 @override