j3d.org Code

org.j3d.loaders
Class SimpleTiledTerrainData

java.lang.Object
  extended by org.j3d.terrain.AbstractTerrainData
      extended by org.j3d.terrain.AbstractTiledTerrainData
          extended by org.j3d.loaders.SimpleTiledTerrainData
All Implemented Interfaces:
TerrainData, TiledTerrainData, HeightDataSource

public class SimpleTiledTerrainData
extends AbstractTiledTerrainData

Simplified implementation of the TiledTerrainData for any file format or loader that supports a static grid based data structure.

This implementation is pretty dumb in that it does no paging of the internal data and just keeps it available in memory. That should make it useful for grids of up to 2049x2049 heights.

If a color interpolator is not provided, then color is not supported in this terrain (unless set by some implementing class).

Version:
$Revision: 1.3 $
Author:
Justin Couch, Alan Hudson

Field Summary
 
Fields inherited from class org.j3d.terrain.AbstractTiledTerrainData
gridPointsPerTile, tileGenerator
 
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
SimpleTiledTerrainData(float[][] data, boolean mustCopy, javax.vecmath.Point2d stepDetails)
          Create a new instance that uses the passed height map data to this loader.
SimpleTiledTerrainData(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.
 void getTilesAvailableBounds(java.awt.Rectangle bounds)
          Fetch the area, in tile coordinates of the area that is currently available in memory.
 void setActiveBounds(java.awt.Rectangle bounds)
          Set the bounding information, in number of tiles, of the area that the terrain rendering code will be limiting its access to.
 void setColorInterpolator(ColorInterpolator interp)
          Set up a height color ramp to provide colour information.
 
Methods inherited from class org.j3d.terrain.AbstractTiledTerrainData
convertGridToTileCoord, convertTileToGridCoord, getTexture, getTileSize, setTextureTileGenerator
 
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

SimpleTiledTerrainData

public SimpleTiledTerrainData(HeightMapSource source)
Create a new instance that sources the data from the given parser. Assumes that the parser has already fetched its information and has the height-grid available for use.

Parameters:
source - The place to source the data from

SimpleTiledTerrainData

public SimpleTiledTerrainData(float[][] data,
                              boolean mustCopy,
                              javax.vecmath.Point2d stepDetails)
Create a new instance that uses the passed height map data to this loader. The data passed can be either referenced or copied, depending on the value of the 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.

Parameters:
data - The source data to use in [length][width] order
mustCopy - true to request an internal copy be made of the data false for it to just reference the data
stepDetails - The distance between each height value in the X and Z coordinates (Y in terrain parlance)
Method Detail

getTilesAvailableBounds

public void getTilesAvailableBounds(java.awt.Rectangle bounds)
Fetch the area, in tile coordinates of the area that is currently available in memory. This is a hint to the caller that it would be a good strategy to start with these tiles for fastest load time.

The implementation should fill in the passed rectangle with the bounds information. The bounds are inclusive, so if the implementation of this interface provides the value of {0, 0, 2, 2} this will indicate a 3x3 area is available.

Parameters:
bounds - The bounds of the available data, to be filled in by the implementation of this class

setActiveBounds

public void setActiveBounds(java.awt.Rectangle bounds)
Set the bounding information, in number of tiles, of the area that the terrain rendering code will be limiting its access to. Ignored for the moment.

Parameters:
bounds - The bounds of the area, in tile coordinates, that will be accessed

getHeight

public float getHeight(float x,
                       float z)
Get the height at the given X,Z coordinate in the local coordinate system. The

Parameters:
x - The x coordinate for the height sampling
z - The z coordinate for the height sampling
Returns:
The height at the current point or NaN

getCoordinate

public void getCoordinate(float[] coord,
                          int gridX,
                          int gridY)
Get the coordinate of the point in the grid.

Parameters:
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 grid
gridY - The Y coordinate of the position in the grid

getCoordinate

public void getCoordinate(float[] coord,
                          float[] tex,
                          float[] color,
                          int gridX,
                          int gridY)
Get the coordinate with all the information - texture and colors.

Parameters:
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 elements
color - 3 component colors are placed in the first 3 elements
gridX - The X coordinate of the position in the grid
gridY - The Y coordinate of the position in the grid

getCoordinateWithTexture

public 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. Assumes that the grid covers a single large texture rather than multiple smaller textures.

Parameters:
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 elements
gridX - The X coordinate of the position in the grid
gridY - The Y coordinate of the position in the grid

getCoordinateWithColor

public void getCoordinateWithColor(float[] coord,
                                   float[] color,
                                   int gridX,
                                   int gridY)
Get the coordinate of the point and the corresponding color value in the grid. Color values are used when there is no texture supplied, so this should always provide something useful.

Parameters:
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 elements
gridX - The X coordinate of the position in the grid
gridY - The Y coordinate of the position in the grid

getHeightFromGrid

public float getHeightFromGrid(int gridX,
                               int gridY)
Get the height at the specified grid position.

Parameters:
gridX - The X coordinate of the position in the grid
gridY - The Y coordinate of the position in the grid
Returns:
The height at the given grid position

setColorInterpolator

public void setColorInterpolator(ColorInterpolator interp)
Set up a height color ramp to provide colour information. This should be set before passing the terrain data to a rendering algorithm as it sets the hasColor() flag to true. Heights should be based on sea-level as value zero. A value of null clears the current reference.

Parameters:
interp - The interpolator instance to use

j3d.org Code

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