+ // Image on top of base plane, if specified
+ final boolean showTerrain = _terrainDefinition != null && _terrainDefinition.getUseTerrain();
+ if (_baseImage != null && !showTerrain)
+ {
+ QuadArray baseSquare = new QuadArray (4, QuadArray.COORDINATES | GeometryArray.TEXTURE_COORDINATE_2);
+ baseSquare.setCoordinate(0, new Point3f(-10f, 0.05f, -10f));
+ baseSquare.setCoordinate(1, new Point3f(-10f, 0.05f, 10f));
+ baseSquare.setCoordinate(2, new Point3f( 10f, 0.05f, 10f));
+ baseSquare.setCoordinate(3, new Point3f( 10f, 0.05f, -10f));
+ // and set anchor points for the texture
+ baseSquare.setTextureCoordinate(0, 0, new TexCoord2f(0.0f, 1.0f));
+ baseSquare.setTextureCoordinate(0, 1, new TexCoord2f(0.0f, 0.0f));
+ baseSquare.setTextureCoordinate(0, 2, new TexCoord2f(1.0f, 0.0f));
+ baseSquare.setTextureCoordinate(0, 3, new TexCoord2f(1.0f, 1.0f));
+ // Set appearance including image
+ Appearance baseAppearance = new Appearance();
+ Texture mapImage = new TextureLoader(_baseImage.getImage(), _frame).getTexture();
+ baseAppearance.setTexture(mapImage);
+ objTrans.addChild(new Shape3D(baseSquare, baseAppearance));
+ }
+
+ // Create model containing track information
+ _model = new ThreeDModel(_track);
+ _model.setAltitudeFactor(_altFactor);
+
+ if (showTerrain)
+ {
+ // TODO: Is it maybe possible to cache the last terrainTrack?
+ // (if the dataTrack and the resolution haven't changed)
+ // Construct the terrain track according to these extents and the grid size
+ TerrainHelper terrainHelper = new TerrainHelper(_terrainDefinition.getGridSize());
+ Track terrainTrack = terrainHelper.createGridTrack(_track);
+ // Get the altitudes from SRTM for all the points in the track
+ LookupSrtmFunction srtmLookup = (LookupSrtmFunction) FunctionLibrary.FUNCTION_LOOKUP_SRTM;
+ srtmLookup.begin(terrainTrack);
+ while (srtmLookup.isRunning())
+ {
+ try {
+ Thread.sleep(750); // just polling in a wait loop isn't ideal but simple
+ }
+ catch (InterruptedException e) {}
+ }
+
+ // Fix the voids
+ terrainHelper.fixVoids(terrainTrack);
+
+ // Give the terrain definition to the _model as well
+ _model.setTerrain(terrainTrack);
+ _model.scale();
+
+ objTrans.addChild(createTerrain(_model, terrainHelper, _baseImage));
+ }
+ else
+ {
+ // No terrain, so just scale the model as it is
+ _model.scale();
+ }
+