Created
July 14, 2012 09:34
-
-
Save twyatt/3110195 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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