瀏覽代碼

Merge pull request #6059 from TrevorDev/deviceOrientationPointerOption

allow snap back pointer behavior on orientation camera
David Catuhe 6 年之前
父節點
當前提交
ca46d12f61
共有 1 個文件被更改,包括 17 次插入11 次删除
  1. 17 11
      src/Cameras/deviceOrientationCamera.ts

+ 17 - 11
src/Cameras/deviceOrientationCamera.ts

@@ -34,23 +34,29 @@ export class DeviceOrientationCamera extends FreeCamera {
         // When the orientation sensor fires it's first event, disable mouse input
         if (this.inputs._deviceOrientationInput) {
             this.inputs._deviceOrientationInput._onDeviceOrientationChangedObservable.addOnce(() => {
-                if (this.inputs._mouseInput) {
-                    this.inputs._mouseInput._allowCameraRotation = false;
-                    this.inputs._mouseInput.onPointerMovedObservable.add((e) => {
-                        if (this._dragFactor != 0) {
-                            if (!this._initialQuaternion) {
-                                this._initialQuaternion = new Quaternion();
+                if (this.disablePointerInputWhenUsingDeviceOrientation) {
+                    if (this.inputs._mouseInput) {
+                        this.inputs._mouseInput._allowCameraRotation = false;
+                        this.inputs._mouseInput.onPointerMovedObservable.add((e) => {
+                            if (this._dragFactor != 0) {
+                                if (!this._initialQuaternion) {
+                                    this._initialQuaternion = new Quaternion();
+                                }
+                                // Rotate the initial space around the y axis to allow users to "turn around" via touch/mouse
+                                Quaternion.FromEulerAnglesToRef(0, e.offsetX * this._dragFactor, 0, this._tmpDragQuaternion);
+                                this._initialQuaternion.multiplyToRef(this._tmpDragQuaternion, this._initialQuaternion);
                             }
-                            // Rotate the initial space around the y axis to allow users to "turn around" via touch/mouse
-                            Quaternion.FromEulerAnglesToRef(0, e.offsetX * this._dragFactor, 0, this._tmpDragQuaternion);
-                            this._initialQuaternion.multiplyToRef(this._tmpDragQuaternion, this._initialQuaternion);
-                        }
-                    });
+                        });
+                    }
                 }
             });
         }
     }
 
+    /**
+     * Disabled pointer input on first orientation sensor update (Default: true)
+     */
+    public disablePointerInputWhenUsingDeviceOrientation = true;
     private _dragFactor = 0;
     /**
      * Enabled turning on the y axis when the orientation sensor is active