public class TerrainGrid

  1. Object
  2. TerrainGrid
A height grid for a 3D GameLevel: a #getCols() x #getRows() array of vertex heights spaced #getCellSize() world units apart. It is plain authoring data – turning it into a renderable mesh is the realizer’s job and needs the GPU device, so that happens at runtime, not here.

Fields

public static final float NO_GROUND = -1024.0fSentinel height meaning “no ground in this cell” (an open hole / sky gap).

Constructors

public TerrainGrid()
public TerrainGrid(int cols, int rows, float cellSize)

Methods

public int getCols()
public int getRows()
public float getCellSize()
public TerrainGrid setCellSize(float cellSize)
public float[] heights()The raw row-major heights array (length cols * rows).
public float[] walls()The raw row-major wall-height array (length cols * rows); 0 = no wall.
public String[] materials()The raw row-major surface-material array (length cols * rows) of MaterialRegistry ids; a null entry means the default MaterialRegistry#GRASS.
public String getMaterial(int col, int row)The surface material id at a cell (a MaterialRegistry id); never null – an unpainted cell reads as MaterialRegistry#GRASS.
public TerrainGrid setMaterial(int col, int row, String material)
public float getHeight(int col, int row)
public TerrainGrid setHeight(int col, int row, float height)
public boolean hasGround(int col, int row)Whether the given cell has a floor (true) or is an open hole / sky gap (false).
public TerrainGrid setGround(int col, int row, boolean present)
public float getWall(int col, int row)Wall height stacked on top of the ground in this cell (0 = none).
public TerrainGrid setWall(int col, int row, float height)

Inherited methods

Field details

NO_GROUND

public static final float NO_GROUND = -1024.0f
Sentinel height meaning “no ground in this cell” (an open hole / sky gap). Lets a level have a partial floor – e.g. a flight level with only a few ground patches.

Constructor details

TerrainGrid

public TerrainGrid()

TerrainGrid

public TerrainGrid(int cols, int rows, float cellSize)

Method details

getCols

public int getCols()

getRows

public int getRows()

getCellSize

public float getCellSize()

setCellSize

public TerrainGrid setCellSize(float cellSize)

heights

public float[] heights()
The raw row-major heights array (length cols * rows).

walls

public float[] walls()
The raw row-major wall-height array (length cols * rows); 0 = no wall.

materials

public String[] materials()
The raw row-major surface-material array (length cols * rows) of MaterialRegistry ids; a null entry means the default MaterialRegistry#GRASS.

getMaterial

public String getMaterial(int col, int row)
The surface material id at a cell (a MaterialRegistry id); never null – an unpainted cell reads as MaterialRegistry#GRASS.

setMaterial

public TerrainGrid setMaterial(int col, int row, String material)

getHeight

public float getHeight(int col, int row)

setHeight

public TerrainGrid setHeight(int col, int row, float height)

hasGround

public boolean hasGround(int col, int row)
Whether the given cell has a floor (true) or is an open hole / sky gap (false).

setGround

public TerrainGrid setGround(int col, int row, boolean present)

getWall

public float getWall(int col, int row)
Wall height stacked on top of the ground in this cell (0 = none).

setWall

public TerrainGrid setWall(int col, int row, float height)