Class TerrainGrid

java.lang.Object
com.codename1.gaming.level.TerrainGrid

public class TerrainGrid extends Object
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.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final float
    Sentinel height meaning "no ground in this cell" (an open hole / sky gap).
  • Constructor Summary

    Constructors
    Constructor
    Description
     
    TerrainGrid(int cols, int rows, float cellSize)
     
  • Method Summary

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

    Methods inherited from class Object

    clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • NO_GROUND

      public static final float NO_GROUND
      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.
      See Also:
  • 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)