Skip to content

Commit

Permalink
Skip camera surface collision check if altitude is above Everest.
Browse files Browse the repository at this point in the history
  • Loading branch information
ComBatVision committed Sep 1, 2022
1 parent b1fe177 commit e495778
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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

/**
Expand Down Expand Up @@ -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)
Expand Down
36 changes: 20 additions & 16 deletions worldwind/src/main/java/gov/nasa/worldwind/WorldWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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));
}
}
}
}
Expand Down

0 comments on commit e495778

Please sign in to comment.