aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Editing
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Editing/Flatten.cs102
-rw-r--r--OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Editing/Raise.cs142
2 files changed, 244 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/*
2Redistribution and use in source and binary forms, with or without
3modification, are permitted provided that the following conditions are
4met:
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
19THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30*/
31
32
33using System;
34using System.Collections.Generic;
35using System.Text;
36
37namespace 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
diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Editing/Raise.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Editing/Raise.cs
new file mode 100644
index 0000000..21d2645
--- /dev/null
+++ b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Editing/Raise.cs
@@ -0,0 +1,142 @@
1/*
2Redistribution and use in source and binary forms, with or without
3modification, are permitted provided that the following conditions are
4met:
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
19THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30*/
31
32
33using System;
34using System.Collections.Generic;
35using System.Text;
36
37namespace libTerrain
38{
39 partial class Channel
40 {
41 /// <summary>
42 /// Raises land around the selection
43 /// </summary>
44 /// <param name="rx">The center the X coordinate of where you wish to raise the land</param>
45 /// <param name="ry">The center the Y coordinate of where you wish to raise the land</param>
46 /// <param name="size">The radius of the dimple</param>
47 /// <param name="amount">How much impact to add to the terrain (0..2 usually)</param>
48 public void raise(double rx, double ry, double size, double amount)
49 {
50 raiseSphere(rx, ry, size, amount);
51 }
52
53 /// <summary>
54 /// Raises land in a sphere around the selection
55 /// </summary>
56 /// <param name="rx">The center the X coordinate of where you wish to raise the land</param>
57 /// <param name="ry">The center the Y coordinate of where you wish to raise the land</param>
58 /// <param name="size">The radius of the sphere dimple</param>
59 /// <param name="amount">How much impact to add to the terrain (0..2 usually)</param>
60 public void raiseSphere(double rx, double ry, double size, double amount)
61 {
62 int x, y;
63 for (x = 0; x < w; x++)
64 {
65 for (y = 0; y < h; y++)
66 {
67 double z = size;
68 z *= z;
69 z -= ((x - rx) * (x - rx)) + ((y - ry) * (y - ry));
70
71 if (z < 0)
72 z = 0;
73
74 map[x, y] += z * amount;
75 }
76 }
77 }
78
79 /// <summary>
80 /// Raises land in a cone around the selection
81 /// </summary>
82 /// <param name="rx">The center the X coordinate of where you wish to raise the land</param>
83 /// <param name="ry">The center the Y coordinate of where you wish to raise the land</param>
84 /// <param name="size">The radius of the cone</param>
85 /// <param name="amount">How much impact to add to the terrain (0..2 usually)</param>
86 public void raiseCone(double rx, double ry, double size, double amount)
87 {
88 int x, y;
89 for (x = 0; x < w; x++)
90 {
91 for (y = 0; y < h; y++)
92 {
93 double z = size;
94 z -= Math.Sqrt(((x - rx) * (x - rx)) + ((y - ry) * (y - ry)));
95
96 if (z < 0)
97 z = 0;
98
99 map[x, y] += z * amount;
100 }
101 }
102 }
103
104 /// <summary>
105 /// Lowers land in a sphere around the selection
106 /// </summary>
107 /// <param name="rx">The center the X coordinate of where you wish to lower the land</param>
108 /// <param name="ry">The center the Y coordinate of where you wish to lower the land</param>
109 /// <param name="size">The radius of the sphere dimple</param>
110 /// <param name="amount">How much impact to remove from the terrain (0..2 usually)</param>
111 public void lower(double rx, double ry, double size, double amount)
112 {
113 lowerSphere(rx, ry, size, amount);
114 }
115
116 /// <summary>
117 /// Lowers land in a sphere around the selection
118 /// </summary>
119 /// <param name="rx">The center the X coordinate of where you wish to lower the land</param>
120 /// <param name="ry">The center the Y coordinate of where you wish to lower the land</param>
121 /// <param name="size">The radius of the sphere dimple</param>
122 /// <param name="amount">How much impact to remove from the terrain (0..2 usually)</param>
123 public void lowerSphere(double rx, double ry, double size, double amount)
124 {
125 int x, y;
126 for (x = 0; x < w; x++)
127 {
128 for (y = 0; y < h; y++)
129 {
130 double z = size;
131 z *= z;
132 z -= ((x - rx) * (x - rx)) + ((y - ry) * (y - ry));
133
134 if (z < 0)
135 z = 0;
136
137 map[x, y] -= z * amount;
138 }
139 }
140 }
141 }
142} \ No newline at end of file