# HG changeset patch # User postspectacular # Date 1326688426 0 # Node ID 6012bfd45a1437fa52e7cd5b01546d9d03fd4a23 # Parent 94bd573365f09c8b732a0153d969a4c319952b0c adding Terrain.clear() & updateElevation() methods diff -r 94bd573365f09c8b732a0153d969a4c319952b0c -r 6012bfd45a1437fa52e7cd5b01546d9d03fd4a23 src.core/toxi/geom/mesh/Terrain.java --- a/src.core/toxi/geom/mesh/Terrain.java Mon Jan 16 04:32:26 2012 +0000 +++ b/src.core/toxi/geom/mesh/Terrain.java Mon Jan 16 04:33:46 2012 +0000 @@ -79,6 +79,13 @@ } } + public Terrain clear() { + for (int i = 0; i < elevation.length; i++) { + elevation[i] = 0; + } + return updateElevation(); + } + /** * @return number of grid cells along the Z axis. */ @@ -205,12 +212,11 @@ */ public Terrain setElevation(float[] elevation) { if (this.elevation.length == elevation.length) { - for (int i = 0; i < elevation.length; i++) { - this.vertices[i].y = this.elevation[i] = elevation[i]; - } + this.elevation = elevation; + updateElevation(); } else { throw new IllegalArgumentException( - "the given elevation array size does not match terrain"); + "the given elevation array size does not match existing terrain size"); } return this; } @@ -362,4 +368,11 @@ } return mesh; } + + public Terrain updateElevation() { + for (int i = 0; i < elevation.length; i++) { + vertices[i].y = elevation[i]; + } + return this; + } }