Skip to content

BasicDragger terrain regression fix #20

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 1 commit 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
31 changes: 25 additions & 6 deletions src/gov/nasa/worldwind/util/BasicDragger.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,11 @@ else if (dragObject instanceof Movable)
if (refPos == null)
return;

Vec4 refPoint = globe.computePointFromPosition(refPos);
Vec4 refPoint = null;
if (this.isUseTerrain() && refPos.getElevation() < globe.getMaxElevation())
refPoint = wwd.getSceneController().getTerrain().getSurfacePoint(refPos);
if (refPoint == null)
refPoint = globe.computePointFromPosition(refPos);

if (!this.isDragging()) // Dragging started
{
Expand All @@ -122,10 +126,25 @@ else if (dragObject instanceof Movable)
double y = event.getMouseEvent().getComponent().getSize().height - this.dragRefObjectPoint.y + dy - 1;
Line ray = view.computeRayFromScreenPoint(x, y);
Position pickPos = null;
// Use intersection with sphere at reference altitude.
Intersection inters[] = globe.intersect(ray, this.dragRefAltitude);
if (inters != null)
pickPos = globe.computePositionFromPoint(inters[0].getIntersectionPoint());
if (this.isUseTerrain() && view.getEyePosition().getElevation() < globe.getMaxElevation() * 10)
{
// Use ray casting below some altitude
// Try ray intersection with current terrain geometry
Intersection[] intersections = wwd.getSceneController().getTerrain().intersect(ray);
if (intersections != null && intersections.length > 0)
pickPos = globe.computePositionFromPoint(intersections[0].getIntersectionPoint());
else
// Fallback on raycasting using elevation data
pickPos = RayCastingSupport.intersectRayWithTerrain(globe, ray.getOrigin(), ray.getDirection(),
200, 20);
}
if (pickPos == null)
{
// Use intersection with sphere at reference altitude.
Intersection inters[] = globe.intersect(ray, this.dragRefAltitude);
if (inters != null)
pickPos = globe.computePositionFromPoint(inters[0].getIntersectionPoint());
}

if (pickPos != null)
{
Expand All @@ -141,4 +160,4 @@ else if (dragObject instanceof Movable)
event.consume();
}
}
}
}