@Override protected void doRender(RenderContext rc) { if (rc.terrain.getSector().isEmpty()) { return; // no terrain surface to render on } this.determineActiveProgram(rc); this.assembleTiles(rc); this.activeProgram = null; // clear the active program to avoid leaking render resources this.ancestorTile = null; // clear the ancestor tile and texture this.ancestorTexture = null; }
if (rc.terrain != null && rc.terrain.surfacePoint(lat, lon, this.scratchPoint)) { this.centerPoint.set(this.scratchPoint); // found a point on the terrain if (rc.terrain != null && rc.terrain.surfacePoint(lat, lon, this.scratchPoint)) { this.centerPoint.set(this.scratchPoint); // found a point on the terrain if (alt != 0) { // Offset along the normal vector at the terrain surface point.
protected void renderTerrainPickedObject(RenderContext rc) { if (rc.terrain.getSector().isEmpty()) { return; // no terrain to pick } // Acquire a unique picked object ID for terrain. int pickedObjectId = rc.nextPickedObjectId(); // Enqueue a drawable for processing on the OpenGL thread that displays terrain in the unique pick color. Pool<DrawableSurfaceColor> pool = rc.getDrawablePool(DrawableSurfaceColor.class); DrawableSurfaceColor drawable = DrawableSurfaceColor.obtain(pool); drawable.color = PickedObject.identifierToUniqueColor(pickedObjectId, drawable.color); drawable.program = (BasicShaderProgram) rc.getShaderProgram(BasicShaderProgram.KEY); if (drawable.program == null) { drawable.program = (BasicShaderProgram) rc.putShaderProgram(BasicShaderProgram.KEY, new BasicShaderProgram(rc.resources)); } rc.offerSurfaceDrawable(drawable, Double.NEGATIVE_INFINITY /*z-order before all other surface drawables*/); // If the pick ray intersects the terrain, enqueue a picked object that associates the terrain drawable with its // picked object ID and the intersection position. if (rc.pickRay != null && rc.terrain.intersect(rc.pickRay, this.pickPoint)) { rc.globe.cartesianToGeographic(this.pickPoint.x, this.pickPoint.y, this.pickPoint.z, this.pickPos); this.pickPos.altitude = 0; // report the actual altitude, which may not lie on the terrain's surface rc.offerPickedObject(PickedObject.fromTerrain(pickedObjectId, this.pickPos)); } }
if (this.terrain != null && this.terrain.surfacePoint(latitude, longitude, result)) { return result; // found a point on the terrain } else if (this.globe != null) { if (this.terrain != null && this.terrain.surfacePoint(latitude, longitude, result)) { if (altitude != 0) { // Offset along the normal vector at the terrain surface point. this.globe.geographicToCartesianNormal(latitude, longitude, this.scratchVector);
@Test public void testGetSector() throws Exception { Sector expected = new Sector(0, 0, 1, 1); Sector actual = this.terrain.getSector(); assertEquals("sector", expected, actual); }
@SuppressWarnings("ConstantConditions") @Test public void testSurfacePoint_SouthEdge() throws Exception { double lat = 0.0; double lon = 0.5; double alt = 0.0; Vec3 expected = worldWindEcef(officialWgs84Ecef(lat, lon, alt)); boolean expectedReturn = true; Vec3 actual = new Vec3(); boolean actualReturn = this.terrain.surfacePoint(lat, lon, actual); assertEquals("surfacePoint South edge x", expected.x, actual.x, TOLERANCE); assertEquals("surfacePoint South edge y", expected.y, actual.y, TOLERANCE); assertEquals("surfacePoint South edge z", expected.z, actual.z, TOLERANCE); assertEquals("surfacePoint South edge return", expectedReturn, actualReturn); }
@Override protected void doRender(RenderContext rc) { if (rc.terrain.getSector().isEmpty()) { return; // no terrain to render } // Use WorldWind's basic GLSL program. BasicShaderProgram program = (BasicShaderProgram) rc.getShaderProgram(BasicShaderProgram.KEY); if (program == null) { program = (BasicShaderProgram) rc.putShaderProgram(BasicShaderProgram.KEY, new BasicShaderProgram(rc.resources)); } Pool<DrawableTessellation> pool = rc.getDrawablePool(DrawableTessellation.class); Drawable drawable = DrawableTessellation.obtain(pool).set(program, this.color); rc.offerSurfaceDrawable(drawable, 1.0 /*z-order after surface textures*/); } }
@SuppressWarnings("ConstantConditions") @Test public void testSurfacePoint_WestEdge() throws Exception { double lat = 0.5; double lon = 0.0; double alt = 0.0; Vec3 expected = worldWindEcef(officialWgs84Ecef(lat, lon, alt)); boolean expectedReturn = true; Vec3 actual = new Vec3(); boolean actualReturn = this.terrain.surfacePoint(lat, lon, actual); assertEquals("surfacePoint West edge x", expected.x, actual.x, TOLERANCE); assertEquals("surfacePoint West edge y", expected.y, actual.y, TOLERANCE); assertEquals("surfacePoint West edge z", expected.z, actual.z, TOLERANCE); assertEquals("surfacePoint West edge return", expectedReturn, actualReturn); }
protected void renderGround(RenderContext rc) { if (rc.terrain.getSector().isEmpty()) { return; // no terrain surface to render on } Pool<DrawableGroundAtmosphere> pool = rc.getDrawablePool(DrawableGroundAtmosphere.class); DrawableGroundAtmosphere drawable = DrawableGroundAtmosphere.obtain(pool); drawable.program = (GroundProgram) rc.getShaderProgram(GroundProgram.KEY); if (drawable.program == null) { drawable.program = (GroundProgram) rc.putShaderProgram(GroundProgram.KEY, new GroundProgram(rc.resources)); } drawable.lightDirection.set(this.activeLightDirection); drawable.globeRadius = rc.globe.getEquatorialRadius(); // Use this layer's night image when the light location is different than the eye location. if (this.nightImageSource != null && this.lightLocation != null) { drawable.nightTexture = rc.getTexture(this.nightImageSource); if (drawable.nightTexture == null) { drawable.nightTexture = rc.retrieveTexture(this.nightImageSource, this.nightImageOptions); } } else { drawable.nightTexture = null; } rc.offerSurfaceDrawable(drawable, Double.POSITIVE_INFINITY /*z-order after all other surface drawables*/); }
@SuppressWarnings("ConstantConditions") @Test public void testSurfacePoint_NortheastCorner() throws Exception { double lat = 1.0; double lon = 1.0; double alt = 0.0; Vec3 expected = worldWindEcef(officialWgs84Ecef(lat, lon, alt)); boolean expectedReturn = true; Vec3 actual = new Vec3(); boolean actualReturn = this.terrain.surfacePoint(lat, lon, actual); assertEquals("surfacePoint Northeast corner x", expected.x, actual.x, TOLERANCE); assertEquals("surfacePoint Northeast corner y", expected.y, actual.y, TOLERANCE); assertEquals("surfacePoint Northeast corner z", expected.z, actual.z, TOLERANCE); assertEquals("surfacePoint Northeast corner return", expectedReturn, actualReturn); }
@Override protected void doRender(RenderContext rc) { if (this.sector.isEmpty()) { return; // nothing to render } if (!rc.terrain.getSector().intersects(this.sector)) { return; // no terrain surface to render on } Texture texture = rc.getTexture(this.imageSource); // try to get the texture from the cache if (texture == null) { texture = rc.retrieveTexture(this.imageSource, this.imageOptions); // puts retrieved textures in the cache } if (texture == null) { return; // no texture to draw } // Enqueue a drawable surface texture for processing on the OpenGL thread. SurfaceTextureProgram program = this.getShaderProgram(rc); Pool<DrawableSurfaceTexture> pool = rc.getDrawablePool(DrawableSurfaceTexture.class); DrawableSurfaceTexture drawable = DrawableSurfaceTexture.obtain(pool).set(program, this.sector, texture, texture.getTexCoordTransform()); rc.offerSurfaceDrawable(drawable, 0 /*z-order*/); // Enqueue a picked object that associates the drawable surface texture with this surface image. if (rc.pickMode) { int pickedObjectId = rc.nextPickedObjectId(); PickedObject.identifierToUniqueColor(pickedObjectId, drawable.color); rc.offerPickedObject(PickedObject.fromRenderable(pickedObjectId, this, rc.currentLayer)); } }
@SuppressWarnings("ConstantConditions") @Test public void testSurfacePoint_EastEdge() throws Exception { double lat = 0.5; double lon = 1.0; double alt = 0.0; Vec3 expected = worldWindEcef(officialWgs84Ecef(lat, lon, alt)); boolean expectedReturn = true; Vec3 actual = new Vec3(); boolean actualReturn = this.terrain.surfacePoint(lat, lon, actual); assertEquals("surfacePoint East edge x", expected.x, actual.x, TOLERANCE); assertEquals("surfacePoint East edge y", expected.y, actual.y, TOLERANCE); assertEquals("surfacePoint East edge z", expected.z, actual.z, TOLERANCE); assertEquals("surfacePoint East edge return", expectedReturn, actualReturn); }
@SuppressWarnings("ConstantConditions") @Test public void testSurfacePoint_SouthwestCorner() throws Exception { double lat = 0.0; double lon = 0.0; double alt = 0.0; Vec3 expected = worldWindEcef(officialWgs84Ecef(lat, lon, alt)); boolean expectedReturn = true; Vec3 actual = new Vec3(); boolean actualReturn = this.terrain.surfacePoint(lat, lon, actual); assertEquals("surfacePoint Southwest corner x", expected.x, actual.x, TOLERANCE); assertEquals("surfacePoint Southwest corner y", expected.y, actual.y, TOLERANCE); assertEquals("surfacePoint Southwest corner z", expected.z, actual.z, TOLERANCE); assertEquals("surfacePoint Southwest corner return", expectedReturn, actualReturn); }
@SuppressWarnings("ConstantConditions") @Test public void testSurfacePoint_SoutheastCorner() throws Exception { double lat = 0.0; double lon = 1.0; double alt = 0.0; Vec3 expected = worldWindEcef(officialWgs84Ecef(lat, lon, alt)); boolean expectedReturn = true; Vec3 actual = new Vec3(); boolean actualReturn = this.terrain.surfacePoint(lat, lon, actual); assertEquals("surfacePoint Southeast corner x", expected.x, actual.x, TOLERANCE); assertEquals("surfacePoint Southeast corner y", expected.y, actual.y, TOLERANCE); assertEquals("surfacePoint Southeast corner z", expected.z, actual.z, TOLERANCE); assertEquals("surfacePoint Southeast corner return", expectedReturn, actualReturn); }
@SuppressWarnings("ConstantConditions") @Test public void testSurfacePoint_NorthwestCorner() throws Exception { double lat = 1.0; double lon = 0.0; double alt = 0.0; Vec3 expected = worldWindEcef(officialWgs84Ecef(lat, lon, alt)); boolean expectedReturn = true; Vec3 actual = new Vec3(); boolean actualReturn = this.terrain.surfacePoint(lat, lon, actual); assertEquals("surfacePoint Northwest corner x", expected.x, actual.x, TOLERANCE); assertEquals("surfacePoint Northwest corner y", expected.y, actual.y, TOLERANCE); assertEquals("surfacePoint Northwest corner z", expected.z, actual.z, TOLERANCE); assertEquals("surfacePoint Northwest corner return", expectedReturn, actualReturn); }
@SuppressWarnings("ConstantConditions") @Test public void testSurfacePoint_NorthEdge() throws Exception { double lat = 1.0; double lon = 0.5; double alt = 0.0; Vec3 expected = worldWindEcef(officialWgs84Ecef(lat, lon, alt)); boolean expectedReturn = true; Vec3 actual = new Vec3(); boolean actualReturn = this.terrain.surfacePoint(lat, lon, actual); assertEquals("surfacePoint North edge x", expected.x, actual.x, TOLERANCE); assertEquals("surfacePoint North edge y", expected.y, actual.y, TOLERANCE); assertEquals("surfacePoint North edge z", expected.z, actual.z, TOLERANCE); assertEquals("surfacePoint North edge return", expectedReturn, actualReturn); }
@SuppressWarnings("ConstantConditions") @Test public void testSurfacePoint_Centroid() throws Exception { double lat = 0.5; double lon = 0.5; double alt = 0.0; Vec3 expected = worldWindEcef(officialWgs84Ecef(lat, lon, alt)); boolean expectedReturn = true; Vec3 actual = new Vec3(); boolean actualReturn = this.terrain.surfacePoint(lat, lon, actual); assertEquals("surfacePoint centroid x", expected.x, actual.x, TOLERANCE); assertEquals("surfacePoint centroid y", expected.y, actual.y, TOLERANCE); assertEquals("surfacePoint centroid z", expected.z, actual.z, TOLERANCE); assertEquals("surfacePoint centroid return", expectedReturn, actualReturn); } }
@SuppressWarnings("ConstantConditions") @Test public void testSurfacePoint_SoutheastCell() throws Exception { Vec3 sw = officialWgs84Ecef(0.0, 0.75, 0.0); Vec3 se = officialWgs84Ecef(0.0, 1.0, 0.0); Vec3 nw = officialWgs84Ecef(0.25, 0.75, 0.0); Vec3 ne = officialWgs84Ecef(0.25, 1.0, 0.0); Vec3 expected = worldWindEcef(bilinearCentroid(sw, se, nw, ne)); boolean expectedReturn = true; Vec3 actual = new Vec3(); boolean actualReturn = this.terrain.surfacePoint(0.125, 0.875, actual); assertEquals("surfacePoint Southeast cell x", expected.x, actual.x, TOLERANCE); assertEquals("surfacePoint Southeast cell y", expected.y, actual.y, TOLERANCE); assertEquals("surfacePoint Southeast cell z", expected.z, actual.z, TOLERANCE); assertEquals("surfacePoint Southeast cell return", expectedReturn, actualReturn); }
@SuppressWarnings("ConstantConditions") @Test public void testSurfacePoint_NortheastCell() throws Exception { Vec3 sw = officialWgs84Ecef(0.75, 0.75, 0.0); Vec3 se = officialWgs84Ecef(0.75, 1.0, 0.0); Vec3 nw = officialWgs84Ecef(1.0, 0.75, 0.0); Vec3 ne = officialWgs84Ecef(1.0, 1.0, 0.0); Vec3 expected = worldWindEcef(bilinearCentroid(sw, se, nw, ne)); boolean expectedReturn = true; Vec3 actual = new Vec3(); boolean actualReturn = this.terrain.surfacePoint(0.875, 0.875, actual); assertEquals("surfacePoint Northeast cell x", expected.x, actual.x, TOLERANCE); assertEquals("surfacePoint Northeast cell y", expected.y, actual.y, TOLERANCE); assertEquals("surfacePoint Northeast cell z", expected.z, actual.z, TOLERANCE); assertEquals("surfacePoint Northeast cell return", expectedReturn, actualReturn); }
@SuppressWarnings("ConstantConditions") @Test public void testSurfacePoint_SouthwestCell() throws Exception { Vec3 sw = officialWgs84Ecef(0.0, 0.0, 0.0); Vec3 se = officialWgs84Ecef(0.0, 0.25, 0.0); Vec3 nw = officialWgs84Ecef(0.25, 0.0, 0.0); Vec3 ne = officialWgs84Ecef(0.25, 0.25, 0.0); Vec3 expected = worldWindEcef(bilinearCentroid(sw, se, nw, ne)); boolean expectedReturn = true; Vec3 actual = new Vec3(); boolean actualReturn = this.terrain.surfacePoint(0.125, 0.125, actual); assertEquals("surfacePoint Southwest cell x", expected.x, actual.x, TOLERANCE); assertEquals("surfacePoint Southwest cell y", expected.y, actual.y, TOLERANCE); assertEquals("surfacePoint Southwest cell z", expected.z, actual.z, TOLERANCE); assertEquals("surfacePoint Southwest cell return", expectedReturn, actualReturn); }