add sensor control
This commit is contained in:
parent
e1f856f963
commit
9da4d8f268
5 changed files with 41 additions and 17 deletions
|
|
@ -35,7 +35,9 @@ class _MyHomePageState extends State<MyHomePage> {
|
||||||
title: Text(widget.title),
|
title: Text(widget.title),
|
||||||
),
|
),
|
||||||
body: Panorama(
|
body: Panorama(
|
||||||
animSpeed: 2.0,
|
animSpeed: 0,
|
||||||
|
interactive: false,
|
||||||
|
sensorControl: SensorControl.Orientation,
|
||||||
child: _imageFile != null ? Image.file(_imageFile) : Image.asset('assets/panorama.jpg'),
|
child: _imageFile != null ? Image.file(_imageFile) : Image.asset('assets/panorama.jpg'),
|
||||||
),
|
),
|
||||||
floatingActionButton: FloatingActionButton(
|
floatingActionButton: FloatingActionButton(
|
||||||
|
|
|
||||||
|
|
@ -109,6 +109,13 @@ packages:
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.1.8"
|
version: "1.1.8"
|
||||||
|
motion_sensors:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: motion_sensors
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "0.0.1"
|
||||||
panorama:
|
panorama:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
|
|
@ -123,13 +130,6 @@ packages:
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.6.4"
|
version: "1.6.4"
|
||||||
pedantic:
|
|
||||||
dependency: transitive
|
|
||||||
description:
|
|
||||||
name: pedantic
|
|
||||||
url: "https://pub.dartlang.org"
|
|
||||||
source: hosted
|
|
||||||
version: "1.8.0+1"
|
|
||||||
petitparser:
|
petitparser:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
|
|
@ -190,7 +190,7 @@ packages:
|
||||||
name: test_api
|
name: test_api
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "0.2.11"
|
version: "0.2.15"
|
||||||
typed_data:
|
typed_data:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,12 @@ import 'dart:ui' as ui;
|
||||||
import 'dart:math' as math;
|
import 'dart:math' as math;
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_cube/flutter_cube.dart';
|
import 'package:flutter_cube/flutter_cube.dart';
|
||||||
|
import 'package:motion_sensors/motion_sensors.dart';
|
||||||
|
|
||||||
|
enum SensorControl {
|
||||||
|
None,
|
||||||
|
Orientation,
|
||||||
|
}
|
||||||
|
|
||||||
class Panorama extends StatefulWidget {
|
class Panorama extends StatefulWidget {
|
||||||
Panorama({
|
Panorama({
|
||||||
|
|
@ -24,6 +30,7 @@ class Panorama extends StatefulWidget {
|
||||||
this.latSegments = 32,
|
this.latSegments = 32,
|
||||||
this.lonSegments = 64,
|
this.lonSegments = 64,
|
||||||
this.interactive = true,
|
this.interactive = true,
|
||||||
|
this.sensorControl = SensorControl.None,
|
||||||
this.child,
|
this.child,
|
||||||
}) : super(key: key);
|
}) : super(key: key);
|
||||||
|
|
||||||
|
|
@ -72,6 +79,9 @@ class Panorama extends StatefulWidget {
|
||||||
/// Interact with the panorama. default to true
|
/// Interact with the panorama. default to true
|
||||||
final bool interactive;
|
final bool interactive;
|
||||||
|
|
||||||
|
/// Control the panorama with motion sensors.
|
||||||
|
final SensorControl sensorControl;
|
||||||
|
|
||||||
/// Specify an Image(equirectangular image) widget to the panorama.
|
/// Specify an Image(equirectangular image) widget to the panorama.
|
||||||
final Image child;
|
final Image child;
|
||||||
|
|
||||||
|
|
@ -148,6 +158,16 @@ class _PanoramaState extends State<Panorama> with SingleTickerProviderStateMixin
|
||||||
latitude = widget.latitude;
|
latitude = widget.latitude;
|
||||||
longitude = widget.longitude;
|
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)
|
_controller = AnimationController(duration: Duration(milliseconds: 60000), vsync: this)
|
||||||
..addListener(() {
|
..addListener(() {
|
||||||
if (scene == null) return;
|
if (scene == null) return;
|
||||||
|
|
|
||||||
17
pubspec.lock
17
pubspec.lock
|
|
@ -95,6 +95,13 @@ packages:
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.1.8"
|
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:
|
path:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
|
|
@ -102,13 +109,6 @@ packages:
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.6.4"
|
version: "1.6.4"
|
||||||
pedantic:
|
|
||||||
dependency: transitive
|
|
||||||
description:
|
|
||||||
name: pedantic
|
|
||||||
url: "https://pub.dartlang.org"
|
|
||||||
source: hosted
|
|
||||||
version: "1.8.0+1"
|
|
||||||
petitparser:
|
petitparser:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
|
|
@ -169,7 +169,7 @@ packages:
|
||||||
name: test_api
|
name: test_api
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "0.2.11"
|
version: "0.2.15"
|
||||||
typed_data:
|
typed_data:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
|
|
@ -193,3 +193,4 @@ packages:
|
||||||
version: "3.5.0"
|
version: "3.5.0"
|
||||||
sdks:
|
sdks:
|
||||||
dart: ">=2.4.0 <3.0.0"
|
dart: ">=2.4.0 <3.0.0"
|
||||||
|
flutter: ">=1.10.0"
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@ dependencies:
|
||||||
flutter:
|
flutter:
|
||||||
sdk: flutter
|
sdk: flutter
|
||||||
flutter_cube: ^0.0.3
|
flutter_cube: ^0.0.3
|
||||||
|
motion_sensors: ^0.0.1
|
||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
flutter_test:
|
flutter_test:
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue