com.jmex.terrain.util
Class BresenhamTerrainPicker

java.lang.Object
  extended by com.jmex.terrain.util.BresenhamTerrainPicker

public class BresenhamTerrainPicker
extends java.lang.Object

Utility class for doing ray based picking of TerrainPages using the BresenhamYUpGridTracer. It basically works by casting a pick ray against the bounding volumes of the TerrainPage and its children, gathering all of the TerrainBlocks hit (in distance order.) The triangles of each block are then tested using the BresenhamYUpGridTracer to determine which triangles to test and in what order. When a hit is found, it is guarenteed to be the first such hit and can immediately be returned.

Author:
Joshua Slack

Constructor Summary
BresenhamTerrainPicker(Spatial root)
          Construct a new BresenhamTerrainPicker that works on the given TerrainPage.
 
Method Summary
protected  boolean checkTriangles(float gridX, float gridY, Ray pick, Vector3f intersection, TerrainBlock block)
          Check the two triangles of a given grid space for intersection.
protected  int findClosestHeightIndex(Vector3f position, TerrainBlock block)
          Finds the closest height point to a position.
 Vector3f getTerrainIntersection(Ray worldPick, Vector3f store)
          Ask for the point of intersection between the given ray and the terrain.
protected  boolean getTriangles(float gridX, float gridY, TerrainBlock block)
          Request the triangles (in world coord space) of a TerrainBlock that correspond to the given grid location.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BresenhamTerrainPicker

public BresenhamTerrainPicker(Spatial root)
Construct a new BresenhamTerrainPicker that works on the given TerrainPage.

Parameters:
page - the TerrainPage to work on.
Method Detail

getTerrainIntersection

public Vector3f getTerrainIntersection(Ray worldPick,
                                       Vector3f store)
Ask for the point of intersection between the given ray and the terrain.

Parameters:
worldPick - our pick ray, in world space.
store - if not null, the results will be stored in this vector and the vector returned. If store is null, a new vector will be created.
Returns:
null if no pick is found. Otherwise it returns a Vector3f (the store param, if that was not null) populated with the pick coordinates.

checkTriangles

protected boolean checkTriangles(float gridX,
                                 float gridY,
                                 Ray pick,
                                 Vector3f intersection,
                                 TerrainBlock block)
Check the two triangles of a given grid space for intersection.

Parameters:
gridX - grid row
gridY - grid column
pick - our pick ray
intersection - the store variable
block - the terrain block we are currently testing against.
Returns:
true if a pick was found on these triangles.

getTriangles

protected boolean getTriangles(float gridX,
                               float gridY,
                               TerrainBlock block)
Request the triangles (in world coord space) of a TerrainBlock that correspond to the given grid location. The triangles are stored in the class fields _gridTriA and _gridTriB.

Parameters:
gridX - grid row
gridY - grid column
block - the TerrainBlock we are working with
Returns:
true if the grid point is valid for the given block, false if it is off the block.

findClosestHeightIndex

protected int findClosestHeightIndex(Vector3f position,
                                     TerrainBlock block)
Finds the closest height point to a position. Will always be left/above that position.

Parameters:
position - the position to check at
block - the block to get height values from
Returns:
an index to the height position of the given block.