/** * Causes the View attached to the specified WorldWindow to animate to the specified sector. The * View starts animating at its current location and stops when the sector fills the window. * * @param wwd the WorldWindow who's View animates. * @param sector the sector to go to. * @throws IllegalArgumentException if either the <code>wwd</code> or the <code>sector</code> are * <code>null</code>. */ public static void goTo(WorldWindow wwd, Sector sector) { if (wwd == null) { String message = Logging.getMessage("nullValue.WorldWindow"); Logging.logger().severe(message); throw new IllegalArgumentException(message); } if (sector == null) { String message = Logging.getMessage("nullValue.SectorIsNull"); Logging.logger().severe(message); throw new IllegalArgumentException(message); } // Create a bounding box for the specified sector in order to estimate its size in model // coordinates. Box extent = Sector.computeBoundingBox( wwd.getModel().getGlobe(), wwd.getSceneController().getVerticalExaggeration(), sector); // Estimate the distance between the center position and the eye position that is necessary to // cause the sector to // fill a viewport with the specified field of view. Note that we change the distance between // the center and eye // position here, and leave the field of view constant. Angle fov = wwd.getView().getFieldOfView(); double zoom = extent.getRadius() / fov.cosHalfAngle() / fov.tanHalfAngle(); // Configure OrbitView to look at the center of the sector from our estimated distance. This // causes OrbitView to // animate to the specified position over several seconds. To affect this change immediately use // the following: // ((OrbitView) wwd.getView()).setCenterPosition(new Position(sector.getCentroid(), 0d)); // ((OrbitView) wwd.getView()).setZoom(zoom); wwd.getView().goTo(new Position(sector.getCentroid(), 0d), zoom); }
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)); }
private static boolean isGaeaShadingSupported(WorldWindow wwd) { DrawContext dc = null; // shading is suppored if a deferredRenderer appears in dc relatively quickly AND this // deferredRenderer says it is supported for (int wait = 0; wait < 10; wait++) { dc = wwd.getSceneController().getDrawContext(); if (dc != null && dc.getDeferredRenderer() != null) { return dc.getDeferredRenderer().isSupported(dc); } try { Thread.sleep(1000); } catch (InterruptedException e) { // ignore } } return false; }
/** * Find out where on the terrain surface the eye would be looking at with the given heading and * pitch angles. * * @param view the orbit view * @param heading heading direction clockwise from north. * @param pitch view pitch angle from the surface normal at the center point. * @return the terrain surface point the view would be looking at in the viewport center. */ protected Vec4 computeSurfacePoint(OrbitView view, Angle heading, Angle pitch) { Globe globe = wwd.getModel().getGlobe(); // Compute transform to be applied to north pointing Y so that it would point in the view // direction // Move coordinate system to view center point Matrix transform = globe.computeSurfaceOrientationAtPosition(view.getCenterPosition()); // Rotate so that the north pointing axes Y will point in the look at direction transform = transform.multiply(Matrix.fromRotationZ(heading.multiply(-1))); transform = transform.multiply(Matrix.fromRotationX(Angle.NEG90.add(pitch))); // Compute forward vector Vec4 forward = Vec4.UNIT_Y.transformBy4(transform); // Return intersection with terrain Intersection[] intersections = wwd.getSceneController().getTerrain().intersect(new Line(view.getEyePoint(), forward)); return (intersections != null && intersections.length != 0) ? intersections[0].getIntersectionPoint() : null; }