Skip to content

Commit

Permalink
fix(#9): hide globe when pivot is blockd by curvature
Browse files Browse the repository at this point in the history
  • Loading branch information
adriahso committed Sep 27, 2025
1 parent fefe11b commit 1b3a9d8
Showing 1 changed file with 38 additions and 4 deletions.
42 changes: 38 additions & 4 deletions src/cameraSync.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ export function syncCameras(potreeViewer, cesiumViewer) {
new Cesium.Cartesian3()
)

// Hide globe when camera is below surface
const camHeight = Cesium.Cartographic.fromCartesian(cPos).height
cesiumViewer.scene.globe.show = camHeight >= 0;
cesiumViewer.scene.skyAtmosphere.show = camHeight >= 0;
// Hide globe when the camera is below the surface or blocked by the curvature of the Earth
const showGlobe = shouldShowGlobe(cPos, cTarget);
cesiumViewer.scene.globe.show = showGlobe;
cesiumViewer.scene.skyAtmosphere.show = showGlobe;

cesiumViewer.camera.setView({
destination: cPos,
Expand All @@ -46,4 +46,38 @@ export function syncCameras(potreeViewer, cesiumViewer) {
const fovx = Math.atan(Math.tan(0.5 * fovy) * aspect) * 2
cesiumViewer.camera.frustum.fov = fovx
}
}

/**
* Determines whether the globe should be visible based on the camera position.
*
* Returns false if the camera is below the globe surface or if the pivot
* point would be blocked by the curvature of the Earth. This is handled
* in a unified way by projecting the pivot to the globe surface and
* comparing the camera and pivot positions along the axis from the Earth's
* center through the pivot.
*
* @param cameraPos - The camera position in Cesium Cartesian3 coordinates
* @param pivot - The pivot point in the point cloud (Cartesian3)
* @returns true if the globe should be visible, false if it should be hidden
*/
function shouldShowGlobe(cameraPos, pivot) {
const ellipsoid = Cesium.Ellipsoid.WGS84;
const earthCenter = Cesium.Cartesian3.ZERO;

// Get point on globe surface directly above the pivot
const carto = Cesium.Cartographic.fromCartesian(pivot);
const pivotSurface = Cesium.Cartesian3.fromRadians(carto.longitude, carto.latitude, 0, ellipsoid);

// Axis vector from Earth center through pivot
const axis = Cesium.Cartesian3.subtract(pivotSurface, earthCenter, new Cesium.Cartesian3());
Cesium.Cartesian3.normalize(axis, axis);

// Project camera and pivot onto this axis
const camProj = Cesium.Cartesian3.dot(cameraPos, axis);
const pivotProj = Cesium.Cartesian3.dot(pivotSurface, axis);

// If camera is "above" pivot on this axis, the globe should be visible
// If camera is "below" pivot on this axis, the globe should be not be visible
return camProj >= pivotProj;
}

0 comments on commit 1b3a9d8

Please sign in to comment.