|
@@ -31,6 +31,16 @@ export class ArcRotateCameraMouseWheelInput implements ICameraInput<ArcRotateCam
|
|
private _wheel: Nullable<(p: PointerInfo, s: EventState) => void>;
|
|
private _wheel: Nullable<(p: PointerInfo, s: EventState) => void>;
|
|
private _observer: Nullable<Observer<PointerInfo>>;
|
|
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.
|
|
* 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
|
|
* @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;
|
|
let mouseWheelLegacyEvent = event as any;
|
|
if (mouseWheelLegacyEvent.wheelDelta) {
|
|
if (mouseWheelLegacyEvent.wheelDelta) {
|
|
if (this.wheelDeltaPercentage) {
|
|
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 {
|
|
} else {
|
|
delta = mouseWheelLegacyEvent.wheelDelta / (this.wheelPrecision * 40);
|
|
delta = mouseWheelLegacyEvent.wheelDelta / (this.wheelPrecision * 40);
|