feat!: expose velocity, rotation and timestamp for scale events in listener. accept rotationSensitivity/zoomSensitivity for FixedOrbitRotateInputHandlerDelegate
This commit is contained in:
@@ -260,10 +260,10 @@ class DelegateInputHandler implements InputHandler {
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> onScaleEnd(int pointerCount) async {}
|
||||
Future<void> onScaleEnd(int pointerCount, double velocity) async {}
|
||||
|
||||
@override
|
||||
Future<void> onScaleStart(Vector2 localPosition, int pointerCount) async {
|
||||
Future<void> onScaleStart(Vector2 localPosition, int pointerCount, Duration? sourceTimestamp ) async {
|
||||
// noop
|
||||
}
|
||||
|
||||
@@ -276,7 +276,9 @@ class DelegateInputHandler implements InputHandler {
|
||||
double horizontalScale,
|
||||
double verticalScale,
|
||||
double scale,
|
||||
int pointerCount) async {
|
||||
int pointerCount,
|
||||
double rotation,
|
||||
Duration? sourceTimestamp) async {
|
||||
if (pointerCount == 1) {
|
||||
_inputDeltas[InputType.SCALE1] =
|
||||
Vector3(focalPointDelta.x, focalPointDelta.y, 0);
|
||||
|
||||
@@ -14,6 +14,9 @@ class FixedOrbitRotateInputHandlerDelegate implements InputHandlerDelegate {
|
||||
late Future<Camera> _camera;
|
||||
final double minimumDistance;
|
||||
late final Vector3 target;
|
||||
|
||||
final double rotationSensitivity;
|
||||
final double zoomSensitivity;
|
||||
|
||||
Vector2 _queuedRotationDelta = Vector2.zero();
|
||||
double _queuedZoomDelta = 0.0;
|
||||
@@ -24,6 +27,8 @@ class FixedOrbitRotateInputHandlerDelegate implements InputHandlerDelegate {
|
||||
this.viewer, {
|
||||
Vector3? target,
|
||||
this.minimumDistance = 10.0,
|
||||
this.rotationSensitivity = 0.01,
|
||||
this.zoomSensitivity = 0.1,
|
||||
}) {
|
||||
this.target = target ?? Vector3.zero();
|
||||
_camera = viewer.getMainCamera().then((Camera cam) async {
|
||||
@@ -95,7 +100,7 @@ class FixedOrbitRotateInputHandlerDelegate implements InputHandlerDelegate {
|
||||
// Zoom
|
||||
if (_queuedZoomDelta != 0.0) {
|
||||
var newPosition = currentPosition +
|
||||
(currentPosition - target).scaled(_queuedZoomDelta * 0.1);
|
||||
(currentPosition - target).scaled(_queuedZoomDelta * zoomSensitivity);
|
||||
|
||||
var distToTarget = (newPosition - target).length;
|
||||
|
||||
@@ -113,8 +118,8 @@ class FixedOrbitRotateInputHandlerDelegate implements InputHandlerDelegate {
|
||||
await (await _camera).setModelMatrix(newViewMatrix);
|
||||
}
|
||||
} else if (_queuedRotationDelta.length != 0) {
|
||||
double rotateX = _queuedRotationDelta.x * 0.01;
|
||||
double rotateY = _queuedRotationDelta.y * 0.01;
|
||||
double rotateX = _queuedRotationDelta.x * rotationSensitivity;
|
||||
double rotateY = _queuedRotationDelta.y * rotationSensitivity;
|
||||
|
||||
var modelMatrix = await viewer.getCameraModelMatrix();
|
||||
|
||||
@@ -126,9 +131,8 @@ class FixedOrbitRotateInputHandlerDelegate implements InputHandlerDelegate {
|
||||
var rot2 = Matrix4.identity()
|
||||
..setRotation(Quaternion.axisAngle(modelMatrix.right, rotateY)
|
||||
.asRotationMatrix());
|
||||
|
||||
modelMatrix = rot1 *
|
||||
rot2 * modelMatrix;
|
||||
|
||||
modelMatrix = rot1 * rot2 * modelMatrix;
|
||||
await (await _camera).setModelMatrix(modelMatrix);
|
||||
}
|
||||
|
||||
|
||||
@@ -35,9 +35,9 @@ abstract class InputHandler {
|
||||
Future<void> onPointerMove(
|
||||
Vector2 localPosition, Vector2 delta, bool isMiddle);
|
||||
Future<void> onPointerUp(bool isMiddle);
|
||||
Future<void> onScaleStart(Vector2 focalPoint, int pointerCount);
|
||||
Future<void> onScaleUpdate(Vector2 focalPoint, Vector2 focalPointDelta, double horizontalScale, double verticalScale, double scale, int pointerCount);
|
||||
Future<void> onScaleEnd(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, double rotation, Duration? sourceTimestamp);
|
||||
Future<void> onScaleEnd(int pointerCount, double velocity);
|
||||
Future<bool> get initialized;
|
||||
Future dispose();
|
||||
|
||||
|
||||
@@ -165,7 +165,7 @@ class _MobileListenerWidgetState extends State<_MobileListenerWidget> {
|
||||
},
|
||||
onScaleStart: (details) async {
|
||||
await widget.inputHandler.onScaleStart(
|
||||
details.localFocalPoint.toVector2(), details.pointerCount);
|
||||
details.localFocalPoint.toVector2(), details.pointerCount, details.sourceTimeStamp);
|
||||
},
|
||||
onScaleUpdate: (ScaleUpdateDetails details) async {
|
||||
await widget.inputHandler.onScaleUpdate(
|
||||
@@ -174,10 +174,12 @@ class _MobileListenerWidgetState extends State<_MobileListenerWidget> {
|
||||
details.horizontalScale,
|
||||
details.verticalScale,
|
||||
details.scale,
|
||||
details.pointerCount);
|
||||
details.pointerCount,
|
||||
details.rotation,
|
||||
details.sourceTimeStamp);
|
||||
},
|
||||
onScaleEnd: (details) async {
|
||||
await widget.inputHandler.onScaleEnd(details.pointerCount);
|
||||
await widget.inputHandler.onScaleEnd(details.pointerCount, details.scaleVelocity);
|
||||
},
|
||||
child: widget.child);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user