Heightmaps

Hi,



I am playing with some heightmap generation. I have the feeling there is still place for imporvement, especially the heightmap heightscale value that is not even used by the TerrainQuad which use values from the data directly. Moreover, there is a normalizing function to 1 in the HilHeightMap class and another one, normalizing to another value, in the AbstractHeightMap.



I have ported the Heightmap classes present in jme2. The MidPointDisplacement and Fault heightmaps are new implementations which look better. I also have made some changes to AbstractHeightMap, here is a summary


  • new flatten (from HillHeightMap), and smooth functions
  • flatten, smooth, erode and normalizeTerrain does not take heightData as arguments but instead modify directly the values.
  • normalizeTerrain accepts a value to normalize to (for instance to normalize to 1 prior flattening)
  • a new function getScaledHeightMap() returns the scaled heightData. This is a workaround so that a scaled heightmap can be passed to a the terrain constructor. It fills a new array with values and returns it.
  • An HeightMap interface has been created to allow different implementations. All references to AbstractHeightMap are still left as it in the code, but i wanted to to make use of this interface in the TerrainQuad class for instance. I am still not sure if the getTrueHeight and getScaledHeight function are needed, i think a single getHeight function should return the scaled height and interpolate it if needed.



    the diff is available at http://jmonkeyengine.pastebin.com/UwmQgkYH.



    Comments more than welcome.



    regards,



    Charly
2 Likes

Awesome @cghislai ! I will take a look at the diff and put the changes in today.

I was hoping someone would come along and clean up the hightmap stuff a bit :slight_smile:

The heightmap interface is a good idea, relying on the abstract heightmap class is too restrictive.



I think I might change the getHeight() function to getHeightmapHeight() so the user can get the actual heightmap value. That is useful in height modification.

But I think there should also be an interpolated getHeight() method that will get the real world height.

Your heightmap patch is in. Thanks for the contribution @cghislai !