diff options
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Editing/Flatten.cs | 102 |
1 files changed, 102 insertions, 0 deletions
diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Editing/Flatten.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Editing/Flatten.cs new file mode 100644 index 0000000..5e5254d --- /dev/null +++ b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Editing/Flatten.cs | |||
@@ -0,0 +1,102 @@ | |||
1 | /* | ||
2 | Redistribution and use in source and binary forms, with or without | ||
3 | modification, are permitted provided that the following conditions are | ||
4 | met: | ||
5 | |||
6 | * Redistributions of source code must retain the above copyright | ||
7 | notice, this list of conditions and the following disclaimer. | ||
8 | |||
9 | * Redistributions in binary form must reproduce the above | ||
10 | copyright notice, this list of conditions and the following | ||
11 | disclaimer in the documentation and/or other materials provided | ||
12 | with the distribution. | ||
13 | |||
14 | * Neither the name of libTerrain nor the names of | ||
15 | its contributors may be used to endorse or promote products | ||
16 | derived from this software without specific prior written | ||
17 | permission. | ||
18 | |||
19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
20 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
21 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
22 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
23 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
24 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
25 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
26 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
27 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
28 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
29 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
30 | */ | ||
31 | |||
32 | |||
33 | using System; | ||
34 | using System.Collections.Generic; | ||
35 | using System.Text; | ||
36 | |||
37 | namespace libTerrain | ||
38 | { | ||
39 | partial class Channel | ||
40 | { | ||
41 | /// <summary> | ||
42 | /// Flattens the area underneath rx,ry by moving it to the average of the area. Uses a spherical mask provided by the raise() function. | ||
43 | /// </summary> | ||
44 | /// <param name="rx">The X coordinate of the terrain mask</param> | ||
45 | /// <param name="ry">The Y coordinate of the terrain mask</param> | ||
46 | /// <param name="size">The size of the terrain mask</param> | ||
47 | /// <param name="amount">The scale of the terrain mask</param> | ||
48 | public void flatten(double rx, double ry, double size, double amount) | ||
49 | { | ||
50 | // Generate the mask | ||
51 | Channel temp = new Channel(w, h); | ||
52 | temp.fill(0); | ||
53 | temp.raise(rx, ry, size, amount); | ||
54 | temp.normalise(); | ||
55 | double total_mod = temp.sum(); | ||
56 | |||
57 | // Establish the average height under the area | ||
58 | Channel newmap = new Channel(w, h); | ||
59 | newmap.map = (double[,])map.Clone(); | ||
60 | |||
61 | newmap *= temp; | ||
62 | |||
63 | double total_terrain = newmap.sum(); | ||
64 | double avg_height = total_terrain / total_mod; | ||
65 | |||
66 | // Create a flat terrain using the average height | ||
67 | Channel flat = new Channel(w, h); | ||
68 | flat.fill(avg_height); | ||
69 | |||
70 | // Blend the current terrain with the average height terrain | ||
71 | // using the "raised" empty terrain as a mask | ||
72 | blend(flat, temp); | ||
73 | |||
74 | } | ||
75 | |||
76 | public void flatten(Channel mask, double amount) | ||
77 | { | ||
78 | // Generate the mask | ||
79 | Channel temp = mask * amount; | ||
80 | temp.clip(0, 1); // Cut off out-of-bounds values | ||
81 | |||
82 | double total_mod = temp.sum(); | ||
83 | |||
84 | // Establish the average height under the area | ||
85 | Channel map = new Channel(w, h); | ||
86 | map.map = (double[,])this.map.Clone(); | ||
87 | |||
88 | map *= temp; | ||
89 | |||
90 | double total_terrain = map.sum(); | ||
91 | double avg_height = total_terrain / total_mod; | ||
92 | |||
93 | // Create a flat terrain using the average height | ||
94 | Channel flat = new Channel(w, h); | ||
95 | flat.fill(avg_height); | ||
96 | |||
97 | // Blend the current terrain with the average height terrain | ||
98 | // using the "raised" empty terrain as a mask | ||
99 | blend(flat, temp); | ||
100 | } | ||
101 | } | ||
102 | } \ No newline at end of file | ||