com.jme.terrain
Class TerrainBlock

java.lang.Object
  extended bycom.jme.scene.Spatial
      extended bycom.jme.scene.Geometry
          extended bycom.jme.scene.TriMesh
              extended bycom.jme.scene.lod.ClodMesh
                  extended bycom.jme.scene.lod.AreaClodMesh
                      extended bycom.jme.terrain.TerrainBlock
All Implemented Interfaces:
java.io.Serializable

public class TerrainBlock
extends AreaClodMesh

TerrainBlock defines the lowest level of the terrain system. TerrainBlock is the actual part of the terrain system that renders to the screen. The terrain is built from a heightmap defined by a one dimenensional int array. The step scale is used to define the amount of units each block line will extend. Clod can be used to allow for level of detail control. By directly creating a TerrainBlock yourself, you can generate a brute force terrain. This is many times sufficient for small terrains on modern hardware. If terrain is to be large, it is recommended that you make use of the TerrainPage class.

Version:
$Id: TerrainBlock.java,v 1.32 2004/09/14 21:52:11 mojomonkey Exp $
Author:
Mark Powell
See Also:
Serialized Form

Field Summary
 
Fields inherited from class com.jme.scene.TriMesh
indices, triangleQuantity
 
Fields inherited from class com.jme.scene.Geometry
bound, color, colorBuf, normal, normBuf, texBuf, texture, vertBuf, vertex, vertQuantity
 
Fields inherited from class com.jme.scene.Spatial
currentStates, defaultStateList, forceCull, forceView, frustrumIntersects, geometricalControllers, lightCombineMode, localRotation, localScale, localTranslation, name, parent, queueDistance, renderQueueMode, renderStateList, textureCombineMode, worldBound, worldRotation, worldScale, worldTranslation, zOrder
 
Constructor Summary
  TerrainBlock()
          Empty Constructor to be used internally only.
  TerrainBlock(java.lang.String name)
          For internal use only.
  TerrainBlock(java.lang.String name, int size, Vector3f stepScale, int[] heightMap, Vector3f origin, boolean clod)
          Constructor instantiates a new TerrainBlock object.
protected TerrainBlock(java.lang.String name, int size, Vector3f stepScale, int[] heightMap, Vector3f origin, boolean clod, int totalSize, Vector2f offset, int offsetAmount)
          Constructor instantiates a new TerrainBlock object.
 
Method Summary
 int chooseTargetRecord(Renderer r)
          chooseTargetRecord determines which level of detail to use.
 float getHeight(float x, float z)
          getHeight returns the height of an arbitrary point on the terrain.
 float getHeight(Vector2f position)
          getHeight returns the height of an arbitrary point on the terrain.
 float getHeight(Vector3f position)
          getHeight returns the height of an arbitrary point on the terrain.
 int[] getHeightMap()
          Returns the height map this terrain block is using.
 Vector2f getOffset()
          Returns the current offset amount.
 int getOffsetAmount()
          Returns the offset amount this terrain block uses for textures.
 int getSize()
          Returns the size of this terrain block.
 Vector3f getStepScale()
          Returns the step scale that stretches the height map.
 int getTotalSize()
          Returns the total size of the terrain.
 boolean isUseClod()
          Returns true if this TerrainBlock was created as a clod.
 void setDetailTexture(int unit, int repeat)
          setDetailTexture sets the detail texture unit's repeat value.
 void setHeightMap(int[] heightMap)
          Sets the terrain's height map.
 void setOffset(Vector2f offset)
          Sets the value for the current offset amount to use when building texture coordinates.
 void setOffsetAmount(int offsetAmount)
          Sets the offset of this terrain texture map.
 void setSize(int size)
          Sets the size of this terrain block.
 void setStepScale(Vector3f stepScale)
          Sets the step scale of this terrain block's height map.
 void setTotalSize(int totalSize)
          Sets the total size of the terrain .
 void setUseClod(boolean useClod)
          If true, the terrain is created as a ClodMesh.
 
Methods inherited from class com.jme.scene.lod.AreaClodMesh
getDistanceTolerance, getTrisPerPixel, setDistanceTolerance, setTargetRecord, setTrisPerPixel
 
Methods inherited from class com.jme.scene.lod.ClodMesh
create, draw, getRecordQuantity, getRecords, getTargetRecord, setRecords
 
Methods inherited from class com.jme.scene.TriMesh
clearBuffers, drawBounds, findCollisions, findTriangleCollision, findTrianglePick, findWorldRotMat, getIndexAsBuffer, getIndices, getMeshAsTriangles, getTriangle, getTriangle, getTriangleQuantity, hasCollision, hasTriangleCollision, putClone, reconstruct, setIndexBuffer, setIndices, updateCollisionTree, updateIndexBuffer
 
Methods inherited from class com.jme.scene.Geometry
applyRenderState, applyStates, copyTextureCoords, findPick, getAllTextures, getCloneID, getColorAsFloatBuffer, getColors, getModelBound, getNormalAsFloatBuffer, getNormals, getNumberOfUnits, getTextureAsFloatBuffer, getTextureAsFloatBuffer, getTextures, getTextures, getVBOColorID, getVBONormalID, getVBOTextureID, getVBOVertexID, getVerticeAsFloatBuffer, getVertices, getVertQuantity, isVBOColorEnabled, isVBONormalEnabled, isVBOTextureEnabled, isVBOVertexEnabled, randomVertice, reconstruct, setAllTextures, setColor, setColors, setFloatBuffer, setForceView, setModelBound, setNormal, setNormalBuffer, setNormals, setRandomColors, setSolidColor, setTexture, setTexture, setTextureBuffer, setTextureCoord, setTextures, setTextures, setVBOColorEnabled, setVBOColorID, setVBONormalEnabled, setVBONormalID, setVBOTextureEnabled, setVBOTextureID, setVBOVertexEnabled, setVBOVertexID, setVertex, setVertexBuffer, setVertices, updateColorBuffer, updateColorBuffer, updateModelBound, updateNormalBuffer, updateNormalBuffer, updateTextureBuffer, updateTextureBuffer, updateTextureBuffer, updateVertexBuffer, updateVertexBuffer, updateWorldBound
 
Methods inherited from class com.jme.scene.Spatial
addController, applyDefaultStates, calculateCollisions, calculatePick, clearCurrentState, clearCurrentStates, clearRenderState, getController, getControllers, getCurrentState, getLastFrustumIntersection, getLightCombineMode, getLocalRotation, getLocalScale, getLocalTranslation, getName, getParent, getRenderQueueMode, getRenderStateList, getTextureCombineMode, getWorldBound, getWorldRotation, getWorldScale, getWorldTranslation, getZOrder, isForceCulled, isForceView, onDraw, onDrawBounds, propagateBoundToRoot, propagateStatesFromRoot, removeController, removeFromParent, setForceCull, setLightCombineMode, setLocalRotation, setLocalRotation, setLocalScale, setLocalScale, setLocalTranslation, setName, setParent, setRenderQueueMode, setRenderState, setTextureCombineMode, setWorldBound, setZOrder, toString, updateGeometricState, updateRenderState, updateRenderState, updateWorldData
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

TerrainBlock

public TerrainBlock()
Empty Constructor to be used internally only.


TerrainBlock

public TerrainBlock(java.lang.String name)
For internal use only. Creates a new Terrainblock with the given name by simply calling super(name)

Parameters:
name - The name.
See Also:
AreaClodMesh.AreaClodMesh(java.lang.String)

TerrainBlock

public TerrainBlock(java.lang.String name,
                    int size,
                    Vector3f stepScale,
                    int[] heightMap,
                    Vector3f origin,
                    boolean clod)
Constructor instantiates a new TerrainBlock object. The parameters and heightmap data are then processed to generate a TriMesh object for renderering.

Parameters:
name - the name of the terrain block.
size - the size of the heightmap.
stepScale - the scale for the axes.
heightMap - the height data.
origin - the origin offset of the block.
clod - true will use level of detail, false will not.

TerrainBlock

protected TerrainBlock(java.lang.String name,
                       int size,
                       Vector3f stepScale,
                       int[] heightMap,
                       Vector3f origin,
                       boolean clod,
                       int totalSize,
                       Vector2f offset,
                       int offsetAmount)
Constructor instantiates a new TerrainBlock object. The parameters and heightmap data are then processed to generate a TriMesh object for renderering.

Parameters:
name - the name of the terrain block.
size - the size of the block.
stepScale - the scale for the axes.
heightMap - the height data.
origin - the origin offset of the block.
clod - true will use level of detail, false will not.
totalSize - the total size of the terrain. (Higher if the block is part of a TerrainPage tree.
offset - the offset for texture coordinates.
offsetAmount - the total offset amount. Used for texture coordinates.
Method Detail

chooseTargetRecord

public int chooseTargetRecord(Renderer r)
chooseTargetRecord determines which level of detail to use. If CLOD is not used, the index 0 is always returned.

Overrides:
chooseTargetRecord in class AreaClodMesh
Parameters:
r - the renderer to use for determining the LOD record.
Returns:
the index of the record to use.

setDetailTexture

public void setDetailTexture(int unit,
                             int repeat)
setDetailTexture sets the detail texture unit's repeat value.

Parameters:
unit - int
repeat - int

getHeight

public float getHeight(Vector2f position)
getHeight returns the height of an arbitrary point on the terrain. If the point is between height point values, the height is linearly interpolated. This provides smooth height calculations. If the point provided is not within the bounds of the height map, the NaN float value is returned (Float.NaN).

Parameters:
position - the vector representing the height location to check.
Returns:
the height at the provided location.

getHeight

public float getHeight(Vector3f position)
getHeight returns the height of an arbitrary point on the terrain. If the point is between height point values, the height is linearly interpolated. This provides smooth height calculations. If the point provided is not within the bounds of the height map, the NaN float value is returned (Float.NaN).

Parameters:
position - the vector representing the height location to check. Only the x and z values are used.
Returns:
the height at the provided location.

getHeight

public float getHeight(float x,
                       float z)
getHeight returns the height of an arbitrary point on the terrain. If the point is between height point values, the height is linearly interpolated. This provides smooth height calculations. If the point provided is not within the bounds of the height map, the NaN float value is returned (Float.NaN).

Parameters:
x - the x coordinate to check.
z - the z coordinate to check.
Returns:
the height at the provided location.

getHeightMap

public int[] getHeightMap()
Returns the height map this terrain block is using.

Returns:
This terrain block's height map.

getOffsetAmount

public int getOffsetAmount()
Returns the offset amount this terrain block uses for textures.

Returns:
The current offset amount.

getStepScale

public Vector3f getStepScale()
Returns the step scale that stretches the height map.

Returns:
The current step scale.

getTotalSize

public int getTotalSize()
Returns the total size of the terrain.

Returns:
The terrain's total size.

getSize

public int getSize()
Returns the size of this terrain block.

Returns:
The current block size.

setUseClod

public void setUseClod(boolean useClod)
If true, the terrain is created as a ClodMesh. This is only usefull as a call after the default constructor.

Parameters:
useClod -

getOffset

public Vector2f getOffset()
Returns the current offset amount. This is used when building texture coordinates.

Returns:
The current offset amount.

setOffset

public void setOffset(Vector2f offset)
Sets the value for the current offset amount to use when building texture coordinates. Note that this does NOT rebuild the terrain at all. This is mostly used for outside constructors of terrain blocks.

Parameters:
offset - The new texture offset.

isUseClod

public boolean isUseClod()
Returns true if this TerrainBlock was created as a clod.

Returns:
True if this terrain block is a clod. False otherwise.

setSize

public void setSize(int size)
Sets the size of this terrain block. Note that this does NOT rebuild the terrain at all. This is mostly used for outside constructors of terrain blocks.

Parameters:
size - The new size.

setTotalSize

public void setTotalSize(int totalSize)
Sets the total size of the terrain . Note that this does NOT rebuild the terrain at all. This is mostly used for outside constructors of terrain blocks.

Parameters:
totalSize - The new total size.

setStepScale

public void setStepScale(Vector3f stepScale)
Sets the step scale of this terrain block's height map. Note that this does NOT rebuild the terrain at all. This is mostly used for outside constructors of terrain blocks.

Parameters:
stepScale - The new step scale.

setOffsetAmount

public void setOffsetAmount(int offsetAmount)
Sets the offset of this terrain texture map. Note that this does NOT rebuild the terrain at all. This is mostly used for outside constructors of terrain blocks.

Parameters:
offsetAmount - The new texture offset.

setHeightMap

public void setHeightMap(int[] heightMap)
Sets the terrain's height map. Note that this does NOT rebuild the terrain at all. This is mostly used for outside constructors of terrain blocks.

Parameters:
heightMap - The new height map.