protected void positionView(WorldWindow wwd) { LookAt lookAt = new LookAt().set(46.230, -122.190, 500, WorldWind.ABSOLUTE, 1.5e4 /*range*/, 45.0 /*heading*/, 70.0 /*tilt*/, 0 /*roll*/); wwd.getNavigator().setAsLookAt(this.getWorldWindow().getGlobe(), lookAt); } }
public LookAt getAsLookAt(Globe globe, LookAt result) { if (globe == null) { throw new IllegalArgumentException( Logger.logMessage(Logger.ERROR, "Navigator", "getAsLookAt", "missingGlobe")); } if (result == null) { throw new IllegalArgumentException( Logger.logMessage(Logger.ERROR, "Navigator", "getAsLookAt", "missingResult")); } this.getAsCamera(globe, this.scratchCamera); // get this navigator's properties as a Camera this.cameraToLookAt(globe, this.scratchCamera, result); // convert the Camera to a LookAt return result; }
protected void gestureDidBegin() { if (this.activeGestures++ == 0) { this.wwd.getNavigator().getAsLookAt(this.wwd.getGlobe(), this.beginLookAt); this.lookAt.set(this.beginLookAt); } }
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; }
public Matrix4 getAsViewingMatrix(Globe globe, Matrix4 result) { if (globe == null) { throw new IllegalArgumentException( Logger.logMessage(Logger.ERROR, "Navigator", "getAsViewingMatrix", "missingGlobe")); } if (result == null) { throw new IllegalArgumentException( Logger.logMessage(Logger.ERROR, "Navigator", "getAsViewingMatrix", "missingResult")); } this.getAsCamera(globe, this.scratchCamera); // get this navigator's properties as a Camera this.cameraToViewingMatrix(globe, this.scratchCamera, result); // convert the Camera to a viewing matrix return result; }
@Override public void creationSucceeded(LayerFactory factory, Layer layer) { // Add the finished GeoPackage layer to the WorldWindow. getWorldWindow().getLayers().addLayer(layer); // Place the viewer directly over the GeoPackage image. getWorldWindow().getNavigator().setLatitude(36.8139677556754); getWorldWindow().getNavigator().setLongitude(-76.03260320181615); getWorldWindow().getNavigator().setAltitude(20e3); Log.i("gov.nasa.worldwind", "GeoPackage layer creation succeeded"); }
Navigator navigator = new Navigator(); navigator.setAsLookAt(globe, lookAt); double nearDistance = navigator.getAltitude() * 0.75; double farDistance = globe.horizonDistance(navigator.getAltitude()) + globe.horizonDistance(160000); Matrix4 projection = new Matrix4(); projection.setToPerspectiveProjection(viewport.width, viewport.height, 45d /*fovy*/, nearDistance, farDistance); navigator.getAsViewingMatrix(globe, modelview);
/** * 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 onNavigatorEvent(WorldWindow wwd, NavigatorEvent event) { long currentTime = System.currentTimeMillis(); long elapsedTime = currentTime - lastEventTime; int eventAction = event.getAction(); boolean receivedUserInput = (eventAction == WorldWind.NAVIGATOR_MOVED && event.getLastInputEvent() != null); // Update the status overlay views whenever the navigator stops moving, // and also it is moving but at an (arbitrary) maximum refresh rate of 20 Hz. if (eventAction == WorldWind.NAVIGATOR_STOPPED || elapsedTime > 50) { // Get the current navigator state to apply to the overlays event.getNavigator().getAsLookAt(wwd.getGlobe(), lookAt); event.getNavigator().getAsCamera(wwd.getGlobe(), camera); // Update the overlays updateOverlayContents(lookAt, camera); updateOverlayColor(eventAction); lastEventTime = currentTime; } // Show the crosshairs while the user is gesturing and fade them out after the user stops if (receivedUserInput) { showCrosshairs(); } else { fadeCrosshairs(); } } };
@Override public void doFrame(long frameTimeNanos) { if (this.lastFrameTimeNanos != 0) { // Compute the frame duration in seconds. double frameDurationSeconds = (frameTimeNanos - this.lastFrameTimeNanos) * 1.0e-9; double cameraDegrees = (frameDurationSeconds * this.cameraDegreesPerSecond); // Move the navigator to continuously bring new tiles into view. Navigator navigator = getWorldWindow().getNavigator(); navigator.setLongitude(navigator.getLongitude() + cameraDegrees); // Redraw the WorldWindow to display the above changes. this.getWorldWindow().requestRedraw(); } Choreographer.getInstance().postFrameCallback(this); this.lastFrameTimeNanos = frameTimeNanos; }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setAboutBoxTitle("About the " + this.getResources().getText(R.string.title_day_night_cycle)); setAboutBoxText("Demonstrates how to display a continuous day-night cycle on the WorldWind globe.\n" + "This gradually changes both the Navigator's location and the AtmosphereLayer's light location."); // Initialize the Atmosphere layer's light location to our custom location. By default the light location is // always behind the viewer. LayerList layers = this.getWorldWindow().getLayers(); this.atmosphereLayer = (AtmosphereLayer) layers.getLayer(layers.indexOfLayerNamed("Atmosphere")); this.atmosphereLayer.setLightLocation(this.sunLocation); // Initialize the Navigator so that the sun is behind the viewer. Navigator navigator = this.getWorldWindow().getNavigator(); navigator.setLatitude(20); navigator.setLongitude(this.sunLocation.longitude); // Use this Activity's Choreographer to animate the day-night cycle. Choreographer.getInstance().postFrameCallback(this); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); this.setAboutBoxTitle("About the " + this.getResources().getText(R.string.title_basic_stress_test)); this.setAboutBoxText("Continuously moves the navigator in an Easterly direction from a low altitude."); // Add the ShowTessellation layer to provide some visual feedback regardless of texture details this.getWorldWindow().getLayers().addLayer(new ShowTessellationLayer()); // Initialize the Navigator so that it's looking in the direction of movement and the horizon is visible. Navigator navigator = this.getWorldWindow().getNavigator(); navigator.setAltitude(1e3); // 1 km navigator.setHeading(90); // looking east navigator.setTilt(75); // looking at the horizon }
this.rc.verticalExaggeration = this.verticalExaggeration; this.rc.fieldOfView = this.fieldOfView; this.rc.horizonDistance = this.globe.horizonDistance(this.navigator.getAltitude()); this.rc.camera = this.navigator.getAsCamera(this.globe, this.rc.camera); this.rc.cameraPoint = this.globe.geographicToCartesian(this.rc.camera.latitude, this.rc.camera.longitude, this.rc.camera.altitude, this.rc.cameraPoint); this.rc.renderResourceCache = this.renderResourceCache;
/** * Saves the Navigator's camera data to a SharedPreferences object. */ protected void saveNavigatorState() { WorldWindow wwd = this.getWorldWindow(); if (wwd != null) { SharedPreferences preferences = this.getPreferences(MODE_PRIVATE); SharedPreferences.Editor editor = preferences.edit(); // Write an identifier to the preferences for this session; editor.putLong(SESSION_TIMESTAMP, getSessionTimestamp()); // Write the camera data Camera camera = wwd.getNavigator().getAsCamera(wwd.getGlobe(), new Camera()); editor.putFloat(CAMERA_LATITUDE, (float) camera.latitude); editor.putFloat(CAMERA_LONGITUDE, (float) camera.longitude); editor.putFloat(CAMERA_ALTITUDE, (float) camera.altitude); editor.putFloat(CAMERA_HEADING, (float) camera.heading); editor.putFloat(CAMERA_TILT, (float) camera.tilt); editor.putFloat(CAMERA_ROLL, (float) camera.roll); editor.putInt(CAMERA_ALTITUDE_MODE, camera.altitudeMode); editor.apply(); } }
double eyeAltitude = this.navigator.getAltitude(); double eyeHorizon = this.globe.horizonDistance(eyeAltitude); double atmosphereHorizon = this.globe.horizonDistance(160000); this.navigator.getAsViewingMatrix(this.globe, modelview);
/** * Prepares this WorldWindow for drawing and event handling. * * @param configChooser optional argument for choosing an EGL configuration; may be null */ protected void init(EGLConfigChooser configChooser) { // Initialize the WorldWindow's navigator. Location initLocation = Location.fromTimeZone(TimeZone.getDefault()); double initAltitude = this.distanceToViewGlobeExtents() * 1.1; // add 10% to the minimum distance to allow for space around the screen edges this.navigator.setLatitude(initLocation.latitude); this.navigator.setLongitude(initLocation.longitude); this.navigator.setAltitude(initAltitude); // Initialize the WorldWindow's controller. this.worldWindowController.setWorldWindow(this); // Initialize the WorldWindow's render resource cache. int cacheCapacity = RenderResourceCache.recommendedCapacity(this.getContext()); this.renderResourceCache = new RenderResourceCache(cacheCapacity); // Set up to render on demand to an OpenGL ES 2.x context // TODO Investigate and use the EGL chooser submitted by jgiovino this.setEGLConfigChooser(configChooser); this.setEGLContextClientVersion(2); // must be called before setRenderer this.setRenderer(this); this.setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY); // must be called after setRenderer // Log a message with some basic information about the WorldWindow's configuration. Logger.log(Logger.INFO, "WorldWindow initialized"); }
Navigator navigator = new Navigator(); navigator.setAsLookAt(globe, lookAt); double nearDistance = navigator.getAltitude() * 0.75; double farDistance = globe.horizonDistance(navigator.getAltitude()) + globe.horizonDistance(160000); Matrix4 projection = new Matrix4(); projection.setToPerspectiveProjection(viewport.width, viewport.height, 45d /*fovy*/, nearDistance, farDistance); navigator.getAsViewingMatrix(globe, modelview);
@Override public void run() { this.wwd.getNavigator().setAsCamera(this.wwd.getGlobe(), this.camera); this.wwd.requestRedraw(); pool.release(this.reset()); } }
@Override public void onNavigatorEvent(WorldWindow wwd, NavigatorEvent event) { long currentTime = System.currentTimeMillis(); long elapsedTime = currentTime - lastEventTime; int eventAction = event.getAction(); boolean receivedUserInput = (eventAction == WorldWind.NAVIGATOR_MOVED && event.getLastInputEvent() != null); // Update the status overlay views whenever the navigator stops moving, // and also it is moving but at an (arbitrary) maximum refresh rate of 20 Hz. if (eventAction == WorldWind.NAVIGATOR_STOPPED || elapsedTime > 50) { // Get the current navigator state to apply to the overlays event.getNavigator().getAsLookAt(wwd.getGlobe(), lookAt); event.getNavigator().getAsCamera(wwd.getGlobe(), camera); // Update the overlays updateOverlayContents(lookAt, camera); updateOverlayColor(eventAction); lastEventTime = currentTime; } // Show the crosshairs while the user is gesturing and fade them out after the user stops if (receivedUserInput) { showCrosshairs(); } else { fadeCrosshairs(); } } };
@Override public void doFrame(long frameTimeNanos) { if (this.lastFrameTimeNanos != 0) { // Compute the frame duration in seconds. double frameDurationSeconds = (frameTimeNanos - this.lastFrameTimeNanos) * 1.0e-9; double cameraDegrees = (frameDurationSeconds * this.cameraDegreesPerSecond); // Move the navigator to simulate the Earth's rotation about its axis. Navigator navigator = getWorldWindow().getNavigator(); navigator.setLongitude(navigator.getLongitude() - cameraDegrees); // Redraw the WorldWindow to display the above changes. this.getWorldWindow().requestRedraw(); } if (!this.activityPaused) { // stop animating when this Activity is paused Choreographer.getInstance().postFrameCallback(this); } this.lastFrameTimeNanos = frameTimeNanos; }