Hello,
I use TerrainQuad#adjustHeight, which works fine:
quad.adjustHeight(new Vector2f(terrainX, terrainY), 1.0f);
But I want now use getHeight and setHeight to keep the height between 0.0f and 255.0f.
final Vector2f loc = new Vector2f(terrainX, terrainY);
final float height = quad.getHeight(loc);
System.out.println(height);
if(height < 255.0f) {
quad.setHeight(loc, Math.min(height * 1.0f, 255.0f));
}
This doesn’t work, because getHeight returns mostly NaN.
I looked in the source and figure out, that adjustHeight and getHeight calculate the real terrain coordinates different:
// TerrainQuad:1066 (getHeight(Vector2f))
float x = (float)(((xz.x - getWorldTranslation().x) / getWorldScale().x) + (float)(totalSize-1) / 2f);
float z = (float)(((xz.y - getWorldTranslation().z) / getWorldScale().z) + (float)(totalSize-1) / 2f);
// TerrainQuad:1159 (called by adjustHeight(Vector2f, float))
int x = Math.round((xz.get(i).x / getWorldScale().x) + halfSize);
int z = Math.round((xz.get(i).y / getWorldScale().z) + halfSize);
setHeight(Vector2f, float) call the same method as adjustHeight. Can me please somebody explain the different? I have no Idea and don’t found anything about.
Thank you