Skip to content

Instantly share code, notes, and snippets.

@twyatt
Created July 14, 2012 09:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save twyatt/3110195 to your computer and use it in GitHub Desktop.
Save twyatt/3110195 to your computer and use it in GitHub Desktop.
package com.traviswyatt.example.models;
public class Heightmap {
public final int width;
public final int height;
public final float[] elevations;
public final boolean flipY;
public Heightmap(int width, int height, float[] elevations, boolean flipY) {
this.width = width;
this.height = height;
this.elevations = elevations;
this.flipY = flipY;
if (width * height != elevations.length) {
throw new IllegalArgumentException("Height map dimension mismatch, width * height (" + (width * height) + ") != data.length (" + elevations.length + ")");
}
}
public int index(int x, int y) {
if (flipY) {
y = height - 1 - y;
}
return y * width + x;
}
// [0f, 1f]
public float elevation(int x, int y) {
return elevations[index(x, y)];
}
@Override
public String toString() {
return "[HeightMap: " + elevations.length + " data points, " + width + "x" + height + "]";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment