private void adjustDateLineCrossingPoints() { ArrayList<LatLon> corners = new ArrayList<LatLon>(Arrays.asList(sw, se, nw, ne)); if (!LatLon.locationsCrossDateLine(corners)) return; double lonSign = 0; for (LatLon corner : corners) { if (Math.abs(corner.getLongitude().degrees) != 180) lonSign = Math.signum(corner.getLongitude().degrees); } if (lonSign == 0) return; if (Math.abs(sw.getLongitude().degrees) == 180 && Math.signum(sw.getLongitude().degrees) != lonSign) sw = new Position(sw.getLatitude(), sw.getLongitude().multiply(-1), sw.getElevation()); if (Math.abs(se.getLongitude().degrees) == 180 && Math.signum(se.getLongitude().degrees) != lonSign) se = new Position(se.getLatitude(), se.getLongitude().multiply(-1), se.getElevation()); if (Math.abs(nw.getLongitude().degrees) == 180 && Math.signum(nw.getLongitude().degrees) != lonSign) nw = new Position(nw.getLatitude(), nw.getLongitude().multiply(-1), nw.getElevation()); if (Math.abs(ne.getLongitude().degrees) == 180 && Math.signum(ne.getLongitude().degrees) != lonSign) ne = new Position(ne.getLatitude(), ne.getLongitude().multiply(-1), ne.getElevation()); }
protected void movePolygon(Point previousMousePoint, Point mousePoint) { // Intersect a ray through each mouse point, with a geoid passing through the reference // elevation. // If either ray fails to intersect the geoid, then ignore this event. Use the difference // between the two // intersected positions to move the control point's location. View view = this.wwd.getView(); Globe globe = this.wwd.getModel().getGlobe(); Position refPos = this.polygon.getReferencePosition(); if (refPos == null) return; Line ray = view.computeRayFromScreenPoint(mousePoint.getX(), mousePoint.getY()); Line previousRay = view.computeRayFromScreenPoint(previousMousePoint.getX(), previousMousePoint.getY()); Vec4 vec = AirspaceEditorUtil.intersectGlobeAt(this.wwd, refPos.getElevation(), ray); Vec4 previousVec = AirspaceEditorUtil.intersectGlobeAt(this.wwd, refPos.getElevation(), previousRay); if (vec == null || previousVec == null) { return; } Position pos = globe.computePositionFromPoint(vec); Position previousPos = globe.computePositionFromPoint(previousVec); LatLon change = pos.subtract(previousPos); this.polygon.move(new Position(change.getLatitude(), change.getLongitude(), 0.0)); }
/** * Select the visible grid elements * * @param dc the current <code>DrawContext</code>. */ protected void selectRenderables(DrawContext dc) { if (dc == null) { String message = Logging.getMessage("nullValue.DrawContextIsNull"); Logging.logger().severe(message); throw new IllegalArgumentException(message); } Sector vs = dc.getVisibleSector(); OrbitView view = (OrbitView) dc.getView(); // Compute labels offset from view center Position centerPos = view.getCenterPosition(); Double pixelSizeDegrees = Angle.fromRadians( view.computePixelSizeAtDistance(view.getZoom()) / dc.getGlobe().getEquatorialRadius()) .degrees; Double labelOffsetDegrees = pixelSizeDegrees * view.getViewport().getWidth() / 4; Position labelPos = Position.fromDegrees( centerPos.getLatitude().degrees - labelOffsetDegrees, centerPos.getLongitude().degrees - labelOffsetDegrees, 0); Double labelLatDegrees = labelPos.getLatitude().normalizedLatitude().degrees; labelLatDegrees = Math.min(Math.max(labelLatDegrees, -76), 78); labelPos = new Position( Angle.fromDegrees(labelLatDegrees), labelPos.getLongitude().normalizedLongitude(), 0); if (vs != null) { for (GridElement ge : this.gridElements) { if (ge.isInView(dc)) { if (ge.renderable instanceof GeographicText) { GeographicText gt = (GeographicText) ge.renderable; if (labelPos.getLatitude().degrees < 72 || "*32*34*36*".indexOf("*" + gt.getText() + "*") == -1) { // Adjust label position according to eye position Position pos = gt.getPosition(); if (ge.type.equals(GridElement.TYPE_LATITUDE_LABEL)) pos = Position.fromDegrees( pos.getLatitude().degrees, labelPos.getLongitude().degrees, pos.getElevation()); else if (ge.type.equals(GridElement.TYPE_LONGITUDE_LABEL)) pos = Position.fromDegrees( labelPos.getLatitude().degrees, pos.getLongitude().degrees, pos.getElevation()); gt.setPosition(pos); } } this.graticuleSupport.addRenderable(ge.renderable, GRATICULE_UTM); } } // System.out.println("Total elements: " + count + " visible sector: " + vs); } }
protected void doMoveAirspaceLaterally( WorldWindow wwd, Airspace airspace, Point mousePoint, Point previousMousePoint) { // Intersect a ray throuh each mouse point, with a geoid passing through the reference // elevation. Since // most airspace control points follow a fixed altitude, this will track close to the intended // mouse position. // If either ray fails to intersect the geoid, then ignore this event. Use the difference // between the two // intersected positions to move the control point's location. if (!(airspace instanceof Movable)) { return; } Movable movable = (Movable) airspace; View view = wwd.getView(); Globe globe = wwd.getModel().getGlobe(); Position refPos = movable.getReferencePosition(); if (refPos == null) return; // Convert the reference position into a cartesian point. This assumes that the reference // elevation is defined // by the airspace's lower altitude. Vec4 refPoint = null; if (airspace.isTerrainConforming()[LOWER_ALTITUDE]) refPoint = wwd.getSceneController().getTerrain().getSurfacePoint(refPos); if (refPoint == null) refPoint = globe.computePointFromPosition(refPos); // Convert back to a position. refPos = globe.computePositionFromPoint(refPoint); Line ray = view.computeRayFromScreenPoint(mousePoint.getX(), mousePoint.getY()); Line previousRay = view.computeRayFromScreenPoint(previousMousePoint.getX(), previousMousePoint.getY()); Vec4 vec = AirspaceEditorUtil.intersectGlobeAt(wwd, refPos.getElevation(), ray); Vec4 previousVec = AirspaceEditorUtil.intersectGlobeAt(wwd, refPos.getElevation(), previousRay); if (vec == null || previousVec == null) { return; } Position pos = globe.computePositionFromPoint(vec); Position previousPos = globe.computePositionFromPoint(previousVec); LatLon change = pos.subtract(previousPos); movable.move(new Position(change.getLatitude(), change.getLongitude(), 0.0)); this.fireAirspaceMoved(new AirspaceEditEvent(wwd, airspace, this)); }
protected void dragWholeShape(DragSelectEvent dragEvent, Movable dragObject) { View view = getWwd().getView(); EllipsoidalGlobe globe = (EllipsoidalGlobe) getWwd().getModel().getGlobe(); // Compute ref-point position in screen coordinates. Position refPos = dragObject.getReferencePosition(); if (refPos == null) return; Vec4 refPoint = globe.computePointFromPosition(refPos); Vec4 screenRefPoint = view.project(refPoint); // Compute screen-coord delta since last event. int dx = dragEvent.getPickPoint().x - dragEvent.getPreviousPickPoint().x; int dy = dragEvent.getPickPoint().y - dragEvent.getPreviousPickPoint().y; // Find intersection of screen coord ref-point with globe. double x = screenRefPoint.x + dx; double y = dragEvent.getMouseEvent().getComponent().getSize().height - screenRefPoint.y + dy - 1; Line ray = view.computeRayFromScreenPoint(x, y); Intersection inters[] = globe.intersect(ray, refPos.getElevation()); if (inters != null) { // Intersection with globe. Move reference point to the intersection point. Position p = globe.computePositionFromPoint(inters[0].getIntersectionPoint()); dragObject.moveTo(p); } }
protected void setDepthFunc(DrawContext dc, OrderedIcon uIcon, Vec4 screenPoint) { GL gl = dc.getGL(); if (uIcon.icon.isAlwaysOnTop()) { gl.glDepthFunc(GL.GL_ALWAYS); return; } Position eyePos = dc.getView().getEyePosition(); if (eyePos == null) { gl.glDepthFunc(GL.GL_ALWAYS); return; } double altitude = eyePos.getElevation(); if (altitude < (dc.getGlobe().getMaxElevation() * dc.getVerticalExaggeration())) { double depth = screenPoint.z - (8d * 0.00048875809d); depth = depth < 0d ? 0d : (depth > 1d ? 1d : depth); gl.glDepthFunc(GL.GL_LESS); gl.glDepthRange(depth, depth); } else if (uIcon.eyeDistance > uIcon.horizonDistance) { gl.glDepthFunc(GL.GL_EQUAL); gl.glDepthRange(1d, 1d); } else { gl.glDepthFunc(GL.GL_ALWAYS); } }
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); }
public void onSuccess(Position[] positions) { for (Position p : positions) { Logging.logger() .info( p.getLatitude().degrees + "," + p.getLongitude().degrees + " --> " + p.getElevation()); } }
protected void moveControlPoint( ControlPointMarker controlPoint, Point lastMousePoint, Point moveToPoint) { View view = this.wwd.getView(); Globe globe = this.wwd.getModel().getGlobe(); Position refPos = controlPoint.getPosition(); if (refPos == null) return; Line ray = view.computeRayFromScreenPoint(moveToPoint.getX(), moveToPoint.getY()); Line previousRay = view.computeRayFromScreenPoint(lastMousePoint.getX(), lastMousePoint.getY()); Vec4 vec = AirspaceEditorUtil.intersectGlobeAt(this.wwd, refPos.getElevation(), ray); Vec4 previousVec = AirspaceEditorUtil.intersectGlobeAt(this.wwd, refPos.getElevation(), previousRay); if (vec == null || previousVec == null) { return; } Position pos = globe.computePositionFromPoint(vec); Position previousPos = globe.computePositionFromPoint(previousVec); LatLon change = pos.subtract(previousPos); java.util.List<LatLon> boundary = new ArrayList<LatLon>(); for (LatLon ll : this.polygon.getOuterBoundary()) { boundary.add(ll); } boundary.set(controlPoint.getIndex(), new Position(pos.add(change), refPos.getAltitude())); // ExtrudedPolygon ensures that the last boundary position is the same as the first. Remove the // last point // before setting the boundary. boundary.remove(boundary.size() - 1); this.polygon.setOuterBoundary(boundary); }
/** * Compute the view range footprint on the globe. * * @param dc the current <code>DrawContext</code> * @param steps the number of steps. * @return an array list of <code>LatLon</code> forming a closed shape. */ protected ArrayList<LatLon> computeViewFootPrint(DrawContext dc, int steps) { ArrayList<LatLon> positions = new ArrayList<LatLon>(); Position eyePos = dc.getView().getEyePosition(); Angle distance = Angle.fromRadians( Math.asin( dc.getView().getFarClipDistance() / (dc.getGlobe().getRadius() + eyePos.getElevation()))); if (distance.degrees > 10) { double headStep = 360d / steps; Angle heading = Angle.ZERO; for (int i = 0; i <= steps; i++) { LatLon p = LatLon.greatCircleEndPosition(eyePos, heading, distance); positions.add(p); heading = heading.addDegrees(headStep); } return positions; } else return null; }
protected void doMoveAirspaceVertically( WorldWindow wwd, Airspace airspace, Point mousePoint, Point previousMousePoint) { // 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 airspace altitude. // // If the state keepControlPointsAboveTerrain is set, we prevent the control point from passing // any lower than // the terrain elevation beneath it. if (!(airspace instanceof Movable)) { return; } Movable movable = (Movable) airspace; Position referencePos = movable.getReferencePosition(); if (referencePos == null) return; Vec4 referencePoint = wwd.getModel().getGlobe().computePointFromPosition(referencePos); Vec4 surfaceNormal = wwd.getModel() .getGlobe() .computeSurfaceNormalAtLocation( referencePos.getLatitude(), referencePos.getLongitude()); Line verticalRay = new Line(referencePoint, surfaceNormal); Line screenRay = wwd.getView() .computeRayFromScreenPoint(previousMousePoint.getX(), previousMousePoint.getY()); Line previousScreenRay = wwd.getView().computeRayFromScreenPoint(mousePoint.getX(), mousePoint.getY()); Vec4 pointOnLine = AirspaceEditorUtil.nearestPointOnLine(verticalRay, screenRay); Vec4 previousPointOnLine = AirspaceEditorUtil.nearestPointOnLine(verticalRay, previousScreenRay); Position pos = wwd.getModel().getGlobe().computePositionFromPoint(pointOnLine); Position previousPos = wwd.getModel().getGlobe().computePositionFromPoint(previousPointOnLine); double elevationChange = previousPos.getElevation() - pos.getElevation(); double[] altitudes = this.getAirspace().getAltitudes(); boolean[] terrainConformance = this.getAirspace().isTerrainConforming(); if (this.isKeepControlPointsAboveTerrain()) { if (terrainConformance[LOWER_ALTITUDE]) { if (altitudes[LOWER_ALTITUDE] + elevationChange < 0.0) elevationChange = 0.0 - altitudes[LOWER_ALTITUDE]; } else { double height = AirspaceEditorUtil.computeLowestHeightAboveSurface( wwd, this.getCurrentControlPoints(), LOWER_ALTITUDE); if (elevationChange <= -height) { elevationChange = -height; } } } altitudes[LOWER_ALTITUDE] += elevationChange; altitudes[UPPER_ALTITUDE] += elevationChange; this.getAirspace().setAltitudes(altitudes[LOWER_ALTITUDE], altitudes[UPPER_ALTITUDE]); this.fireAirspaceMoved(new AirspaceEditEvent(wwd, airspace, this)); }
protected void drawMany(DrawContext dc, Iterable<? extends WWIcon> icons, Layer layer) { if (dc == null) { String msg = Logging.getMessage("nullValue.DrawContextIsNull"); Logging.logger().severe(msg); throw new IllegalArgumentException(msg); } if (dc.getVisibleSector() == null) return; SectorGeometryList geos = dc.getSurfaceGeometry(); //noinspection RedundantIfStatement if (geos == null) return; if (icons == null) { String msg = Logging.getMessage("nullValue.IconIterator"); Logging.logger().severe(msg); throw new IllegalArgumentException(msg); } Iterator<? extends WWIcon> iterator = icons.iterator(); if (!iterator.hasNext()) return; double horizon = dc.getView().getHorizonDistance(); while (iterator.hasNext()) { WWIcon icon = iterator.next(); if (!isIconValid(icon, true)) { // Record feedback data for this WWIcon if feedback is enabled. if (icon != null) this.recordFeedback(dc, icon, null, null); continue; } if (!icon.isVisible()) { // Record feedback data for this WWIcon if feedback is enabled. this.recordFeedback(dc, icon, null, null); continue; } // Determine Cartesian position from the surface geometry if the icon is near the surface, // otherwise draw it from the globe. Position pos = icon.getPosition(); Vec4 iconPoint = null; if (pos.getElevation() < dc.getGlobe().getMaxElevation() && !this.isAlwaysUseAbsoluteElevation()) { iconPoint = dc.getSurfaceGeometry().getSurfacePoint(icon.getPosition()); } if (iconPoint == null) { Angle lat = pos.getLatitude(); Angle lon = pos.getLongitude(); double elevation = pos.getElevation(); if (!this.isAlwaysUseAbsoluteElevation()) elevation += dc.getGlobe().getElevation(lat, lon); iconPoint = dc.getGlobe().computePointFromPosition(lat, lon, elevation); } double eyeDistance = icon.isAlwaysOnTop() ? 0 : dc.getView().getEyePoint().distanceTo3(iconPoint); // X-PATCH Marjan // extracted skip conditions into an overrideable method if (!meetsRenderCriteria(dc, icon, iconPoint, eyeDistance)) { this.recordFeedback(dc, icon, iconPoint, null); continue; } // X-END // The icons aren't drawn here, but added to the ordered queue to be drawn back-to-front. dc.addOrderedRenderable(new OrderedIcon(icon, iconPoint, layer, eyeDistance, horizon)); if (icon.isShowToolTip()) this.addToolTip(dc, icon, iconPoint); } }