diff options
Diffstat (limited to 'OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD')
-rw-r--r-- | OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Editing/Raise.cs | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Editing/Raise.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Editing/Raise.cs index 523a065..20bca51 100644 --- a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Editing/Raise.cs +++ b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Editing/Raise.cs | |||
@@ -127,5 +127,67 @@ namespace libTerrain | |||
127 | } | 127 | } |
128 | } | 128 | } |
129 | } | 129 | } |
130 | |||
131 | public double SphericalFactor(double x, double y, double rx, double ry, double size) | ||
132 | { | ||
133 | double z = size * size - ((x - rx) * (x - rx) + (y - ry) * (y - ry)); | ||
134 | return z; | ||
135 | } | ||
136 | |||
137 | public void SmoothRegion(double rx, double ry, double size, double amount) | ||
138 | { | ||
139 | int x, y; | ||
140 | double[,] tweak = new double[w, h]; | ||
141 | |||
142 | double n, l; | ||
143 | double area = size; | ||
144 | double step = size / 4.0; | ||
145 | |||
146 | // compute delta map | ||
147 | for (x = 0; x < w; x++) | ||
148 | { | ||
149 | for (y = 0; y < h; y++) | ||
150 | { | ||
151 | double z = SphericalFactor(x, y, rx, ry, size); | ||
152 | |||
153 | if (z > 0) // add in non-zero amount | ||
154 | { | ||
155 | double average = 0.0; | ||
156 | int avgsteps = 0; | ||
157 | |||
158 | for (n = 0.0 - area; n < area; n += step) | ||
159 | { | ||
160 | for (l = 0.0 - area; l < area; l += step) | ||
161 | { | ||
162 | avgsteps++; | ||
163 | average += GetBilinearInterpolate(x + n, y + l); | ||
164 | } | ||
165 | } | ||
166 | tweak[x, y] = average / avgsteps; | ||
167 | //if (x == rx && y == ry) | ||
168 | // Console.WriteLine("tweak[ " + x + " , " + y + " ] = " + tweak[x, y]); | ||
169 | } | ||
170 | } | ||
171 | } | ||
172 | // blend in map | ||
173 | for (x = 0; x < w; x++) | ||
174 | { | ||
175 | for (y = 0; y < h; y++) | ||
176 | { | ||
177 | double z = SphericalFactor(x, y, rx, ry, size); | ||
178 | |||
179 | if (z > 0) // add in non-zero amount | ||
180 | { | ||
181 | double da = z * amount; | ||
182 | double a = (map[x, y] - tweak[x, y]) * da; | ||
183 | double newz = map[x, y] - a; | ||
184 | //if (rx == x || ry == y) | ||
185 | // Console.WriteLine("map[ " + x + " , " + y + " ] = " + map[x, y] + " tweak, a , da, z, size, amount = " + tweak[x, y] + " " + a + " " + da + " " + z + " " + size + " " + amount); | ||
186 | if (newz > 0.0) | ||
187 | Set(x, y, newz); | ||
188 | } | ||
189 | } | ||
190 | } | ||
191 | } | ||
130 | } | 192 | } |
131 | } \ No newline at end of file | 193 | } \ No newline at end of file |