Hello guys,
I am working on a client server application. The server generates a heightmap and transfers it to the client, then the client generates the terrain based on that heightmap. I did already try the client generating the heightmap itself but I have the same problem, so I guess the transferring works.
My problem is that the value I get with heightmap.getScaledHeightAtPoint() does not fit to the way the terrain is generated (For example I get a height of around 0.9f while the terrain is at 0).
Here is some code for you:
/**
* Creates a new map, containing the heightmap and static objects (dungeons etc)
* @param settings The world settings
*/
public Map(WorldSettings settings) throws Exception{
this.settings = settings;
random = new Random(settings.seed);
heightmap = new HillHeightMap(settings.realmSize + 1, 100, 10, 50, 3);
heightmap.setHeightScale(0.1f);
}
public float getHeightAt(Vector2f pos){ return heightmap.getScaledHeightAtPoint((int)pos.x, (int)pos.y); }
public HeightMap getHeightMap(){ return heightmap; }
The terrain is generated like this (I will add more textures and stuff later):
private void loadTerrain(float hm){
terrain = new TerrainQuad(“terrain”, 33, worldSettings.realmSize + 1, hm);
Material terMat = new Material(assetManager, "Common/MatDefs/Terrain/Terrain.j3md");
Texture grass = assetManager.loadTexture("Textures/grass.png"); grass.setWrap(Texture.WrapMode.Repeat); terMat.setTexture("Tex1", grass); terMat.setFloat("Tex1Scale", worldSettings.realmSize);
terrain.setMaterial(terMat);
terrain.addControl(new TerrainLodControl(terrain, cam));
rootNode.attachChild(terrain);
niftyDisplay.getNifty().gotoScreen("hud"); }
I am sure it is something really stupid but I can’t find what I did wrong…
Thank you
Smire