From 79fd5449ffdf47d3c59703d461fdaae4ce613270 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20LAGIER?= Date: Fri, 4 Oct 2024 11:42:21 +0200 Subject: [PATCH] Better touch rotation for perspective projection --- .../handlers/TouchPanRotateAndDollyHandler.js | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/viewer/scene/CameraControl/lib/handlers/TouchPanRotateAndDollyHandler.js b/src/viewer/scene/CameraControl/lib/handlers/TouchPanRotateAndDollyHandler.js index c8297033e..5b2452520 100644 --- a/src/viewer/scene/CameraControl/lib/handlers/TouchPanRotateAndDollyHandler.js +++ b/src/viewer/scene/CameraControl/lib/handlers/TouchPanRotateAndDollyHandler.js @@ -198,20 +198,20 @@ class TouchPanRotateAndDollyHandler { } } else { - // if (!absorbTinyFirstDrag) { + if (scene.camera.projection === "perspective") { + const { fov, fovAxis } = scene.camera.perspective; + const fovX = fovAxis === "x" || (fovAxis === "min" && canvasWidth < canvasHeight) ? fov : fov * (canvasWidth / canvasHeight); + const fovY = fovAxis === "y" || (fovAxis === "min" && canvasHeight < canvasWidth) ? fov : fov * (canvasHeight / canvasWidth); + + const dx = xPanDelta / canvasWidth * fovX * configs.dragRotationRate / 360; + const dy = yPanDelta / canvasHeight * fovY * configs.dragRotationRate / 360; + + updates.rotateDeltaY -= dx; + updates.rotateDeltaX += dy; + } else { updates.rotateDeltaY -= (xPanDelta / canvasWidth) * (configs.dragRotationRate * 1.0); // Full horizontal rotation updates.rotateDeltaX += (yPanDelta / canvasHeight) * (configs.dragRotationRate * 1.5); // Half vertical rotation - // } else { - // firstDragDeltaY -= (xPanDelta / canvasWidth) * (configs.dragRotationRate * 1.0); // Full horizontal rotation - // firstDragDeltaX += (yPanDelta / canvasHeight) * (configs.dragRotationRate * 1.5); // Half vertical rotation - // if (Math.abs(firstDragDeltaX) > 5 || Math.abs(firstDragDeltaY) > 5) { - // updates.rotateDeltaX += firstDragDeltaX; - // updates.rotateDeltaY += firstDragDeltaY; - // firstDragDeltaX = 0; - // firstDragDeltaY = 0; - // absorbTinyFirstDrag = false; - // } - // } + } } } else if (numTouches === 2) {