/** * Loads the image data from top left to bottom right */ public boolean load() { return load(false, false); }
public RawHeightMap(InputStream stream, int size, int format, boolean swapxy) throws Exception { setup(stream, size, format, swapxy); }
/** * 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); }
unloadHeightMap(); float[] temp1 = map1.getHeightMap(); float[] temp2 = map2.getHeightMap();
float[] minmax = findMinMaxHeights(); normalizeTerrain(1f); normalizeTerrain(height);
protected void addFault(float[][] tempBuffer, Random random) { float faultHeight = minFaultHeight + random.nextFloat() * (maxFaultHeight - minFaultHeight); float range = minRange + random.nextFloat() * (maxRange - minRange); switch (faultShape) { case FAULTSHAPE_LINE: addLineFault(tempBuffer, random, faultHeight, range); break; case FAULTSHAPE_CIRCLE: addCircleFault(tempBuffer, random, faultHeight, range); break; } }
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; }
public TerrainQuad getTerrainQuadAt(Vector3f location) { HeightMap heightMapAt = getHeightMapAt(location); TerrainQuad q = new TerrainQuad("Quad" + location, patchSize, quadSize, heightMapAt == null ? null : heightMapAt.getHeightMap()); return q; }
cornerAverage += tempBuffer[x][y + stepSize]; cornerAverage /= 4; float offset = getOffset(random, offsetRange, coords, cornerAverage); tempBuffer[x + stepSize / 2][y + stepSize / 2] = cornerAverage + offset;
/** * <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); }
private void setup(InputStream stream, int size, int format, boolean swapxy) throws Exception { // varify that filename and size are valid. if (null == stream || size <= 0) { throw new Exception("Must supply valid stream and " + "size (> 0)"); } this.stream = stream; this.size = size; this.format = format; this.swapxy = swapxy; load(); }
/** * <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; }
/** * Constructor sets the attributes of the hill system and generates the * height map. * * @param size * size the size of the terrain to be generated * @param iterations * the number of iterations to do * @throws JmeException * if size of the terrain is not greater that zero, or number of * iterations is not greater that zero */ public FluidSimHeightMap(int size, int iterations) throws Exception { if (size <= 0 || iterations <= 0) { throw new Exception( "Either size of the terrain is not greater that zero, " + "or number of iterations is not greater that zero"); } this.size = size; this.iterations = iterations; load(); }
protected void addLineFault(float[][] tempBuffer, Random random, float faultHeight, float range) { int x1 = random.nextInt(size); int x2 = random.nextInt(size); int y1 = random.nextInt(size); int y2 = random.nextInt(size); for (int i = 0; i < size; i++) { for (int j = 0; j < size; j++) { float dist = ((x2 - x1) * (j - y1) - (y2 - y1) * (i - x1)) / (FastMath.sqrt(FastMath.sqr(x2 - x1) + FastMath.sqr(y2 - y1))); tempBuffer[i][j] += calcHeight(dist, random, faultHeight, range); } } }
public RawHeightMap(String filename, int size, int format, boolean swapxy) throws Exception { // varify that filename and size are valid. if (null == filename || size <= 0) { throw new Exception("Must supply valid filename and " + "size (> 0)"); } try { setup(new FileInputStream(filename), size, format, swapxy); } catch (FileNotFoundException e) { throw new Exception("height file not found: " + filename); } }
public TerrainQuad getTerrainQuadAt(Vector3f location) { HeightMap heightMapAt = getHeightMapAt(location); TerrainQuad q = new TerrainQuad("Quad" + location, patchSize, quadSize, heightMapAt == null ? null : heightMapAt.getHeightMap()); return q; }
float offset = getOffset(random, offsetRange, coords, cornerAverage); tempBuffer[x + stepSize / 2][y] = cornerAverage + offset;
public RawHeightMap(URL resource, int size, int format, boolean swapxy) throws Exception { // varify that resource and size are valid. if (null == resource || size <= 0) { throw new Exception("Must supply valid resource and " + "size (> 0)"); } try { setup(resource.openStream(), size, format, swapxy); } catch (IOException e) { throw new Exception("Unable to open height url: " + resource); } }