2 Copyright (C) 2001, 2006 United States Government as represented by
3 the Administrator of the National Aeronautics and Space Administration.
6 package gov
.nasa
.worldwind
.view
;
8 import gov
.nasa
.worldwind
.geom
.*;
9 import gov
.nasa
.worldwind
.util
.Logging
;
11 import java
.lang
.reflect
.Constructor
;
12 import java
.util
.Arrays
;
16 * @version $Id: BasicOrbitViewAnimator.java 2471 2007-07-31 21:50:57Z tgaskins $
18 public class BasicOrbitViewAnimator
implements OrbitViewAnimator
20 protected BasicOrbitViewAnimator()
24 public final void doNextState(double interpolant
, OrbitView orbitView
, BasicOrbitViewStateIterator stateIterator
)
26 if (orbitView
== null)
28 String message
= Logging
.getMessage("nullValue.OrbitViewIsNull");
29 Logging
.logger().severe(message
);
30 throw new IllegalArgumentException(message
);
32 if (stateIterator
== null)
34 String message
= Logging
.getMessage("nullValue.OrbitViewStateIteratorIsNull");
35 Logging
.logger().severe(message
);
36 throw new IllegalArgumentException(message
);
39 this.doNextStateImpl(interpolant
, orbitView
, stateIterator
);
42 protected void doNextStateImpl(double interpolant
, OrbitView orbitView
,
43 BasicOrbitViewStateIterator stateIterator
)
47 public final OrbitViewAnimator
coalesceWith(OrbitView orbitView
, OrbitViewAnimator animator
)
49 if (orbitView
== null)
51 String message
= Logging
.getMessage("nullValue.OrbitViewIsNull");
52 Logging
.logger().severe(message
);
53 throw new IllegalArgumentException(message
);
57 String message
= Logging
.getMessage("nullValue.OrbitViewAnimatorIsNull");
58 Logging
.logger().severe(message
);
59 throw new IllegalArgumentException(message
);
62 return this.coalesceWithImpl(orbitView
, animator
);
65 protected OrbitViewAnimator
coalesceWithImpl(OrbitView orbitView
, OrbitViewAnimator animator
)
70 // ============== Implementations ======================= //
71 // ============== Implementations ======================= //
72 // ============== Implementations ======================= //
74 public static class AngleAnimator
extends BasicOrbitViewAnimator
76 private final Angle begin
;
77 private final Angle end
;
78 private final OrbitViewPropertyAccessor
.AngleAccessor propertyAccessor
;
81 Angle begin
, Angle end
,
82 OrbitViewPropertyAccessor
.AngleAccessor propertyAccessor
)
84 if (begin
== null || end
== null)
86 String message
= Logging
.getMessage("nullValue.AngleIsNull");
87 Logging
.logger().severe(message
);
88 throw new IllegalArgumentException(message
);
90 if (propertyAccessor
== null)
92 String message
= Logging
.getMessage("nullValue.OrbitViewPropertyAccessorIsNull");
93 Logging
.logger().severe(message
);
94 throw new IllegalArgumentException(message
);
99 this.propertyAccessor
= propertyAccessor
;
102 public final Angle
getBegin()
107 public final Angle
getEnd()
112 public final OrbitViewPropertyAccessor
.AngleAccessor
getPropertyAccessor()
114 return this.propertyAccessor
;
117 protected final void doNextStateImpl(double interpolant
, OrbitView orbitView
, BasicOrbitViewStateIterator stateIterator
)
119 Angle newValue
= this.nextAngle(interpolant
, orbitView
);
120 if (newValue
== null)
123 boolean success
= this.propertyAccessor
.setAngle(orbitView
, newValue
);
125 stateIterator
.stop();
128 public Angle
nextAngle(double interpolant
, OrbitView orbitView
)
137 public static class DoubleAnimator
extends BasicOrbitViewAnimator
139 private final double begin
;
140 private final double end
;
141 private final OrbitViewPropertyAccessor
.DoubleAccessor propertyAccessor
;
143 public DoubleAnimator(
144 double begin
, double end
,
145 OrbitViewPropertyAccessor
.DoubleAccessor propertyAccessor
)
147 if (propertyAccessor
== null)
149 String message
= Logging
.getMessage("nullValue.OrbitViewPropertyAccessorIsNull");
150 Logging
.logger().severe(message
);
151 throw new IllegalArgumentException(message
);
156 this.propertyAccessor
= propertyAccessor
;
159 public final Double
getBegin()
164 public final Double
getEnd()
169 public final OrbitViewPropertyAccessor
.DoubleAccessor
getPropertyAccessor()
171 return this.propertyAccessor
;
174 protected final void doNextStateImpl(double interpolant
, OrbitView orbitView
, BasicOrbitViewStateIterator stateIterator
)
176 Double newValue
= this.nextDouble(interpolant
, orbitView
);
177 if (newValue
== null)
180 boolean success
= this.propertyAccessor
.setDouble(orbitView
, newValue
);
182 stateIterator
.stop();
185 public Double
nextDouble(double interpolant
, OrbitView orbitView
)
193 public static double mix(double amount
, double value1
, double value2
)
199 return value1
* (1.0 - amount
) + value2
* amount
;
203 public static class LatLonAnimator
extends BasicOrbitViewAnimator
205 private final LatLon begin
;
206 private final LatLon end
;
207 private final OrbitViewPropertyAccessor
.LatLonAccessor propertyAccessor
;
209 public LatLonAnimator(
212 OrbitViewPropertyAccessor
.LatLonAccessor propertyAccessor
)
214 if (begin
== null || end
== null)
216 String message
= Logging
.getMessage("nullValue.LatLonIsNull");
217 Logging
.logger().severe(message
);
218 throw new IllegalArgumentException(message
);
220 if (propertyAccessor
== null)
222 String message
= Logging
.getMessage("nullValue.OrbitViewPropertyAccessorIsNull");
223 Logging
.logger().severe(message
);
224 throw new IllegalArgumentException(message
);
229 this.propertyAccessor
= propertyAccessor
;
232 public final LatLon
getBegin()
237 public final LatLon
getEnd()
242 public final OrbitViewPropertyAccessor
.LatLonAccessor
getPropertyAccessor()
244 return this.propertyAccessor
;
247 protected final void doNextStateImpl(double interpolant
, OrbitView orbitView
, BasicOrbitViewStateIterator stateIterator
)
249 LatLon newValue
= this.nextLatLon(interpolant
, orbitView
);
250 if (newValue
== null)
253 boolean success
= this.propertyAccessor
.setLatLon(orbitView
, newValue
);
255 stateIterator
.stop();
258 public LatLon
nextLatLon(double interpolant
, OrbitView orbitView
)
260 return LatLon
.interpolate(
267 public static class QuaternionAnimator
extends BasicOrbitViewAnimator
269 private final Quaternion begin
;
270 private final Quaternion end
;
271 private final OrbitViewPropertyAccessor
.QuaternionAccessor propertyAccessor
;
273 public QuaternionAnimator(
274 Quaternion begin
, Quaternion end
,
275 OrbitViewPropertyAccessor
.QuaternionAccessor propertyAccessor
)
277 if (begin
== null || end
== null)
279 String message
= Logging
.getMessage("nullValue.QuaternionIsNull");
280 Logging
.logger().severe(message
);
281 throw new IllegalArgumentException(message
);
283 if (propertyAccessor
== null)
285 String message
= Logging
.getMessage("nullValue.OrbitViewPropertyAccessorIsNull");
286 Logging
.logger().severe(message
);
287 throw new IllegalArgumentException(message
);
292 this.propertyAccessor
= propertyAccessor
;
295 public final Quaternion
getBegin()
300 public final Quaternion
getEnd()
305 public final OrbitViewPropertyAccessor
.QuaternionAccessor
getPropertyAccessor()
307 return this.propertyAccessor
;
310 protected final void doNextStateImpl(double interpolant
, OrbitView orbitView
, BasicOrbitViewStateIterator stateIterator
)
312 Quaternion newValue
= this.nextQuaternion(interpolant
, orbitView
);
313 if (newValue
== null)
316 boolean success
= this.propertyAccessor
.setQuaternion(orbitView
, newValue
);
318 stateIterator
.stop();
321 public Quaternion
nextQuaternion(double interpolant
, OrbitView orbitView
)
323 return Quaternion
.mix(
330 public static class CompoundAnimator
extends BasicOrbitViewAnimator
332 private OrbitViewAnimator
[] animators
;
334 public CompoundAnimator(OrbitViewAnimator
... animators
)
336 if (animators
== null)
338 String message
= Logging
.getMessage("nullValue.ArrayIsNull");
339 Logging
.logger().severe(message
);
340 throw new IllegalArgumentException(message
);
343 int numAnimators
= animators
.length
;
344 this.animators
= new OrbitViewAnimator
[numAnimators
];
345 System
.arraycopy(animators
, 0, this.animators
, 0, numAnimators
);
348 private CompoundAnimator
newInstance(OrbitViewAnimator
... animators
)
350 if (animators
== null)
352 String message
= Logging
.getMessage("nullValue.ArrayIsNull");
353 Logging
.logger().severe(message
);
354 throw new IllegalArgumentException(message
);
357 CompoundAnimator newCompoundAnimator
;
360 Class
<?
extends CompoundAnimator
> cls
= this.getClass();
361 Class
<?
extends OrbitViewAnimator
[]> paramCls
= animators
.getClass();
362 Constructor
<?
extends CompoundAnimator
> constructor
= cls
.getConstructor(paramCls
);
363 newCompoundAnimator
= constructor
.newInstance((Object
) animators
);
367 String message
= Logging
.getMessage(""); // TODO
368 Logging
.logger().severe(message
);
369 throw new IllegalArgumentException(message
);
372 return newCompoundAnimator
;
375 public final Iterable
<OrbitViewAnimator
> getAnimators()
377 return Arrays
.asList(this.animators
);
380 protected final void doNextStateImpl(double interpolant
, OrbitView orbitView
,
381 BasicOrbitViewStateIterator stateIterator
)
383 for (OrbitViewAnimator a
: animators
)
387 a
.doNextState(interpolant
, orbitView
, stateIterator
);
392 protected final OrbitViewAnimator
coalesceWithImpl(OrbitView orbitView
, OrbitViewAnimator animator
)
394 if (!(animator
instanceof CompoundAnimator
))
397 // Cannot coalesce with different number of internal animators.
398 CompoundAnimator that
= (CompoundAnimator
) animator
;
399 if (this.animators
.length
!= that
.animators
.length
)
402 int numAnimators
= this.animators
.length
;
403 OrbitViewAnimator
[] newAnimators
= new OrbitViewAnimator
[numAnimators
];
404 for (int i
= 0; i
< numAnimators
; i
++)
406 if (this.animators
[i
] != null && that
.animators
[i
] != null)
408 newAnimators
[i
] = this.animators
[i
].coalesceWith(orbitView
, that
.animators
[i
]);
410 else if (this.animators
[i
] != null)
412 newAnimators
[i
] = this.animators
[i
];
416 CompoundAnimator newCompoundAnimator
= this.newInstance(newAnimators
);
417 if (newCompoundAnimator
== null)
420 return newCompoundAnimator
;