Browse Source

PinchInput.fractionDelta

dsehnal 3 years ago
parent
commit
8efd943c2b
2 changed files with 12 additions and 7 deletions
  1. 3 3
      src/mol-canvas3d/controls/trackball.ts
  2. 9 4
      src/mol-util/input/input-observer.ts

+ 3 - 3
src/mol-canvas3d/controls/trackball.ts

@@ -409,16 +409,16 @@ namespace TrackballControls {
             }
         }
 
-        function onPinch({ fraction, buttons, modifiers }: PinchInput) {
+        function onPinch({ fractionDelta, buttons, modifiers }: PinchInput) {
             if (Binding.match(p.bindings.scrollZoom, buttons, modifiers)) {
                 _isInteracting = true;
-                _zoomEnd[1] += (fraction - 1) * 0.1;
+                _zoomEnd[1] += p.gestureScaleFactor * fractionDelta;
             }
         }
 
         function onGesture({ deltaScale }: GestureInput) {
             _isInteracting = true;
-            _zoomEnd[1] -= p.gestureScaleFactor * deltaScale;
+            _zoomEnd[1] += p.gestureScaleFactor * deltaScale;
         }
 
         function dispose() {

+ 9 - 4
src/mol-util/input/input-observer.ts

@@ -168,6 +168,7 @@ export type MoveInput = {
 export type PinchInput = {
     delta: number,
     fraction: number,
+    fractionDelta: number,
     distance: number,
     isStart: boolean
 } & BaseInput
@@ -277,7 +278,7 @@ namespace InputObserver {
         let width = element.clientWidth * pixelRatio();
         let height = element.clientHeight * pixelRatio();
 
-        let lastTouchDistance = 0;
+        let lastTouchDistance = 0, lastTouchFraction = 0;
         const pointerDown = Vec2();
         const pointerStart = Vec2();
         const pointerEnd = Vec2();
@@ -470,6 +471,7 @@ namespace InputObserver {
                 pinch.next({
                     distance: touchDistance,
                     fraction: 1,
+                    fractionDelta: 0,
                     delta: 0,
                     isStart: true,
                     buttons,
@@ -510,15 +512,18 @@ namespace InputObserver {
                 } else {
                     buttons = ButtonsType.Flag.Auxilary;
                     updateModifierKeys(ev);
+                    const fraction = lastTouchDistance / touchDistance;
                     pinch.next({
                         delta: touchDelta,
-                        fraction: lastTouchDistance / touchDistance,
+                        fraction,
+                        fractionDelta: lastTouchFraction - fraction,
                         distance: touchDistance,
                         isStart: false,
                         buttons,
                         button,
                         modifiers: getModifierKeys()
                     });
+                    lastTouchFraction = fraction;
                 }
                 lastTouchDistance = touchDistance;
             } else if (ev.touches.length === 3) {
@@ -646,8 +651,8 @@ namespace InputObserver {
             gesture.next({
                 scale: ev.scale,
                 rotation: ev.rotation,
-                deltaRotation: ev.rotation - prevGestureRotation,
-                deltaScale: ev.scale - prevGestureScale,
+                deltaRotation: prevGestureRotation - ev.rotation,
+                deltaScale: prevGestureScale - ev.scale,
                 isEnd
             });
             prevGestureRotation = ev.rotation;