Sunday, May 20, 2007

Adding Stars to World Wind Java

Here is my first attempt at a renderable layer for WWJ. It renders a star background based on a subset of ESA Hipparcos catalog of stars.


Download WWJ_Stars_01.zip (104K) and follow instructions in the readme.txt to add the layer to one of the demo application (one line of code).

In the BasicDemo, the layer list should read like that :
private BasicDemo.LayerAction[] layers = new BasicDemo.LayerAction[] {
  new BasicDemo.LayerAction(new StarsLayer(), true),
  new BasicDemo.LayerAction(new BMNGSurfaceLayer(), true),
  new BasicDemo.LayerAction(new LandsatI3(), true),
  new BasicDemo.LayerAction(new USGSDigitalOrtho(), false),
  new BasicDemo.LayerAction(new USGSUrbanAreaOrtho(), true),
  new BasicDemo.LayerAction(new EarthNASAPlaceNameLayer(), true),
  new BasicDemo.LayerAction(new CompassLayer(), true),
};

Note that it is inserted first in the layer list - so that it renders first too. The code also shows how to create a renderable layer and a renderable object to add to it. It boils down to :

public class StarsLayer extends RenderableLayer {

  // The layer
  public StarsLayer() {
    this.setName("Stars");
    this.addRenderable(new Stars());
  }

  // The renderable
  private static class Stars implements Renderable, Disposable {

    public void render(DrawContext dc) {
      GL gl = dc.getGL();
      // Draw here
    }

    public void dispose() {
      // Cleanup here
    }
  }
}

See discussion in the WWJ forum.

Most of the star background code comes from my 'old' WW plugin Stars3D and its implementation in Java for WW2DPlusOne.

1 comment:

Anonymous said...

hello,I want to join in gov.nasa.worldwind.render.MultiLineTextRenderer.java HTML supports,how to do?