j3d.org Code

org.j3d.geom.terrain
Class ElevationGridGenerator

java.lang.Object
  extended by org.j3d.geom.GeometryGenerator
      extended by org.j3d.geom.terrain.ElevationGridGenerator

public class ElevationGridGenerator
extends GeometryGenerator

A generator that takes a set of height values as a grid and turns it into geometry.

The grid can be created either as absolute or relative height values. This setting is controlled as one of the auxillary flags in the GeometryData class at construction time. In order for this to work, you will also need to provide a base height when setting the terrain.

Points are defined in the height arrays in width first order. Normals, are always smooth blended. Alan: There are some cases where texture generation is not complete. Especially in regards to 3D textures.

Version:
$Revision: 1.9 $
Author:
Justin Couch

Field Summary
static int ABSOLUTE_HEIGHTS
          Auxillary flag to say to generate points as absolute values
static int RELATIVE_HEIGHTS
          Auxillary flag to say to generate points as relative values
 
Constructor Summary
ElevationGridGenerator()
          Construct a default terrain with the following properties:
Size: 100x100 Points: 2x2
ElevationGridGenerator(float w, float d, int wPnts, int dPnts)
          Construct a default terrain with the given dimensions and points in each direction.
ElevationGridGenerator(float w, float d, int wPnts, int dPnts, boolean centerOrigin)
          Construct a default terrain with the given dimensions and points in each direction.
ElevationGridGenerator(float w, float d, int wPnts, int dPnts, float[][] heights, float baseHeight)
          Construct a default cylinder with the option of having end caps and selectable number of faces around the radius.
ElevationGridGenerator(float w, float d, int wPnts, int dPnts, float[][] heights, float baseHeight, boolean centerOrigin)
          Construct a default cylinder with the option of having end caps and selectable number of faces around the radius.
ElevationGridGenerator(float w, float d, int wPnts, int dPnts, float[] heights, float baseHeight)
          Construct a customised terrain according to the full set of configurable data.
ElevationGridGenerator(float w, float d, int wPnts, int dPnts, float[] heights, float baseHeight, boolean centerOrigin)
          Construct a customised terrain according to the full set of configurable data.
 
Method Summary
 void generate(GeometryData data)
          Generate a new set of geometry items based on the passed data.
 float[] getDimensions()
          Get the dimensions of the terrain.
 int getVertexCount(GeometryData data)
          Get the number of vertices that this generator will create for the shape given in the definition based on the current width and height information.
 void setDimensions(float w, float d, int wPnts, int dPnts)
          Change the dimensions of the cone to be generated.
 void setTerrainDetail(float[][] heights, float baseHeight)
          Set the details of the terrain height to use a 2D array of values.
 void setTerrainDetail(float[] heights, float baseHeight)
          Set the details of the terrain height to use a flat array of values.
 
Methods inherited from class org.j3d.geom.GeometryGenerator
createFaceNormal, createFaceNormal, createRadialNormal, createRadialNormal
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

RELATIVE_HEIGHTS

public static final int RELATIVE_HEIGHTS
Auxillary flag to say to generate points as relative values

See Also:
Constant Field Values

ABSOLUTE_HEIGHTS

public static final int ABSOLUTE_HEIGHTS
Auxillary flag to say to generate points as absolute values

See Also:
Constant Field Values
Constructor Detail

ElevationGridGenerator

public ElevationGridGenerator()
Construct a default terrain with the following properties:
Size: 100x100 Points: 2x2


ElevationGridGenerator

public ElevationGridGenerator(float w,
                              float d,
                              int wPnts,
                              int dPnts)
Construct a default terrain with the given dimensions and points in each direction.

Parameters:
w - The width of the terrain
d - The depth of the terrain
wPnts - The number of heights in the width
dPnts - The number of heights in the depth
Throws:
java.lang.IllegalArgumentException - One of the points were <= 1 or the dimensions are non-positive

ElevationGridGenerator

public ElevationGridGenerator(float w,
                              float d,
                              int wPnts,
                              int dPnts,
                              boolean centerOrigin)
Construct a default terrain with the given dimensions and points in each direction.

Parameters:
w - The width of the terrain
d - The depth of the terrain
wPnts - The number of heights in the width
dPnts - The number of heights in the depth
centerOrigin - Whether to use a center origin or a left corner origin. By default it will be center.
Throws:
java.lang.IllegalArgumentException - One of the points were <= 1 or the dimensions are non-positive

ElevationGridGenerator

public ElevationGridGenerator(float w,
                              float d,
                              int wPnts,
                              int dPnts,
                              float[] heights,
                              float baseHeight)
Construct a customised terrain according to the full set of configurable data.

Parameters:
w - The width of the terrain
d - The depth of the terrain
wPnts - The number of heights in the width
dPnts - The number of heights in the depth
heights - The array of height values to use
baseHeight - The base height for relative calcs. May be zero
Throws:
java.lang.IllegalArgumentException - One of the points were <= 1 or the dimensions are non-positive

ElevationGridGenerator

public ElevationGridGenerator(float w,
                              float d,
                              int wPnts,
                              int dPnts,
                              float[][] heights,
                              float baseHeight)
Construct a default cylinder with the option of having end caps and selectable number of faces around the radius. The default height is 2 and radius 1.The minimum number of facets is 3.

Parameters:
w - The width of the terrain
d - The depth of the terrain
wPnts - The number of heights in the width
dPnts - The number of heights in the depth
heights - The array of height values to use
baseHeight - The base height for relative calcs. May be zero
Throws:
java.lang.IllegalArgumentException - One of the points were <= 1 or the dimensions are non-positive

ElevationGridGenerator

public ElevationGridGenerator(float w,
                              float d,
                              int wPnts,
                              int dPnts,
                              float[] heights,
                              float baseHeight,
                              boolean centerOrigin)
Construct a customised terrain according to the full set of configurable data.

Parameters:
w - The width of the terrain
d - The depth of the terrain
wPnts - The number of heights in the width
dPnts - The number of heights in the depth
heights - The array of height values to use
baseHeight - The base height for relative calcs. May be zero
centerOrigin - Whether to use a center origin or a left corner origin
Throws:
java.lang.IllegalArgumentException - One of the points were <= 1 or the dimensions are non-positive

ElevationGridGenerator

public ElevationGridGenerator(float w,
                              float d,
                              int wPnts,
                              int dPnts,
                              float[][] heights,
                              float baseHeight,
                              boolean centerOrigin)
Construct a default cylinder with the option of having end caps and selectable number of faces around the radius. The default height is 2 and radius 1.The minimum number of facets is 3.

Parameters:
w - The width of the terrain
d - The depth of the terrain
wPnts - The number of heights in the width
dPnts - The number of heights in the depth
heights - The array of height values to use
baseHeight - The base height for relative calcs. May be zero
centerOrigin - Whether to use a center origin or a left corner origin
Throws:
java.lang.IllegalArgumentException - One of the points were <= 1 or the dimensions are non-positive
Method Detail

getDimensions

public float[] getDimensions()
Get the dimensions of the terrain. These are returned as 2 values of width and depth respectively for the array. A new array is created each time so you can do what you like with it.

Returns:
The current size of the terrain

setDimensions

public void setDimensions(float w,
                          float d,
                          int wPnts,
                          int dPnts)
Change the dimensions of the cone to be generated. Calling this will make the points be re-calculated next time you ask for geometry or normals.

Parameters:
w - The width of the terrain
d - The depth of the terrain
wPnts - The number of heights in the width
dPnts - The number of heights in the depth
Throws:
java.lang.IllegalArgumentException - One of the points were <= 1 or the dimensions are non-positive

setTerrainDetail

public void setTerrainDetail(float[] heights,
                             float baseHeight)
Set the details of the terrain height to use a flat array of values.

Parameters:
heights - The array of height values to use
baseHeight - The base height for relative calcs. May be zero

setTerrainDetail

public void setTerrainDetail(float[][] heights,
                             float baseHeight)
Set the details of the terrain height to use a 2D array of values.

Parameters:
heights - The array of height values to use
baseHeight - The base height for relative calcs. May be zero

getVertexCount

public int getVertexCount(GeometryData data)
                   throws UnsupportedTypeException
Get the number of vertices that this generator will create for the shape given in the definition based on the current width and height information.

Specified by:
getVertexCount in class GeometryGenerator
Parameters:
data - The data to base the calculations on
Returns:
The vertex count for the object
Throws:
UnsupportedTypeException - The generator cannot handle the type of geometry you have requested.

generate

public void generate(GeometryData data)
              throws UnsupportedTypeException,
                     InvalidArraySizeException
Generate a new set of geometry items based on the passed data. If the data does not contain the right minimum array lengths an exception will be generated. If the array reference is null, this will create arrays of the correct length and assign them to the return value.

Specified by:
generate in class GeometryGenerator
Parameters:
data - The data to base the calculations on
Throws:
InvalidArraySizeException - The array is not big enough to contain the requested geometry
UnsupportedTypeException - The generator cannot handle the type of geometry you have requested

j3d.org Code

Latest Info from http://code.j3d.org/
Copyright © 2001 - j3d.org