I’ve fixed a bug (i think) in TerrainQuad.getHeight, triangle interpolation was broken.
Can someone allowed commit this?
[java]
// gets an interpolated value
protected float getHeight(float x, float z) {
float col = FastMath.floor(x);
float row = FastMath.floor(z);
boolean onX = false;
if(1 - (x - col)-(z - row) < 0) // what triangle to interpolate on
onX = true;
// v1–v2 ^
// | / | |
// | / | |
// v3–v4 | Z
// |
// <
Y
// X
float v1 = getHeightmapHeight((int) FastMath.ceil(x), (int) FastMath.ceil(z));
float v2 = getHeightmapHeight((int) FastMath.floor(x), (int) FastMath.ceil(z));
float v3 = getHeightmapHeight((int) FastMath.ceil(x), (int) FastMath.floor(z));
float v4 = getHeightmapHeight((int) FastMath.floor(x), (int) FastMath.floor(z));
if (onX) {
return ((x - col) + (z - row) - 1)*v1 + (1 - (x - col))*v2 + (1 - (z - row))*v3;
} else {
return (1 - (x - col) - (z - row))*v4 + (z - row)*v2 + (x - col)*v3;
}
}
[/java]