Skip to content

Commit 6b1aa66

Browse files
committed
Merge branch 'develop' of https://github.com/NASAWorldWind/WorldWindJava into develop
2 parents f03a20f + 1fb9608 commit 6b1aa66

File tree

1 file changed

+63
-67
lines changed

1 file changed

+63
-67
lines changed

src/gov/nasa/worldwind/drag/DraggableSupport.java

+63-67
Original file line numberDiff line numberDiff line change
@@ -68,20 +68,18 @@ public class DraggableSupport
6868
*/
6969
protected final Object dragObject;
7070
/**
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.
7372
*/
7473
protected int altitudeMode;
7574

7675
/**
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.
7978
*
8079
* @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.
8381
*
84-
* @throws IllegalArgumentException if the object is null or the altitude mode not valid.
82+
* @throws IllegalArgumentException if the object is null.
8583
*/
8684
public DraggableSupport(Object dragObject, int altitudeMode)
8785
{
@@ -92,11 +90,11 @@ public DraggableSupport(Object dragObject, int altitudeMode)
9290
throw new IllegalArgumentException(msg);
9391
}
9492

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)
9695
{
9796
String msg = Logging.getMessage("generic.InvalidAltitudeMode", altitudeMode);
98-
Logging.logger().severe(msg);
99-
throw new IllegalArgumentException(msg);
97+
Logging.logger().warning(msg);
10098
}
10199

102100
this.dragObject = dragObject;
@@ -312,27 +310,23 @@ public int getAltitudeMode()
312310
}
313311

314312
/**
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.
317314
*
318315
* @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.
321316
*/
322317
public void setAltitudeMode(int altitudeMode)
323318
{
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)
325321
{
326322
String msg = Logging.getMessage("generic.InvalidAltitudeMode", altitudeMode);
327-
Logging.logger().severe(msg);
328-
throw new IllegalArgumentException(msg);
323+
Logging.logger().warning(msg);
329324
}
330325
this.altitudeMode = altitudeMode;
331326
}
332327

333328
/**
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.
336330
*
337331
* @param dragContext the current {@link DragContext} of the dragging event.
338332
* @param screenPoint the {@link Point} of the screen to determine the position.
@@ -381,18 +375,22 @@ protected Vec4 computeScreenOffsetFromReferencePosition(Position dragObjectRefer
381375
{
382376
Vec4 dragObjectPoint;
383377

384-
if (dragContext.getGlobe() instanceof FlatGlobe)
378+
if (dragContext.getGlobe() instanceof Globe2D)
385379
{
386380
dragObjectPoint = dragContext.getGlobe().computePointFromPosition(
387381
new Position(dragObjectReferencePosition, 0.0));
388382
}
389383
else
390384
{
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))
392390
{
393391
dragObjectPoint = dragContext.getGlobe().computePointFromPosition(dragObjectReferencePosition);
394392
}
395-
else
393+
else // Should be any one of the remaining WorldWind altitude modes: CLAMP, RELATIVE, CONSTANT
396394
{
397395
dragObjectPoint = dragContext.getSceneController().getTerrain()
398396
.getSurfacePoint(dragObjectReferencePosition);
@@ -461,7 +459,7 @@ else if (this.dragObject instanceof Movable)
461459

462460
/**
463461
* 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.
465463
*
466464
* @param ray the {@link Line} to calculate the intersection of the {@link Globe}.
467465
* @param altitude the altitude mode for the intersection calculation.
@@ -482,57 +480,55 @@ else if (this.dragObject instanceof Movable)
482480
{
483481
Intersection[] intersections;
484482

485-
if (globe instanceof FlatGlobe)
483+
if (globe instanceof Globe2D)
486484
{
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
489487
intersections = globe.intersect(ray, 0.0);
490488
}
491-
else
489+
else if (this.altitudeMode == WorldWind.ABSOLUTE)
492490
{
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)
494502
{
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)};
525519
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+
}
534526
}
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);
536532
}
537533

538534
if ((intersections != null) && (intersections.length > 0))

0 commit comments

Comments
 (0)