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 244044b
Show file tree
Hide file tree
Showing 18 changed files with 193 additions and 197 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 @@ -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 @@ -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(this.wwd.getGlobe(), this.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,11 @@ 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) {
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
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import gov.nasa.worldwind.geom.Location;
import gov.nasa.worldwind.geom.LookAt;
import gov.nasa.worldwind.geom.Position;
import gov.nasa.worldwind.gesture.GestureListener;
import gov.nasa.worldwind.gesture.GestureRecognizer;
import gov.nasa.worldwind.gesture.MousePanRecognizer;
Expand Down Expand Up @@ -79,7 +80,7 @@ public void resetOrientation(boolean headingOnly) {
this.lookAt.tilt = 0;
this.lookAt.roll = 0;
}
this.wwd.getCamera().setFromLookAt(this.lookAt);
this.wwd.getCamera().setFromLookAt(this.wwd.getGlobe(), this.wwd.getVerticalExaggeration(), this.lookAt);
this.wwd.requestRedraw();
this.gestureDidEnd();
}
Expand All @@ -88,7 +89,7 @@ public void zoomIn() {
this.gestureDidBegin();
this.lookAt.range /= ZOOM_FACTOR;
this.applyLimits(lookAt);
this.wwd.getCamera().setFromLookAt(this.lookAt);
this.wwd.getCamera().setFromLookAt(this.wwd.getGlobe(), this.wwd.getVerticalExaggeration(), this.lookAt);
this.wwd.requestRedraw();
this.gestureDidEnd();
}
Expand All @@ -97,7 +98,7 @@ public void zoomOut() {
this.gestureDidBegin();
this.lookAt.range *= ZOOM_FACTOR;
this.applyLimits(lookAt);
this.wwd.getCamera().setFromLookAt(this.lookAt);
this.wwd.getCamera().setFromLookAt(this.wwd.getGlobe(), this.wwd.getVerticalExaggeration(), this.lookAt);
this.wwd.requestRedraw();
this.gestureDidEnd();
}
Expand Down Expand Up @@ -186,7 +187,7 @@ protected void handlePan(GestureRecognizer recognizer) {
this.lookAt.position.longitude = lon;
}

this.wwd.getCamera().setFromLookAt(this.lookAt);
this.wwd.getCamera().setFromLookAt(this.wwd.getGlobe(), this.wwd.getVerticalExaggeration(), this.lookAt);
this.wwd.requestRedraw();
} else if (state == WorldWind.ENDED || state == WorldWind.CANCELLED) {
this.gestureDidEnd();
Expand All @@ -205,7 +206,7 @@ protected void handlePinch(GestureRecognizer recognizer) {
this.lookAt.range = this.beginLookAt.range / scale;
this.applyLimits(this.lookAt);

this.wwd.getCamera().setFromLookAt(this.lookAt);
this.wwd.getCamera().setFromLookAt(this.wwd.getGlobe(), this.wwd.getVerticalExaggeration(), this.lookAt);
this.wwd.requestRedraw();
}
} else if (state == WorldWind.ENDED || state == WorldWind.CANCELLED) {
Expand All @@ -226,7 +227,7 @@ protected void handleRotate(GestureRecognizer recognizer) {
this.lookAt.heading = WWMath.normalizeAngle360(this.lookAt.heading + headingDegrees);
this.lastRotation = rotation;

this.wwd.getCamera().setFromLookAt(this.lookAt);
this.wwd.getCamera().setFromLookAt(this.wwd.getGlobe(), this.wwd.getVerticalExaggeration(), this.lookAt);
this.wwd.requestRedraw();
} else if (state == WorldWind.ENDED || state == WorldWind.CANCELLED) {
this.gestureDidEnd();
Expand All @@ -250,7 +251,7 @@ protected void handleTilt(GestureRecognizer recognizer) {
this.lookAt.tilt = this.beginLookAt.tilt + tiltDegrees;
this.applyLimits(this.lookAt);

this.wwd.getCamera().setFromLookAt(this.lookAt);
this.wwd.getCamera().setFromLookAt(this.wwd.getGlobe(), this.wwd.getVerticalExaggeration(), this.lookAt);
this.wwd.requestRedraw();
} else if (state == WorldWind.ENDED || state == WorldWind.CANCELLED) {
this.gestureDidEnd();
Expand All @@ -273,7 +274,10 @@ protected void applyLimits(LookAt lookAt) {

protected void gestureDidBegin() {
if (this.activeGestures++ == 0) {
this.wwd.getCamera().getAsLookAt(this.beginLookAt);
// 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;
this.wwd.getCamera().getAsLookAt(wwd.getGlobe(), wwd.getVerticalExaggeration(), terrainPosition, this.beginLookAt);
this.lookAt.set(this.beginLookAt);
}
}
Expand Down
Loading

0 comments on commit 244044b

Please sign in to comment.