Merge pull request #71 from nmfisher/develop

Allow finer control over input handling
This commit is contained in:
Nick Fisher
2024-10-24 15:56:11 +11:00
committed by GitHub
4 changed files with 24 additions and 15 deletions

View File

@@ -260,10 +260,10 @@ class DelegateInputHandler implements InputHandler {
} }
@override @override
Future<void> onScaleEnd(int pointerCount) async {} Future<void> onScaleEnd(int pointerCount, double velocity) async {}
@override @override
Future<void> onScaleStart(Vector2 localPosition, int pointerCount) async { Future<void> onScaleStart(Vector2 localPosition, int pointerCount, Duration? sourceTimestamp ) async {
// noop // noop
} }
@@ -276,7 +276,9 @@ class DelegateInputHandler implements InputHandler {
double horizontalScale, double horizontalScale,
double verticalScale, double verticalScale,
double scale, double scale,
int pointerCount) async { int pointerCount,
double rotation,
Duration? sourceTimestamp) async {
if (pointerCount == 1) { if (pointerCount == 1) {
_inputDeltas[InputType.SCALE1] = _inputDeltas[InputType.SCALE1] =
Vector3(focalPointDelta.x, focalPointDelta.y, 0); Vector3(focalPointDelta.x, focalPointDelta.y, 0);

View File

@@ -14,6 +14,9 @@ class FixedOrbitRotateInputHandlerDelegate implements InputHandlerDelegate {
late Future<Camera> _camera; late Future<Camera> _camera;
final double minimumDistance; final double minimumDistance;
late final Vector3 target; late final Vector3 target;
final double rotationSensitivity;
final double zoomSensitivity;
Vector2 _queuedRotationDelta = Vector2.zero(); Vector2 _queuedRotationDelta = Vector2.zero();
double _queuedZoomDelta = 0.0; double _queuedZoomDelta = 0.0;
@@ -24,6 +27,8 @@ class FixedOrbitRotateInputHandlerDelegate implements InputHandlerDelegate {
this.viewer, { this.viewer, {
Vector3? target, Vector3? target,
this.minimumDistance = 10.0, this.minimumDistance = 10.0,
this.rotationSensitivity = 0.01,
this.zoomSensitivity = 0.1,
}) { }) {
this.target = target ?? Vector3.zero(); this.target = target ?? Vector3.zero();
_camera = viewer.getMainCamera().then((Camera cam) async { _camera = viewer.getMainCamera().then((Camera cam) async {
@@ -95,7 +100,7 @@ class FixedOrbitRotateInputHandlerDelegate implements InputHandlerDelegate {
// Zoom // Zoom
if (_queuedZoomDelta != 0.0) { if (_queuedZoomDelta != 0.0) {
var newPosition = currentPosition + var newPosition = currentPosition +
(currentPosition - target).scaled(_queuedZoomDelta * 0.1); (currentPosition - target).scaled(_queuedZoomDelta * zoomSensitivity);
var distToTarget = (newPosition - target).length; var distToTarget = (newPosition - target).length;
@@ -113,8 +118,8 @@ class FixedOrbitRotateInputHandlerDelegate implements InputHandlerDelegate {
await (await _camera).setModelMatrix(newViewMatrix); await (await _camera).setModelMatrix(newViewMatrix);
} }
} else if (_queuedRotationDelta.length != 0) { } else if (_queuedRotationDelta.length != 0) {
double rotateX = _queuedRotationDelta.x * 0.01; double rotateX = _queuedRotationDelta.x * rotationSensitivity;
double rotateY = _queuedRotationDelta.y * 0.01; double rotateY = _queuedRotationDelta.y * rotationSensitivity;
var modelMatrix = await viewer.getCameraModelMatrix(); var modelMatrix = await viewer.getCameraModelMatrix();
@@ -126,9 +131,8 @@ class FixedOrbitRotateInputHandlerDelegate implements InputHandlerDelegate {
var rot2 = Matrix4.identity() var rot2 = Matrix4.identity()
..setRotation(Quaternion.axisAngle(modelMatrix.right, rotateY) ..setRotation(Quaternion.axisAngle(modelMatrix.right, rotateY)
.asRotationMatrix()); .asRotationMatrix());
modelMatrix = rot1 * modelMatrix = rot1 * rot2 * modelMatrix;
rot2 * modelMatrix;
await (await _camera).setModelMatrix(modelMatrix); await (await _camera).setModelMatrix(modelMatrix);
} }

View File

@@ -14,6 +14,7 @@ enum InputType {
MMB_HOVER, MMB_HOVER,
SCALE1, SCALE1,
SCALE2, SCALE2,
SCALE2_ROTATE,
SCROLLWHEEL, SCROLLWHEEL,
POINTER_MOVE, POINTER_MOVE,
KEYDOWN_W, KEYDOWN_W,
@@ -35,9 +36,9 @@ abstract class InputHandler {
Future<void> onPointerMove( Future<void> onPointerMove(
Vector2 localPosition, Vector2 delta, bool isMiddle); Vector2 localPosition, Vector2 delta, bool isMiddle);
Future<void> onPointerUp(bool isMiddle); Future<void> onPointerUp(bool isMiddle);
Future<void> onScaleStart(Vector2 focalPoint, int pointerCount); Future<void> onScaleStart(Vector2 focalPoint, int pointerCount, Duration? sourceTimestamp);
Future<void> onScaleUpdate(Vector2 focalPoint, Vector2 focalPointDelta, double horizontalScale, double verticalScale, double scale, int pointerCount); Future<void> onScaleUpdate(Vector2 focalPoint, Vector2 focalPointDelta, double horizontalScale, double verticalScale, double scale, int pointerCount, double rotation, Duration? sourceTimestamp);
Future<void> onScaleEnd(int pointerCount); Future<void> onScaleEnd(int pointerCount, double velocity);
Future<bool> get initialized; Future<bool> get initialized;
Future dispose(); Future dispose();

View File

@@ -165,7 +165,7 @@ class _MobileListenerWidgetState extends State<_MobileListenerWidget> {
}, },
onScaleStart: (details) async { onScaleStart: (details) async {
await widget.inputHandler.onScaleStart( await widget.inputHandler.onScaleStart(
details.localFocalPoint.toVector2(), details.pointerCount); details.localFocalPoint.toVector2(), details.pointerCount, details.sourceTimeStamp);
}, },
onScaleUpdate: (ScaleUpdateDetails details) async { onScaleUpdate: (ScaleUpdateDetails details) async {
await widget.inputHandler.onScaleUpdate( await widget.inputHandler.onScaleUpdate(
@@ -174,10 +174,12 @@ class _MobileListenerWidgetState extends State<_MobileListenerWidget> {
details.horizontalScale, details.horizontalScale,
details.verticalScale, details.verticalScale,
details.scale, details.scale,
details.pointerCount); details.pointerCount,
details.rotation,
details.sourceTimeStamp);
}, },
onScaleEnd: (details) async { onScaleEnd: (details) async {
await widget.inputHandler.onScaleEnd(details.pointerCount); await widget.inputHandler.onScaleEnd(details.pointerCount, details.scaleVelocity);
}, },
child: widget.child); child: widget.child);
} }