protected List<Position> computePathPositions( Position startPosition, Position endPosition, Angle delta) { Angle dist = LatLon.greatCircleDistance(startPosition, endPosition); dist = dist.multiply(0.6); Angle azimuth = LatLon.greatCircleAzimuth(startPosition, endPosition); LatLon locA = LatLon.greatCircleEndPosition(startPosition, azimuth.add(delta), dist); dist = dist.multiply(0.9); LatLon locB = LatLon.greatCircleEndPosition(startPosition, azimuth.subtract(delta), dist); return Arrays.asList(startPosition, new Position(locA, 0), new Position(locB, 0), endPosition); }
/** * Setup the view to a first person mode (zoom = 0) * * @param view the orbit view to set into a first person view. */ protected void setupFirstPersonView(OrbitView view) { if (view.getZoom() == 0) // already in first person mode return; Vec4 eyePoint = view.getEyePoint(); // Center pos at eye pos Position centerPosition = wwd.getModel().getGlobe().computePositionFromPoint(eyePoint); // Compute pitch and heading relative to center position Vec4 normal = wwd.getModel() .getGlobe() .computeSurfaceNormalAtLocation( centerPosition.getLatitude(), centerPosition.getLongitude()); Vec4 north = wwd.getModel() .getGlobe() .computeNorthPointingTangentAtLocation( centerPosition.getLatitude(), centerPosition.getLongitude()); // Pitch view.setPitch(Angle.POS180.subtract(view.getForwardVector().angleBetween3(normal))); // Heading Vec4 perpendicular = view.getForwardVector().perpendicularTo3(normal); Angle heading = perpendicular.angleBetween3(north); double direction = Math.signum(-normal.cross3(north).dot3(perpendicular)); view.setHeading(heading.multiply(direction)); // Zoom view.setZoom(0); // Center pos view.setCenterPosition(centerPosition); }
/** * 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; }
/** * Reset the view to an orbit view state if in first person mode (zoom = 0) * * @param view the orbit view to reset */ protected void resetOrbitView(OrbitView view) { if (view.getZoom() > 0) // already in orbit view mode return; // Find out where on the terrain the eye is looking at in the viewport center // TODO: if no terrain is found in the viewport center, iterate toward viewport bottom until it // is found Vec4 centerPoint = computeSurfacePoint(view, view.getHeading(), view.getPitch()); // Reset the orbit view center point heading, pitch and zoom if (centerPoint != null) { Vec4 eyePoint = view.getEyePoint(); // Center pos on terrain surface Position centerPosition = wwd.getModel().getGlobe().computePositionFromPoint(centerPoint); // Compute pitch and heading relative to center position Vec4 normal = wwd.getModel() .getGlobe() .computeSurfaceNormalAtLocation( centerPosition.getLatitude(), centerPosition.getLongitude()); Vec4 north = wwd.getModel() .getGlobe() .computeNorthPointingTangentAtLocation( centerPosition.getLatitude(), centerPosition.getLongitude()); // Pitch view.setPitch(Angle.POS180.subtract(view.getForwardVector().angleBetween3(normal))); // Heading Vec4 perpendicular = view.getForwardVector().perpendicularTo3(normal); Angle heading = perpendicular.angleBetween3(north); double direction = Math.signum(-normal.cross3(north).dot3(perpendicular)); view.setHeading(heading.multiply(direction)); // Zoom view.setZoom(eyePoint.distanceTo3(centerPoint)); // Center pos view.setCenterPosition(centerPosition); } }
/** * Create the list of positions that describe the arrow. * * @param dc Current draw context. */ protected void createShapes(DrawContext dc) { this.paths = new Path[2]; int i = 0; Angle azimuth1 = LatLon.greatCircleAzimuth(this.position1, this.position2); Angle azimuth2 = LatLon.greatCircleAzimuth(this.position1, this.position3); Angle delta = azimuth2.subtract(azimuth1); int sign = delta.degrees > 0 ? 1 : -1; delta = Angle.fromDegrees(sign * 5.0); // Create a path for the line part of the arrow List<Position> positions = this.computePathPositions(this.position1, this.position2, delta); this.paths[i++] = this.createPath(positions); // Create a polygon to draw the arrow head. double arrowLength = this.getArrowLength(); Angle arrowAngle = this.getArrowAngle(); positions = this.computeArrowheadPositions( dc, positions.get(2), positions.get(3), arrowLength, arrowAngle); this.arrowHead1 = this.createPolygon(positions); this.arrowHead1.setLocations(positions); delta = delta.multiply(-1.0); positions = this.computePathPositions(this.position1, this.position3, delta); this.paths[i] = this.createPath(positions); positions = this.computeArrowheadPositions( dc, positions.get(2), positions.get(3), arrowLength, arrowAngle); this.arrowHead2 = this.createPolygon(positions); this.arrowHead2.setLocations(positions); }