@@ -56,7 +56,9 @@ public class WorldWindow extends GLSurfaceView implements Choreographer.FrameCal
56
56
57
57
protected static final int MSG_ID_SET_DEPTH_BITS = 4 ;
58
58
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
60
62
61
63
/**
62
64
* Planet or celestial object displayed by this WorldWindow.
@@ -451,21 +453,23 @@ public void cameraFromLookAt(LookAt lookAt) {
451
453
452
454
// Check if camera altitude is not under the surface
453
455
Position position = this .camera .position ;
454
- double elevation = globe .getElevationAtLocation (position .latitude , position .longitude ) * verticalExaggeration + COLLISION_THRESHOLD ;
455
- if (elevation > position .altitude ) {
456
- // Set camera altitude above the surface
457
- position .altitude = elevation ;
458
- // Compute new camera point
459
- globe .geographicToCartesian (position .latitude , position .longitude , position .altitude , scratchPoint );
460
- // Compute look at point
461
- globe .geographicToCartesian (lookAt .position .latitude , lookAt .position .longitude , lookAt .position .altitude , scratchRay .origin );
462
- // Compute normal to globe in look at point
463
- globe .geographicToCartesianNormal (lookAt .position .latitude , lookAt .position .longitude , scratchRay .direction );
464
- // Calculate tilt angle between new camera point and look at point
465
- scratchPoint .subtract (scratchRay .origin ).normalize ();
466
- double dot = scratchRay .direction .dot (scratchPoint );
467
- if (dot >= -1 || dot <= 1 ) {
468
- this .camera .tilt = Math .toDegrees (Math .acos (dot ));
456
+ if (position .altitude < COLLISION_CHECK_LIMIT * verticalExaggeration + COLLISION_THRESHOLD ) {
457
+ double elevation = globe .getElevationAtLocation (position .latitude , position .longitude ) * verticalExaggeration + COLLISION_THRESHOLD ;
458
+ if (elevation > position .altitude ) {
459
+ // Set camera altitude above the surface
460
+ position .altitude = elevation ;
461
+ // Compute new camera point
462
+ globe .geographicToCartesian (position .latitude , position .longitude , position .altitude , scratchPoint );
463
+ // Compute look at point
464
+ globe .geographicToCartesian (lookAt .position .latitude , lookAt .position .longitude , lookAt .position .altitude , scratchRay .origin );
465
+ // Compute normal to globe in look at point
466
+ globe .geographicToCartesianNormal (lookAt .position .latitude , lookAt .position .longitude , scratchRay .direction );
467
+ // Calculate tilt angle between new camera point and look at point
468
+ scratchPoint .subtract (scratchRay .origin ).normalize ();
469
+ double dot = scratchRay .direction .dot (scratchPoint );
470
+ if (dot >= -1 || dot <= 1 ) {
471
+ this .camera .tilt = Math .toDegrees (Math .acos (dot ));
472
+ }
469
473
}
470
474
}
471
475
}
0 commit comments