Skip to content

Commit e495778

Browse files
committed
Skip camera surface collision check if altitude is above Everest.
1 parent b1fe177 commit e495778

File tree

2 files changed

+29
-20
lines changed

2 files changed

+29
-20
lines changed

worldwind-tutorials/src/main/java/gov/nasa/worldwindx/CameraControlFragment.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
public class CameraControlFragment extends BasicGlobeFragment {
2020

21+
private static final double COLLISION_CHECK_LIMIT = 8848.86; // Everest mountain altitude
22+
2123
private static final double COLLISION_THRESHOLD = 20.0; // 20m above surface
2224

2325
/**
@@ -199,10 +201,13 @@ protected void applyLimits(Camera camera) {
199201
position.altitude = WWMath.clamp(position.altitude, minAltitude, maxAltitude);
200202

201203
// Check if camera altitude is not under the surface
202-
double elevation = this.wwd.getGlobe().getElevationAtLocation(position.latitude, position.longitude)
203-
* wwd.getVerticalExaggeration() + COLLISION_THRESHOLD;
204-
if (elevation > position.altitude) {
205-
position.altitude = elevation;
204+
double ve = wwd.getVerticalExaggeration();
205+
if (position.altitude < COLLISION_CHECK_LIMIT * ve + COLLISION_THRESHOLD) {
206+
double elevation = this.wwd.getGlobe().getElevationAtLocation(position.latitude, position.longitude)
207+
* ve + COLLISION_THRESHOLD;
208+
if (elevation > position.altitude) {
209+
position.altitude = elevation;
210+
}
206211
}
207212

208213
// Limit the tilt to between nadir and the horizon (roughly)

worldwind/src/main/java/gov/nasa/worldwind/WorldWindow.java

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -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.
@@ -451,21 +453,23 @@ public void cameraFromLookAt(LookAt lookAt) {
451453

452454
// Check if camera altitude is not under the surface
453455
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+
}
469473
}
470474
}
471475
}

0 commit comments

Comments
 (0)