Skip to content

Commit

Permalink
Remove WorldWindow dependency from Camera.
Browse files Browse the repository at this point in the history
  • Loading branch information
ComBatVision committed Aug 4, 2022
1 parent 4a7f670 commit 56c4e8d
Show file tree
Hide file tree
Showing 20 changed files with 214 additions and 204 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ public static class AnimateCameraCommand implements Runnable {
public AnimateCameraCommand(WorldWindow wwd, Camera end, int steps) {
this.wwd = wwd;

this.beginCamera = new Camera(wwd);
this.endCamera = new Camera(wwd);
this.curCamera = new Camera(wwd);
this.beginCamera = new Camera();
this.endCamera = new Camera();
this.curCamera = new Camera();

this.endCamera.set(end);
this.steps = steps;
Expand Down Expand Up @@ -117,7 +117,7 @@ public static SetCameraCommand obtain(WorldWindow wwd, Camera camera) {

private SetCameraCommand set(WorldWindow wwd, Camera camera) {
this.wwd = wwd;
this.camera = new Camera(wwd);
this.camera = new Camera();
this.camera.set(camera);
return this;
}
Expand Down Expand Up @@ -240,40 +240,40 @@ protected void onStart() {
exec.execute(new ClearFrameMetricsCommand(wwd));

// After a 1/2 second delay, fly to NASA Ames Research Center over 100 frames.
Camera cam = new Camera(this.getWorldWindow()).set(arc.latitude, arc.longitude, 10e3, WorldWind.ABSOLUTE, 0, 0, 0);
Camera cam = new Camera().set(arc.latitude, arc.longitude, 10e3, WorldWind.ABSOLUTE, 0, 0, 0);
exec.execute(new AnimateCameraCommand(wwd, cam, 100));

// After a 1/2 second delay, rotate the camera to look at NASA Goddard Space Flight Center over 50 frames.
double azimuth = arc.greatCircleAzimuth(gsfc);
cam = new Camera(this.getWorldWindow()).set(arc.latitude, arc.longitude, 10e3, WorldWind.ABSOLUTE, azimuth, 70, 0);
cam = new Camera().set(arc.latitude, arc.longitude, 10e3, WorldWind.ABSOLUTE, azimuth, 70, 0);
exec.execute(new SleepCommand(500));
exec.execute(new AnimateCameraCommand(wwd, cam, 50));

// After a 1/2 second delay, fly the camera to NASA Goddard Space Flight Center over 200 frames.
Location midLoc = arc.interpolateAlongPath(gsfc, WorldWind.GREAT_CIRCLE, 0.5, new Location());
azimuth = midLoc.greatCircleAzimuth(gsfc);
exec.execute(new SleepCommand(500));
cam = new Camera(this.getWorldWindow()).set(midLoc.latitude, midLoc.longitude, 1000e3, WorldWind.ABSOLUTE, azimuth, 0, 0);
cam = new Camera().set(midLoc.latitude, midLoc.longitude, 1000e3, WorldWind.ABSOLUTE, azimuth, 0, 0);
exec.execute(new AnimateCameraCommand(wwd, cam, 100));
cam = new Camera(this.getWorldWindow()).set(gsfc.latitude, gsfc.longitude, 10e3, WorldWind.ABSOLUTE, azimuth, 70, 0);
cam = new Camera().set(gsfc.latitude, gsfc.longitude, 10e3, WorldWind.ABSOLUTE, azimuth, 70, 0);
exec.execute(new AnimateCameraCommand(wwd, cam, 100));

// After a 1/2 second delay, rotate the camera to look at ESA Centre for Earth Observation over 50 frames.
azimuth = gsfc.greatCircleAzimuth(esrin);
cam = new Camera(this.getWorldWindow()).set(gsfc.latitude, gsfc.longitude, 10e3, WorldWind.ABSOLUTE, azimuth, 90, 0);
cam = new Camera().set(gsfc.latitude, gsfc.longitude, 10e3, WorldWind.ABSOLUTE, azimuth, 90, 0);
exec.execute(new SleepCommand(500));
exec.execute(new AnimateCameraCommand(wwd, cam, 50));

// After a 1/2 second delay, fly the camera to ESA Centre for Earth Observation over 200 frames.
midLoc = gsfc.interpolateAlongPath(esrin, WorldWind.GREAT_CIRCLE, 0.5, new Location());
exec.execute(new SleepCommand(500));
cam = new Camera(this.getWorldWindow()).set(midLoc.latitude, midLoc.longitude, 1000e3, WorldWind.ABSOLUTE, azimuth, 60, 0);
cam = new Camera().set(midLoc.latitude, midLoc.longitude, 1000e3, WorldWind.ABSOLUTE, azimuth, 60, 0);
exec.execute(new AnimateCameraCommand(wwd, cam, 100));
cam = new Camera(this.getWorldWindow()).set(esrin.latitude, esrin.longitude, 100e3, WorldWind.ABSOLUTE, azimuth, 30, 0);
cam = new Camera().set(esrin.latitude, esrin.longitude, 100e3, WorldWind.ABSOLUTE, azimuth, 30, 0);
exec.execute(new AnimateCameraCommand(wwd, cam, 100));

// After a 1/2 second delay, back the camera out to look at ESA Centre for Earth Observation over 100 frames.
cam = new Camera(this.getWorldWindow()).set(esrin.latitude, esrin.longitude, 2000e3, WorldWind.ABSOLUTE, 0, 0, 0);
cam = new Camera().set(esrin.latitude, esrin.longitude, 2000e3, WorldWind.ABSOLUTE, 0, 0, 0);
exec.execute(new SleepCommand(500));
exec.execute(new AnimateCameraCommand(wwd, cam, 100));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@

import gov.nasa.worldwind.NavigatorEvent;
import gov.nasa.worldwind.NavigatorListener;
import gov.nasa.worldwind.PickedObject;
import gov.nasa.worldwind.WorldWind;
import gov.nasa.worldwind.WorldWindow;
import gov.nasa.worldwind.geom.Camera;
import gov.nasa.worldwind.geom.LookAt;
import gov.nasa.worldwind.geom.Position;

/**
* Creates a general purpose globe view with touch navigation, a few layers, and a coordinates overlay.
Expand Down Expand Up @@ -79,9 +81,12 @@ public void onNavigatorEvent(WorldWindow wwd, NavigatorEvent event) {
// Update the status overlay views whenever the navigator stops moving,
// and also it is moving but at an (arbitrary) maximum refresh rate of 20 Hz.
if (eventAction == WorldWind.NAVIGATOR_STOPPED || elapsedTime > 50) {
// Pick terrain located behind the viewport center point
PickedObject terrainPickedObject = wwd.pick(wwd.getViewport().width / 2f, wwd.getViewport().height / 2f).terrainPickedObject();
Position terrainPosition = terrainPickedObject != null ? terrainPickedObject.getTerrainPosition() : null;

// Get the current camera state to apply to the overlays
event.getCamera().getAsLookAt(lookAt);
event.getCamera().getAsLookAt(wwd.getGlobe(), wwd.getVerticalExaggeration(), terrainPosition, lookAt);

// Update the overlays
updateOverlayContents(lookAt, event.getCamera());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ protected void onCreate(Bundle savedInstanceState) {

// And finally, for this demo, position the viewer to look at the sightline position
LookAt lookAt = new LookAt().set(pos.latitude, pos.longitude, pos.altitude, WorldWind.ABSOLUTE, 2e4 /*range*/, 0 /*heading*/, 45 /*tilt*/, 0 /*roll*/);
this.getWorldWindow().getCamera().setFromLookAt(lookAt);
this.getWorldWindow().getCamera().setFromLookAt(this.wwd.getGlobe(), this.wwd.getVerticalExaggeration(), lookAt);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ protected void onCreate(Bundle savedInstanceState) {
Position pos = new Position(32.4520, 63.44553, 0);
LookAt lookAt = new LookAt().set(pos.latitude, pos.longitude, pos.altitude, WorldWind.ABSOLUTE,
1e5 /*range*/, 0 /*heading*/, 45 /*tilt*/, 0 /*roll*/);
this.getWorldWindow().getCamera().setFromLookAt(lookAt);
this.getWorldWindow().getCamera().setFromLookAt(this.wwd.getGlobe(), this.wwd.getVerticalExaggeration(), lookAt);

// The MIL-STD-2525 rendering library takes time initialize, we'll perform this task via the
// AsyncTask's background thread and then load the symbols in its post execute handler.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ protected void onCreate(Bundle savedInstanceState) {

// And finally, for this demo, position the viewer to look at the placemarks
LookAt lookAt = new LookAt().set(34.150, -119.150, 0, WorldWind.ABSOLUTE, 2e4 /*range*/, 0 /*heading*/, 45 /*tilt*/, 0 /*roll*/);
this.getWorldWindow().getCamera().setFromLookAt(lookAt);
this.getWorldWindow().getCamera().setFromLookAt(this.wwd.getGlobe(), this.wwd.getVerticalExaggeration(), lookAt);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ <h3>LookAtViewFragment.java</h3>
// Apply the new view
LookAt lookAt = new LookAt();
lookAt.set(airport.latitude, airport.longitude, airport.altitude, WorldWind.ABSOLUTE, range, heading, tilt, 0 /*roll*/);
wwd.getCamera().setFromLookAt(lookAt);
wwd.getCamera().setFromLookAt(wwd.getGlobe(), wwd.getVerticalExaggeration(), lookAt);

return wwd;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,12 @@ <h3>NavigatorEventFragment.java</h3>
// Update the status overlay views whenever the navigator stops moving,
// and also it is moving but at an (arbitrary) maximum refresh rate of 20 Hz.
if (eventAction == WorldWind.NAVIGATOR_STOPPED || elapsedTime > 50) {
// Pick terrain located behind the viewport center point
PickedObject terrainPickedObject = wwd.pick(wwd.getViewport().width / 2f, wwd.getViewport().height / 2f).terrainPickedObject();
Position terrainPosition = terrainPickedObject != null ? terrainPickedObject.getTerrainPosition() : null;

// Get the current camera state to apply to the overlays
event.getCamera().getAsLookAt(lookAt);
event.getCamera().getAsLookAt(wwd.getGlobe(), wwd.getVerticalExaggeration(), terrainPosition, lookAt);

// Update the overlays
updateOverlayContents(lookAt, event.getCamera());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ <h3>PlacemarksPickingFragment.java</h3>

// Position the viewer to look near the airports
LookAt lookAt = new LookAt().set(34.15, -119.15, 0, WorldWind.ABSOLUTE, 2e4 /*range*/, 0 /*heading*/, 45 /*tilt*/, 0 /*roll*/);
wwd.getCamera().setFromLookAt(lookAt);
wwd.getCamera().setFromLookAt(wwd.getGlobe(), wwd.getVerticalExaggeration(), lookAt);

return wwd;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ <h3>PlacemarksFragment.java</h3>
Position pos = airport.getPosition();
LookAt lookAt = new LookAt().set(pos.latitude, pos.longitude, pos.altitude, WorldWind.ABSOLUTE,
1e5 /*range*/, 0 /*heading*/, 80 /*tilt*/, 0 /*roll*/);
wwd.getCamera().setFromLookAt(lookAt);
wwd.getCamera().setFromLookAt(wwd.getGlobe(), wwd.getVerticalExaggeration(), lookAt);

return wwd;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,16 @@
import gov.nasa.worldwind.WorldWindow;
import gov.nasa.worldwind.geom.Camera;
import gov.nasa.worldwind.geom.Location;
import gov.nasa.worldwind.geom.Position;
import gov.nasa.worldwind.gesture.GestureRecognizer;
import gov.nasa.worldwind.gesture.PinchRecognizer;
import gov.nasa.worldwind.gesture.RotationRecognizer;
import gov.nasa.worldwind.util.WWMath;

public class CameraControlFragment extends BasicGlobeFragment {

private static final double COLLISION_THRESHOLD = 20.0; // 20m above surface

/**
* Creates a new WorldWindow object with a custom WorldWindowController.
*/
Expand All @@ -42,7 +45,7 @@ public WorldWindow createWorldWindow() {
* A custom WorldWindController that uses gestures to control the camera directly via the setAsCamera interface
* instead of the default setAsLookAt interface.
*/
private class CameraController extends BasicWorldWindowController {
private static class CameraController extends BasicWorldWindowController {

protected double beginHeading;

Expand Down Expand Up @@ -189,15 +192,22 @@ protected void gestureDidBegin() {
}

protected void applyLimits(Camera camera) {
double distanceToExtents = this.wwd.distanceToViewGlobeExtents();
Position position = camera.position;

double minAltitude = 100;
double maxAltitude = distanceToExtents;
camera.position.altitude = WWMath.clamp(camera.position.altitude, minAltitude, maxAltitude);
double maxAltitude = this.wwd.distanceToViewGlobeExtents();
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;
}

// Limit the tilt to between nadir and the horizon (roughly)
double r = wwd.getGlobe().getRadiusAt(camera.position.latitude, camera.position.latitude);
double maxTilt = Math.toDegrees(Math.asin(r / (r + camera.position.altitude)));
double r = wwd.getGlobe().getRadiusAt(position.latitude, position.latitude);
double maxTilt = Math.toDegrees(Math.asin(r / (r + position.altitude)));
double minTilt = 0;
camera.tilt = WWMath.clamp(camera.tilt, minTilt, maxTilt);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public WorldWindow createWorldWindow() {
// Apply the new view
LookAt lookAt = new LookAt();
lookAt.set(airport.latitude, airport.longitude, airport.altitude, WorldWind.ABSOLUTE, range, heading, tilt, 0 /*roll*/);
wwd.getCamera().setFromLookAt(lookAt);
wwd.getCamera().setFromLookAt(wwd.getGlobe(), wwd.getVerticalExaggeration(), lookAt);

return wwd;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@

import gov.nasa.worldwind.NavigatorEvent;
import gov.nasa.worldwind.NavigatorListener;
import gov.nasa.worldwind.PickedObject;
import gov.nasa.worldwind.WorldWind;
import gov.nasa.worldwind.WorldWindow;
import gov.nasa.worldwind.geom.Camera;
import gov.nasa.worldwind.geom.LookAt;
import gov.nasa.worldwind.geom.Position;

public class NavigatorEventFragment extends BasicGlobeFragment {

Expand Down Expand Up @@ -78,9 +80,12 @@ public void onNavigatorEvent(WorldWindow wwd, NavigatorEvent event) {
// Update the status overlay views whenever the navigator stops moving,
// and also it is moving but at an (arbitrary) maximum refresh rate of 20 Hz.
if (eventAction == WorldWind.NAVIGATOR_STOPPED || elapsedTime > 50) {
// Pick terrain located behind the viewport center point
PickedObject terrainPickedObject = wwd.pick(wwd.getViewport().width / 2f, wwd.getViewport().height / 2f).terrainPickedObject();
Position terrainPosition = terrainPickedObject != null ? terrainPickedObject.getTerrainPosition() : null;

// Get the current camera state to apply to the overlays
event.getCamera().getAsLookAt(lookAt);
event.getCamera().getAsLookAt(wwd.getGlobe(), wwd.getVerticalExaggeration(), terrainPosition, lookAt);

// Update the overlays
updateOverlayContents(lookAt, event.getCamera());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,6 @@ protected void createPlacemark(Position position, RenderableLayer layer) {

protected void positionView(WorldWindow wwd) {
LookAt lookAt = new LookAt().set(46.230, -122.190, 500, WorldWind.ABSOLUTE, 1.5e4 /*range*/, 45.0 /*heading*/, 70.0 /*tilt*/, 0 /*roll*/);
wwd.getCamera().setFromLookAt(lookAt);
wwd.getCamera().setFromLookAt(wwd.getGlobe(), wwd.getVerticalExaggeration(), lookAt);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public WorldWindow createWorldWindow() {
Position pos = airport.getPosition();
LookAt lookAt = new LookAt().set(pos.latitude, pos.longitude, pos.altitude, WorldWind.ABSOLUTE,
1e5 /*range*/, 0 /*heading*/, 80 /*tilt*/, 0 /*roll*/);
wwd.getCamera().setFromLookAt(lookAt);
wwd.getCamera().setFromLookAt(wwd.getGlobe(), wwd.getVerticalExaggeration(), lookAt);

return wwd;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public WorldWindow createWorldWindow() {

// Position the viewer to look near the airports
LookAt lookAt = new LookAt().set(34.15, -119.15, 0, WorldWind.ABSOLUTE, 2e4 /*range*/, 0 /*heading*/, 45 /*tilt*/, 0 /*roll*/);
wwd.getCamera().setFromLookAt(lookAt);
wwd.getCamera().setFromLookAt(wwd.getGlobe(), wwd.getVerticalExaggeration(), lookAt);

return wwd;
}
Expand Down
Loading

0 comments on commit 56c4e8d

Please sign in to comment.