com.jme.terrain
Class TerrainPage

java.lang.Object
  extended bycom.jme.scene.Spatial
      extended bycom.jme.scene.Node
          extended bycom.jme.terrain.TerrainPage
All Implemented Interfaces:
java.io.Serializable

public class TerrainPage
extends Node

TerrainPage is used to build a quad tree of terrain blocks. The TerrainPage will have four children, either four pages or four blocks. The size of the page must be (2^N + 1), to allow for even splitting of the blocks. Organization of the page into a quad tree allows for very fast culling of the terrain. In some instances, using Clod will also improve rendering speeds. The total size of the heightmap is provided, as well as the desired end size for a block. Appropriate values for the end block size is completely dependant on the application. In some cases, a large size will give performance gains, in others, a small size is the best option. It is recommended that different combinations are tried.

Version:
$Id: TerrainPage.java,v 1.24 2005/02/20 23:29:23 renanse Exp $
Author:
Mark Powell
See Also:
Serialized Form

Field Summary
 
Fields inherited from class com.jme.scene.Node
children
 
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
  TerrainPage()
          Empty Constructor to be used internally only.
  TerrainPage(java.lang.String name)
          Creates a TerrainPage to be filled later.
  TerrainPage(java.lang.String name, int blockSize, int size, Vector3f stepScale, int[] heightMap, boolean clod)
          Constructor instantiates a new TerrainPage object.
protected TerrainPage(java.lang.String name, int blockSize, int size, Vector3f stepScale, int[] heightMap, boolean clod, int totalSize, Vector2f offset, int offsetAmount)
          Constructor instantiates a new TerrainPage object.
 
Method Summary
static int[] createHeightSubBlock(int[] heightMap, int x, int y, int side)
           
 void fixNormals()
           
 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.
 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 page.
 Vector3f getStepScale()
          Returns the step scale that stretches the height map.
 int getTotalSize()
          Returns the total size of the terrain.
 void setDetailTexture(int unit, int repeat)
          setDetailTexture sets the detail texture coordinates to be applied on top of the normal terrain texture.
 void setModelBound(BoundingVolume v)
          setModelBound sets the model bounds for the terrain blocks.
 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 page.
 void setStepScale(Vector3f stepScale)
          Sets the step scale of this terrain page's height map.
 void setTotalSize(int totalSize)
          Sets the total size of the terrain .
 void updateModelBound()
          updateModelBound updates the model bounds (generates the bounds from the current vertices).
 
Methods inherited from class com.jme.scene.Node
applyRenderState, attachChild, detachAllChildren, detachChild, detachChildAt, detachChildNamed, draw, drawBounds, findCollisions, findPick, getChild, getChild, getChildren, getQuantity, hasChild, hasCollision, putClone, setChild, setForceView, updateCollisionTree, updateWorldBound, updateWorldData
 
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
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

TerrainPage

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


TerrainPage

public TerrainPage(java.lang.String name)
Creates a TerrainPage to be filled later. Usually, users don't want to call this function unless they have a terrain page already built.

Parameters:
name - The name of the page node.

TerrainPage

public TerrainPage(java.lang.String name,
                   int blockSize,
                   int size,
                   Vector3f stepScale,
                   int[] heightMap,
                   boolean clod)
Constructor instantiates a new TerrainPage object. The data is then split into either 4 new TerrainPages or 4 new TerrainBlock.

Parameters:
name - the name of the page.
blockSize - the size of the leaf nodes. This is used to determine if four new TerrainPage objects should be the child or four new TerrainBlock objects.
size - the size of the heightmap for this page.
stepScale - the scale of the axes.
heightMap - the height data.
clod - true will use level of detail, false will not.

TerrainPage

protected TerrainPage(java.lang.String name,
                      int blockSize,
                      int size,
                      Vector3f stepScale,
                      int[] heightMap,
                      boolean clod,
                      int totalSize,
                      Vector2f offset,
                      int offsetAmount)
Constructor instantiates a new TerrainPage object. The data is then split into either 4 new TerrainPages or 4 new TerrainBlock.

Parameters:
name - the name of the page.
blockSize - the size of the leaf nodes. This is used to determine if four new TerrainPage objects should be the child or four new TerrainBlock objects.
size - the size of the heightmap for this page.
stepScale - the scale of the axes.
heightMap - the height data.
clod - true will use level of detail, false will not.
totalSize - the total terrain size, used if the page is an internal node of a terrain system.
offset - the texture offset for the page.
offsetAmount - the amount of the offset.
Method Detail

setDetailTexture

public void setDetailTexture(int unit,
                             int repeat)
setDetailTexture sets the detail texture coordinates to be applied on top of the normal terrain texture.

Parameters:
unit - the texture unit to set the coordinates.
repeat - the number of tiling for the texture.

setModelBound

public void setModelBound(BoundingVolume v)
setModelBound sets the model bounds for the terrain blocks.

Parameters:
v - the bounding volume to set for the terrain blocks.

updateModelBound

public void updateModelBound()
updateModelBound updates the model bounds (generates the bounds from the current vertices).


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.

getOffset

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

Returns:
The current offset amount.

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 page.

Returns:
The current block size.

getStepScale

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

Returns:
The current step scale.

getOffsetAmount

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

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.

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.

setSize

public void setSize(int size)
Sets the size of this terrain page. 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.

setStepScale

public void setStepScale(Vector3f stepScale)
Sets the step scale of this terrain page'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.

fixNormals

public void fixNormals()

createHeightSubBlock

public static int[] createHeightSubBlock(int[] heightMap,
                                         int x,
                                         int y,
                                         int side)