Exemplo n.º 1
0
  protected void setPolygonHeight(Point previousMousePoint, Point mousePoint) {
    // Find the closest points between the rays through each screen point, and the ray from the
    // control point
    // and in the direction of the globe's surface normal. Compute the elevation difference between
    // these two
    // points, and use that as the change in polygon height.

    Position referencePos = this.polygon.getReferencePosition();
    if (referencePos == null) return;

    Vec4 referencePoint = this.wwd.getModel().getGlobe().computePointFromPosition(referencePos);

    Vec4 surfaceNormal =
        this.wwd
            .getModel()
            .getGlobe()
            .computeSurfaceNormalAtLocation(
                referencePos.getLatitude(), referencePos.getLongitude());
    Line verticalRay = new Line(referencePoint, surfaceNormal);
    Line screenRay =
        this.wwd.getView().computeRayFromScreenPoint(mousePoint.getX(), mousePoint.getY());
    Line previousScreenRay =
        this.wwd
            .getView()
            .computeRayFromScreenPoint(previousMousePoint.getX(), previousMousePoint.getY());

    Vec4 pointOnLine = AirspaceEditorUtil.nearestPointOnLine(verticalRay, screenRay);
    Vec4 previousPointOnLine =
        AirspaceEditorUtil.nearestPointOnLine(verticalRay, previousScreenRay);

    Position pos = this.wwd.getModel().getGlobe().computePositionFromPoint(pointOnLine);
    Position previousPos =
        this.wwd.getModel().getGlobe().computePositionFromPoint(previousPointOnLine);
    double elevationChange = pos.getElevation() - previousPos.getElevation();

    java.util.List<Position> boundary = new ArrayList<Position>();
    for (LatLon ll : this.polygon.getOuterBoundary()) {
      boundary.add(new Position(ll, ((Position) ll).getElevation() + elevationChange));
    }

    this.polygon.setOuterBoundary(boundary);
  }