Skip to content

BasicDragger.java Bug Fix #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 24 additions & 6 deletions src/gov/nasa/worldwind/util/BasicDragger.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public class BasicDragger implements SelectListener
private final WorldWindow wwd;
private boolean dragging = false;
private boolean useTerrain = true;
private boolean isGround = false;

private Point dragRefCursorPoint;
private Vec4 dragRefObjectPoint;
Expand Down Expand Up @@ -77,6 +78,7 @@ public void selected(SelectEvent event)

if (event.getEventAction().equals(SelectEvent.DRAG_END))
{
this.isGround = false;
this.dragging = false;
event.consume();
}
Expand All @@ -99,7 +101,15 @@ else if (dragObject instanceof Movable)
refPos = ((Movable) dragObject).getReferencePosition();
if (refPos == null)
return;


//Check if the symbol is a ground symbol
if(refPos.getAltitude() == 0)
this.isGround = true;

//Change the altitude for ground symbols only
if(this.wwd.getCurrentPosition() != null && this.isGround)
refPos = new Position(refPos, this.wwd.getCurrentPosition().getElevation());

Vec4 refPoint = globe.computePointFromPosition(refPos);

if (!this.isDragging()) // Dragging started
Expand All @@ -110,35 +120,43 @@ else if (dragObject instanceof Movable)
// Save cursor position
this.dragRefCursorPoint = dragEvent.getPreviousPickPoint();
// Save start altitude
this.dragRefAltitude = globe.computePositionFromPoint(refPoint).getElevation();
this.dragRefAltitude = refPos.getElevation();
}

// Compute screen-coord delta since drag started.
int dx = dragEvent.getPickPoint().x - this.dragRefCursorPoint.x;
int dy = dragEvent.getPickPoint().y - this.dragRefCursorPoint.y;
double dz = refPos.getElevation() - this.dragRefAltitude;

// Find intersection of screen coord (refObjectPoint + delta) with globe.
double x = this.dragRefObjectPoint.x + dx;
double y = event.getMouseEvent().getComponent().getSize().height - this.dragRefObjectPoint.y + dy - 1;
double altitude = this.dragRefAltitude + dz;

Line ray = view.computeRayFromScreenPoint(x, y);
Position pickPos = null;
// Use intersection with sphere at reference altitude.
Intersection inters[] = globe.intersect(ray, this.dragRefAltitude);
Intersection inters[] = globe.intersect(ray, altitude);
if (inters != null)
pickPos = globe.computePositionFromPoint(inters[0].getIntersectionPoint());

if (pickPos != null)
{
// Intersection with globe. Move reference point to the intersection point,
// but maintain current altitude.
Position p = new Position(pickPos, refPos.getElevation());
Position p = new Position(pickPos, altitude);
if (dragObject instanceof Movable2)
((Movable2) dragObject).moveTo(globe, p);
else
((Movable) dragObject).moveTo(p);
}

//Set ground symbol altitude back to 0 for the next check
if(this.isGround)
refPos = new Position(refPos, 0);

this.dragging = true;
event.consume();
}
}
}
}