aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Environment/Modules
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/Environment/Modules')
-rw-r--r--OpenSim/Region/Environment/Modules/Terrain/PaintBrushes/ErodeSphere.cs43
-rw-r--r--OpenSim/Region/Environment/Modules/Terrain/PaintBrushes/FlattenSphere.cs2
-rw-r--r--OpenSim/Region/Environment/Modules/Terrain/PaintBrushes/LowerSphere.cs2
-rw-r--r--OpenSim/Region/Environment/Modules/Terrain/PaintBrushes/NoiseSphere.cs2
-rw-r--r--OpenSim/Region/Environment/Modules/Terrain/PaintBrushes/OlsenSphere.cs2
-rw-r--r--OpenSim/Region/Environment/Modules/Terrain/PaintBrushes/RaiseSphere.cs2
-rw-r--r--OpenSim/Region/Environment/Modules/Terrain/PaintBrushes/RevertSphere.cs7
-rw-r--r--OpenSim/Region/Environment/Modules/Terrain/PaintBrushes/SmoothSphere.cs47
-rw-r--r--OpenSim/Region/Environment/Modules/Terrain/PaintBrushes/WeatherSphere.cs43
-rw-r--r--OpenSim/Region/Environment/Modules/Terrain/TerrainUtil.cs51
10 files changed, 79 insertions, 122 deletions
diff --git a/OpenSim/Region/Environment/Modules/Terrain/PaintBrushes/ErodeSphere.cs b/OpenSim/Region/Environment/Modules/Terrain/PaintBrushes/ErodeSphere.cs
index 2d46fd9..e679189 100644
--- a/OpenSim/Region/Environment/Modules/Terrain/PaintBrushes/ErodeSphere.cs
+++ b/OpenSim/Region/Environment/Modules/Terrain/PaintBrushes/ErodeSphere.cs
@@ -146,51 +146,14 @@ namespace OpenSim.Region.Environment.Modules.Terrain.PaintBrushes
146 return coord; 146 return coord;
147 } 147 }
148 148
149 private double SphericalFactor(double x, double y, double rx, double ry, double size)
150 {
151 double z = size * size - ((x - rx) * (x - rx) + (y - ry) * (y - ry));
152 return z;
153 }
154
155 private double GetBilinearInterpolate(double x, double y, ITerrainChannel map)
156 {
157 int w = map.Width;
158 int h = map.Height;
159
160 if (x > w - 2.0)
161 x = w - 2.0;
162 if (y > h - 2.0)
163 y = h - 2.0;
164 if (x < 0.0)
165 x = 0.0;
166 if (y < 0.0)
167 y = 0.0;
168
169 int stepSize = 1;
170 double h00 = map[(int)x, (int)y];
171 double h10 = map[(int)x + stepSize, (int)y];
172 double h01 = map[(int)x, (int)y + stepSize];
173 double h11 = map[(int)x + stepSize, (int)y + stepSize];
174 double h1 = h00;
175 double h2 = h10;
176 double h3 = h01;
177 double h4 = h11;
178 double a00 = h1;
179 double a10 = h2 - h1;
180 double a01 = h3 - h1;
181 double a11 = h1 - h2 - h3 + h4;
182 double partialx = x - (int)x;
183 double partialz = y - (int)y;
184 double hi = a00 + (a10 * partialx) + (a01 * partialz) + (a11 * partialx * partialz);
185 return hi;
186 }
187
188 #endregion 149 #endregion
189 150
190 #region ITerrainPaintableEffect Members 151 #region ITerrainPaintableEffect Members
191 152
192 public void PaintEffect(ITerrainChannel map, double rx, double ry, double strength, double duration) 153 public void PaintEffect(ITerrainChannel map, double rx, double ry, double strength, double duration)
193 { 154 {
155 strength = TerrainUtil.MetersToSphericalStrength(strength);
156
194 int x, y; 157 int x, y;
195 // Using one 'rain' round for this, so skipping a useless loop 158 // Using one 'rain' round for this, so skipping a useless loop
196 // Will need to adapt back in for the Flood brush 159 // Will need to adapt back in for the Flood brush
@@ -201,7 +164,7 @@ namespace OpenSim.Region.Environment.Modules.Terrain.PaintBrushes
201 // Fill with rain 164 // Fill with rain
202 for (x = 0; x < water.Width; x++) 165 for (x = 0; x < water.Width; x++)
203 for (y = 0; y < water.Height; y++) 166 for (y = 0; y < water.Height; y++)
204 water[x, y] = Math.Max(0.0, SphericalFactor(x, y, rx, ry, strength) * rainHeight * duration); 167 water[x, y] = Math.Max(0.0, TerrainUtil.SphericalFactor(x, y, rx, ry, strength) * rainHeight * duration);
205 168
206 for (int i = 0; i < rounds; i++) 169 for (int i = 0; i < rounds; i++)
207 { 170 {
diff --git a/OpenSim/Region/Environment/Modules/Terrain/PaintBrushes/FlattenSphere.cs b/OpenSim/Region/Environment/Modules/Terrain/PaintBrushes/FlattenSphere.cs
index 0e98111..180f37e 100644
--- a/OpenSim/Region/Environment/Modules/Terrain/PaintBrushes/FlattenSphere.cs
+++ b/OpenSim/Region/Environment/Modules/Terrain/PaintBrushes/FlattenSphere.cs
@@ -74,6 +74,8 @@ namespace OpenSim.Region.Environment.Modules.Terrain.PaintBrushes
74 74
75 public void PaintEffect(ITerrainChannel map, double rx, double ry, double strength, double duration) 75 public void PaintEffect(ITerrainChannel map, double rx, double ry, double strength, double duration)
76 { 76 {
77 strength = TerrainUtil.MetersToSphericalStrength(strength);
78
77 int x, y; 79 int x, y;
78 double[,] tweak = new double[map.Width, map.Height]; 80 double[,] tweak = new double[map.Width, map.Height];
79 81
diff --git a/OpenSim/Region/Environment/Modules/Terrain/PaintBrushes/LowerSphere.cs b/OpenSim/Region/Environment/Modules/Terrain/PaintBrushes/LowerSphere.cs
index 2201584..3478927 100644
--- a/OpenSim/Region/Environment/Modules/Terrain/PaintBrushes/LowerSphere.cs
+++ b/OpenSim/Region/Environment/Modules/Terrain/PaintBrushes/LowerSphere.cs
@@ -36,6 +36,8 @@ namespace OpenSim.Region.Environment.Modules.Terrain.PaintBrushes
36 36
37 public void PaintEffect(ITerrainChannel map, double rx, double ry, double strength, double duration) 37 public void PaintEffect(ITerrainChannel map, double rx, double ry, double strength, double duration)
38 { 38 {
39 strength = TerrainUtil.MetersToSphericalStrength(strength);
40
39 int x, y; 41 int x, y;
40 for (x = 0; x < map.Width; x++) 42 for (x = 0; x < map.Width; x++)
41 { 43 {
diff --git a/OpenSim/Region/Environment/Modules/Terrain/PaintBrushes/NoiseSphere.cs b/OpenSim/Region/Environment/Modules/Terrain/PaintBrushes/NoiseSphere.cs
index 776e31f..4a03a17 100644
--- a/OpenSim/Region/Environment/Modules/Terrain/PaintBrushes/NoiseSphere.cs
+++ b/OpenSim/Region/Environment/Modules/Terrain/PaintBrushes/NoiseSphere.cs
@@ -37,6 +37,8 @@ namespace OpenSim.Region.Environment.Modules.Terrain.PaintBrushes
37 37
38 public void PaintEffect(ITerrainChannel map, double rx, double ry, double strength, double duration) 38 public void PaintEffect(ITerrainChannel map, double rx, double ry, double strength, double duration)
39 { 39 {
40 strength = TerrainUtil.MetersToSphericalStrength(strength);
41
40 int x, y; 42 int x, y;
41 for (x = 0; x < map.Width; x++) 43 for (x = 0; x < map.Width; x++)
42 { 44 {
diff --git a/OpenSim/Region/Environment/Modules/Terrain/PaintBrushes/OlsenSphere.cs b/OpenSim/Region/Environment/Modules/Terrain/PaintBrushes/OlsenSphere.cs
index 8855ce7..65c9b12 100644
--- a/OpenSim/Region/Environment/Modules/Terrain/PaintBrushes/OlsenSphere.cs
+++ b/OpenSim/Region/Environment/Modules/Terrain/PaintBrushes/OlsenSphere.cs
@@ -159,6 +159,8 @@ namespace OpenSim.Region.Environment.Modules.Terrain.PaintBrushes
159 159
160 public void PaintEffect(ITerrainChannel map, double rx, double ry, double strength, double duration) 160 public void PaintEffect(ITerrainChannel map, double rx, double ry, double strength, double duration)
161 { 161 {
162 strength = TerrainUtil.MetersToSphericalStrength(strength);
163
162 int x, y; 164 int x, y;
163 165
164 for (x = 0; x < map.Width; x++) 166 for (x = 0; x < map.Width; x++)
diff --git a/OpenSim/Region/Environment/Modules/Terrain/PaintBrushes/RaiseSphere.cs b/OpenSim/Region/Environment/Modules/Terrain/PaintBrushes/RaiseSphere.cs
index 5b9f410..9091846 100644
--- a/OpenSim/Region/Environment/Modules/Terrain/PaintBrushes/RaiseSphere.cs
+++ b/OpenSim/Region/Environment/Modules/Terrain/PaintBrushes/RaiseSphere.cs
@@ -36,6 +36,8 @@ namespace OpenSim.Region.Environment.Modules.Terrain.PaintBrushes
36 36
37 public void PaintEffect(ITerrainChannel map, double rx, double ry, double strength, double duration) 37 public void PaintEffect(ITerrainChannel map, double rx, double ry, double strength, double duration)
38 { 38 {
39 strength = TerrainUtil.MetersToSphericalStrength(strength);
40
39 int x, y; 41 int x, y;
40 for (x = 0; x < map.Width; x++) 42 for (x = 0; x < map.Width; x++)
41 { 43 {
diff --git a/OpenSim/Region/Environment/Modules/Terrain/PaintBrushes/RevertSphere.cs b/OpenSim/Region/Environment/Modules/Terrain/PaintBrushes/RevertSphere.cs
index 9d9c462..bc98b07 100644
--- a/OpenSim/Region/Environment/Modules/Terrain/PaintBrushes/RevertSphere.cs
+++ b/OpenSim/Region/Environment/Modules/Terrain/PaintBrushes/RevertSphere.cs
@@ -43,6 +43,13 @@ namespace OpenSim.Region.Environment.Modules.Terrain.PaintBrushes
43 43
44 public void PaintEffect(ITerrainChannel map, double rx, double ry, double strength, double duration) 44 public void PaintEffect(ITerrainChannel map, double rx, double ry, double strength, double duration)
45 { 45 {
46 strength = TerrainUtil.MetersToSphericalStrength(strength);
47
48 if (duration > 1.0)
49 duration = 1.0;
50 if (duration < 0)
51 return;
52
46 int x, y; 53 int x, y;
47 for (x = 0; x < map.Width; x++) 54 for (x = 0; x < map.Width; x++)
48 { 55 {
diff --git a/OpenSim/Region/Environment/Modules/Terrain/PaintBrushes/SmoothSphere.cs b/OpenSim/Region/Environment/Modules/Terrain/PaintBrushes/SmoothSphere.cs
index 90bbafc..537f961 100644
--- a/OpenSim/Region/Environment/Modules/Terrain/PaintBrushes/SmoothSphere.cs
+++ b/OpenSim/Region/Environment/Modules/Terrain/PaintBrushes/SmoothSphere.cs
@@ -31,49 +31,12 @@ namespace OpenSim.Region.Environment.Modules.Terrain.PaintBrushes
31{ 31{
32 public class SmoothSphere : ITerrainPaintableEffect 32 public class SmoothSphere : ITerrainPaintableEffect
33 { 33 {
34 private double SphericalFactor(double x, double y, double rx, double ry, double size)
35 {
36 double z = size * size - ((x - rx) * (x - rx) + (y - ry) * (y - ry));
37 return z;
38 }
39
40 private double GetBilinearInterpolate(double x, double y, ITerrainChannel map)
41 {
42 int w = map.Width;
43 int h = map.Height;
44
45 if (x > w - 2.0)
46 x = w - 2.0;
47 if (y > h - 2.0)
48 y = h - 2.0;
49 if (x < 0.0)
50 x = 0.0;
51 if (y < 0.0)
52 y = 0.0;
53
54 int stepSize = 1;
55 double h00 = map[(int)x, (int)y];
56 double h10 = map[(int)x + stepSize, (int)y];
57 double h01 = map[(int)x, (int)y + stepSize];
58 double h11 = map[(int)x + stepSize, (int)y + stepSize];
59 double h1 = h00;
60 double h2 = h10;
61 double h3 = h01;
62 double h4 = h11;
63 double a00 = h1;
64 double a10 = h2 - h1;
65 double a01 = h3 - h1;
66 double a11 = h1 - h2 - h3 + h4;
67 double partialx = x - (int)x;
68 double partialz = y - (int)y;
69 double hi = a00 + (a10 * partialx) + (a01 * partialz) + (a11 * partialx * partialz);
70 return hi;
71 }
72
73 #region ITerrainPaintableEffect Members 34 #region ITerrainPaintableEffect Members
74 35
75 public void PaintEffect(ITerrainChannel map, double rx, double ry, double strength, double duration) 36 public void PaintEffect(ITerrainChannel map, double rx, double ry, double strength, double duration)
76 { 37 {
38 strength = TerrainUtil.MetersToSphericalStrength(strength);
39
77 int x, y; 40 int x, y;
78 double[,] tweak = new double[map.Width, map.Height]; 41 double[,] tweak = new double[map.Width, map.Height];
79 42
@@ -86,7 +49,7 @@ namespace OpenSim.Region.Environment.Modules.Terrain.PaintBrushes
86 { 49 {
87 for (y = 0; y < map.Height; y++) 50 for (y = 0; y < map.Height; y++)
88 { 51 {
89 double z = SphericalFactor(x, y, rx, ry, strength); 52 double z = TerrainUtil.SphericalFactor(x, y, rx, ry, strength);
90 53
91 if (z > 0) // add in non-zero amount 54 if (z > 0) // add in non-zero amount
92 { 55 {
@@ -98,7 +61,7 @@ namespace OpenSim.Region.Environment.Modules.Terrain.PaintBrushes
98 for (l = 0.0 - area; l < area; l += step) 61 for (l = 0.0 - area; l < area; l += step)
99 { 62 {
100 avgsteps++; 63 avgsteps++;
101 average += GetBilinearInterpolate(x + n, y + l, map); 64 average += TerrainUtil.GetBilinearInterpolate(x + n, y + l, map);
102 } 65 }
103 } 66 }
104 tweak[x, y] = average / avgsteps; 67 tweak[x, y] = average / avgsteps;
@@ -110,7 +73,7 @@ namespace OpenSim.Region.Environment.Modules.Terrain.PaintBrushes
110 { 73 {
111 for (y = 0; y < map.Height; y++) 74 for (y = 0; y < map.Height; y++)
112 { 75 {
113 double z = SphericalFactor(x, y, rx, ry, strength); 76 double z = TerrainUtil.SphericalFactor(x, y, rx, ry, strength);
114 77
115 if (z > 0) // add in non-zero amount 78 if (z > 0) // add in non-zero amount
116 { 79 {
diff --git a/OpenSim/Region/Environment/Modules/Terrain/PaintBrushes/WeatherSphere.cs b/OpenSim/Region/Environment/Modules/Terrain/PaintBrushes/WeatherSphere.cs
index cac3d35..ef0f9fd 100644
--- a/OpenSim/Region/Environment/Modules/Terrain/PaintBrushes/WeatherSphere.cs
+++ b/OpenSim/Region/Environment/Modules/Terrain/PaintBrushes/WeatherSphere.cs
@@ -142,58 +142,21 @@ namespace OpenSim.Region.Environment.Modules.Terrain.PaintBrushes
142 return coord; 142 return coord;
143 } 143 }
144 144
145 private double SphericalFactor(double x, double y, double rx, double ry, double size)
146 {
147 double z = size * size - ((x - rx) * (x - rx) + (y - ry) * (y - ry));
148 return z;
149 }
150
151 private double GetBilinearInterpolate(double x, double y, ITerrainChannel map)
152 {
153 int w = map.Width;
154 int h = map.Height;
155
156 if (x > w - 2.0)
157 x = w - 2.0;
158 if (y > h - 2.0)
159 y = h - 2.0;
160 if (x < 0.0)
161 x = 0.0;
162 if (y < 0.0)
163 y = 0.0;
164
165 int stepSize = 1;
166 double h00 = map[(int)x, (int)y];
167 double h10 = map[(int)x + stepSize, (int)y];
168 double h01 = map[(int)x, (int)y + stepSize];
169 double h11 = map[(int)x + stepSize, (int)y + stepSize];
170 double h1 = h00;
171 double h2 = h10;
172 double h3 = h01;
173 double h4 = h11;
174 double a00 = h1;
175 double a10 = h2 - h1;
176 double a01 = h3 - h1;
177 double a11 = h1 - h2 - h3 + h4;
178 double partialx = x - (int)x;
179 double partialz = y - (int)y;
180 double hi = a00 + (a10 * partialx) + (a01 * partialz) + (a11 * partialx * partialz);
181 return hi;
182 }
183
184 #endregion 145 #endregion
185 146
186 #region ITerrainPaintableEffect Members 147 #region ITerrainPaintableEffect Members
187 148
188 public void PaintEffect(ITerrainChannel map, double rx, double ry, double strength, double duration) 149 public void PaintEffect(ITerrainChannel map, double rx, double ry, double strength, double duration)
189 { 150 {
151 strength = TerrainUtil.MetersToSphericalStrength(strength);
152
190 int x, y; 153 int x, y;
191 154
192 for (x = 0; x < map.Width; x++) 155 for (x = 0; x < map.Width; x++)
193 { 156 {
194 for (y = 0; y < map.Height; y++) 157 for (y = 0; y < map.Height; y++)
195 { 158 {
196 double z = SphericalFactor(x, y, rx, ry, strength); 159 double z = TerrainUtil.SphericalFactor(x, y, rx, ry, strength);
197 160
198 if (z > 0) // add in non-zero amount 161 if (z > 0) // add in non-zero amount
199 { 162 {
diff --git a/OpenSim/Region/Environment/Modules/Terrain/TerrainUtil.cs b/OpenSim/Region/Environment/Modules/Terrain/TerrainUtil.cs
new file mode 100644
index 0000000..c52d2c8
--- /dev/null
+++ b/OpenSim/Region/Environment/Modules/Terrain/TerrainUtil.cs
@@ -0,0 +1,51 @@
1using System;
2using OpenSim.Region.Environment.Interfaces;
3
4namespace OpenSim.Region.Environment.Modules.Terrain
5{
6 public static class TerrainUtil
7 {
8 public static double MetersToSphericalStrength(double size)
9 {
10 return Math.Pow(2, size);
11 }
12
13 public static double SphericalFactor(double x, double y, double rx, double ry, double size)
14 {
15 return size * size - ((x - rx) * (x - rx) + (y - ry) * (y - ry));
16 }
17
18 public static double GetBilinearInterpolate(double x, double y, ITerrainChannel map)
19 {
20 int w = map.Width;
21 int h = map.Height;
22
23 if (x > w - 2.0)
24 x = w - 2.0;
25 if (y > h - 2.0)
26 y = h - 2.0;
27 if (x < 0.0)
28 x = 0.0;
29 if (y < 0.0)
30 y = 0.0;
31
32 int stepSize = 1;
33 double h00 = map[(int)x, (int)y];
34 double h10 = map[(int)x + stepSize, (int)y];
35 double h01 = map[(int)x, (int)y + stepSize];
36 double h11 = map[(int)x + stepSize, (int)y + stepSize];
37 double h1 = h00;
38 double h2 = h10;
39 double h3 = h01;
40 double h4 = h11;
41 double a00 = h1;
42 double a10 = h2 - h1;
43 double a01 = h3 - h1;
44 double a11 = h1 - h2 - h3 + h4;
45 double partialx = x - (int)x;
46 double partialz = y - (int)y;
47 double hi = a00 + (a10 * partialx) + (a01 * partialz) + (a11 * partialx * partialz);
48 return hi;
49 }
50 }
51}