org.critterai.nmgen
Class BoundedField

java.lang.Object
  extended by org.critterai.nmgen.BoundedField
Direct Known Subclasses:
ContourSet, OpenHeightfield, PolyMeshField, SolidHeightfield

public class BoundedField
extends Object

Defines an axis aligned bounding box containing a grid based field.

There are no enforced usage models for this class. But within this package the following standards apply:

Warning: Behavior is undefined if the minimum bounds is set to be greater than the maximum bounds.

See Also:
Introduction to Height Fields

Constructor Summary
BoundedField()
          Constructor - Default
BoundedField(float[] gridBoundsMin, float[] gridBoundsMax, float cellSize, float cellHeight)
          Constructor - Full
BoundedField(float cellSize, float cellHeight)
          Constructor - Partial
 
Method Summary
 float[] boundsMax()
          The maximum bounds of the field in world units.
 float[] boundsMin()
          The minimum bounds of the field in world units.
 float cellHeight()
          The height increment of the field.
 float cellSize()
          The size of the cells.
 int depth()
          Depth of the field in voxels.
static int getDirOffsetDepth(int dir)
          When used in conjunction with getDirOffsetWidth(int), gets a standard axis-neighbor direction offset that can be used for searching adjacent grid locations.
static int getDirOffsetWidth(int dir)
          When used in conjunction with getDirOffsetDepth(int), gets a standard axis-neighbor direction offset that can be used for searching adjacent grid locations within the field.
protected  int gridIndex(int widthIndex, int depthIndex)
          Generates a standardized grid index suitable for use in flattened storage arrays.
 boolean isInBounds(int widthIndex, int depthIndex)
          Indicates whether or not the provided index values represent a valid cell location within the field.
 boolean overlaps(float[] boundsMin, float[] boundsMax)
          Indicates whether or not the provided bounds overlaps the bounds of the current field.
protected  void resetBounds()
          Resets the bounds to min(0, 0, 0) and max(1, 1, 1).
protected  void resetCellInfo()
          Reset the cell size and height values to 0.1.
protected  void setBounds(float[] min, float[] max)
          Sets the bounds of the field.
protected  void setBounds(float xmin, float ymin, float zmin, float xmax, float ymax, float zmax)
          Sets the bounds of the field.
protected  void setBoundsMax(float[] value)
          Set the maximum bounds of the field.
protected  void setBoundsMin(float[] value)
          Set the minimum bounds of the field.
protected  void setCellHeight(float value)
          Set the cell height.
protected  void setCellSize(float value)
          Set the cell size.
 int width()
          Width of the field in voxels.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BoundedField

public BoundedField()
Constructor - Default

The bounds of the field will default to min(0, 0, 0) and max(1, 1, 1).

The cell size and height will default to 0.1.


BoundedField

public BoundedField(float cellSize,
                    float cellHeight)
Constructor - Partial

The bounds of the field will default to min(0, 0, 0) and max(1, 1, 1).

The cell size and height values are auto-clamped to Float.MIN_VALUE.

Parameters:
cellSize - The size of the cells. (The grid that forms the base of the field.)
cellHeight - The height increment of the field.

BoundedField

public BoundedField(float[] gridBoundsMin,
                    float[] gridBoundsMax,
                    float cellSize,
                    float cellHeight)
             throws IllegalArgumentException
Constructor - Full

The cell size and height values are auto-clamped to Float.MIN_VALUE.

Warning: Behavior is undefined if the minimum bounds is set to be greater than the maximum bounds.

Parameters:
gridBoundsMin - The minimum bounds of the field in the form (minX, minY, minZ).
gridBoundsMax - The maximum bounds of the field in the form (maxX, maxY, maxZ).
cellSize - The size of the cells. (The grid that forms the base of the field.)
cellHeight - The height increment of the field.
Throws:
IllegalArgumentException - If the bounds are null or the wrong size.
Method Detail

boundsMax

public final float[] boundsMax()
The maximum bounds of the field in world units.

Warning: A reference to the internal array is being returned, not a new array.

Form: (maxX, maxY, maxZ)


boundsMin

public final float[] boundsMin()
The minimum bounds of the field in world units.

Warning: A reference to the internal array is being returned, not a new array.

Form: (minX, minY, minZ)

Considered the origin of the field.


cellHeight

public final float cellHeight()
The height increment of the field.


cellSize

public final float cellSize()
The size of the cells. (The grid that forms the base of the field.)


depth

public final int depth()
Depth of the field in voxels.

The maximum depth index for the field is equal to(depth - 1).


isInBounds

public final boolean isInBounds(int widthIndex,
                                int depthIndex)
Indicates whether or not the provided index values represent a valid cell location within the field.

Parameters:
widthIndex - The width index.
depthIndex - The depth index.
Returns:
TRUE if the width and depth indices are valid for the field. Otherwise FALSE.

overlaps

public final boolean overlaps(float[] boundsMin,
                              float[] boundsMax)
Indicates whether or not the provided bounds overlaps the bounds of the current field.

All tests are inclusive. So if there is an edge match, then the bounds overlap.

Parameters:
boundsMin - The minimum bounds of the field to test in the form (minX, minY, minZ).
boundsMax - The maximum bounds of the field to test in the form (maxX, maxY, maxZ).
Returns:
TRUE if the provided bounds overlaps the bounds of the current field. Otherwise FALSE.

width

public final int width()
Width of the field in voxels.

The maximum width index for the field is equal to (width - 1).


gridIndex

protected final int gridIndex(int widthIndex,
                              int depthIndex)
Generates a standardized grid index suitable for use in flattened storage arrays.

Results in depth adjacent storage. (Cells at depth 0, Cells at depth 1, etc.)

Parameters:
widthIndex - The width index.
depthIndex - The depth index.
Returns:
A standardized grid index for the cell identified by the width and depth indices. If the width and depth combination is invalid for the field, a value of -1 will be returned.

resetBounds

protected final void resetBounds()
Resets the bounds to min(0, 0, 0) and max(1, 1, 1).


resetCellInfo

protected final void resetCellInfo()
Reset the cell size and height values to 0.1.


setBounds

protected final void setBounds(float xmin,
                               float ymin,
                               float zmin,
                               float xmax,
                               float ymax,
                               float zmax)
Sets the bounds of the field.

Warning: Behavior is undefined if the minimum bounds is greater than the maximum bounds.

Parameters:
xmin - The x-value for the minimum bounds.
ymin - The y-value for the minimum bounds.
zmin - The z-value for the minimum bounds.
xmax - The x-value for the maximum bounds.
ymax - The y-value for the maximum bounds.
zmax - The z-value for the maximum bounds.

setBounds

protected final void setBounds(float[] min,
                               float[] max)
Sets the bounds of the field.

Null values and arrays of length other than 3 are ignored.

Warning: Behavior is undefined if the minimum bounds is greater than the maximum bounds.

Parameters:
min - The minimum bounds in the form (minX, minY, minZ).
max - The maximum bounds in the form (maxX, maxY, maxZ).

setBoundsMax

protected final void setBoundsMax(float[] value)
Set the maximum bounds of the field.

Null values and arrays of length other than 3 are ignored.

Warning: Behavior is undefined if the new maximum bounds is less than the current minimum bounds.

Parameters:
value - The maximum bounds in the form (maxX, maxY, maxZ).

setBoundsMin

protected final void setBoundsMin(float[] value)
Set the minimum bounds of the field.

Null values and arrays of length other than 3 are ignored.

Warning: Behavior is undefined if the new minimum bounds is greater than the current maximum bounds.

Parameters:
value - The minimum bounds in the form (minX, minY, minZ).

setCellHeight

protected final void setCellHeight(float value)
Set the cell height.

The cell height value is clamped to Float.MIN_VALUE.

Parameters:
value - The new cell height.

setCellSize

protected final void setCellSize(float value)
Set the cell size.

The cell size value is clamped to Float.MIN_VALUE.

Parameters:
value - The new cell size.

getDirOffsetDepth

public static int getDirOffsetDepth(int dir)
When used in conjunction with getDirOffsetWidth(int), gets a standard axis-neighbor direction offset that can be used for searching adjacent grid locations.

The combined offset will be in the clockwise direction for direction 0 to 3, starting at (-1, 0).

For example, if a direction value of 3 is passed to both this operation and getDirOffsetWidth(int), then the combined width/depth offset will be (0, -1).

Parameters:
dir - A value representing the direction to get the offset for. The value will be automatically constrained to a valid value between 0 and 3 inclusive using wrapping. E.g. A value of 4 will be automatically wrapped to 0, a value of 9 will be automatically wrapped to 1, etc.
Returns:
The standard offset for the provided direction.
See Also:
Neighbor Searches

getDirOffsetWidth

public static int getDirOffsetWidth(int dir)
When used in conjunction with getDirOffsetDepth(int), gets a standard axis-neighbor direction offset that can be used for searching adjacent grid locations within the field.

The combined offset will be in the clockwise direction for direction 0 to 3, starting at (-1, 0).

For example, if a direction value of 3 is passed to both this operation and getDirOffsetDepth(int), then the combined width/depth offset will be (0, -1).

Parameters:
dir - A value representing the direction to get the offset for. The value will be automatically constrained to a valid value between 0 and 3 inclusive, using wrapping. E.g. A value of 4 will be automatically wrapped to 0, a value of 9 will be automatically wrapped to 1, etc.
Returns:
The standard offset for the provided direction.
See Also:
Neighbor Searches


Project Home and Source Code

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