From: <diz...@us...> - 2007-08-15 15:12:07
|
Revision: 75 http://fortress.svn.sourceforge.net/fortress/?rev=75&view=rev Author: dizzutch Date: 2007-08-15 08:12:08 -0700 (Wed, 15 Aug 2007) Log Message: ----------- fixed normalization Modified Paths: -------------- trunk/mapgen/MapGenApp.java trunk/mapgen/MapGenerator.java Modified: trunk/mapgen/MapGenApp.java =================================================================== --- trunk/mapgen/MapGenApp.java 2007-08-15 12:19:54 UTC (rev 74) +++ trunk/mapgen/MapGenApp.java 2007-08-15 15:12:08 UTC (rev 75) @@ -25,7 +25,7 @@ public static void main(String[] args) { MapGenApp app = new MapGenApp(); app.map = new MapGenerator(600,600); - app.map.generateMap_HillAlgorithm(5); + app.map.generateMap_HillAlgorithm(1000); JFrame frame = new JFrame("mapgen"); frame.setBackground(Color.white); app.setBackground(Color.white); Modified: trunk/mapgen/MapGenerator.java =================================================================== --- trunk/mapgen/MapGenerator.java 2007-08-15 12:19:54 UTC (rev 74) +++ trunk/mapgen/MapGenerator.java 2007-08-15 15:12:08 UTC (rev 75) @@ -40,14 +40,12 @@ public void generateMap_HillAlgorithm(int iterations) { Random rand = new Random(); - double min = 0; - double max = 0; for (int i = 0; i < iterations; i++) { //generate random centerpoint int x1 = rand.nextInt(this.height); int y1 = rand.nextInt(this.width); //generate random radius - int radius = rand.nextInt(this.width/2) + 1; + int radius = rand.nextInt(this.width/4) + 1; double radius2 = java.lang.Math.pow(radius, 2); //for each point on the map, calculate height for (int x2 = 0; x2 < this.height; x2++) { @@ -55,9 +53,7 @@ double left = java.lang.Math.pow((x2-x1),2); double right = java.lang.Math.pow((y2-y1),2); double value = radius2 - (left + right); - if (value >= 0) { - min = (value < min) ? value : min; - max = (value > max) ? value : max; + if (value > 0) { double h = map[x2][y2].getHeight(); map[x2][y2].setHeight(value + h); } @@ -65,6 +61,15 @@ } } //normalize + //find min and max + double min = map[0][0].getHeight(); + double max = map[0][0].getHeight(); + for (int x = 0; x < this.height; x++) { + for (int y = 0; y < this.width; y++) { + min = (map[x][y].getHeight() < min) ? map[x][y].getHeight() : min; + max = (map[x][y].getHeight() > max) ? map[x][y].getHeight() : max; + } + } System.out.println("max : "+ max); System.out.println("min : "+ min); double nmin = 0; @@ -72,13 +77,14 @@ for (int x = 0; x < this.height; x++) { for (int y = 0; y < this.width; y++) { double h = map[x][y].getHeight(); - double value = ((h - min) / (max - min)); + double value = (h - min) / (max - min); nmin = (value < nmin) ? value : nmin; nmax = (value > nmax) ? value : nmax; + //System.out.println(x + " " + y + " " + map[x][y].getHeight() + " " + value); map[x][y].setHeight(value); } } System.out.println("nmax : "+ nmax); System.out.println("nmin : "+ nmin); } -} +} \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |