Monday, January 18, 2010

Textured Wall for World Wind Java

Following up on a WWJ Forum post regarding a 'vertical image' to display atmospheric data, i quickly put together a simple renderable that will draw an image on a plane perpendicular to the globe surface.

Textured wall for WWJ
Download - remove the .txt extension and save in the SDK render package.

Nothing fancy, really, a texture rendered over a quad - it will not 'curve' around the globe on long distances. The quad is defined with two LatLon locations, a bottom and a top altitude. It is also an example of a simple renderable using OGL primitives that may serve as a base template for more sophisticated objects.


DBM said...

Very interesting example. I wonder, I have captured some 360 degree street level images,and I am trying to figure out how I can use them in world wind? The images are capture along with lat,lon info from a gps(some what like google street view).Can you suggest how to get them into WWJ?

Anonymous said...

I made a change to your code to take four positions (one for each corner of the image), but the image tends to wobble. It seems to be worse when the image covers smaller areas on the globe (e.g. tens of meters). Any idea why? Here's the draw method:

protected void draw(DrawContext dc)
GL gl = dc.getGL();

Vec4 p;
double ve = dc.getVerticalExaggeration();
TextureCoords coords = this.texture.getTexCoords();

double base = dc.getGlobe().getElevation(bottomLeft.latitude, bottomLeft.longitude);
p = dc.getGlobe().computePointFromPosition(bottomLeft, Math.round(base + bottomLeft.elevation * ve));
gl.glTexCoord2d(coords.left(), coords.bottom());
gl.glVertex3d(p.x, p.y, p.z);

p = dc.getGlobe().computePointFromPosition(topLeft, Math.round(base + topLeft.elevation * ve));
gl.glVertex3d(p.x, p.y, p.z);

p = dc.getGlobe().computePointFromPosition(bottiomRight, Math.round(base + bottiomRight.elevation * ve));
gl.glTexCoord2d(coords.right(), coords.bottom());
gl.glVertex3d(p.x, p.y, p.z);

p = dc.getGlobe().computePointFromPosition(topRight, Math.round(base + topRight.elevation * ve));
gl.glVertex3d(p.x, p.y, p.z);


Patrick Murris said...

The 'wobbling' is a precision issue with 16 bits floats used by OGL for vertex coordinates. Earth Cartesian coordinates (in meter) are in the range of 4 to 6 millions which does not leave much room for precision at the meter scale.

To work around this issue, simply make the numbers smaller by subtracting a common nearby reference point coordinates - like the center of your shape. However, before drawing you need to translate the model view to your reference center and pop it back after drawing.

Most WWJ renderables use such a reference center.

Anonymous said...

Hi Patrick,
indeed a great job, i'm using the class, nevertheless the input file has to be a local one, do you think it would be possible to give an URL string of a remote image ?

Patrick Murris said...

This small example class has been written some time ago and the SDK has evolved a lot since then. Loading and caching images from a network has been implemented to support KML among other things. You may want to check the examples in the current release and look for something like 'RemoteImage'.

Anonymous said...

In fact, it works very well with a valid URL passing as the first Object argument, thanks to 1.2 !
But I have another problem with a generated jpeg in my software :

Oct 26, 2011 5:17:59 PM gov.nasa.worldwind.render.BasicWWTexture initializeTexture
SEVERE: Exception attempting to read texture file http://xxxxx:8080/WAM/exports/toto.jpg No suitable reader for given stream
at com.sun.opengl.util.texture.TextureIO.newTextureDataImpl(
at com.sun.opengl.util.texture.TextureIO.newTextureData(
at gov.nasa.worldwind.render.BasicWWTexture.initializeTexture(Unknown Source)
at gov.nasa.worldwind.render.BasicWWTexture.bind(Unknown Source)
at gov.nasa.worldwind.render.TexturedWall.render(Unknown Source)

Waht do you think Patrick ?

(frenchy in the wwj forum)

Patrick Murris said...

Sorry, no idea and no time to look into it...

Anonymous said...

No problem, I'll throw this in the forum so see if someone has a solution. Txs

Anonymous said...

how would I plot a point cloud in wwj?

Patrick Murris said...

To plot a point cloud you'd probably want to use the OGL point primitive. Have a look at the stars layer where you will find such code.