diff --git a/worldwind-tutorials/src/main/java/gov/nasa/worldwindx/CameraControlFragment.java b/worldwind-tutorials/src/main/java/gov/nasa/worldwindx/CameraControlFragment.java index c0c1e9ce..4d8f261b 100644 --- a/worldwind-tutorials/src/main/java/gov/nasa/worldwindx/CameraControlFragment.java +++ b/worldwind-tutorials/src/main/java/gov/nasa/worldwindx/CameraControlFragment.java @@ -18,6 +18,8 @@ public class CameraControlFragment extends BasicGlobeFragment { + private static final double COLLISION_CHECK_LIMIT = 8848.86; // Everest mountain altitude + private static final double COLLISION_THRESHOLD = 20.0; // 20m above surface /** @@ -199,10 +201,13 @@ protected void applyLimits(Camera camera) { position.altitude = WWMath.clamp(position.altitude, minAltitude, maxAltitude); // Check if camera altitude is not under the surface - double elevation = this.wwd.getGlobe().getElevationAtLocation(position.latitude, position.longitude) - * wwd.getVerticalExaggeration() + COLLISION_THRESHOLD; - if (elevation > position.altitude) { - position.altitude = elevation; + double ve = wwd.getVerticalExaggeration(); + if (position.altitude < COLLISION_CHECK_LIMIT * ve + COLLISION_THRESHOLD) { + double elevation = this.wwd.getGlobe().getElevationAtLocation(position.latitude, position.longitude) + * ve + COLLISION_THRESHOLD; + if (elevation > position.altitude) { + position.altitude = elevation; + } } // Limit the tilt to between nadir and the horizon (roughly) diff --git a/worldwind/src/main/java/gov/nasa/worldwind/WorldWindow.java b/worldwind/src/main/java/gov/nasa/worldwind/WorldWindow.java index 334f74c2..03b55110 100644 --- a/worldwind/src/main/java/gov/nasa/worldwind/WorldWindow.java +++ b/worldwind/src/main/java/gov/nasa/worldwind/WorldWindow.java @@ -56,7 +56,9 @@ public class WorldWindow extends GLSurfaceView implements Choreographer.FrameCal protected static final int MSG_ID_SET_DEPTH_BITS = 4; - protected final static double COLLISION_THRESHOLD = 10.0; // 10m above surface + protected static final double COLLISION_CHECK_LIMIT = 8848.86; // Everest mountain altitude + + protected static final double COLLISION_THRESHOLD = 10.0; // 10m above surface /** * Planet or celestial object displayed by this WorldWindow. @@ -451,21 +453,23 @@ public void cameraFromLookAt(LookAt lookAt) { // Check if camera altitude is not under the surface Position position = this.camera.position; - double elevation = globe.getElevationAtLocation(position.latitude, position.longitude) * verticalExaggeration + COLLISION_THRESHOLD; - if(elevation > position.altitude) { - // Set camera altitude above the surface - position.altitude = elevation; - // Compute new camera point - globe.geographicToCartesian(position.latitude, position.longitude, position.altitude, scratchPoint); - // Compute look at point - globe.geographicToCartesian(lookAt.position.latitude, lookAt.position.longitude, lookAt.position.altitude, scratchRay.origin); - // Compute normal to globe in look at point - globe.geographicToCartesianNormal(lookAt.position.latitude, lookAt.position.longitude, scratchRay.direction); - // Calculate tilt angle between new camera point and look at point - scratchPoint.subtract(scratchRay.origin).normalize(); - double dot = scratchRay.direction.dot(scratchPoint); - if (dot >= -1 || dot <= 1) { - this.camera.tilt = Math.toDegrees(Math.acos(dot)); + if (position.altitude < COLLISION_CHECK_LIMIT * verticalExaggeration + COLLISION_THRESHOLD) { + double elevation = globe.getElevationAtLocation(position.latitude, position.longitude) * verticalExaggeration + COLLISION_THRESHOLD; + if (elevation > position.altitude) { + // Set camera altitude above the surface + position.altitude = elevation; + // Compute new camera point + globe.geographicToCartesian(position.latitude, position.longitude, position.altitude, scratchPoint); + // Compute look at point + globe.geographicToCartesian(lookAt.position.latitude, lookAt.position.longitude, lookAt.position.altitude, scratchRay.origin); + // Compute normal to globe in look at point + globe.geographicToCartesianNormal(lookAt.position.latitude, lookAt.position.longitude, scratchRay.direction); + // Calculate tilt angle between new camera point and look at point + scratchPoint.subtract(scratchRay.origin).normalize(); + double dot = scratchRay.direction.dot(scratchPoint); + if (dot >= -1 || dot <= 1) { + this.camera.tilt = Math.toDegrees(Math.acos(dot)); + } } } }