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.
This commit is contained in:
2026-01-03 00:28:52 +01:00
parent 46b5466701
commit 2f63e54d13

View File

@@ -117,28 +117,30 @@ export class CameraManager {
} }
pan(dx, dy) { pan(dx, dy) {
// Move Target and Camera together // Move Speed Factor
// We pan on the logical "Ground Plane" relative to screen movement
const moveSpeed = this.panSpeed * 0.05 * (this.zoomLevel / 10); const moveSpeed = this.panSpeed * 0.05 * (this.zoomLevel / 10);
// Transform screen delta to world delta // Direction: Dragging the "World"
// In Iso view, Right on screen = (1, 0, 1) in world? // Mouse Left (dx < 0) -> Camera moves Right (+X)
// Or using camera right/up vectors // 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 // Apply to Camera (Local Space)
const forward = new THREE.Vector3(-1, 0, 1).normalize(); this.camera.translateX(moveX);
this.camera.translateY(moveY);
// Let's use camera vectors for generic support // Calculate World Movement to update Target
// Project camera right/up onto XZ plane const vRight = new THREE.Vector3(1, 0, 0).applyQuaternion(this.camera.quaternion);
// Or just direct translation: const vUp = new THREE.Vector3(0, 1, 0).applyQuaternion(this.camera.quaternion);
this.camera.translateX(dx * moveSpeed); const worldTranslation = new THREE.Vector3()
this.camera.translateY(dy * moveSpeed); .addScaledVector(vRight, moveX)
.addScaledVector(vUp, moveY);
// This moves camera. We need to update target reference too if we want to snap back correctly // Apply same movement to Target so relative offset is preserved
// But for now, simple pan is "offsetting everything". // This ensures lookAt() doesn't pivot the camera around the old center
// centerOn resets this. this.target.add(worldTranslation);
} }
update(deltaTime) { update(deltaTime) {