@@ -68,20 +68,18 @@ public class DraggableSupport
68
68
*/
69
69
protected final Object dragObject ;
70
70
/**
71
- * The altitude mode of the object to be dragged. The values {@link WorldWind#ABSOLUTE},
72
- * {@link WorldWind#CLAMP_TO_GROUND}, and {@link WorldWind#RELATIVE_TO_GROUND} are acceptable values.
71
+ * The altitude mode of the object to be dragged.
73
72
*/
74
73
protected int altitudeMode ;
75
74
76
75
/**
77
- * Provides persistence of initial values of a drag operation to increase dragging precision and provide for better
78
- * of globe dragging behavior.
76
+ * Provides persistence of initial values of a drag operation to increase dragging precision and provide better
77
+ * dragging behavior.
79
78
*
80
79
* @param dragObject the object to be dragged.
81
- * @param altitudeMode the altitude mode as defined by {@link WorldWind#ABSOLUTE}, {@link WorldWind#CLAMP_TO_GROUND}
82
- * or {@link WorldWind#RELATIVE_TO_GROUND}.
80
+ * @param altitudeMode the altitude mode.
83
81
*
84
- * @throws IllegalArgumentException if the object is null or the altitude mode not valid .
82
+ * @throws IllegalArgumentException if the object is null.
85
83
*/
86
84
public DraggableSupport (Object dragObject , int altitudeMode )
87
85
{
@@ -92,11 +90,11 @@ public DraggableSupport(Object dragObject, int altitudeMode)
92
90
throw new IllegalArgumentException (msg );
93
91
}
94
92
95
- if (altitudeMode < 0 || altitudeMode > WorldWind .RELATIVE_TO_GROUND )
93
+ if (altitudeMode != WorldWind .ABSOLUTE && altitudeMode != WorldWind .CLAMP_TO_GROUND &&
94
+ altitudeMode != WorldWind .RELATIVE_TO_GROUND && altitudeMode != WorldWind .CONSTANT )
96
95
{
97
96
String msg = Logging .getMessage ("generic.InvalidAltitudeMode" , altitudeMode );
98
- Logging .logger ().severe (msg );
99
- throw new IllegalArgumentException (msg );
97
+ Logging .logger ().warning (msg );
100
98
}
101
99
102
100
this .dragObject = dragObject ;
@@ -312,27 +310,23 @@ public int getAltitudeMode()
312
310
}
313
311
314
312
/**
315
- * Sets the altitude mode to be used during dragging calculations. Must be either: {@link WorldWind#ABSOLUTE},
316
- * {@link WorldWind#CLAMP_TO_GROUND}, or {@link WorldWind#RELATIVE_TO_GROUND}.
313
+ * Sets the altitude mode to be used during dragging calculations.
317
314
*
318
315
* @param altitudeMode the altitude mode to use for dragging calculations.
319
- *
320
- * @throws IllegalArgumentException if the altitude mode is not one of the modes specified above.
321
316
*/
322
317
public void setAltitudeMode (int altitudeMode )
323
318
{
324
- if (altitudeMode < WorldWind .ABSOLUTE || altitudeMode > WorldWind .RELATIVE_TO_GROUND )
319
+ if (altitudeMode != WorldWind .ABSOLUTE && altitudeMode != WorldWind .CLAMP_TO_GROUND &&
320
+ altitudeMode != WorldWind .RELATIVE_TO_GROUND && altitudeMode != WorldWind .CONSTANT )
325
321
{
326
322
String msg = Logging .getMessage ("generic.InvalidAltitudeMode" , altitudeMode );
327
- Logging .logger ().severe (msg );
328
- throw new IllegalArgumentException (msg );
323
+ Logging .logger ().warning (msg );
329
324
}
330
325
this .altitudeMode = altitudeMode ;
331
326
}
332
327
333
328
/**
334
- * Determines the cartesian coordinate of a screen point given the altitude mode and altitude on an ellipsoidal
335
- * globe.
329
+ * Determines the cartesian coordinate of a screen point given the altitude mode.
336
330
*
337
331
* @param dragContext the current {@link DragContext} of the dragging event.
338
332
* @param screenPoint the {@link Point} of the screen to determine the position.
@@ -381,18 +375,22 @@ protected Vec4 computeScreenOffsetFromReferencePosition(Position dragObjectRefer
381
375
{
382
376
Vec4 dragObjectPoint ;
383
377
384
- if (dragContext .getGlobe () instanceof FlatGlobe )
378
+ if (dragContext .getGlobe () instanceof Globe2D )
385
379
{
386
380
dragObjectPoint = dragContext .getGlobe ().computePointFromPosition (
387
381
new Position (dragObjectReferencePosition , 0.0 ));
388
382
}
389
383
else
390
384
{
391
- if (this .altitudeMode == WorldWind .ABSOLUTE )
385
+ // If the altitude mode is ABSOLUTE, or not recognized as a standard WorldWind altitude mode, use the
386
+ // ABSOLUTE method as the default
387
+ if (this .altitudeMode == WorldWind .ABSOLUTE ||
388
+ (this .altitudeMode != WorldWind .RELATIVE_TO_GROUND && this .altitudeMode != WorldWind .CLAMP_TO_GROUND
389
+ && this .altitudeMode != WorldWind .CONSTANT ))
392
390
{
393
391
dragObjectPoint = dragContext .getGlobe ().computePointFromPosition (dragObjectReferencePosition );
394
392
}
395
- else
393
+ else // Should be any one of the remaining WorldWind altitude modes: CLAMP, RELATIVE, CONSTANT
396
394
{
397
395
dragObjectPoint = dragContext .getSceneController ().getTerrain ()
398
396
.getSurfacePoint (dragObjectReferencePosition );
@@ -461,7 +459,7 @@ else if (this.dragObject instanceof Movable)
461
459
462
460
/**
463
461
* Computes the intersection of the provided {@link Line} with the {@link Globe} while accounting for the altitude
464
- * mode. If a {@link FlatGlobe } is specified, then
462
+ * mode. If a {@link Globe2D } is specified, then the intersection is calculated using the globe objects method.
465
463
*
466
464
* @param ray the {@link Line} to calculate the intersection of the {@link Globe}.
467
465
* @param altitude the altitude mode for the intersection calculation.
@@ -482,57 +480,55 @@ else if (this.dragObject instanceof Movable)
482
480
{
483
481
Intersection [] intersections ;
484
482
485
- if (globe instanceof FlatGlobe )
483
+ if (globe instanceof Globe2D )
486
484
{
487
- // Utilize the globe intersection method for a FlatGlobe as it best describes the appearance and the
488
- // terrain intersection method returns null when crossing the dateline on a FlatGlobe
485
+ // Utilize the globe intersection method for a Globe2D as it best describes the appearance and the
486
+ // terrain intersection method returns null when crossing the dateline on a Globe2D
489
487
intersections = globe .intersect (ray , 0.0 );
490
488
}
491
- else
489
+ else if ( this . altitudeMode == WorldWind . ABSOLUTE )
492
490
{
493
- switch (this .altitudeMode )
491
+ // Accounts for the object being visually placed on the surface in a Globe2D Globe
492
+ intersections = globe .intersect (ray , altitude );
493
+ }
494
+ else if (this .altitudeMode == WorldWind .CLAMP_TO_GROUND || this .altitudeMode == WorldWind .CONSTANT )
495
+ {
496
+ intersections = sceneController .getTerrain ().intersect (ray );
497
+ }
498
+ else if (this .altitudeMode == WorldWind .RELATIVE_TO_GROUND )
499
+ {
500
+ // If an object is RELATIVE_TO_GROUND but has an altitude close to 0.0, use CLAMP_TO_GROUND method
501
+ if (altitude < 1.0 )
494
502
{
495
- case WorldWind .ABSOLUTE :
496
- // Accounts for the object being visually placed on the surface in a FlatGlobe
497
- intersections = globe .intersect (ray , altitude );
498
- break ;
499
- case WorldWind .CLAMP_TO_GROUND :
500
- intersections = sceneController .getTerrain ().intersect (ray );
501
- break ;
502
- case WorldWind .RELATIVE_TO_GROUND :
503
- // If an object is RELATIVE_TO_GROUND but has an altitude close to 0.0, use CLAMP_TO_GROUND method
504
- if (altitude < 1.0 )
505
- {
506
- intersections = sceneController .getTerrain ().intersect (ray );
507
- break ;
508
- }
509
-
510
- // When an object maintains a constant screen size independent of globe orientation or eye location,
511
- // the dragger attempts to determine the position by testing different points of the ray for a
512
- // matching altitude above elevation. The method is only used in objects maintain a constant screen
513
- // size as the effects are less pronounced in globe constant features.
514
- if (useSearchMethod )
515
- {
516
- Vec4 intersectionPoint = this .computeRelativePoint (ray , globe , sceneController , altitude );
517
- // In the event the computeRelativePoint fails with the numeric approach it falls back to a
518
- // ellipsoidal intersection. Need to check if the result of that calculation was also null,
519
- // indicating the screen point doesn't intersect with the globe.
520
- if (intersectionPoint != null )
521
- intersections = new Intersection [] {new Intersection (intersectionPoint , false )};
522
- else
523
- intersections = null ;
524
- }
503
+ intersections = sceneController .getTerrain ().intersect (ray );
504
+ }
505
+ else
506
+ {
507
+ // When an object maintains a constant screen size independent of globe orientation or eye location,
508
+ // the dragger attempts to determine the position by testing different points of the ray for a
509
+ // matching altitude above elevation. The method is only used in objects maintain a constant screen
510
+ // size as the effects are less pronounced in globe constant features.
511
+ if (useSearchMethod )
512
+ {
513
+ Vec4 intersectionPoint = this .computeRelativePoint (ray , globe , sceneController , altitude );
514
+ // In the event the computeRelativePoint fails with the numeric approach it falls back to a
515
+ // ellipsoidal intersection. Need to check if the result of that calculation was also null,
516
+ // indicating the screen point doesn't intersect with the globe.
517
+ if (intersectionPoint != null )
518
+ intersections = new Intersection [] {new Intersection (intersectionPoint , false )};
525
519
else
526
- {
527
- intersections = globe .intersect (ray , altitude );
528
- }
529
- break ;
530
- default :
531
- String msg = Logging .getMessage ("generic.InvalidAltitudeMode" , this .altitudeMode );
532
- Logging .logger ().severe (msg );
533
- throw new IllegalArgumentException (msg );
520
+ intersections = null ;
521
+ }
522
+ else
523
+ {
524
+ intersections = globe .intersect (ray , altitude );
525
+ }
534
526
}
535
-
527
+ }
528
+ else
529
+ {
530
+ // If the altitude mode isn't recognized, the ABSOLUTE determination method is used as a fallback/default
531
+ intersections = globe .intersect (ray , altitude );
536
532
}
537
533
538
534
if ((intersections != null ) && (intersections .length > 0 ))
0 commit comments