org.xith3d.terrain.legacy.heightmap
Class HeightMap

java.lang.Object
  extended by org.xith3d.terrain.legacy.heightmap.HeightMap
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
Faulting, MillerFractal

public class HeightMap
extends java.lang.Object
implements java.io.Serializable

Storage and conversion for height maps (two dimentional arrays of height data). The height maps can be created in many ways such as a random generator, or reading an image. This class allows the 2D height map to be exported to ASCII (for debuggin), 2D images (for terrain detailing and cloud textures) and 3D geometry (for intereactive terrain).

See Also:
Serialized Form

Field Summary
static int FLIP_STARTING
          Changes starting
protected  float[][] heightmap
           
static int ZIGZAG_COLS
          Alternate collumns when exporting 3D triangular geometry.
static int ZIGZAG_ROWS
          Alternate rows when exporting 3D triangular geometry (default)
 
Constructor Summary
protected HeightMap()
          Empty Constructor
  HeightMap(float[][] heightmap)
          Initialises using the given two dimentional array as the hight map.
  HeightMap(float[] heights, int nodesPerSide)
          Initialises using the given one dimentional array, unfolded using the given node count per side.
 
Method Summary
 org.openmali.vecmath2.Point3f[][] calculateCoords(float startX, float startY, float stepX, float stepY)
          Calculates vertex points using given offsets and spacing.
static int[] calculateIndicies(int width, int height, int flags)
          Converts the two dimentional table of points into 3D geometry by calculating the connecting edges between the verticies by using Triangular primitives.
static org.openmali.vecmath2.Point3f[] flatten2DArray(org.openmali.vecmath2.Point3f[][] vertices)
           
 java.awt.image.BufferedImage generate2D()
           
 Geometry generate3D(float startX, float startY, float stepX, float stepY)
          Builds 3D geometrical representation of this height map using the given offsets and spacing.
 IndexedTriangleArray generate3D(float startX, float startY, float stepX, float stepY, int flags)
          Builds 3D geometrical representation of this height map using the given offsets and spacing.
 java.lang.String generateUTF()
           
static float[] point2float(org.openmali.vecmath2.Point3f[] coords)
           
static org.openmali.vecmath2.Point3f[] unIndex(org.openmali.vecmath2.Point3f[] vertices, int[] indices)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ZIGZAG_ROWS

public static final int ZIGZAG_ROWS
Alternate rows when exporting 3D triangular geometry (default)

See Also:
Constant Field Values

ZIGZAG_COLS

public static final int ZIGZAG_COLS
Alternate collumns when exporting 3D triangular geometry.

See Also:
Constant Field Values

FLIP_STARTING

public static final int FLIP_STARTING
Changes starting

See Also:
Constant Field Values

heightmap

protected float[][] heightmap
Constructor Detail

HeightMap

protected HeightMap()
Empty Constructor


HeightMap

public HeightMap(float[][] heightmap)
Initialises using the given two dimentional array as the hight map.

Parameters:
heightmap - the heightmap to be used

HeightMap

public HeightMap(float[] heights,
                 int nodesPerSide)
Initialises using the given one dimentional array, unfolded using the given node count per side.

Parameters:
heights - the table of heights to be used
nodesPerSide - width of table in number of cells.
Method Detail

generateUTF

public java.lang.String generateUTF()
Returns:
string representation of this heightmap.

generate2D

public java.awt.image.BufferedImage generate2D()
Returns:
graphical grayscale image representation of this heightmap

generate3D

public Geometry generate3D(float startX,
                           float startY,
                           float stepX,
                           float stepY)
Builds 3D geometrical representation of this height map using the given offsets and spacing.

Parameters:
startX - starting X value (used to offset the geometry)
startY - starting Y value (used to offset the geometry)
stepX - distance along the X-axis between vertexes
stepY - distance along the Y-axis between vertexes

generate3D

public IndexedTriangleArray generate3D(float startX,
                                       float startY,
                                       float stepX,
                                       float stepY,
                                       int flags)
Builds 3D geometrical representation of this height map using the given offsets and spacing. internally calls the relevent tesselate for the geometry you have specified.

Parameters:
startX - starting X value (used to offset the geometry)
startY - starting Y value (used to offset the geometry)
stepX - distance along the X-axis between vertexes
stepY - distance along the Y-axis between vertexes
flags - modifiers including using Triangles instead of Quads to generate the geom.

calculateCoords

public org.openmali.vecmath2.Point3f[][] calculateCoords(float startX,
                                                         float startY,
                                                         float stepX,
                                                         float stepY)
Calculates vertex points using given offsets and spacing.

Parameters:
startX - starting X value (used to offset the geometry)
startY - starting Y value (used to offset the geometry)
stepX - distance along the X-axis between vertexes
stepY - distance along the Y-axis between vertexes

unIndex

public static org.openmali.vecmath2.Point3f[] unIndex(org.openmali.vecmath2.Point3f[] vertices,
                                                      int[] indices)

calculateIndicies

public static int[] calculateIndicies(int width,
                                      int height,
                                      int flags)
Converts the two dimentional table of points into 3D geometry by calculating the connecting edges between the verticies by using Triangular primitives.

Parameters:
width -
height -
flags - modifiers
Returns:
built geometry
See Also:
ZIGZAG_ROWS, ZIGZAG_COLS, (float startX, float startY, float stepX, float stepY, int flags)

flatten2DArray

public static org.openmali.vecmath2.Point3f[] flatten2DArray(org.openmali.vecmath2.Point3f[][] vertices)

point2float

public static float[] point2float(org.openmali.vecmath2.Point3f[] coords)