fix(earth-controls): zoom-aware drag sensitivity and bump version to 0.22.13
This commit is contained in:
@@ -108,6 +108,7 @@ import {
|
||||
getShowTerrain,
|
||||
setAutoRotate,
|
||||
resetView,
|
||||
getZoomLevel,
|
||||
teardownControls,
|
||||
} from "./controls.js";
|
||||
import {
|
||||
@@ -170,7 +171,6 @@ const scratchBGPDirection = new THREE.Vector3();
|
||||
const scratchBGPWorldPosition = new THREE.Vector3();
|
||||
|
||||
const cleanupFns = [];
|
||||
const DRAG_ROTATION_FACTOR = 0.005;
|
||||
const DRAG_SMOOTHING_FACTOR = 0.18;
|
||||
const INERTIA_DAMPING = 0.92;
|
||||
const INERTIA_MIN_VELOCITY = 0.00008;
|
||||
@@ -201,6 +201,16 @@ function isEventOnHud(event) {
|
||||
return HUD_INTERACTIVE_SELECTORS.some((selector) => target.closest(selector));
|
||||
}
|
||||
|
||||
function getDragRotationFactor() {
|
||||
const zoom = Math.max(getZoomLevel(), 0.01);
|
||||
const scale = THREE.MathUtils.clamp(
|
||||
1 / zoom,
|
||||
CONFIG.dragRotationScaleMin,
|
||||
CONFIG.dragRotationScaleMax,
|
||||
);
|
||||
return CONFIG.dragRotationFactorBase * scale;
|
||||
}
|
||||
|
||||
function disposeMaterial(material) {
|
||||
if (!material) return;
|
||||
if (Array.isArray(material)) {
|
||||
@@ -1142,8 +1152,9 @@ function onMouseMove(event) {
|
||||
|
||||
const deltaX = event.clientX - previousMousePosition.x;
|
||||
const deltaY = event.clientY - previousMousePosition.y;
|
||||
const rotationDeltaY = deltaX * DRAG_ROTATION_FACTOR;
|
||||
const rotationDeltaX = deltaY * DRAG_ROTATION_FACTOR;
|
||||
const dragRotationFactor = getDragRotationFactor();
|
||||
const rotationDeltaY = deltaX * dragRotationFactor;
|
||||
const rotationDeltaX = deltaY * dragRotationFactor;
|
||||
|
||||
targetRotation.y += rotationDeltaY;
|
||||
targetRotation.x += rotationDeltaX;
|
||||
|
||||
Reference in New Issue
Block a user