# Geomap

Any chance you could put up a few examples for the usage of the Geomap object?

I remember an example for a while back, but everything was commented, and I was hoping for an update on it… But now it seems you deleted it?

• Mikkel

The geomap system hasn't been touched in a while, we are still waiting for a certain someone to make a terrain system

Usage is in general easy, you load a heightmap via the GeomapLoader, then you can split the geomap in whatever way you like (optional) and there's a special method to create a mesh out of it. So once you get the mesh you just put it into a geometry, assign a material, and you got terrain.

Sorry for bumping this rather old thread.

Alright, so I got the Geomap running now, I just have one last question

In jME2, you can do map.getHeight(x, z);

Is there any way to do the same thing for the geomap?

The map.getValue(x, y) is only dealing with integers (and I'm pretty sure those coordinates are local index variables??)

• Mikkel

The map.getValue() method gives you the unscaled height at the given point, if you want to get the actual height, you have to scale it by the Y scale value you gave to the createMesh method.

Momoko_Fan said:

The map.getValue() method gives you the unscaled height at the given point, if you want to get the actual height, you have to scale it by the Y scale value you gave to the createMesh method.

Lets say we have a map of 4 * 4 height map values, and it takes up 40 * 40 world units..

With a slight bit of magic, I can have 16 perfect points, but for a proper game I'd need 1600? (actually more but yeah)

- Mikkel

EDIT: I guess I'll just make my map more detailed.
I should be good to go :)
Yep, got it working with a more detailed map. :) (Although its sligthly bumpy, but its good enough really)
If anyone else needs it:

```    /**     * Gets the height of the {@link Geomap} at a current position.     * @param location The location at which we want the height.     * @return The height of the {@link Geomap}, at the point specified.     */    public static float getHeight(Vector3f location) {       int x = (int) (location.x / scale.x);       int y = (int) (location.z / scale.z);       return map.getValue(x, y) * scale.y;    } ```

EDIT2:
And I realized the method from jME2 would spare me the bumps xD

```    /**     * <code>getHeight</code> returns the height of an arbitrary point on the     * terrain. If the point is between height point values, the height is     * linearly interpolated. This provides smooth height calculations. If the     * point provided is not within the bounds of the height map, 0 is returned.     *     * @param x     *            the x coordinate to check.     * @param z     *            the z coordinate to check.     * @return the height at the provided location.     */    public float getHeight(float x, float z) {       x /= SCALE.x;       z /= SCALE.z;       int col = (int) Math.floor(x);       int row = (int) Math.floor(z);       if (col < 0 || row < 0 || col >= map.getHeight() - 1 || row >= map.getWidth() - 1) {          return 0;       }       float offsetX = x - col;       float offsetY = z - row;       int focalSpot = (col + row * map.getWidth());       // The height at the upper left corner.       float upperLeft = map.getValue(focalSpot) * SCALE.y;       //The height at the lower right corner.       float lowerRight = map.getValue(focalSpot + map.getWidth() + 1) * SCALE.y;       // Use linear interpolation to find the height.       if(offsetX > offsetY) {          // The height at the upper left corner.          float upperRight = map.getValue(focalSpot + 1) * SCALE.y;          return upperLeft * (1 - offsetX) + upperRight * (offsetX - offsetY) + lowerRight * offsetY;       } else {          // The height at the lower left corner.          float lowerLeft = map.getValue(focalSpot + map.getWidth()) * SCALE.y;          return upperLeft * (1 - offsetY) + lowerLeft * (offsetY - offsetX) + lowerRight * offsetX;       }    } ```

I know this is an old thread, but could you post your basic heightmap loading code? I can't seem to get it working on my end and a working example would be invaluable.