@@ -56,7 +56,9 @@ public class WorldWindow extends GLSurfaceView implements Choreographer.FrameCal
5656
5757 protected static final int MSG_ID_SET_DEPTH_BITS = 4 ;
5858
59- protected final static double COLLISION_THRESHOLD = 10.0 ; // 10m above surface
59+ protected static final double COLLISION_CHECK_LIMIT = 8848.86 ; // Everest mountain altitude
60+
61+ protected static final double COLLISION_THRESHOLD = 10.0 ; // 10m above surface
6062
6163 /**
6264 * Planet or celestial object displayed by this WorldWindow.
@@ -460,21 +462,23 @@ public void cameraFromLookAt(LookAt lookAt) {
460462
461463 // Check if camera altitude is not under the surface
462464 Position position = this .camera .position ;
463- double elevation = globe .getElevationAtLocation (position .latitude , position .longitude ) * verticalExaggeration + COLLISION_THRESHOLD ;
464- if (elevation > position .altitude ) {
465- // Set camera altitude above the surface
466- position .altitude = elevation ;
467- // Compute new camera point
468- globe .geographicToCartesian (position .latitude , position .longitude , position .altitude , scratchPoint );
469- // Compute look at point
470- globe .geographicToCartesian (lookAt .position .latitude , lookAt .position .longitude , lookAt .position .altitude , scratchRay .origin );
471- // Compute normal to globe in look at point
472- globe .geographicToCartesianNormal (lookAt .position .latitude , lookAt .position .longitude , scratchRay .direction );
473- // Calculate tilt angle between new camera point and look at point
474- scratchPoint .subtract (scratchRay .origin ).normalize ();
475- double dot = scratchRay .direction .dot (scratchPoint );
476- if (dot >= -1 || dot <= 1 ) {
477- this .camera .tilt = Math .toDegrees (Math .acos (dot ));
465+ if (position .altitude < COLLISION_CHECK_LIMIT * verticalExaggeration + COLLISION_THRESHOLD ) {
466+ double elevation = globe .getElevationAtLocation (position .latitude , position .longitude ) * verticalExaggeration + COLLISION_THRESHOLD ;
467+ if (elevation > position .altitude ) {
468+ // Set camera altitude above the surface
469+ position .altitude = elevation ;
470+ // Compute new camera point
471+ globe .geographicToCartesian (position .latitude , position .longitude , position .altitude , scratchPoint );
472+ // Compute look at point
473+ globe .geographicToCartesian (lookAt .position .latitude , lookAt .position .longitude , lookAt .position .altitude , scratchRay .origin );
474+ // Compute normal to globe in look at point
475+ globe .geographicToCartesianNormal (lookAt .position .latitude , lookAt .position .longitude , scratchRay .direction );
476+ // Calculate tilt angle between new camera point and look at point
477+ scratchPoint .subtract (scratchRay .origin ).normalize ();
478+ double dot = scratchRay .direction .dot (scratchPoint );
479+ if (dot >= -1 || dot <= 1 ) {
480+ this .camera .tilt = Math .toDegrees (Math .acos (dot ));
481+ }
478482 }
479483 }
480484 }
0 commit comments