pitch gefixt

This commit is contained in:
2026-05-12 21:42:04 +02:00
parent 270ea2b771
commit 4fb8dc2b62
3 changed files with 14 additions and 45 deletions

49
main.js
View File

@@ -106,77 +106,46 @@ function syncCamera() {
// ----------------------------------------- // -----------------------------------------
// Abstand abhängig vom Zoom // Abstand abhängig vom Zoom
// ----------------------------------------- // -----------------------------------------
const earthCircumference = 40075016.686; const earthCircumference = 40075016.686;
const metersPerPixel = earthCircumference * Math.cos(center.lat * Math.PI / 180) / Math.pow(2, zoom + 8);
const metersPerPixel = const distance = metersPerPixel * map.getCanvas().height;
earthCircumference *
Math.cos(center.lat * Math.PI / 180) /
Math.pow(2, zoom + 8);
const distance =
metersPerPixel * map.getCanvas().height;
// ----------------------------------------- // -----------------------------------------
// Zielpunkt = Kartenzentrum // Zielpunkt = Kartenzentrum
// ----------------------------------------- // -----------------------------------------
const target = new THREE.Vector3(x, y, 0);
const target = new THREE.Vector3(
x,
y,
0
);
// ----------------------------------------- // -----------------------------------------
// Kameraoffset // Kameraoffset
// ----------------------------------------- // -----------------------------------------
const offset = new THREE.Vector3(0, -distance * Math.sin(pitch), distance * Math.cos(pitch)
const offset = new THREE.Vector3(
0,
-distance * Math.cos(pitch),
distance * Math.sin(pitch)
); );
// Bearing rotieren // Bearing rotieren
offset.applyAxisAngle( offset.applyAxisAngle(new THREE.Vector3(0, 0, 1), -bearing);
new THREE.Vector3(0, 0, 1),
-bearing
);
// ----------------------------------------- // -----------------------------------------
// Kameraposition // Kameraposition
// ----------------------------------------- // -----------------------------------------
const cameraPosition = target.clone().add(offset);
const cameraPosition =
target.clone().add(offset);
// ----------------------------------------- // -----------------------------------------
// Potree Kamera setzen // Potree Kamera setzen
// ----------------------------------------- // -----------------------------------------
const camera = viewer.scene.getActiveCamera();
const camera =
viewer.scene.getActiveCamera();
camera.position.copy(cameraPosition); camera.position.copy(cameraPosition);
camera.lookAt(target); camera.lookAt(target);
viewer.scene.view.position.copy(cameraPosition); viewer.scene.view.position.copy(cameraPosition);
viewer.scene.view.lookAt(target); viewer.scene.view.lookAt(target);
camera.updateMatrixWorld(); camera.updateMatrixWorld();
viewer.renderer.render( viewer.renderer.render(
viewer.scene.scene, viewer.scene.scene,
camera camera
); );
} }
map.on('move', ()=>{ // Kameras bei jeder Kartenbewegung synchronisieren
console.log(viewer.scene.view) map.on('move', syncCamera);
syncCamera();
});
map.on('zoom', syncCamera); map.on('zoom', syncCamera);
map.on('pitch', syncCamera); map.on('pitch', syncCamera);
map.on('rotate', syncCamera); map.on('rotate', syncCamera);

8
package-lock.json generated
View File

@@ -14,7 +14,7 @@
"deck.gl": "^9.3.1", "deck.gl": "^9.3.1",
"maplibre-gl": "^5.22.0", "maplibre-gl": "^5.22.0",
"proj4": "^2.20.8", "proj4": "^2.20.8",
"three": "^0.184.0", "three": "^0.124.0",
"vite": "^8.0.7" "vite": "^8.0.7"
} }
}, },
@@ -4916,9 +4916,9 @@
} }
}, },
"node_modules/three": { "node_modules/three": {
"version": "0.184.0", "version": "0.124.0",
"resolved": "https://registry.npmjs.org/three/-/three-0.184.0.tgz", "resolved": "https://registry.npmjs.org/three/-/three-0.124.0.tgz",
"integrity": "sha512-wtTRjG92pM5eUg/KuUnHsqSAlPM296brTOcLgMRqEeylYTh/CdtvKUvCyyCQTzFuStieWxvZb8mVTMvdPyUpxg==", "integrity": "sha512-ROXp1Ly7YyF+jC910DQyAWj++Qlw2lQv0qwYLNQwdDbjk4bsOXAfGO92wYTMPNei1GMJUmCxSxc3MjGBTS09Rg==",
"license": "MIT" "license": "MIT"
}, },
"node_modules/timezone-groups": { "node_modules/timezone-groups": {

View File

@@ -17,7 +17,7 @@
"deck.gl": "^9.3.1", "deck.gl": "^9.3.1",
"maplibre-gl": "^5.22.0", "maplibre-gl": "^5.22.0",
"proj4": "^2.20.8", "proj4": "^2.20.8",
"three": "^0.184.0", "three": "^0.124.0",
"vite": "^8.0.7" "vite": "^8.0.7"
} }
} }