Skip to content

Commit 16c724e

Browse files
committed
Remove WorldWindow dependency from Camera.
1 parent 4a7f670 commit 16c724e

19 files changed

+198
-198
lines changed

worldwind-examples/src/main/java/gov/nasa/worldwindx/BasicPerformanceBenchmarkActivity.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,9 @@ public static class AnimateCameraCommand implements Runnable {
6767
public AnimateCameraCommand(WorldWindow wwd, Camera end, int steps) {
6868
this.wwd = wwd;
6969

70-
this.beginCamera = new Camera(wwd);
71-
this.endCamera = new Camera(wwd);
72-
this.curCamera = new Camera(wwd);
70+
this.beginCamera = new Camera();
71+
this.endCamera = new Camera();
72+
this.curCamera = new Camera();
7373

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

118118
private SetCameraCommand set(WorldWindow wwd, Camera camera) {
119119
this.wwd = wwd;
120-
this.camera = new Camera(wwd);
120+
this.camera = new Camera();
121121
this.camera.set(camera);
122122
return this;
123123
}
@@ -240,40 +240,40 @@ protected void onStart() {
240240
exec.execute(new ClearFrameMetricsCommand(wwd));
241241

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

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

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

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

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

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

worldwind-examples/src/main/java/gov/nasa/worldwindx/GeneralGlobeActivity.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@
1616

1717
import gov.nasa.worldwind.NavigatorEvent;
1818
import gov.nasa.worldwind.NavigatorListener;
19+
import gov.nasa.worldwind.PickedObject;
1920
import gov.nasa.worldwind.WorldWind;
2021
import gov.nasa.worldwind.WorldWindow;
2122
import gov.nasa.worldwind.geom.Camera;
2223
import gov.nasa.worldwind.geom.LookAt;
24+
import gov.nasa.worldwind.geom.Position;
2325

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

8388
// Get the current camera state to apply to the overlays
84-
event.getCamera().getAsLookAt(lookAt);
89+
event.getCamera().getAsLookAt(wwd.getGlobe(), wwd.getVerticalExaggeration(), terrainPosition, lookAt);
8590

8691
// Update the overlays
8792
updateOverlayContents(lookAt, event.getCamera());

worldwind-examples/src/main/java/gov/nasa/worldwindx/OmnidirectionalSightlineActivity.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ protected void onCreate(Bundle savedInstanceState) {
8989

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

9595
/**

worldwind-examples/src/main/java/gov/nasa/worldwindx/PlacemarksMilStd2525Activity.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ protected void onCreate(Bundle savedInstanceState) {
3939
Position pos = new Position(32.4520, 63.44553, 0);
4040
LookAt lookAt = new LookAt().set(pos.latitude, pos.longitude, pos.altitude, WorldWind.ABSOLUTE,
4141
1e5 /*range*/, 0 /*heading*/, 45 /*tilt*/, 0 /*roll*/);
42-
this.getWorldWindow().getCamera().setFromLookAt(lookAt);
42+
this.getWorldWindow().getCamera().setFromLookAt(this.wwd.getGlobe(), this.wwd.getVerticalExaggeration(), lookAt);
4343

4444
// The MIL-STD-2525 rendering library takes time initialize, we'll perform this task via the
4545
// AsyncTask's background thread and then load the symbols in its post execute handler.

worldwind-examples/src/main/java/gov/nasa/worldwindx/PlacemarksSelectDragActivity.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ protected void onCreate(Bundle savedInstanceState) {
172172

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

178178
/**

worldwind-tutorials/src/main/assets/look_at_view_tutorial.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ <h3>LookAtViewFragment.java</h3>
5858
// Apply the new view
5959
LookAt lookAt = new LookAt();
6060
lookAt.set(airport.latitude, airport.longitude, airport.altitude, WorldWind.ABSOLUTE, range, heading, tilt, 0 /*roll*/);
61-
wwd.getCamera().setFromLookAt(lookAt);
61+
wwd.getCamera().setFromLookAt(wwd.getGlobe(), wwd.getVerticalExaggeration(), lookAt);
6262

6363
return wwd;
6464
}

worldwind-tutorials/src/main/assets/navigator_events_tutorial.html

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,12 @@ <h3>NavigatorEventFragment.java</h3>
8585
// Update the status overlay views whenever the navigator stops moving,
8686
// and also it is moving but at an (arbitrary) maximum refresh rate of 20 Hz.
8787
if (eventAction == WorldWind.NAVIGATOR_STOPPED || elapsedTime > 50) {
88+
// Pick terrain located behind the viewport center point
89+
PickedObject terrainPickedObject = wwd.pick(wwd.getViewport().width / 2f, wwd.getViewport().height / 2f).terrainPickedObject();
90+
Position terrainPosition = terrainPickedObject != null ? terrainPickedObject.getTerrainPosition() : null;
8891

8992
// Get the current camera state to apply to the overlays
90-
event.getCamera().getAsLookAt(lookAt);
93+
event.getCamera().getAsLookAt(wwd.getGlobe(), wwd.getVerticalExaggeration(), terrainPosition, lookAt);
9194

9295
// Update the overlays
9396
updateOverlayContents(lookAt, event.getCamera());

worldwind-tutorials/src/main/assets/placemarks_picking_tutorial.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ <h3>PlacemarksPickingFragment.java</h3>
6262

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

6767
return wwd;
6868
}

worldwind-tutorials/src/main/assets/placemarks_tutorial.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ <h3>PlacemarksFragment.java</h3>
9090
Position pos = airport.getPosition();
9191
LookAt lookAt = new LookAt().set(pos.latitude, pos.longitude, pos.altitude, WorldWind.ABSOLUTE,
9292
1e5 /*range*/, 0 /*heading*/, 80 /*tilt*/, 0 /*roll*/);
93-
wwd.getCamera().setFromLookAt(lookAt);
93+
wwd.getCamera().setFromLookAt(wwd.getGlobe(), wwd.getVerticalExaggeration(), lookAt);
9494

9595
return wwd;
9696
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public WorldWindow createWorldWindow() {
3939
// Apply the new view
4040
LookAt lookAt = new LookAt();
4141
lookAt.set(airport.latitude, airport.longitude, airport.altitude, WorldWind.ABSOLUTE, range, heading, tilt, 0 /*roll*/);
42-
wwd.getCamera().setFromLookAt(lookAt);
42+
wwd.getCamera().setFromLookAt(this.wwd.getGlobe(), this.wwd.getVerticalExaggeration(), lookAt);
4343

4444
return wwd;
4545
}

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,12 @@
1818

1919
import gov.nasa.worldwind.NavigatorEvent;
2020
import gov.nasa.worldwind.NavigatorListener;
21+
import gov.nasa.worldwind.PickedObject;
2122
import gov.nasa.worldwind.WorldWind;
2223
import gov.nasa.worldwind.WorldWindow;
2324
import gov.nasa.worldwind.geom.Camera;
2425
import gov.nasa.worldwind.geom.LookAt;
26+
import gov.nasa.worldwind.geom.Position;
2527

2628
public class NavigatorEventFragment extends BasicGlobeFragment {
2729

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

8287
// Get the current camera state to apply to the overlays
83-
event.getCamera().getAsLookAt(lookAt);
88+
event.getCamera().getAsLookAt(wwd.getGlobe(), wwd.getVerticalExaggeration(), terrainPosition, lookAt);
8489

8590
// Update the overlays
8691
updateOverlayContents(lookAt, event.getCamera());

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,6 @@ protected void createPlacemark(Position position, RenderableLayer layer) {
6969

7070
protected void positionView(WorldWindow wwd) {
7171
LookAt lookAt = new LookAt().set(46.230, -122.190, 500, WorldWind.ABSOLUTE, 1.5e4 /*range*/, 45.0 /*heading*/, 70.0 /*tilt*/, 0 /*roll*/);
72-
wwd.getCamera().setFromLookAt(lookAt);
72+
wwd.getCamera().setFromLookAt(wwd.getGlobe(), wwd.getVerticalExaggeration(), lookAt);
7373
}
7474
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public WorldWindow createWorldWindow() {
8080
Position pos = airport.getPosition();
8181
LookAt lookAt = new LookAt().set(pos.latitude, pos.longitude, pos.altitude, WorldWind.ABSOLUTE,
8282
1e5 /*range*/, 0 /*heading*/, 80 /*tilt*/, 0 /*roll*/);
83-
wwd.getCamera().setFromLookAt(lookAt);
83+
wwd.getCamera().setFromLookAt(wwd.getGlobe(), wwd.getVerticalExaggeration(), lookAt);
8484

8585
return wwd;
8686
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public WorldWindow createWorldWindow() {
5353

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

5858
return wwd;
5959
}

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

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
import gov.nasa.worldwind.geom.Location;
1414
import gov.nasa.worldwind.geom.LookAt;
15+
import gov.nasa.worldwind.geom.Position;
1516
import gov.nasa.worldwind.gesture.GestureListener;
1617
import gov.nasa.worldwind.gesture.GestureRecognizer;
1718
import gov.nasa.worldwind.gesture.MousePanRecognizer;
@@ -79,7 +80,7 @@ public void resetOrientation(boolean headingOnly) {
7980
this.lookAt.tilt = 0;
8081
this.lookAt.roll = 0;
8182
}
82-
this.wwd.getCamera().setFromLookAt(this.lookAt);
83+
this.wwd.getCamera().setFromLookAt(this.wwd.getGlobe(), this.wwd.getVerticalExaggeration(), this.lookAt);
8384
this.wwd.requestRedraw();
8485
this.gestureDidEnd();
8586
}
@@ -88,7 +89,7 @@ public void zoomIn() {
8889
this.gestureDidBegin();
8990
this.lookAt.range /= ZOOM_FACTOR;
9091
this.applyLimits(lookAt);
91-
this.wwd.getCamera().setFromLookAt(this.lookAt);
92+
this.wwd.getCamera().setFromLookAt(this.wwd.getGlobe(), this.wwd.getVerticalExaggeration(), this.lookAt);
9293
this.wwd.requestRedraw();
9394
this.gestureDidEnd();
9495
}
@@ -97,7 +98,7 @@ public void zoomOut() {
9798
this.gestureDidBegin();
9899
this.lookAt.range *= ZOOM_FACTOR;
99100
this.applyLimits(lookAt);
100-
this.wwd.getCamera().setFromLookAt(this.lookAt);
101+
this.wwd.getCamera().setFromLookAt(this.wwd.getGlobe(), this.wwd.getVerticalExaggeration(), this.lookAt);
101102
this.wwd.requestRedraw();
102103
this.gestureDidEnd();
103104
}
@@ -186,7 +187,7 @@ protected void handlePan(GestureRecognizer recognizer) {
186187
this.lookAt.position.longitude = lon;
187188
}
188189

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

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

229-
this.wwd.getCamera().setFromLookAt(this.lookAt);
230+
this.wwd.getCamera().setFromLookAt(this.wwd.getGlobe(), this.wwd.getVerticalExaggeration(), this.lookAt);
230231
this.wwd.requestRedraw();
231232
} else if (state == WorldWind.ENDED || state == WorldWind.CANCELLED) {
232233
this.gestureDidEnd();
@@ -250,7 +251,7 @@ protected void handleTilt(GestureRecognizer recognizer) {
250251
this.lookAt.tilt = this.beginLookAt.tilt + tiltDegrees;
251252
this.applyLimits(this.lookAt);
252253

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

274275
protected void gestureDidBegin() {
275276
if (this.activeGestures++ == 0) {
276-
this.wwd.getCamera().getAsLookAt(this.beginLookAt);
277+
// Pick terrain located behind the viewport center point
278+
PickedObject terrainPickedObject = wwd.pick(wwd.getViewport().width / 2f, wwd.getViewport().height / 2f).terrainPickedObject();
279+
Position terrainPosition = terrainPickedObject != null ? terrainPickedObject.getTerrainPosition() : null;
280+
this.wwd.getCamera().getAsLookAt(wwd.getGlobe(), wwd.getVerticalExaggeration(), terrainPosition, this.beginLookAt);
277281
this.lookAt.set(this.beginLookAt);
278282
}
279283
}

0 commit comments

Comments
 (0)