org.critterai.nmgen
Class OpenHeightSpan

java.lang.Object
  extended by org.critterai.nmgen.OpenHeightSpan

public final class OpenHeightSpan
extends Object

Represents the open space above a solid span within the cell column of a heightfield.

See Also:
Introduction to Heightfields, HeightSpan

Field Summary
 int flags
          Temporary flags associated with the span.
static int NULL_REGION
          A value representing a span in the null region.
 
Constructor Summary
OpenHeightSpan(int floor, int height)
          Constructor
 
Method Summary
 int ceiling()
          The height of the ceiling.
 int distanceToBorder()
          The distance this span is from the nearest border of the heightfield it belongs to.
 int distanceToRegionCore()
          The distance this span is from the core of the heightfield region it belongs to.
 int floor()
          The base height of the span.
 void getDetailedRegionMap(int[] out, int insertIndex)
          Populates an array with information on the regions a span's 8-neighbors are assigned to.
 OpenHeightSpan getNeighbor(int direction)
          Gets a reference to the span that is considered an axis-neighbor to this span for the specified direction.
 int height()
          The height of the unobstructed space above the floor.
 OpenHeightSpan next()
          The next span higher in the span's heightfield column.
 int regionID()
          The heightfield region this span belongs to.
 void setDistanceToBorder(int value)
          Set the distance this span is from the nearest border of the heightfield it belongs to.
 void setDistanceToRegionCore(int value)
          Set the distance this span is from the core of the heightfield region it belongs to.
 void setNeighbor(int direction, OpenHeightSpan neighbor)
          Sets the specified span at the neighbor of the current span.
 void setNext(OpenHeightSpan value)
          Set the next heigher span in the span's heightfield column.
 void setRegionID(int value)
          The heightfield region this span belongs to.
 String toString()
          
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

NULL_REGION

public static final int NULL_REGION
A value representing a span in the null region. Spans in the null are considered not traversable.

Spans in the null-region are often skipped during processing. Other processing is only applied when the null-region is involved.

See Also:
Constant Field Values

flags

public int flags
Temporary flags associated with the span.

The value is meaningless outside the operation in which the flags are needed. Since various operations may use this flag for their own purpose, always reset the flag after use.

The contract is that an operation expects the flag to be zero when it receives the span data.

Constructor Detail

OpenHeightSpan

public OpenHeightSpan(int floor,
                      int height)
               throws IllegalArgumentException
Constructor

Parameters:
floor - The base height of the span.
height - The height of the unobstructed space above the floor. Integer.MAX_VALUE is generally used to indicate no obstructions exist above the floor.
Throws:
IllegalArgumentException - If the floor is below zero or the height is less than 1.
Method Detail

ceiling

public int ceiling()
The height of the ceiling.

Returns:
The height of the ceiling.

distanceToBorder

public int distanceToBorder()
The distance this span is from the nearest border of the heightfield it belongs to.

Returns:
The distance this span is from the nearest heightfield border.

distanceToRegionCore

public int distanceToRegionCore()
The distance this span is from the core of the heightfield region it belongs to.

Returns:
The distance this span is from the core of the heightfield region it belongs to.

floor

public int floor()
The base height of the span.

Returns:
The base height of the span.

getDetailedRegionMap

public void getDetailedRegionMap(int[] out,
                                 int insertIndex)
Populates an array with information on the regions a span's 8-neighbors are assigned to.

If necessary, both of a diagonal neighbor's associated axis-neighbors will be used to detect the diagonal neighbor.

Special case: Since, diagonal neighbors are detected through axis-neighbors, if the span has no axis-neighbors in the direction of the diagonal-neighbor, then the diagonal-neighbor will not be detected.

Neighbor order:
0 - 3 : Standard axis-neighbor order. (E.g. Starting at standard zero direction.)
4 - 7 : Standard diagonal neighbors. (E.g. Clockwise of associated axis-neighbor.)
So the standard diagonal neigbor of an axis-neighbor can be found at "axis-neighbor index + 4".

Parameters:
out - An array of at least size 8.
See Also:
Neighbor Searches

getNeighbor

public OpenHeightSpan getNeighbor(int direction)
Gets a reference to the span that is considered an axis-neighbor to this span for the specified direction. Uses the standard direction indices (0 through 3) where zero is the neighbor offset at (-1, 0) and the search proceeds clockwise.

Parameters:
direction - The direction to search.
Returns:
A reference to the axis-neighbor in the specified direction. Or null if there is no neighbor in the direction or the direction index is invalid.
See Also:
Neighbor Searches

height

public int height()
The height of the unobstructed space above the floor.

Integer.MAX_VALUE is generally used to indicate no obstructions exist above the floor.

Returns:
The height of the unobstructed space above the floor.

next

public OpenHeightSpan next()
The next span higher in the span's heightfield column.

The space between this span's ceiling and the next span's floor is considered to be obstructed space.

Returns:
The next higher span in the span's heightfield column. Or null if there is no heigher span.

regionID

public int regionID()
The heightfield region this span belongs to.

This value will never be less than NULL_REGION for a finished, properly constructed heightfield.

For a partially constructed heightfield the contract is that any region ID less than or equal to NULL_REGION belongs to the null region.

Returns:
The heightfield region this span belongs to.

setDistanceToBorder

public void setDistanceToBorder(int value)
Set the distance this span is from the nearest border of the heightfield it belongs to.

Parameters:
value - The new distance. Auto-clamped at a minimum of zero.

setDistanceToRegionCore

public void setDistanceToRegionCore(int value)
Set the distance this span is from the core of the heightfield region it belongs to.

Parameters:
value - The new distance. Auto-clamped at a minimum of zero.

setNeighbor

public void setNeighbor(int direction,
                        OpenHeightSpan neighbor)
Sets the specified span at the neighbor of the current span.

Uses the standard direction indices (0 through 3) where Zero is the neighbor offset at (-1, 0) and the search proceeds clockwise.

Parameters:
direction - The direction of the neighbor.
neighbor - The neighbor of this span.
See Also:
Neighbor Searches

setNext

public void setNext(OpenHeightSpan value)
Set the next heigher span in the span's heightfield column.

Parameters:
value - The new value. null is an acceptable value.

setRegionID

public void setRegionID(int value)
The heightfield region this span belongs to.

See regionID() for important contract information.

Parameters:
value - The new value.

toString

public String toString()

Overrides:
toString in class Object


Project Home and Source Code

Copyright 2010 Stephen Pratt. All rights reserved. Use is subject to license terms.