From 9d2ebc9ae096be0377e7f0979504761b971bad73 Mon Sep 17 00:00:00 2001
From: johnshaughnessy <johnfshaughnessy@gmail.com>
Date: Mon, 22 Oct 2018 15:22:55 -0700
Subject: [PATCH] Remove pinch-to-move and replace it with a binding.

---
 src/components/character-controller.js          |  7 ++++++-
 src/components/virtual-gamepad-controls.js      |  2 +-
 src/hub.html                                    |  1 -
 .../userinput/bindings/touchscreen-user.js      | 17 +++++++++++++++++
 .../userinput/devices/app-aware-touchscreen.js  | 14 ++++++--------
 src/systems/userinput/paths.js                  |  7 ++++---
 6 files changed, 34 insertions(+), 14 deletions(-)

diff --git a/src/components/character-controller.js b/src/components/character-controller.js
index 05bb83ff3..80260e0fc 100644
--- a/src/components/character-controller.js
+++ b/src/components/character-controller.js
@@ -126,7 +126,11 @@ AFRAME.registerComponent("character-controller", {
       }
       const acc = userinput.readFrameValueAtPath(paths.actions.characterAcceleration);
       if (acc) {
-        this.accelerationInput.set(acc[0], 0, acc[1]);
+        this.accelerationInput.set(
+          this.accelerationInput.x + acc[0],
+          this.accelerationInput.y + 0,
+          this.accelerationInput.z + acc[1]
+        );
       }
 
       pivotPos.copy(pivot.position);
@@ -138,6 +142,7 @@ AFRAME.registerComponent("character-controller", {
       pivotRotationMatrix.makeRotationAxis(rotationAxis, pivot.rotation.y);
       pivotRotationInvMatrix.makeRotationAxis(rotationAxis, -pivot.rotation.y);
       this.updateVelocity(deltaSeconds);
+      this.accelerationInput.set(0, 0, 0);
 
       const boost = userinput.readFrameValueAtPath(paths.actions.boost) ? 2 : 1;
       move.makeTranslation(
diff --git a/src/components/virtual-gamepad-controls.js b/src/components/virtual-gamepad-controls.js
index 309b2210b..f4790dd2b 100644
--- a/src/components/virtual-gamepad-controls.js
+++ b/src/components/virtual-gamepad-controls.js
@@ -94,7 +94,7 @@ AFRAME.registerComponent("virtual-gamepad-controls", {
   onMoveJoystickChanged(event, joystick) {
     const angle = joystick.angle.radian;
     const force = joystick.force < 1 ? joystick.force : 1;
-    const moveStrength = 0.85;
+    const moveStrength = 1.85;
     const x = Math.cos(angle) * force * moveStrength;
     const z = Math.sin(angle) * force * moveStrength;
     this.moving = true;
diff --git a/src/hub.html b/src/hub.html
index a5eef877d..de2bf1f52 100644
--- a/src/hub.html
+++ b/src/hub.html
@@ -30,7 +30,6 @@
         freeze-controller="toggleEvent: action_freeze"
         personal-space-bubble="debug: false;"
         vr-mode-ui="enabled: false"
-        pinch-to-move
         stats-plus="false"
     >
 
diff --git a/src/systems/userinput/bindings/touchscreen-user.js b/src/systems/userinput/bindings/touchscreen-user.js
index 770fe3f38..92ef99eab 100644
--- a/src/systems/userinput/bindings/touchscreen-user.js
+++ b/src/systems/userinput/bindings/touchscreen-user.js
@@ -2,8 +2,25 @@ import { paths } from "../paths";
 import { sets } from "../sets";
 import { xforms } from "./xforms";
 
+const zero = "/vars/touchscreen/zero";
+const forward = "/vars/touchscreen/pinchDeltaForward";
+
 export const touchscreenUserBindings = {
   [sets.global]: [
+    {
+      src: { value: paths.device.touchscreen.pinch.delta },
+      dest: { value: forward },
+      xform: xforms.scale(0.25)
+    },
+    {
+      dest: { value: zero },
+      xform: xforms.always(0)
+    },
+    {
+      src: { x: zero, y: forward },
+      dest: { value: paths.actions.characterAcceleration },
+      xform: xforms.compose_vec2
+    },
     {
       src: { value: paths.device.touchscreen.cursorPose },
       dest: { value: paths.actions.cursor.pose },
diff --git a/src/systems/userinput/devices/app-aware-touchscreen.js b/src/systems/userinput/devices/app-aware-touchscreen.js
index 31bf0fb7b..ab30d2e25 100644
--- a/src/systems/userinput/devices/app-aware-touchscreen.js
+++ b/src/systems/userinput/devices/app-aware-touchscreen.js
@@ -36,7 +36,7 @@ export class AppAwareTouchscreenDevice {
   constructor() {
     this.raycaster = new THREE.Raycaster(new THREE.Vector3(), new THREE.Vector3(), 0, 3);
     this.assignments = [];
-    this.pinch = {};
+    this.pinch = { initialDistance: 0, currentDistance: 0, delta: 0 };
     this.events = [];
     ["touchstart", "touchend", "touchmove", "touchcancel"].map(x =>
       document.querySelector("canvas").addEventListener(x, this.events.push.bind(this.events))
@@ -57,7 +57,7 @@ export class AppAwareTouchscreenDevice {
         break;
       case FIRST_PINCHER_JOB:
         unassign(assignment.touch, assignment.job, this.assignments);
-        this.pinch = undefined;
+        this.pinch = { initialDistance: 0, currentDistance: 0, delta: 0 };
 
         if (jobIsAssigned(SECOND_PINCHER_JOB, this.assignments)) {
           const second = findByJob(SECOND_PINCHER_JOB, this.assignments);
@@ -78,7 +78,7 @@ export class AppAwareTouchscreenDevice {
         break;
       case SECOND_PINCHER_JOB:
         unassign(assignment.touch, assignment.job, this.assignments);
-        this.pinch = undefined;
+        this.pinch = { initialDistance: 0, currentDistance: 0, delta: 0 };
         if (jobIsAssigned(FIRST_PINCHER_JOB, this.assignments) && !jobIsAssigned(MOVE_CAMERA_JOB, this.assignments)) {
           //reassign firstPincher to moveCamera
           const first = findByJob(FIRST_PINCHER_JOB, this.assignments);
@@ -235,10 +235,8 @@ export class AppAwareTouchscreenDevice {
       frame[path.cameraDelta] = findByJob(MOVE_CAMERA_JOB, this.assignments).delta;
     }
 
-    if (this.pinch) {
-      frame[path.pinchDelta] = this.pinch.delta;
-      frame[path.initialPinchDistance] = this.pinch.initialDistance;
-      frame[path.currentPinchDistance] = this.pinch.currentDistance;
-    }
+    frame[path.pinch.delta] = this.pinch.delta;
+    frame[path.pinch.initialDistance] = this.pinch.initialDistance;
+    frame[path.pinch.currentDistance] = this.pinch.currentDistance;
   }
 }
diff --git a/src/systems/userinput/paths.js b/src/systems/userinput/paths.js
index 9ec460491..3acb4a740 100644
--- a/src/systems/userinput/paths.js
+++ b/src/systems/userinput/paths.js
@@ -70,9 +70,10 @@ paths.device.smartMouse.cameraDelta = "/device/smartMouse/cameraDelta";
 paths.device.touchscreen = {};
 paths.device.touchscreen.cursorPose = "/device/touchscreen/cursorPose";
 paths.device.touchscreen.cameraDelta = "/device/touchscreen/cameraDelta";
-paths.device.touchscreen.pinchDelta = "/device/touchscreen/pinchDelta";
-paths.device.touchscreen.initialPinchDistance = "/device/touchscreen/initialPinchDistance";
-paths.device.touchscreen.currentPinchDistance = "/device/touchscreen/currentPinchDistance";
+paths.device.touchscreen.pinch = {};
+paths.device.touchscreen.pinch.delta = "/device/touchscreen/pinch/delta";
+paths.device.touchscreen.pinch.initialDistance = "/device/touchscreen/pinch/initialDistance";
+paths.device.touchscreen.pinch.currentDistance = "/device/touchscreen/pinch/currentDistance";
 paths.device.touchscreen.isTouchingGrabbable = "/device/touchscreen/isTouchingGrabbable";
 paths.device.hud = {};
 paths.device.hud.penButton = "/device/hud/penButton";
-- 
GitLab