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) {
// 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) {