📄 elevationplane.java
字号:
package gov.nasa.worldwind.render;
import gov.nasa.worldwind.geom.LatLon;
import gov.nasa.worldwind.render.airspaces.Polygon;
import gov.nasa.worldwind.util.*;
import javax.media.opengl.GL;
import java.util.*;
/**
* Renders a textured plane at a given elevation.
*
* @author Patrick Murris
* @version $Id: ElevationPlane.java 10816 2009-05-04 02:54:51Z patrickmurris $
*/
public class ElevationPlane extends Polygon
{
private Object imageSource;
protected WWTexture texture;
private double imageSize = 500; // meter
protected OGLStackHandler osh = new OGLStackHandler();
public ElevationPlane()
{
this.getRenderer().setEnableLighting(false);
}
/**
* Get the source for the fill pattern image. Can be a file path to a local image or
* a {@link java.awt.image.BufferedImage} reference.
*
* @return the source for the fill pattern image - can be null.
*/
public Object getImageSource()
{
return this.imageSource;
}
/**
* Set the source for the fill pattern image. Can be a file path to a local image or
* a {@link java.awt.image.BufferedImage} reference.
*
* @param imageSource the source for the fill pattern image - can be null.
*/
public void setImageSource(Object imageSource)
{
this.imageSource = imageSource;
this.texture = null;
}
/**
* Get the real world image size in meter. The image source is repeated so that one tile covers this distance.
*
* @return the real world image size in meter.
*/
public double getImageSize()
{
return this.imageSize;
}
/**
* Set the real world image size in meter. The image source will be repeated so that one tile will
* covers this distance.
*
* @param sizeInMeter the real world image size in meter.
*/
public void setImageSize(double sizeInMeter)
{
this.imageSize = sizeInMeter;
}
// Airspace Polygon overload
protected void doRenderGeometry(DrawContext dc, String drawStyle, List<LatLon> locations, List<Boolean> edgeFlags)
{
this.beginRendering(dc);
try
{
// Setup texture coordinates generation
this.setupTextureState(dc);
// Draw
super.doRenderGeometry(dc, drawStyle, locations, edgeFlags);
}
finally
{
this.endRendering(dc);
}
}
protected void beginRendering(DrawContext dc)
{
// TODO: review attributes
GL gl = dc.getGL();
osh.pushAttrib(gl, GL.GL_COLOR_BUFFER_BIT // for alpha func
| GL.GL_ENABLE_BIT
| GL.GL_CURRENT_BIT
| GL.GL_DEPTH_BUFFER_BIT // for depth func
| GL.GL_TEXTURE_BIT // for texture env
| GL.GL_TRANSFORM_BIT);
osh.pushTextureIdentity(gl);
}
protected void endRendering(DrawContext dc)
{
osh.pop(dc.getGL());
}
protected void setupTextureState(DrawContext dc)
{
WWTexture texture = getTexture();
if (texture == null)
return;
if (!texture.bind(dc))
return;
GL gl = dc.getGL();
// Texture coordinates generation
double[] sPlane = {1, 0, 0, 0}; // TODO: define planes relative to shape center?
double[] tPlane = {0, 1, 0, 0};
gl.glTexGeni(GL.GL_S, GL.GL_TEXTURE_GEN_MODE, GL.GL_OBJECT_LINEAR);
gl.glTexGeni(GL.GL_T, GL.GL_TEXTURE_GEN_MODE, GL.GL_OBJECT_LINEAR);
gl.glTexGendv(GL.GL_S, GL.GL_OBJECT_PLANE, sPlane, 0);
gl.glTexGendv(GL.GL_T, GL.GL_OBJECT_PLANE, tPlane, 0);
gl.glEnable(GL.GL_TEXTURE_GEN_S);
gl.glEnable(GL.GL_TEXTURE_GEN_T);
// Pattern scaling
gl.glMatrixMode(GL.GL_TEXTURE_MATRIX);
gl.glScaled(1 / this.imageSize, 1 / this.imageSize, 1f);
// Texture setup
gl.glEnable(GL.GL_BLEND);
gl.glBlendFunc(GL.GL_ONE, GL.GL_ONE_MINUS_SRC_ALPHA);
gl.glEnable(GL.GL_TEXTURE_2D);
gl.glTexEnvf(GL.GL_TEXTURE_ENV, GL.GL_TEXTURE_ENV_MODE, GL.GL_MODULATE);
gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_S, GL.GL_REPEAT);
gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_T, GL.GL_REPEAT);
}
protected WWTexture getTexture()
{
if (this.texture == null && this.imageSource != null)
this.texture = new BasicWWTexture(this.imageSource);
return this.texture;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -