|
@@ -19,6 +19,9 @@ module BABYLON {
|
|
|
@serialize()
|
|
|
public panningSensibility: number = 50.0;
|
|
|
|
|
|
+ @serialize()
|
|
|
+ public multiTouchPanning: boolean = true;
|
|
|
+
|
|
|
private _isPanClick: boolean = false;
|
|
|
public pinchInwards = true;
|
|
|
|
|
@@ -35,7 +38,9 @@ module BABYLON {
|
|
|
var engine = this.camera.getEngine();
|
|
|
var cacheSoloPointer: { x: number, y: number, pointerId: number, type: any }; // cache pointer object for better perf on camera rotation
|
|
|
var pointA: { x: number, y: number, pointerId: number, type: any }, pointB: { x: number, y: number, pointerId: number, type: any };
|
|
|
+ var previousPinchSquaredDistance = 0;
|
|
|
var previousPinchDistance = 0;
|
|
|
+ var previousMultiTouchPanPosition: { x: number, y: number, isPaning: boolean } = { x: 0, y:0, isPaning: false };
|
|
|
|
|
|
this._pointerInput = (p, s) => {
|
|
|
var evt = <PointerEvent>p.event;
|
|
@@ -78,7 +83,9 @@ module BABYLON {
|
|
|
}
|
|
|
|
|
|
cacheSoloPointer = null;
|
|
|
+ previousPinchSquaredDistance = 0;
|
|
|
previousPinchDistance = 0;
|
|
|
+ previousMultiTouchPanPosition.isPaning = false;
|
|
|
|
|
|
//would be better to use pointers.remove(evt.pointerId) for multitouch gestures,
|
|
|
//but emptying completly pointers collection is required to fix a bug on iPhone :
|
|
@@ -97,8 +104,7 @@ module BABYLON {
|
|
|
// One button down
|
|
|
if (pointA && pointB === undefined) {
|
|
|
if (this.panningSensibility !== 0 &&
|
|
|
- ((evt.ctrlKey && this.camera._useCtrlForPanning) ||
|
|
|
- (!this.camera._useCtrlForPanning && this._isPanClick))) {
|
|
|
+ ((evt.ctrlKey && this.camera._useCtrlForPanning) || this._isPanClick)) {
|
|
|
this.camera.inertialPanningX += -(evt.clientX - cacheSoloPointer.x) / this.panningSensibility;
|
|
|
this.camera.inertialPanningY += (evt.clientY - cacheSoloPointer.y) / this.panningSensibility;
|
|
|
} else {
|
|
@@ -112,7 +118,7 @@ module BABYLON {
|
|
|
cacheSoloPointer.y = evt.clientY;
|
|
|
}
|
|
|
|
|
|
- // Two buttons down: pinch
|
|
|
+ // Two buttons down: pinch/pan
|
|
|
else if (pointA && pointB) {
|
|
|
//if (noPreventDefault) { evt.preventDefault(); } //if pinch gesture, could be useful to force preventDefault to avoid html page scroll/zoom in some mobile browsers
|
|
|
var ed = (pointA.pointerId === evt.pointerId) ? pointA : pointB;
|
|
@@ -122,19 +128,42 @@ module BABYLON {
|
|
|
var distX = pointA.x - pointB.x;
|
|
|
var distY = pointA.y - pointB.y;
|
|
|
var pinchSquaredDistance = (distX * distX) + (distY * distY);
|
|
|
- if (previousPinchDistance === 0) {
|
|
|
- previousPinchDistance = pinchSquaredDistance;
|
|
|
+ var pinchDistance = Math.sqrt(pinchSquaredDistance);
|
|
|
+ if (previousPinchSquaredDistance === 0) {
|
|
|
+ previousPinchSquaredDistance = pinchSquaredDistance;
|
|
|
+ previousPinchDistance = pinchDistance;
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- if (pinchSquaredDistance !== previousPinchDistance) {
|
|
|
+ if (Math.abs(pinchDistance - previousPinchDistance) > this.camera.pinchToPanMaxDistance) {
|
|
|
this.camera
|
|
|
- .inertialRadiusOffset += (pinchSquaredDistance - previousPinchDistance) /
|
|
|
+ .inertialRadiusOffset += (pinchSquaredDistance - previousPinchSquaredDistance) /
|
|
|
(this.pinchPrecision *
|
|
|
((this.angularSensibilityX + this.angularSensibilityY) / 2) *
|
|
|
direction);
|
|
|
- previousPinchDistance = pinchSquaredDistance;
|
|
|
+ previousMultiTouchPanPosition.isPaning = false;
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ if (cacheSoloPointer.pointerId === ed.pointerId && this.panningSensibility !== 0 && this.multiTouchPanning) {
|
|
|
+ if (!previousMultiTouchPanPosition.isPaning) {
|
|
|
+ previousMultiTouchPanPosition.isPaning = true;
|
|
|
+ previousMultiTouchPanPosition.x = ed.x;
|
|
|
+ previousMultiTouchPanPosition.y = ed.y;
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ this.camera.inertialPanningX += -(ed.x - previousMultiTouchPanPosition.x) / this.panningSensibility;
|
|
|
+ this.camera.inertialPanningY += (ed.y - previousMultiTouchPanPosition.y) / this.panningSensibility;
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
+ if (cacheSoloPointer.pointerId === evt.pointerId) {
|
|
|
+ previousMultiTouchPanPosition.x = ed.x;
|
|
|
+ previousMultiTouchPanPosition.y = ed.y;
|
|
|
+ }
|
|
|
+
|
|
|
+ previousPinchSquaredDistance = pinchSquaredDistance;
|
|
|
+ previousPinchDistance = pinchDistance;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -152,7 +181,9 @@ module BABYLON {
|
|
|
this._onLostFocus = () => {
|
|
|
//this._keys = [];
|
|
|
pointA = pointB = undefined;
|
|
|
+ previousPinchSquaredDistance = 0;
|
|
|
previousPinchDistance = 0;
|
|
|
+ previousMultiTouchPanPosition.isPaning = false;
|
|
|
cacheSoloPointer = null;
|
|
|
};
|
|
|
|