add sensor control

This commit is contained in:
Mark Hu 2020-06-14 20:15:09 +08:00
parent e1f856f963
commit 9da4d8f268
5 changed files with 41 additions and 17 deletions

View file

@ -35,7 +35,9 @@ class _MyHomePageState extends State<MyHomePage> {
title: Text(widget.title),
),
body: Panorama(
animSpeed: 2.0,
animSpeed: 0,
interactive: false,
sensorControl: SensorControl.Orientation,
child: _imageFile != null ? Image.file(_imageFile) : Image.asset('assets/panorama.jpg'),
),
floatingActionButton: FloatingActionButton(

View file

@ -109,6 +109,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.8"
motion_sensors:
dependency: transitive
description:
name: motion_sensors
url: "https://pub.dartlang.org"
source: hosted
version: "0.0.1"
panorama:
dependency: "direct main"
description:
@ -123,13 +130,6 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.6.4"
pedantic:
dependency: transitive
description:
name: pedantic
url: "https://pub.dartlang.org"
source: hosted
version: "1.8.0+1"
petitparser:
dependency: transitive
description:
@ -190,7 +190,7 @@ packages:
name: test_api
url: "https://pub.dartlang.org"
source: hosted
version: "0.2.11"
version: "0.2.15"
typed_data:
dependency: transitive
description:

View file

@ -5,6 +5,12 @@ import 'dart:ui' as ui;
import 'dart:math' as math;
import 'package:flutter/material.dart';
import 'package:flutter_cube/flutter_cube.dart';
import 'package:motion_sensors/motion_sensors.dart';
enum SensorControl {
None,
Orientation,
}
class Panorama extends StatefulWidget {
Panorama({
@ -24,6 +30,7 @@ class Panorama extends StatefulWidget {
this.latSegments = 32,
this.lonSegments = 64,
this.interactive = true,
this.sensorControl = SensorControl.None,
this.child,
}) : super(key: key);
@ -72,6 +79,9 @@ class Panorama extends StatefulWidget {
/// Interact with the panorama. default to true
final bool interactive;
/// Control the panorama with motion sensors.
final SensorControl sensorControl;
/// Specify an Image(equirectangular image) widget to the panorama.
final Image child;
@ -148,6 +158,16 @@ class _PanoramaState extends State<Panorama> with SingleTickerProviderStateMixin
latitude = widget.latitude;
longitude = widget.longitude;
if (widget.sensorControl == SensorControl.Orientation) {
motionSensors.orientation.listen((OrientationEvent event) {
Quaternion q = Quaternion.euler(-event.roll, event.pitch, event.yaw);
q *= Quaternion.axisAngle(Vector3(1, 0, 0), math.pi * 0.5);
q.rotate(scene.camera.target..setFrom(Vector3(0, 0, -_radius)));
q.rotate(scene.camera.up..setFrom(Vector3(0, 1, 0)));
scene.update();
});
}
_controller = AnimationController(duration: Duration(milliseconds: 60000), vsync: this)
..addListener(() {
if (scene == null) return;

View file

@ -95,6 +95,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.8"
motion_sensors:
dependency: "direct main"
description:
name: motion_sensors
url: "https://pub.dartlang.org"
source: hosted
version: "0.0.1"
path:
dependency: transitive
description:
@ -102,13 +109,6 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.6.4"
pedantic:
dependency: transitive
description:
name: pedantic
url: "https://pub.dartlang.org"
source: hosted
version: "1.8.0+1"
petitparser:
dependency: transitive
description:
@ -169,7 +169,7 @@ packages:
name: test_api
url: "https://pub.dartlang.org"
source: hosted
version: "0.2.11"
version: "0.2.15"
typed_data:
dependency: transitive
description:
@ -193,3 +193,4 @@ packages:
version: "3.5.0"
sdks:
dart: ">=2.4.0 <3.0.0"
flutter: ">=1.10.0"

View file

@ -10,6 +10,7 @@ dependencies:
flutter:
sdk: flutter
flutter_cube: ^0.0.3
motion_sensors: ^0.0.1
dev_dependencies:
flutter_test: