Skip to content

Commit 1727068

Browse files
committed
Wrap latitude, longitude and altitude into Position object inside of Navigator, Camera and LookAt.
Move field of view attribute into Camera. Deprecate Navigator and use direct Camera control instead. Use two-fingers tilt. Do not change heading on tilt. Set gesture interpret distance based on Android screen density instead of hard-coded pixels. Add additional zoomIn, zoomOut and resetOrientation commands to BasicWorldWindowController. Add secondary mouse button tilt support to BasicWorldWindowController. Remove code which never executes due to a bug in WWMath.
1 parent 7431823 commit 1727068

File tree

59 files changed

+639
-647
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+639
-647
lines changed

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

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -127,17 +127,17 @@ protected void onResume() {
127127
this.navigationView.setCheckedItem(selectedItemId);
128128
// Use this Activity's Handler to periodically print the FrameMetrics.
129129
this.handler.sendEmptyMessageDelayed(PRINT_METRICS, PRINT_METRICS_DELAY);
130-
// Restore the navigator's camera state from previously saved session data
131-
this.restoreNavigatorState();
130+
// Restore camera state from previously saved session data
131+
this.restoreCameraState();
132132
}
133133

134134
@Override
135135
protected void onPause() {
136136
super.onPause();
137137
// Stop printing frame metrics when this activity is paused.
138138
this.handler.removeMessages(PRINT_METRICS);
139-
// Save the navigator's camera state.
140-
this.saveNavigatorState();
139+
// Save camera state.
140+
this.saveCameraState();
141141
}
142142

143143
@Override
@@ -163,9 +163,9 @@ public boolean onOptionsItemSelected(MenuItem item) {
163163
}
164164

165165
/**
166-
* Saves the Navigator's camera data to a SharedPreferences object.
166+
* Saves camera state to a SharedPreferences object.
167167
*/
168-
protected void saveNavigatorState() {
168+
protected void saveCameraState() {
169169
WorldWindow wwd = this.getWorldWindow();
170170
if (wwd != null) {
171171
SharedPreferences preferences = this.getPreferences(MODE_PRIVATE);
@@ -175,10 +175,10 @@ protected void saveNavigatorState() {
175175
editor.putLong(SESSION_TIMESTAMP, getSessionTimestamp());
176176

177177
// Write the camera data
178-
Camera camera = wwd.getNavigator().getAsCamera(wwd.getGlobe(), new Camera());
179-
editor.putFloat(CAMERA_LATITUDE, (float) camera.latitude);
180-
editor.putFloat(CAMERA_LONGITUDE, (float) camera.longitude);
181-
editor.putFloat(CAMERA_ALTITUDE, (float) camera.altitude);
178+
Camera camera = wwd.getCamera();
179+
editor.putFloat(CAMERA_LATITUDE, (float) camera.position.latitude);
180+
editor.putFloat(CAMERA_LONGITUDE, (float) camera.position.longitude);
181+
editor.putFloat(CAMERA_ALTITUDE, (float) camera.position.altitude);
182182
editor.putFloat(CAMERA_HEADING, (float) camera.heading);
183183
editor.putFloat(CAMERA_TILT, (float) camera.tilt);
184184
editor.putFloat(CAMERA_ROLL, (float) camera.roll);
@@ -189,9 +189,9 @@ protected void saveNavigatorState() {
189189
}
190190

191191
/**
192-
* Restores the Navigator's camera state from a SharedPreferences object.
192+
* Restores camera state from a SharedPreferences object.
193193
*/
194-
protected void restoreNavigatorState() {
194+
protected void restoreCameraState() {
195195
WorldWindow wwd = this.getWorldWindow();
196196
if (wwd != null) {
197197
SharedPreferences preferences = this.getPreferences(MODE_PRIVATE);
@@ -215,8 +215,7 @@ protected void restoreNavigatorState() {
215215
}
216216

217217
// Restore the camera state.
218-
Camera camera = new Camera(lat, lon, alt, altMode, heading, tilt, roll);
219-
wwd.getNavigator().setAsCamera(wwd.getGlobe(), camera);
218+
wwd.getCamera().set(lat, lon, alt, altMode, heading, tilt, roll);
220219
}
221220
}
222221

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

Lines changed: 21 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,6 @@ public WorldWindow getWorldWindow() {
4646
return null;
4747
}
4848

49-
@Override
50-
public void setWorldWindow(WorldWindow wwd) {
51-
}
52-
5349
@Override
5450
public boolean onTouchEvent(MotionEvent event) {
5551
return false;
@@ -60,40 +56,34 @@ public static class AnimateCameraCommand implements Runnable {
6056

6157
protected WorldWindow wwd;
6258

63-
protected Camera beginCamera = new Camera();
64-
65-
protected Camera endCamera = new Camera();
59+
protected Camera beginCamera;
6660

67-
protected Camera curCamera = new Camera();
61+
protected Camera endCamera;
6862

69-
protected Position beginPos = new Position();
70-
71-
protected Position endPos = new Position();
72-
73-
protected Position curPos = new Position();
63+
protected Camera curCamera;
7464

7565
protected int steps;
7666

7767
public AnimateCameraCommand(WorldWindow wwd, Camera end, int steps) {
7868
this.wwd = wwd;
69+
70+
this.beginCamera = new Camera(wwd);
71+
this.endCamera = new Camera(wwd);
72+
this.curCamera = new Camera(wwd);
73+
7974
this.endCamera.set(end);
80-
this.endPos.set(end.latitude, end.longitude, end.altitude);
8175
this.steps = steps;
8276
}
8377

8478
@Override
8579
public void run() {
86-
this.wwd.getNavigator().getAsCamera(this.wwd.getGlobe(), this.beginCamera);
87-
this.beginPos.set(this.beginCamera.latitude, this.beginCamera.longitude, this.beginCamera.altitude);
80+
this.beginCamera.set(this.wwd.getCamera());
8881

8982
for (int i = 0; i < this.steps; i++) {
9083

9184
double amount = (double) i / (double) (this.steps - 1);
92-
this.beginPos.interpolateAlongPath(this.endPos, WorldWind.GREAT_CIRCLE, amount, this.curPos);
85+
this.beginCamera.position.interpolateAlongPath(this.endCamera.position, WorldWind.GREAT_CIRCLE, amount, this.curCamera.position);
9386

94-
this.curCamera.latitude = this.curPos.latitude;
95-
this.curCamera.longitude = this.curPos.longitude;
96-
this.curCamera.altitude = this.curPos.altitude;
9787
this.curCamera.heading = WWMath.interpolateAngle360(amount, this.beginCamera.heading, this.endCamera.heading);
9888
this.curCamera.tilt = WWMath.interpolateAngle180(amount, this.beginCamera.tilt, this.endCamera.tilt);
9989
this.curCamera.roll = WWMath.interpolateAngle180(amount, this.beginCamera.roll, this.endCamera.roll);
@@ -111,7 +101,7 @@ public static class SetCameraCommand implements Runnable {
111101

112102
private WorldWindow wwd;
113103

114-
private Camera camera = new Camera();
104+
private Camera camera;
115105

116106
private SetCameraCommand() {
117107
}
@@ -127,6 +117,7 @@ public static SetCameraCommand obtain(WorldWindow wwd, Camera camera) {
127117

128118
private SetCameraCommand set(WorldWindow wwd, Camera camera) {
129119
this.wwd = wwd;
120+
this.camera = new Camera(wwd);
130121
this.camera.set(camera);
131122
return this;
132123
}
@@ -138,7 +129,7 @@ private SetCameraCommand reset() {
138129

139130
@Override
140131
public void run() {
141-
this.wwd.getNavigator().setAsCamera(this.wwd.getGlobe(), this.camera);
132+
this.wwd.getCamera().set(this.camera);
142133
this.wwd.requestRedraw();
143134
pool.release(this.reset());
144135
}
@@ -249,40 +240,40 @@ protected void onStart() {
249240
exec.execute(new ClearFrameMetricsCommand(wwd));
250241

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

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

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

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

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

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

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import android.os.Bundle;
99
import android.view.Choreographer;
1010

11-
import gov.nasa.worldwind.Navigator;
11+
import gov.nasa.worldwind.geom.Camera;
1212
import gov.nasa.worldwind.layer.ShowTessellationLayer;
1313

1414
public class BasicStressTestActivity extends GeneralGlobeActivity implements Choreographer.FrameCallback {
@@ -21,16 +21,16 @@ public class BasicStressTestActivity extends GeneralGlobeActivity implements Cho
2121
protected void onCreate(Bundle savedInstanceState) {
2222
super.onCreate(savedInstanceState);
2323
this.setAboutBoxTitle("About the " + this.getResources().getText(R.string.title_basic_stress_test));
24-
this.setAboutBoxText("Continuously moves the navigator in an Easterly direction from a low altitude.");
24+
this.setAboutBoxText("Continuously moves the camera in an Easterly direction from a low altitude.");
2525

2626
// Add the ShowTessellation layer to provide some visual feedback regardless of texture details
2727
this.getWorldWindow().getLayers().addLayer(new ShowTessellationLayer());
2828

29-
// Initialize the Navigator so that it's looking in the direction of movement and the horizon is visible.
30-
Navigator navigator = this.getWorldWindow().getNavigator();
31-
navigator.setAltitude(1e3); // 1 km
32-
navigator.setHeading(90); // looking east
33-
navigator.setTilt(75); // looking at the horizon
29+
// Initialize the Camera so that it's looking in the direction of movement and the horizon is visible.
30+
Camera camera = this.getWorldWindow().getCamera();
31+
camera.position.altitude = 1e3; // 1 km
32+
camera.heading = 90; // looking east
33+
camera.tilt = 75; // looking at the horizon
3434
}
3535

3636
@Override
@@ -40,9 +40,9 @@ public void doFrame(long frameTimeNanos) {
4040
double frameDurationSeconds = (frameTimeNanos - this.lastFrameTimeNanos) * 1.0e-9;
4141
double cameraDegrees = (frameDurationSeconds * this.cameraDegreesPerSecond);
4242

43-
// Move the navigator to continuously bring new tiles into view.
44-
Navigator navigator = getWorldWindow().getNavigator();
45-
navigator.setLongitude(navigator.getLongitude() + cameraDegrees);
43+
// Move the camera to continuously bring new tiles into view.
44+
Camera camera = getWorldWindow().getCamera();
45+
camera.position.longitude += cameraDegrees;
4646

4747
// Redraw the WorldWindow to display the above changes.
4848
this.getWorldWindow().requestRedraw();
@@ -63,7 +63,7 @@ protected void onPause() {
6363
@Override
6464
protected void onResume() {
6565
super.onResume();
66-
// Use this Activity's Choreographer to animate the Navigator.
66+
// Use this Activity's Choreographer to animate the Camera.
6767
Choreographer.getInstance().postFrameCallback(this);
6868
this.lastFrameTimeNanos = 0;
6969
}

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import android.os.Bundle;
99
import android.view.Choreographer;
1010

11-
import gov.nasa.worldwind.Navigator;
11+
import gov.nasa.worldwind.geom.Camera;
1212
import gov.nasa.worldwind.geom.Location;
1313
import gov.nasa.worldwind.layer.LayerList;
1414
import gov.nasa.worldwindx.experimental.AtmosphereLayer;
@@ -34,18 +34,18 @@ protected void onCreate(Bundle savedInstanceState) {
3434
super.onCreate(savedInstanceState);
3535
setAboutBoxTitle("About the " + this.getResources().getText(R.string.title_day_night_cycle));
3636
setAboutBoxText("Demonstrates how to display a continuous day-night cycle on the WorldWind globe.\n" +
37-
"This gradually changes both the Navigator's location and the AtmosphereLayer's light location.");
37+
"This gradually changes both the Camera's location and the AtmosphereLayer's light location.");
3838

3939
// Initialize the Atmosphere layer's light location to our custom location. By default the light location is
4040
// always behind the viewer.
4141
LayerList layers = this.getWorldWindow().getLayers();
4242
this.atmosphereLayer = (AtmosphereLayer) layers.getLayer(layers.indexOfLayerNamed("Atmosphere"));
4343
this.atmosphereLayer.setLightLocation(this.sunLocation);
4444

45-
// Initialize the Navigator so that the sun is behind the viewer.
46-
Navigator navigator = this.getWorldWindow().getNavigator();
47-
navigator.setLatitude(20);
48-
navigator.setLongitude(this.sunLocation.longitude);
45+
// Initialize the Camera so that the sun is behind the viewer.
46+
Camera camera = this.getWorldWindow().getCamera();
47+
camera.position.latitude = 20;
48+
camera.position.longitude = this.sunLocation.longitude;
4949

5050
// Use this Activity's Choreographer to animate the day-night cycle.
5151
Choreographer.getInstance().postFrameCallback(this);
@@ -59,9 +59,9 @@ public void doFrame(long frameTimeNanos) {
5959
double cameraDegrees = (frameDurationSeconds * this.cameraDegreesPerSecond);
6060
double lightDegrees = (frameDurationSeconds * this.lightDegreesPerSecond);
6161

62-
// Move the navigator to simulate the Earth's rotation about its axis.
63-
Navigator navigator = getWorldWindow().getNavigator();
64-
navigator.setLongitude(navigator.getLongitude() - cameraDegrees);
62+
// Move the camera to simulate the Earth's rotation about its axis.
63+
Camera camera = getWorldWindow().getCamera();
64+
camera.position.longitude -= cameraDegrees;
6565

6666
// Move the sun location to simulate the Sun's rotation about the Earth.
6767
this.sunLocation.set(this.sunLocation.latitude, this.sunLocation.longitude - lightDegrees);

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

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,8 @@ public class GeneralGlobeActivity extends BasicGlobeActivity {
3333
protected TextView altView;
3434
protected ImageView crosshairs;
3535
protected ViewGroup overlay;
36-
// Use pre-allocated navigator state objects to avoid per-event memory allocations
36+
// Use pre-allocated lookAt state object to avoid per-event memory allocations
3737
private LookAt lookAt = new LookAt();
38-
private Camera camera = new Camera();
3938
// Track the navigation event time so the overlay refresh rate can be throttled
4039
private long lastEventTime;
4140
// Animation object used to fade the overlays
@@ -81,12 +80,11 @@ public void onNavigatorEvent(WorldWindow wwd, NavigatorEvent event) {
8180
// and also it is moving but at an (arbitrary) maximum refresh rate of 20 Hz.
8281
if (eventAction == WorldWind.NAVIGATOR_STOPPED || elapsedTime > 50) {
8382

84-
// Get the current navigator state to apply to the overlays
85-
event.getNavigator().getAsLookAt(wwd.getGlobe(), lookAt);
86-
event.getNavigator().getAsCamera(wwd.getGlobe(), camera);
83+
// Get the current camera state to apply to the overlays
84+
event.getCamera().getAsLookAt(lookAt);
8785

8886
// Update the overlays
89-
updateOverlayContents(lookAt, camera);
87+
updateOverlayContents(lookAt, event.getCamera());
9088
updateOverlayColor(eventAction);
9189

9290
lastEventTime = currentTime;
@@ -129,16 +127,16 @@ protected void fadeCrosshairs() {
129127
}
130128

131129
/**
132-
* Displays navigator state information in the status overlay views.
130+
* Displays camera state information in the status overlay views.
133131
*
134-
* @param lookAt Where the navigator is looking
132+
* @param lookAt Where the camera is looking
135133
* @param camera Where the camera is positioned
136134
*/
137135
protected void updateOverlayContents(LookAt lookAt, Camera camera) {
138-
latView.setText(formatLatitude(lookAt.latitude));
139-
lonView.setText(formatLongitude(lookAt.longitude));
140-
elevView.setText(formatElevaton(wwd.getGlobe().getElevationAtLocation(lookAt.latitude, lookAt.longitude)));
141-
altView.setText(formatAltitude(camera.altitude));
136+
latView.setText(formatLatitude(lookAt.position.latitude));
137+
lonView.setText(formatLongitude(lookAt.position.longitude));
138+
elevView.setText(formatElevaton(wwd.getGlobe().getElevationAtLocation(lookAt.position.latitude, lookAt.position.longitude)));
139+
altView.setText(formatAltitude(camera.position.altitude));
142140
}
143141

144142
/**

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import gov.nasa.worldwind.PickedObject;
1515
import gov.nasa.worldwind.PickedObjectList;
1616
import gov.nasa.worldwind.WorldWind;
17+
import gov.nasa.worldwind.WorldWindow;
1718
import gov.nasa.worldwind.geom.Line;
1819
import gov.nasa.worldwind.geom.LookAt;
1920
import gov.nasa.worldwind.geom.Position;
@@ -83,12 +84,12 @@ protected void onCreate(Bundle savedInstanceState) {
8384
this.wwd.getLayers().addLayer(sightlineLayer);
8485

8586
// Override the WorldWindow's built-in navigation behavior with conditional dragging support.
86-
this.controller = new SimpleSelectDragNavigateController();
87+
this.controller = new SimpleSelectDragNavigateController(this.wwd);
8788
this.wwd.setWorldWindowController(this.controller);
8889

8990
// And finally, for this demo, position the viewer to look at the sightline position
9091
LookAt lookAt = new LookAt().set(pos.latitude, pos.longitude, pos.altitude, WorldWind.ABSOLUTE, 2e4 /*range*/, 0 /*heading*/, 45 /*tilt*/, 0 /*roll*/);
91-
this.getWorldWindow().getNavigator().setAsLookAt(this.getWorldWindow().getGlobe(), lookAt);
92+
this.getWorldWindow().getCamera().setFromLookAt(lookAt);
9293
}
9394

9495
/**
@@ -133,6 +134,10 @@ public boolean onScroll(MotionEvent downEvent, MotionEvent moveEvent, float dist
133134
}
134135
});
135136

137+
public SimpleSelectDragNavigateController(WorldWindow wwd) {
138+
super(wwd);
139+
}
140+
136141
/**
137142
* Delegates events to the select/drag handlers or the native World Wind navigation handlers.
138143
*/

0 commit comments

Comments
 (0)