Wrong terrain height

TerrainQuad.getHeight() sometimes (even for coorinates 0,0) return correct value and sometimes returns 0, even though heightmap

does not contain any value near zero.

Graphicaly terrain looks like there are no zero height regions.



Is it known bug/caused by common programing mistake on my side?

It could be a bug, I haven’t encountered it returning 0 height when it is really a non-zero height.

Do you have a test case that demonstrates this?

I have seen this before also. It seems that if the coordinate is at EXACTLY a power of 2, then it returns 0. For example, (0,0), (64, 64). This would rarely be the case unless I set it as initial condition.

It happens after one of the initial 4 terraintiles are replaced and you try to get the height on a new tile. The initial tiles still return the right height. Test case would be to add something like this to simpleupdate of TerrainFractalGridTest:

[java]

if(terrain.getHeight(new Vector2f(this.getCamera().getLocation().x,this.getCamera().getLocation().z) )==0.0f)

{

System.out.println("Terrain height returns zero.");

}

[/java]

and move around so the terrain tiles gets updated.

I look into the problem and can confirm that it exists. The source of the problem is that in the early days of TerrainGrid the tiles were positioned by translating the whole grid to the location and the calculation relied on this information. Now the grid stays at 0 and the patches are moved to their location in space and the algorithm was not modified.



I’ll see how it can be fixed.

It also explains why we have to offset coordonnates with changeHeight() in TerrainGrid.