Browse Source

Merge pull request #7557 from rwedoff/master

Add/Fix ArcRotateCamera Pinch to Zoom with new NaturalPinchZoom type
David Catuhe 5 years ago
parent
commit
99675c3eb4
3 changed files with 39 additions and 2 deletions
  1. 15 2
      src/Cameras/Inputs/arcRotateCameraPointersInput.ts
  2. 23 0
      src/Cameras/arcRotateCamera.ts
  3. 1 0
      what's new.md

+ 15 - 2
src/Cameras/Inputs/arcRotateCameraPointersInput.ts

@@ -59,6 +59,15 @@ export class ArcRotateCameraPointersInput extends BaseCameraPointersInput {
     public pinchDeltaPercentage = 0;
 
     /**
+     * When useNaturalPinchZoom is true, multi touch zoom will zoom in such
+     * that any object in the plane at the camera's target point will scale
+     * perfectly with finger motion.
+     * Overrides pinchDeltaPercentage and pinchPrecision.
+     */
+    @serialize()
+    public useNaturalPinchZoom: boolean = false;
+
+    /**
      * Defines the pointer panning sensibility or how fast is the camera moving.
      */
     @serialize()
@@ -135,11 +144,15 @@ export class ArcRotateCameraPointersInput extends BaseCameraPointersInput {
         var direction = this.pinchInwards ? 1 : -1;
 
         if (this.multiTouchPanAndZoom) {
-            if (this.pinchDeltaPercentage) {
+            if (this.useNaturalPinchZoom) {
+                this.camera.radius = this.camera.radius *
+                    Math.sqrt(previousPinchSquaredDistance) / Math.sqrt(pinchSquaredDistance);
+            } else if (this.pinchDeltaPercentage) {
                 this.camera.inertialRadiusOffset +=
                     (pinchSquaredDistance - previousPinchSquaredDistance) * 0.001 *
                     this.camera.radius * this.pinchDeltaPercentage;
-            } else {
+            }
+            else {
                 this.camera.inertialRadiusOffset +=
                     (pinchSquaredDistance - previousPinchSquaredDistance) /
                     (this.pinchPrecision * direction *

+ 23 - 0
src/Cameras/arcRotateCamera.ts

@@ -298,6 +298,29 @@ export class ArcRotateCamera extends TargetCamera {
     }
 
     /**
+     * Gets or Set the pointer use natural pinch zoom to override the pinch precision
+     * and pinch delta percentage.
+     * When useNaturalPinchZoom is true, multi touch zoom will zoom in such
+     * that any object in the plane at the camera's target point will scale
+     * perfectly with finger motion.
+     */
+    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 {

+ 1 - 0
what's new.md

@@ -222,6 +222,7 @@
 - Improving visual quality on SSAO2 shader ([CraigFeldspar](https://github.com/CraigFeldspar))
 - Fixed a bug where changing the sample count on `PostProcess` would not update the WebGL Texture ([CraigFeldspar](https://github.com/CraigFeldspar))
 - Fixed multi camera support in defaultRenderingPipeline depth of field ([sebavan](http://www.github.com/sebavan))
+- Added a new NaturalPinchZoom for the ArcRotateCamera, which adds a new pinch type that is based on the camera and pinch distance. ([rwedoff](https://github.com/rwedoff))
 
 ### Viewer