float[] temp1 = map1.getHeightMap(); float[] temp2 = map2.getHeightMap();
heightmap.setHeightScale(1); heightmap.load();
/** * Smooth the terrain. For each node, its 8 neighbors heights * are averaged and will participate in the node new height * by a factor <code>np</code> between 0 and 1 * * You must first load() the heightmap data before this will have any effect. * * @param np * The factor to what extend the neighbors average has an influence. * Value of 0 will ignore neighbors (no smoothing) * Value of 1 will ignore the node old height. */ public void smooth(float np) { smooth(np, 1); }
float[] minmax = findMinMaxHeights(); normalizeTerrain(1f); normalizeTerrain(height);
try { heightmap = new ImageBasedHeightMap(heightMapImage.getImage(), 0.25f); heightmap.load(); } catch (Exception e) { e.printStackTrace(); terrain = new TerrainQuad("terrain", 65, 513, heightmap.getHeightMap()); List<Camera> cameras = new ArrayList<Camera>(); cameras.add(getCamera());
try { heightmap = new ImageBasedHeightMap(heightMapImage.getImage(), 0.5f); heightmap.load(); heightmap.smooth(0.9f, 1); terrain = new TerrainQuad("terrain", 65, 513, heightmap.getHeightMap()); TerrainLodControl control = new TerrainLodControl(terrain, getCamera()); control.setLodCalculator( new DistanceLodCalculator(65, 2.7f) ); // patch size, and a multiplier
private HeightMap getHeightMapAt(Vector3f location) { AbstractHeightMap heightmap = null; FloatBuffer buffer = this.base.getBuffer(location.x * (this.quadSize - 1), location.z * (this.quadSize - 1), 0, this.quadSize); float[] arr = buffer.array(); for (int i = 0; i < arr.length; i++) { arr[i] = arr[i] * this.heightScale; } heightmap = new FloatBufferHeightMap(buffer); heightmap.load(); return heightmap; }
/** * <code>setHeightMaps</code> sets the height maps to combine. * The size of the height maps must be the same. * @param map1 the first height map. * @param map2 the second height map. * @throws JmeException if the either heightmap is null, or their * sizes do not match. */ public void setHeightMaps(AbstractHeightMap map1, AbstractHeightMap map2) throws Exception { if (null == map1 || null == map2) { throw new Exception("Height map may not be null"); } if (map1.getSize() != map2.getSize()) { throw new Exception("The two maps must be of the same size"); } this.size = map1.getSize(); this.map1 = map1; this.map2 = map2; }
/** * <code>getInterpolatedHeight</code> returns the height of a point that * does not fall directly on the height posts. * * @param x * the x coordinate of the point. * @param z * the y coordinate of the point. * @return the interpolated height at this point. */ public float getInterpolatedHeight(float x, float z) { float low, highX, highZ; float intX, intZ; float interpolation; low = getScaledHeightAtPoint((int) x, (int) z); if (x + 1 >= size) { return low; } highX = getScaledHeightAtPoint((int) x + 1, (int) z); interpolation = x - (int) x; intX = ((highX - low) * interpolation) + low; if (z + 1 >= size) { return low; } highZ = getScaledHeightAtPoint((int) x, (int) z + 1); interpolation = z - (int) z; intZ = ((highZ - low) * interpolation) + low; return ((intX + intZ) / 2); }
try { heightmap = new ImageBasedHeightMap(heightMapImage.getImage(), 0.25f); heightmap.load(); } catch (Exception e) { e.printStackTrace(); terrain = new TerrainQuad("terrain", 65, 513, heightmap.getHeightMap()); List<Camera> cameras = new ArrayList<Camera>(); cameras.add(getCamera());
try { heightmap = new ImageBasedHeightMap(heightMapImage.getImage(), 0.3f); heightmap.load(); heightmap.smooth(0.9f, 1); terrain = new TerrainQuad("terrain", 65, 513, heightmap.getHeightMap());//, new LodPerspectiveCalculatorFactory(getCamera(), 4)); // add this in to see it use entropy for LOD calculations TerrainLodControl control = new TerrainLodControl(terrain, getCamera()); control.setLodCalculator( new DistanceLodCalculator(65, 2.7f) ); // patch size, and a multiplier
private HeightMap getHeightMapAt(Vector3f location) { AbstractHeightMap heightmap = null; FloatBuffer buffer = this.base.getBuffer(location.x * (this.quadSize - 1), location.z * (this.quadSize - 1), 0, this.quadSize); float[] arr = buffer.array(); for (int i = 0; i < arr.length; i++) { arr[i] = arr[i] * this.heightScale; } heightmap = new FloatBufferHeightMap(buffer); heightmap.load(); return heightmap; }
float[] minmax = findMinMaxHeights(); normalizeTerrain(1f); normalizeTerrain(height);
/** * <code>getInterpolatedHeight</code> returns the height of a point that * does not fall directly on the height posts. * * @param x * the x coordinate of the point. * @param z * the y coordinate of the point. * @return the interpolated height at this point. */ public float getInterpolatedHeight(float x, float z) { float low, highX, highZ; float intX, intZ; float interpolation; low = getScaledHeightAtPoint((int) x, (int) z); if (x + 1 >= size) { return low; } highX = getScaledHeightAtPoint((int) x + 1, (int) z); interpolation = x - (int) x; intX = ((highX - low) * interpolation) + low; if (z + 1 >= size) { return low; } highZ = getScaledHeightAtPoint((int) x, (int) z + 1); interpolation = z - (int) z; intZ = ((highZ - low) * interpolation) + low; return ((intX + intZ) / 2); }
try { heightmap = new ImageBasedHeightMap(heightMapImage.getImage(), 0.25f); heightmap.load(); } catch (Exception e) { e.printStackTrace(); terrain = new TerrainQuad("terrain", 65, 513, heightmap.getHeightMap()); List<Camera> cameras = new ArrayList<Camera>(); cameras.add(getCamera());
public HeightMap getHeightMapAt(Vector3f location) { // HEIGHTMAP image (for the terrain heightmap) int x = (int) location.x; int z = (int) location.z; AbstractHeightMap heightmap = null; //BufferedImage im = null; try { String name = namer.getName(x, z); logger.log(Level.FINE, "Loading heightmap from file: {0}", name); final Texture texture = assetManager.loadTexture(new TextureKey(name)); // CREATE HEIGHTMAP heightmap = new ImageBasedHeightMap(texture.getImage()); heightmap.setHeightScale(1); heightmap.load(); } catch (AssetNotFoundException e) { logger.log(Level.SEVERE, "Asset Not found! ", e); } return heightmap; }
float[] temp1 = map1.getHeightMap(); float[] temp2 = map2.getHeightMap();
/** * Smooth the terrain. For each node, its 8 neighbors heights * are averaged and will participate in the node new height * by a factor <code>np</code> between 0 and 1 * * You must first load() the heightmap data before this will have any effect. * * @param np * The factor to what extend the neighbors average has an influence. * Value of 0 will ignore neighbors (no smoothing) * Value of 1 will ignore the node old height. */ public void smooth(float np) { smooth(np, 1); }