Sfoglia il codice sorgente

Merge branch 'rywedoff/arcRotateCameraPinch'

Ryan Wedoff 5 anni fa
parent
commit
d97ff41afd

+ 13 - 1
src/Cameras/Inputs/arcRotateCameraPointersInput.ts

@@ -59,6 +59,14 @@ export class ArcRotateCameraPointersInput extends BaseCameraPointersInput {
     public pinchDeltaPercentage = 0;
 
     /**
+     * useNaturalPinchZoom will be used instead of pinchPrecision if set to true.
+     * Pinch natural zoom is a calculation based off the distance of the
+     * pinch and the camera distance.
+     */
+    @serialize()
+    public useNaturalPinchZoom: boolean = false;
+
+    /**
      * Defines the pointer panning sensibility or how fast is the camera moving.
      */
     @serialize()
@@ -139,7 +147,11 @@ export class ArcRotateCameraPointersInput extends BaseCameraPointersInput {
                 this.camera.inertialRadiusOffset +=
                     (pinchSquaredDistance - previousPinchSquaredDistance) * 0.001 *
                     this.camera.radius * this.pinchDeltaPercentage;
-            } else {
+            } else if (this.useNaturalPinchZoom) {
+                this.camera.radius = this.camera.radius *
+                    Math.sqrt(previousPinchSquaredDistance) / Math.sqrt(pinchSquaredDistance);
+            }
+            else {
                 this.camera.inertialRadiusOffset +=
                     (pinchSquaredDistance - previousPinchSquaredDistance) /
                     (this.pinchPrecision * direction *

+ 21 - 0
src/Cameras/arcRotateCamera.ts

@@ -298,6 +298,27 @@ export class ArcRotateCamera extends TargetCamera {
     }
 
     /**
+     * Gets or Set the pointer use natural pinch zoom to override the pinch precision
+     * and pinch delta percentage. Natural pinch zoom  in uses the distance of the pinch
+     * in relation to the camera distance to determine the zoom.
+     */
+    public get useNaturalPinchZoom(): boolean {
+        var pointers = <ArcRotateCameraPointersInput>this.inputs.attached["pointers"];
+        if (pointers) {
+            return pointers.useNaturalPinchZoom;
+        }
+
+        return false;
+    }
+
+    public set useNaturalPinchZoom(value: boolean) {
+        var pointers = <ArcRotateCameraPointersInput>this.inputs.attached["pointers"];
+        if (pointers) {
+            pointers.useNaturalPinchZoom = value;
+        }
+    }
+
+    /**
      * Gets or Set the pointer panning sensibility or how fast is the camera moving.
      */
     public get panningSensibility(): number {