public Navigator setAsLookAt(Globe globe, LookAt lookAt) { if (globe == null) { throw new IllegalArgumentException( Logger.logMessage(Logger.ERROR, "Navigator", "setAsLookAt", "missingGlobe")); } if (lookAt == null) { throw new IllegalArgumentException( Logger.logMessage(Logger.ERROR, "Navigator", "setAsLookAt", "missingLookAt")); } this.lookAtToCamera(globe, lookAt, this.scratchCamera); // convert the LookAt to a Camera this.setAsCamera(globe, this.scratchCamera); // set this navigator's properties as a Camera return this; }
/** * Restores the Navigator's camera state from a SharedPreferences object. */ protected void restoreNavigatorState() { WorldWindow wwd = this.getWorldWindow(); if (wwd != null) { SharedPreferences preferences = this.getPreferences(MODE_PRIVATE); // We only want to restore preferences from the same session. if (preferences.getLong(SESSION_TIMESTAMP, -1) != getSessionTimestamp()) { return; } // Read the camera data float lat = preferences.getFloat(CAMERA_LATITUDE, Float.MAX_VALUE); float lon = preferences.getFloat(CAMERA_LONGITUDE, Float.MAX_VALUE); float alt = preferences.getFloat(CAMERA_ALTITUDE, Float.MAX_VALUE); float heading = preferences.getFloat(CAMERA_HEADING, Float.MAX_VALUE); float tilt = preferences.getFloat(CAMERA_TILT, Float.MAX_VALUE); float roll = preferences.getFloat(CAMERA_ROLL, Float.MAX_VALUE); @WorldWind.AltitudeMode int altMode = preferences.getInt(CAMERA_ALTITUDE_MODE, WorldWind.ABSOLUTE); if (lat == Float.MAX_VALUE || lon == Float.MAX_VALUE || alt == Float.MAX_VALUE || heading == Float.MAX_VALUE || tilt == Float.MAX_VALUE || roll == Float.MAX_VALUE) { return; } // Restore the camera state. Camera camera = new Camera(lat, lon, alt, altMode, heading, tilt, roll); wwd.getNavigator().setAsCamera(wwd.getGlobe(), camera); } }
@Override public void run() { this.wwd.getNavigator().setAsCamera(this.wwd.getGlobe(), this.camera); this.wwd.requestRedraw(); pool.release(this.reset()); } }
protected void positionView(WorldWindow wwd) { Position mtRainier = new Position(46.852886, -121.760374, 4392.0); Position eye = new Position(46.912, -121.527, 2000.0); // Compute heading and distance from peak to eye Globe globe = wwd.getGlobe(); double heading = eye.greatCircleAzimuth(mtRainier); double distanceRadians = mtRainier.greatCircleDistance(eye); double distance = distanceRadians * globe.getRadiusAt(mtRainier.latitude, mtRainier.longitude); // Compute camera settings double altitude = eye.altitude - mtRainier.altitude; double range = Math.sqrt(altitude * altitude + distance * distance); double tilt = Math.toDegrees(Math.atan(distance / eye.altitude)); // Apply the new view Camera camera = new Camera(); camera.set(eye.latitude, eye.longitude, eye.altitude, WorldWind.ABSOLUTE, heading, tilt, 0.0 /*roll*/); wwd.getNavigator().setAsCamera(globe, camera); } }
wwd.getNavigator().setAsCamera(globe, camera);
this.wwd.getNavigator().setAsCamera(this.wwd.getGlobe(), this.camera); this.wwd.requestRedraw(); } else if (state == WorldWind.ENDED || state == WorldWind.CANCELLED) {
/** * Creates a new WorldWindow object with a custom WorldWindowController. */ @Override public WorldWindow createWorldWindow() { // Let the super class (BasicGlobeFragment) do the creation WorldWindow wwd = super.createWorldWindow(); // Override the default "look at" gesture behavior with a camera centric gesture controller wwd.setWorldWindowController(new CameraController()); // Create a camera position above KOXR airport, Oxnard, CA Camera camera = new Camera(); camera.set(34.2, -119.2, 10000, WorldWind.ABSOLUTE, 90, // Looking east 70, // Lookup up from nadir 0); // No roll // Apply the new camera position Globe globe = wwd.getGlobe(); wwd.getNavigator().setAsCamera(globe, camera); return wwd; }
@Override protected void handleRotate(GestureRecognizer recognizer) { int state = recognizer.getState(); float rotation = ((RotationRecognizer) recognizer).getRotation(); if (state == WorldWind.BEGAN) { this.gestureDidBegin(); this.lastRotation = 0; } else if (state == WorldWind.CHANGED) { // Apply the change in rotation to the navigator, relative to the navigator's current values. double headingDegrees = this.lastRotation - rotation; this.camera.heading = WWMath.normalizeAngle360(this.camera.heading + headingDegrees); this.lastRotation = rotation; this.wwd.getNavigator().setAsCamera(this.wwd.getGlobe(), this.camera); this.wwd.requestRedraw(); } else if (state == WorldWind.ENDED || state == WorldWind.CANCELLED) { this.gestureDidEnd(); } }
@Override protected void handlePinch(GestureRecognizer recognizer) { int state = recognizer.getState(); float scale = ((PinchRecognizer) recognizer).getScale(); if (state == WorldWind.BEGAN) { this.gestureDidBegin(); } else if (state == WorldWind.CHANGED) { if (scale != 0) { // Apply the change in scale to the navigator, relative to when the gesture began. scale = ((scale - 1) * 0.1f) + 1; // dampen the scale factor this.camera.altitude = this.camera.altitude * scale; this.applyLimits(this.camera); this.wwd.getNavigator().setAsCamera(this.wwd.getGlobe(), this.camera); this.wwd.requestRedraw(); } } else if (state == WorldWind.ENDED || state == WorldWind.CANCELLED) { this.gestureDidEnd(); } }
@Override protected void handleTilt(GestureRecognizer recognizer) { int state = recognizer.getState(); float dx = recognizer.getTranslationX(); float dy = recognizer.getTranslationY(); if (state == WorldWind.BEGAN) { this.gestureDidBegin(); this.lastRotation = 0; } else if (state == WorldWind.CHANGED) { // Apply the change in tilt to the navigator, relative to when the gesture began. double headingDegrees = 180 * dx / this.wwd.getWidth(); double tiltDegrees = -180 * dy / this.wwd.getHeight(); this.camera.heading = WWMath.normalizeAngle360(this.beginCamera.heading + headingDegrees); this.camera.tilt = this.beginCamera.tilt + tiltDegrees; this.applyLimits(camera); this.wwd.getNavigator().setAsCamera(this.wwd.getGlobe(), this.camera); this.wwd.requestRedraw(); } else if (state == WorldWind.ENDED || state == WorldWind.CANCELLED) { this.gestureDidEnd(); } }