فهرست منبع

zoom with estimated radius to avoid zooming to far

Trevor Baron 6 سال پیش
والد
کامیت
fd12f7ac1c
2فایلهای تغییر یافته به همراه23 افزوده شده و 5 حذف شده
  1. 1 0
      dist/preview release/what's new.md
  2. 22 5
      src/Cameras/Inputs/arcRotateCameraMouseWheelInput.ts

+ 1 - 0
dist/preview release/what's new.md

@@ -262,6 +262,7 @@
 - Add hemispheric lighting to gizmos to avoid flat look ([TrevorDev](https://github.com/TrevorDev))
 - Fix a bug causing `WebRequest.open` to crash if `WebRequest.CustomRequestHeaders` are set [#6055](https://github.com/BabylonJS/Babylon.js/issues/6055)([susares](https://github.com/susares))
 - Fix a bug causing `Mesh.clone` to crash if no physicsEngineComponent is used  ([barroij](https://github.com/barroij))
+- Fix zoom inertia making it difficult to zoom out with ArcRotateCamera ([TrevorDev](https://github.com/TrevorDev))
 
 ### Viewer
 

+ 22 - 5
src/Cameras/Inputs/arcRotateCameraMouseWheelInput.ts

@@ -31,6 +31,16 @@ export class ArcRotateCameraMouseWheelInput implements ICameraInput<ArcRotateCam
     private _wheel: Nullable<(p: PointerInfo, s: EventState) => void>;
     private _observer: Nullable<Observer<PointerInfo>>;
 
+    private computeDeltaFromMouseWheelLegacyEvent(mouseWheelLegacyEvent: any, radius: number) {
+        var delta = 0;
+        var wheelDelta = (mouseWheelLegacyEvent.wheelDelta * 0.01 * this.wheelDeltaPercentage) * radius;
+        if (mouseWheelLegacyEvent.wheelDelta > 0) {
+            delta = wheelDelta / (1.0 + this.wheelDeltaPercentage);
+        } else {
+            delta = wheelDelta * (1.0 + this.wheelDeltaPercentage);
+        }
+        return delta;
+    }
     /**
      * Attach the input controls to a specific dom element to get the input from.
      * @param element Defines the element the controls should be listened from
@@ -46,11 +56,18 @@ export class ArcRotateCameraMouseWheelInput implements ICameraInput<ArcRotateCam
             let mouseWheelLegacyEvent = event as any;
             if (mouseWheelLegacyEvent.wheelDelta) {
                 if (this.wheelDeltaPercentage) {
-                    var wheelDelta = (mouseWheelLegacyEvent.wheelDelta * 0.01 * this.wheelDeltaPercentage) * this.camera.radius;
-                    if (mouseWheelLegacyEvent.wheelDelta > 0) {
-                        delta = wheelDelta / (1.0 + this.wheelDeltaPercentage);
-                    } else {
-                        delta = wheelDelta * (1.0 + this.wheelDeltaPercentage);
+                    delta = this.computeDeltaFromMouseWheelLegacyEvent(mouseWheelLegacyEvent, this.camera.radius);
+
+                    // If zooming in, estimate the target radius and use that to compute the delta for inertia
+                    // this will stop multiple scroll events zooming in from adding too much inertia
+                    if (delta > 0) {
+                        var estimatedTargetRadius = this.camera.radius;
+                        var targetInertia = this.camera.inertialRadiusOffset + delta;
+                        for (var i = 0; i < 20 && Math.abs(targetInertia) > 0.001; i++) {
+                            estimatedTargetRadius -= targetInertia;
+                            targetInertia *= this.camera.inertia;
+                        }
+                        delta = this.computeDeltaFromMouseWheelLegacyEvent(mouseWheelLegacyEvent, estimatedTargetRadius);
                     }
                 } else {
                     delta = mouseWheelLegacyEvent.wheelDelta / (this.wheelPrecision * 40);