From 2f63e54d132076054cf832c66f08ab8dbded2530 Mon Sep 17 00:00:00 2001 From: marti Date: Sat, 3 Jan 2026 00:28:52 +0100 Subject: [PATCH] Fix camera panning logic to update target position. Previously, panning only moved the camera, causing orbital rotation issues when changing views or centering because the target reference point wasn't updated. Now both camera and target move in sync. --- src/view/CameraManager.js | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/src/view/CameraManager.js b/src/view/CameraManager.js index de93bd7..2da8c64 100644 --- a/src/view/CameraManager.js +++ b/src/view/CameraManager.js @@ -117,28 +117,30 @@ export class CameraManager { } pan(dx, dy) { - // Move Target and Camera together - // We pan on the logical "Ground Plane" relative to screen movement - + // Move Speed Factor const moveSpeed = this.panSpeed * 0.05 * (this.zoomLevel / 10); - // Transform screen delta to world delta - // In Iso view, Right on screen = (1, 0, 1) in world? - // Or using camera right/up vectors + // Direction: Dragging the "World" + // Mouse Left (dx < 0) -> Camera moves Right (+X) + // Mouse Up (dy < 0) -> Camera moves Down (-Y) + const moveX = -dx * moveSpeed; + const moveY = dy * moveSpeed; - const right = new THREE.Vector3(1, 0, 1).normalize(); // Approx logic for standard Iso - const forward = new THREE.Vector3(-1, 0, 1).normalize(); + // Apply to Camera (Local Space) + this.camera.translateX(moveX); + this.camera.translateY(moveY); - // Let's use camera vectors for generic support - // Project camera right/up onto XZ plane - // Or just direct translation: + // Calculate World Movement to update Target + const vRight = new THREE.Vector3(1, 0, 0).applyQuaternion(this.camera.quaternion); + const vUp = new THREE.Vector3(0, 1, 0).applyQuaternion(this.camera.quaternion); - this.camera.translateX(dx * moveSpeed); - this.camera.translateY(dy * moveSpeed); + const worldTranslation = new THREE.Vector3() + .addScaledVector(vRight, moveX) + .addScaledVector(vUp, moveY); - // This moves camera. We need to update target reference too if we want to snap back correctly - // But for now, simple pan is "offsetting everything". - // centerOn resets this. + // Apply same movement to Target so relative offset is preserved + // This ensures lookAt() doesn't pivot the camera around the old center + this.target.add(worldTranslation); } update(deltaTime) {