Heightmap Terrain Rendering 
by Mikael Baros

 
Listing One

public static Mesh createQuad(short[] heights, int cullFlags)
  {
    // The vertrices of the quad
    short[] vertrices = {-255, heights[0], -255,
      255, heights[1], -255,
      255, heights[2], 255,
      -255, heights[3], 255};

Listing Two

// Create the model's vertex colors
VertexArray colorArray = new VertexArray(color.length/3, 3, 1);
colorArray.set(0, color.length / 3, color);

// Compose VertexBuffer out of previous vertrices and texture coordinates
VertexBuffer vertexBuffer = new VertexBuffer();
vertexBuffer.setPositions(vertexArray, 1.0f, null);
vertexBuffer.setColors(colorArray);

// Create indices and face lengths
int indices[] = new int[] {0, 1, 3, 2};
int[] stripLengths = new int[] {4};

// Create the model's triangles
triangles = new TriangleStripArray(indices, stripLengths);

Listing Three

// Create the appearance
  Appearance appearance = new Appearance();
  PolygonMode pm = new PolygonMode();
  pm.setCulling(cullFlags);
  pm.setPerspectiveCorrectionEnable(true);
  pm.setShading(PolygonMode.SHADE_SMOOTH);
  appearance.setPolygonMode(pm);


Listing Four


// Actual heightmap containing the Y-coords of our triangles
    private short[] heightMap;
    private int[] data;
    private int imgw, imgh;
   
    // Map dimensions
    private int mapWidth;
    private int mapHeight;
   
    // Actual quads
    private Mesh[][] map;
   
    // Water
    private Mesh water;
   
    // Local transform used for internal calculations
    private Transform localTransform = new Transform();


2


