|
j3d.org Code | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.j3d.terrain.AbstractTerrainData org.j3d.terrain.AbstractStaticTerrainData org.j3d.loaders.HeightMapTerrainData
public class HeightMapTerrainData
Generalised implementation of the TerrainData
for
any file format or loader that supports a static grid based data structure.
Supporting the height data source methods requires a bit of assumption about the data. Because we have data in quads, and we don't know how the underlying terrain rendering code is triangulating the data, we have to punt and take a guess. To interpolate a height value for a point that is not directly on a grid position, the code will take the average height of the grid square. This is a really horrible algorithm, but is the fastest to implement currently. We need to re-visit this to get something a little more accurate and is proportional to the position in the cell.
The basic implementation here does not support a texture. If an application
wishes to use a texture, they should extend this class and override the
getTexture()
method. If you wish to provide a pre-loaded texture,
then you can use the setTexture(BufferedImage)
method of this class to
place one here.
If a color interpolator is not provided, then color is not supported in this terrain (unless set by some implementing class).
Field Summary |
---|
Fields inherited from class org.j3d.terrain.AbstractStaticTerrainData |
---|
gridDepth, gridWidth |
Fields inherited from class org.j3d.terrain.AbstractTerrainData |
---|
colorAvailable, gridStepX, gridStepY, textureAvailable |
Fields inherited from interface org.j3d.terrain.TerrainData |
---|
FREEFORM_DATA, STATIC_DATA, TILED_DATA |
Constructor Summary | |
---|---|
HeightMapTerrainData(float[][] data,
boolean mustCopy,
javax.vecmath.Point2d stepDetails)
Create a new instance that uses the passed height map data to this loader. |
|
HeightMapTerrainData(HeightMapSource source)
Create a new instance that sources the data from the given parser. |
Method Summary | |
---|---|
void |
getCoordinate(float[] coord,
float[] tex,
float[] color,
int gridX,
int gridY)
Get the coordinate with all the information - texture and colors. |
void |
getCoordinate(float[] coord,
int gridX,
int gridY)
Get the coordinate of the point in the grid. |
void |
getCoordinateWithColor(float[] coord,
float[] color,
int gridX,
int gridY)
Get the coordinate of the point and the corresponding color value in the grid. |
void |
getCoordinateWithTexture(float[] coord,
float[] textureCoord,
int gridX,
int gridY,
int patchX,
int patchY)
Get the coordinate of the point and correspond texture coordinate in the grid. |
float |
getHeight(float x,
float z)
Get the height at the given X,Z coordinate in the local coordinate system. |
float |
getHeightFromGrid(int gridX,
int gridY)
Get the height at the specified grid position. |
java.awt.image.BufferedImage |
getTexture()
Fetch the BufferedImage that is used to cover the entire terrain. |
void |
setColorInterpolator(ColorInterpolator interp)
Set up a height color ramp to provide colour information. |
void |
setTexture(java.awt.image.BufferedImage tex)
Set the texture to the new instance. |
Methods inherited from class org.j3d.terrain.AbstractStaticTerrainData |
---|
getGridDepth, getGridWidth |
Methods inherited from class org.j3d.terrain.AbstractTerrainData |
---|
getGridXStep, getGridYStep, getSourceDataType, hasColor, hasTexture |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface org.j3d.terrain.TerrainData |
---|
getGridXStep, getGridYStep, getSourceDataType, hasColor, hasTexture |
Constructor Detail |
---|
public HeightMapTerrainData(HeightMapSource source)
source
- The place to source the data frompublic HeightMapTerrainData(float[][] data, boolean mustCopy, javax.vecmath.Point2d stepDetails)
mustCopy
parameter. If it is not
copied, then the calling code should make sure that it does not change
values in the array after calling this method. If copying, the code
assumes a rectangular grid of points where the second dimension size is
based on data[0].length
.
data
- The source data to use in [length][width] ordermustCopy
- true to request an internal copy be made of the data
false for it to just reference the datastepDetails
- The distance between each height value in the X and
Z coordinates (Y in terrain parlance)Method Detail |
---|
public float getHeight(float x, float z)
x
- The x coordinate for the height samplingz
- The z coordinate for the height sampling
public void getCoordinate(float[] coord, int gridX, int gridY)
coord
- the x, y, and z coordinates will be placed in the
first three elements of the array.gridX
- The X coordinate of the position in the gridgridY
- The Y coordinate of the position in the gridpublic void getCoordinate(float[] coord, float[] tex, float[] color, int gridX, int gridY)
coord
- he x, y, and z coordinates will be placed in the first
three elements of the array.tex
- 2D coordinates are placed in the first two elementscolor
- 3 component colors are placed in the first 3 elementsgridX
- The X coordinate of the position in the gridgridY
- The Y coordinate of the position in the gridpublic void getCoordinateWithTexture(float[] coord, float[] textureCoord, int gridX, int gridY, int patchX, int patchY)
coord
- he x, y, and z coordinates will be placed in the first
three elements of the array.textureCoord
- 2D coordinates are placed in the first two elementsgridX
- The X coordinate of the position in the gridgridY
- The Y coordinate of the position in the gridpublic void getCoordinateWithColor(float[] coord, float[] color, int gridX, int gridY)
coord
- he x, y, and z coordinates will be placed in the first
three elements of the array.color
- 3 component colors are placed in the first 3 elementsgridX
- The X coordinate of the position in the gridgridY
- The Y coordinate of the position in the gridpublic java.awt.image.BufferedImage getTexture()
getTexture
in interface StaticTerrainData
getTexture
in class AbstractStaticTerrainData
public float getHeightFromGrid(int gridX, int gridY)
gridX
- The X coordinate of the position in the gridgridY
- The Y coordinate of the position in the grid
public void setTexture(java.awt.image.BufferedImage tex)
setTexture
in class AbstractStaticTerrainData
tex
- The new texture to usepublic void setColorInterpolator(ColorInterpolator interp)
interp
- The interpolator instance to use
|
j3d.org Code | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |