forked from NASAWorldWind/WorldWindJava
-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathViewIteration.java
More file actions
255 lines (222 loc) · 8.89 KB
/
ViewIteration.java
File metadata and controls
255 lines (222 loc) · 8.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
/*
* Copyright 2006-2009, 2017, 2020 United States Government, as represented by the
* Administrator of the National Aeronautics and Space Administration.
* All rights reserved.
*
* The NASA World Wind Java (WWJ) platform is licensed under the Apache License,
* Version 2.0 (the "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*
* NASA World Wind Java (WWJ) also contains the following 3rd party Open Source
* software:
*
* Jackson Parser – Licensed under Apache 2.0
* GDAL – Licensed under MIT
* JOGL – Licensed under Berkeley Software Distribution (BSD)
* Gluegen – Licensed under Berkeley Software Distribution (BSD)
*
* A complete listing of 3rd Party software notices and licenses included in
* NASA World Wind Java (WWJ) can be found in the WorldWindJava-v2.2 3rd-party
* notices and licenses PDF found in code directory.
*/
package gov.nasa.worldwindx.examples;
import gov.nasa.worldwind.geom.*;
import gov.nasa.worldwind.view.orbit.BasicOrbitView;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.ArrayList;
/**
* Example of how to animate the view from one position to another.
* <p>
* Use the buttons on the left side of the frame to animate the view: <ul> <li> Zero: Move the view to look at 0 degrees
* latitude, 0 degrees longitude.</li> <li> Heading: Animate the view from 0 degrees heading to 90 degrees heading.</li>
* <li> Follow: Animate the view to along a path of geographic positions.</li> <li> Forward: Animate the view to look at
* the next position in a list.</li> <li> Backward: Animate the view to look at the previous position in a list.</li>
* </ul>
*
* @author tag
* @version $Id: ViewIteration.java 1171 2013-02-11 21:45:02Z dcollins $
*/
public class ViewIteration extends ApplicationTemplate
{
public static class AppFrame extends JFrame
{
static ArrayList<Position> path;
static
{
path = new ArrayList<Position>();
path.add(Position.fromDegrees(0, 0, 1e5));
path.add(Position.fromDegrees(0, 10, 1e5));
path.add(Position.fromDegrees(0, 20, 1e5));
path.add(Position.fromDegrees(0, 30, 1e5));
path.add(Position.fromDegrees(0, 40, 1e5));
path.add(Position.fromDegrees(0, 50, 1e5));
path.add(Position.fromDegrees(0, 60, 1e5));
path.add(Position.fromDegrees(0, 70, 1e5));
}
protected int pathPosition = 0;
protected PathAction[] pathActions =
new PathAction[] {
new GoToLatLonFromCurrent("Zero", LatLon.ZERO),
new FollowPath("Follow"),
new Heading("Heading"),
new Forward("Forward"),
new Backwards("Backwards"),
};
protected Dimension canvasSize = new Dimension(800, 600);
protected ApplicationTemplate.AppPanel wwjPanel;
public AppFrame()
{
// Create the WorldWindow.
this.wwjPanel = new ApplicationTemplate.AppPanel(this.canvasSize, true);
this.wwjPanel.setPreferredSize(canvasSize);
JPanel controlPanel = makeControlPanel();
controlPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
this.getContentPane().add(wwjPanel, BorderLayout.CENTER);
this.getContentPane().add(controlPanel, BorderLayout.WEST);
this.pack();
// Center the application on the screen.
Dimension prefSize = this.getPreferredSize();
Dimension parentSize;
java.awt.Point parentLocation = new java.awt.Point(0, 0);
parentSize = Toolkit.getDefaultToolkit().getScreenSize();
int x = parentLocation.x + (parentSize.width - prefSize.width) / 2;
int y = parentLocation.y + (parentSize.height - prefSize.height) / 2;
this.setLocation(x, y);
this.setResizable(true);
}
protected JPanel makeControlPanel()
{
JPanel innerPanel = new JPanel(new GridLayout(8, 1));
innerPanel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createTitledBorder("Go To"),
BorderFactory.createEmptyBorder(5, 5, 5, 5)));
for (PathAction pa : pathActions)
{
JButton btn = new JButton(pa);
innerPanel.add(btn);
}
JPanel cp = new JPanel(new BorderLayout());
cp.add(innerPanel, BorderLayout.CENTER);
return cp;
}
protected abstract class PathAction extends AbstractAction
{
PathAction(String name)
{
super(name);
}
}
//
// Specific Actions
//
protected class Forward extends PathAction
{
public Forward(String name)
{
super(name);
}
public void actionPerformed(ActionEvent actionEvent)
{
if (pathPosition < path.size() - 1)
{
BasicOrbitView view = (BasicOrbitView) wwjPanel.getWwd().getView();
view.setHeading(Angle.fromDegrees(90));
view.addEyePositionAnimator(4000, view.getEyePosition(), path.get(++pathPosition));
}
}
}
protected class Backwards extends PathAction
{
public Backwards(String name)
{
super(name);
}
public void actionPerformed(ActionEvent actionEvent)
{
if (pathPosition > 0)
{
BasicOrbitView view = (BasicOrbitView) wwjPanel.getWwd().getView();
view.addEyePositionAnimator(4000, view.getEyePosition(), path.get(--pathPosition));
}
}
}
protected class Heading extends PathAction
{
public Heading(String name)
{
super(name);
}
public void actionPerformed(ActionEvent actionEvent)
{
Angle heading;
if (pathPosition == 0)
heading = computeHeading(path.get(0), path.get(1));
else
heading = computeHeading(path.get(pathPosition - 1), path.get(pathPosition));
BasicOrbitView view = (BasicOrbitView) wwjPanel.getWwd().getView();
view.addHeadingAnimator(view.getHeading(), heading);
}
}
protected Angle computeHeading(Position pa, Position pb)
{
return LatLon.greatCircleAzimuth(pa, pb);
}
protected class GoToLatLonFromCurrent extends PathAction
{
protected final LatLon latlon;
GoToLatLonFromCurrent(String name, LatLon latlon)
{
super(name);
this.latlon = latlon;
}
public void actionPerformed(ActionEvent actionEvent)
{
BasicOrbitView view = (BasicOrbitView) wwjPanel.getWwd().getView();
view.addEyePositionAnimator(
4000, view.getEyePosition(), new Position(this.latlon, view.getEyePosition().getElevation()));
}
}
protected class FollowPath extends PathAction
{
ArrayList<Position> path = new ArrayList<Position>();
FollowPath(String name)
{
super(name);
path.add(Position.fromDegrees(0, 0, 1e5));
path.add(Position.fromDegrees(1, 3, 1e5));
path.add(Position.fromDegrees(2, 4, 1e5));
path.add(Position.fromDegrees(3, 5, 1e5));
}
public void actionPerformed(ActionEvent actionEvent)
{
for (Position p : path)
{
final BasicOrbitView view = (BasicOrbitView) wwjPanel.getWwd().getView();
view.addEyePositionAnimator(4000,
view.getEyePosition(), new Position(p, view.getEyePosition().getElevation()));
}
}
}
}
public static void main(String[] args)
{
try
{
AppFrame frame = new AppFrame();
frame.setTitle("WorldWind View Paths");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
catch (Exception e)
{
e.printStackTrace();
}
}
}