diff options
author | lbsa71 | 2007-10-30 09:05:31 +0000 |
---|---|---|
committer | lbsa71 | 2007-10-30 09:05:31 +0000 |
commit | 67e12b95ea7b68f4904a7484d77ecfd787d16d0c (patch) | |
tree | 20b00d24c8a7617017960432ec044852e3ad5fa9 /OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel | |
parent | * Deleted .user file (diff) | |
download | opensim-SC-67e12b95ea7b68f4904a7484d77ecfd787d16d0c.zip opensim-SC-67e12b95ea7b68f4904a7484d77ecfd787d16d0c.tar.gz opensim-SC-67e12b95ea7b68f4904a7484d77ecfd787d16d0c.tar.bz2 opensim-SC-67e12b95ea7b68f4904a7484d77ecfd787d16d0c.tar.xz |
* Optimized usings
* Shortened type references
* Removed redundant 'this' qualifier
Diffstat (limited to '')
19 files changed, 240 insertions, 282 deletions
diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Channel.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Channel.cs index 093bfb1..4cb70c2 100644 --- a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Channel.cs +++ b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Channel.cs | |||
@@ -26,12 +26,7 @@ | |||
26 | * | 26 | * |
27 | */ | 27 | */ |
28 | 28 | ||
29 | using System; | 29 | /* Channel |
30 | using System.Collections.Generic; | ||
31 | using System.Text; | ||
32 | |||
33 | |||
34 | /* Channel | ||
35 | * A channel is a single heightmap array | 30 | * A channel is a single heightmap array |
36 | * */ | 31 | * */ |
37 | 32 | ||
@@ -50,17 +45,16 @@ namespace libTerrain | |||
50 | { | 45 | { |
51 | w = 256; | 46 | w = 256; |
52 | h = 256; | 47 | h = 256; |
53 | map = new double[w, h]; | 48 | map = new double[w,h]; |
54 | diff = new int[(int)(w / 16), (int)(h / 16)]; | 49 | diff = new int[(int) (w/16),(int) (h/16)]; |
55 | } | 50 | } |
56 | 51 | ||
57 | public Channel(int width, int height) | 52 | public Channel(int width, int height) |
58 | { | 53 | { |
59 | w = width; | 54 | w = width; |
60 | h = height; | 55 | h = height; |
61 | map = new double[w, h]; | 56 | map = new double[w,h]; |
62 | diff = new int[(int)(w / 16), (int)(h / 16)]; | 57 | diff = new int[(int) (w/16),(int) (h/16)]; |
63 | } | 58 | } |
64 | |||
65 | } | 59 | } |
66 | } | 60 | } \ No newline at end of file |
diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Common.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Common.cs index 730f206..2ad784b 100644 --- a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Common.cs +++ b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Common.cs | |||
@@ -28,8 +28,6 @@ | |||
28 | 28 | ||
29 | 29 | ||
30 | using System; | 30 | using System; |
31 | using System.Collections.Generic; | ||
32 | using System.Text; | ||
33 | 31 | ||
34 | namespace libTerrain | 32 | namespace libTerrain |
35 | { | 33 | { |
@@ -39,6 +37,7 @@ namespace libTerrain | |||
39 | { | 37 | { |
40 | return w; | 38 | return w; |
41 | } | 39 | } |
40 | |||
42 | public int GetHeight() | 41 | public int GetHeight() |
43 | { | 42 | { |
44 | return h; | 43 | return h; |
@@ -47,7 +46,7 @@ namespace libTerrain | |||
47 | public Channel Copy() | 46 | public Channel Copy() |
48 | { | 47 | { |
49 | Channel x = new Channel(w, h); | 48 | Channel x = new Channel(w, h); |
50 | x.map = (double[,])this.map.Clone(); | 49 | x.map = (double[,]) map.Clone(); |
51 | return x; | 50 | return x; |
52 | } | 51 | } |
53 | 52 | ||
@@ -58,9 +57,9 @@ namespace libTerrain | |||
58 | 57 | ||
59 | public void SetDiff(int val) | 58 | public void SetDiff(int val) |
60 | { | 59 | { |
61 | for (int x = 0; x < w / 16; x++) | 60 | for (int x = 0; x < w/16; x++) |
62 | { | 61 | { |
63 | for (int y = 0; y < h / 16; y++) | 62 | for (int y = 0; y < h/16; y++) |
64 | { | 63 | { |
65 | diff[x, y] = val; | 64 | diff[x, y] = val; |
66 | } | 65 | } |
@@ -69,7 +68,7 @@ namespace libTerrain | |||
69 | 68 | ||
70 | public void SetDiff(int x, int y) | 69 | public void SetDiff(int x, int y) |
71 | { | 70 | { |
72 | diff[x / 16, y / 16]++; | 71 | diff[x/16, y/16]++; |
73 | } | 72 | } |
74 | 73 | ||
75 | public void Set(int x, int y, double val) | 74 | public void Set(int x, int y, double val) |
@@ -124,10 +123,10 @@ namespace libTerrain | |||
124 | y = 0.0; | 123 | y = 0.0; |
125 | 124 | ||
126 | int stepSize = 1; | 125 | int stepSize = 1; |
127 | double h00 = Get((int)x, (int)y); | 126 | double h00 = Get((int) x, (int) y); |
128 | double h10 = Get((int)x + stepSize, (int)y); | 127 | double h10 = Get((int) x + stepSize, (int) y); |
129 | double h01 = Get((int)x, (int)y + stepSize); | 128 | double h01 = Get((int) x, (int) y + stepSize); |
130 | double h11 = Get((int)x + stepSize, (int)y + stepSize); | 129 | double h11 = Get((int) x + stepSize, (int) y + stepSize); |
131 | double h1 = h00; | 130 | double h1 = h00; |
132 | double h2 = h10; | 131 | double h2 = h10; |
133 | double h3 = h01; | 132 | double h3 = h01; |
@@ -136,9 +135,9 @@ namespace libTerrain | |||
136 | double a10 = h2 - h1; | 135 | double a10 = h2 - h1; |
137 | double a01 = h3 - h1; | 136 | double a01 = h3 - h1; |
138 | double a11 = h1 - h2 - h3 + h4; | 137 | double a11 = h1 - h2 - h3 + h4; |
139 | double partialx = x - (int)x; | 138 | double partialx = x - (int) x; |
140 | double partialz = y - (int)y; | 139 | double partialz = y - (int) y; |
141 | double hi = a00 + (a10 * partialx) + (a01 * partialz) + (a11 * partialx * partialz); | 140 | double hi = a00 + (a10*partialx) + (a01*partialz) + (a11*partialx*partialz); |
142 | return hi; | 141 | return hi; |
143 | } | 142 | } |
144 | 143 | ||
@@ -159,7 +158,7 @@ namespace libTerrain | |||
159 | { | 158 | { |
160 | SetDiff(x, y); | 159 | SetDiff(x, y); |
161 | 160 | ||
162 | map[x % w, y % h] = val; | 161 | map[x%w, y%h] = val; |
163 | } | 162 | } |
164 | 163 | ||
165 | public void SetWrapClip(int x, int y, double val) | 164 | public void SetWrapClip(int x, int y, double val) |
@@ -171,7 +170,7 @@ namespace libTerrain | |||
171 | if (val < 0.0) | 170 | if (val < 0.0) |
172 | val = 0.0; | 171 | val = 0.0; |
173 | 172 | ||
174 | map[x % w, y % h] = val; | 173 | map[x%w, y%h] = val; |
175 | } | 174 | } |
176 | 175 | ||
177 | public void Fill(double val) | 176 | public void Fill(double val) |
@@ -255,7 +254,7 @@ namespace libTerrain | |||
255 | 254 | ||
256 | public double Avg() | 255 | public double Avg() |
257 | { | 256 | { |
258 | return Sum() / (w * h); | 257 | return Sum()/(w*h); |
259 | } | 258 | } |
260 | 259 | ||
261 | public bool ContainsNaN() | 260 | public bool ContainsNaN() |
@@ -274,4 +273,4 @@ namespace libTerrain | |||
274 | return false; | 273 | return false; |
275 | } | 274 | } |
276 | } | 275 | } |
277 | } | 276 | } \ No newline at end of file |
diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Editing/Flatten.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Editing/Flatten.cs index 45bb06b..e753847 100644 --- a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Editing/Flatten.cs +++ b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Editing/Flatten.cs | |||
@@ -28,8 +28,6 @@ | |||
28 | 28 | ||
29 | 29 | ||
30 | using System; | 30 | using System; |
31 | using System.Collections.Generic; | ||
32 | using System.Text; | ||
33 | 31 | ||
34 | namespace libTerrain | 32 | namespace libTerrain |
35 | { | 33 | { |
@@ -58,12 +56,12 @@ namespace libTerrain | |||
58 | 56 | ||
59 | // Establish the average height under the area | 57 | // Establish the average height under the area |
60 | Channel newmap = new Channel(w, h); | 58 | Channel newmap = new Channel(w, h); |
61 | newmap.map = (double[,])map.Clone(); | 59 | newmap.map = (double[,]) map.Clone(); |
62 | 60 | ||
63 | newmap *= temp; | 61 | newmap *= temp; |
64 | 62 | ||
65 | double total_terrain = newmap.Sum(); | 63 | double total_terrain = newmap.Sum(); |
66 | double avg_height = total_terrain / total_mod; | 64 | double avg_height = total_terrain/total_mod; |
67 | 65 | ||
68 | // Create a flat terrain using the average height | 66 | // Create a flat terrain using the average height |
69 | Channel flat = new Channel(w, h); | 67 | Channel flat = new Channel(w, h); |
@@ -72,7 +70,6 @@ namespace libTerrain | |||
72 | // Blend the current terrain with the average height terrain | 70 | // Blend the current terrain with the average height terrain |
73 | // using the "raised" empty terrain as a mask | 71 | // using the "raised" empty terrain as a mask |
74 | Blend(flat, temp); | 72 | Blend(flat, temp); |
75 | |||
76 | } | 73 | } |
77 | 74 | ||
78 | private void FlattenFast(double rx, double ry, double size, double amount) | 75 | private void FlattenFast(double rx, double ry, double size, double amount) |
@@ -81,10 +78,10 @@ namespace libTerrain | |||
81 | double avg = 0; | 78 | double avg = 0; |
82 | double div = 0; | 79 | double div = 0; |
83 | 80 | ||
84 | int minX = Math.Max(0, (int)(rx - (size + 1))); | 81 | int minX = Math.Max(0, (int) (rx - (size + 1))); |
85 | int maxX = Math.Min(w, (int)(rx + (size + 1))); | 82 | int maxX = Math.Min(w, (int) (rx + (size + 1))); |
86 | int minY = Math.Max(0, (int)(ry - (size + 1))); | 83 | int minY = Math.Max(0, (int) (ry - (size + 1))); |
87 | int maxY = Math.Min(h, (int)(ry + (size + 1))); | 84 | int maxY = Math.Min(h, (int) (ry + (size + 1))); |
88 | 85 | ||
89 | for (x = minX; x < maxX; x++) | 86 | for (x = minX; x < maxX; x++) |
90 | { | 87 | { |
@@ -92,17 +89,17 @@ namespace libTerrain | |||
92 | { | 89 | { |
93 | double z = size; | 90 | double z = size; |
94 | z *= z; | 91 | z *= z; |
95 | z -= ((x - rx) * (x - rx)) + ((y - ry) * (y - ry)); | 92 | z -= ((x - rx)*(x - rx)) + ((y - ry)*(y - ry)); |
96 | 93 | ||
97 | if (z < 0) | 94 | if (z < 0) |
98 | z = 0; | 95 | z = 0; |
99 | 96 | ||
100 | avg += z * amount; | 97 | avg += z*amount; |
101 | div += z; | 98 | div += z; |
102 | } | 99 | } |
103 | } | 100 | } |
104 | 101 | ||
105 | double height = avg / div; | 102 | double height = avg/div; |
106 | 103 | ||
107 | for (x = minX; x < maxX; x++) | 104 | for (x = minX; x < maxX; x++) |
108 | { | 105 | { |
@@ -110,7 +107,7 @@ namespace libTerrain | |||
110 | { | 107 | { |
111 | double z = size; | 108 | double z = size; |
112 | z *= z; | 109 | z *= z; |
113 | z -= ((x - rx) * (x - rx)) + ((y - ry) * (y - ry)); | 110 | z -= ((x - rx)*(x - rx)) + ((y - ry)*(y - ry)); |
114 | 111 | ||
115 | if (z < 0) | 112 | if (z < 0) |
116 | z = 0; | 113 | z = 0; |
@@ -123,19 +120,19 @@ namespace libTerrain | |||
123 | public void Flatten(Channel mask, double amount) | 120 | public void Flatten(Channel mask, double amount) |
124 | { | 121 | { |
125 | // Generate the mask | 122 | // Generate the mask |
126 | Channel temp = mask * amount; | 123 | Channel temp = mask*amount; |
127 | temp.Clip(0, 1); // Cut off out-of-bounds values | 124 | temp.Clip(0, 1); // Cut off out-of-bounds values |
128 | 125 | ||
129 | double total_mod = temp.Sum(); | 126 | double total_mod = temp.Sum(); |
130 | 127 | ||
131 | // Establish the average height under the area | 128 | // Establish the average height under the area |
132 | Channel map = new Channel(w, h); | 129 | Channel map = new Channel(w, h); |
133 | map.map = (double[,])this.map.Clone(); | 130 | map.map = (double[,]) this.map.Clone(); |
134 | 131 | ||
135 | map *= temp; | 132 | map *= temp; |
136 | 133 | ||
137 | double total_terrain = map.Sum(); | 134 | double total_terrain = map.Sum(); |
138 | double avg_height = total_terrain / total_mod; | 135 | double avg_height = total_terrain/total_mod; |
139 | 136 | ||
140 | // Create a flat terrain using the average height | 137 | // Create a flat terrain using the average height |
141 | Channel flat = new Channel(w, h); | 138 | Channel flat = new Channel(w, h); |
diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Editing/Raise.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Editing/Raise.cs index 15631df..9e8f3a4 100644 --- a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Editing/Raise.cs +++ b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Editing/Raise.cs | |||
@@ -28,8 +28,6 @@ | |||
28 | 28 | ||
29 | 29 | ||
30 | using System; | 30 | using System; |
31 | using System.Collections.Generic; | ||
32 | using System.Text; | ||
33 | 31 | ||
34 | namespace libTerrain | 32 | namespace libTerrain |
35 | { | 33 | { |
@@ -63,12 +61,12 @@ namespace libTerrain | |||
63 | { | 61 | { |
64 | double z = size; | 62 | double z = size; |
65 | z *= z; | 63 | z *= z; |
66 | z -= ((x - rx) * (x - rx)) + ((y - ry) * (y - ry)); | 64 | z -= ((x - rx)*(x - rx)) + ((y - ry)*(y - ry)); |
67 | 65 | ||
68 | if (z < 0) | 66 | if (z < 0) |
69 | z = 0; | 67 | z = 0; |
70 | 68 | ||
71 | Set(x, y, map[x, y] + (z * amount)); | 69 | Set(x, y, map[x, y] + (z*amount)); |
72 | } | 70 | } |
73 | } | 71 | } |
74 | } | 72 | } |
@@ -88,12 +86,12 @@ namespace libTerrain | |||
88 | for (y = 0; y < h; y++) | 86 | for (y = 0; y < h; y++) |
89 | { | 87 | { |
90 | double z = size; | 88 | double z = size; |
91 | z -= Math.Sqrt(((x - rx) * (x - rx)) + ((y - ry) * (y - ry))); | 89 | z -= Math.Sqrt(((x - rx)*(x - rx)) + ((y - ry)*(y - ry))); |
92 | 90 | ||
93 | if (z < 0) | 91 | if (z < 0) |
94 | z = 0; | 92 | z = 0; |
95 | 93 | ||
96 | Set(x, y, map[x, y] + (z * amount)); | 94 | Set(x, y, map[x, y] + (z*amount)); |
97 | } | 95 | } |
98 | } | 96 | } |
99 | } | 97 | } |
@@ -126,12 +124,12 @@ namespace libTerrain | |||
126 | { | 124 | { |
127 | double z = size; | 125 | double z = size; |
128 | z *= z; | 126 | z *= z; |
129 | z -= ((x - rx) * (x - rx)) + ((y - ry) * (y - ry)); | 127 | z -= ((x - rx)*(x - rx)) + ((y - ry)*(y - ry)); |
130 | 128 | ||
131 | if (z < 0) | 129 | if (z < 0) |
132 | z = 0; | 130 | z = 0; |
133 | 131 | ||
134 | Set(x, y, map[x, y] - (z * amount)); | 132 | Set(x, y, map[x, y] - (z*amount)); |
135 | } | 133 | } |
136 | } | 134 | } |
137 | } | 135 | } |
diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/File.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/File.cs index 5949759..b4eda47 100644 --- a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/File.cs +++ b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/File.cs | |||
@@ -27,9 +27,8 @@ | |||
27 | */ | 27 | */ |
28 | 28 | ||
29 | using System; | 29 | using System; |
30 | using System.Collections.Generic; | ||
31 | using System.Text; | ||
32 | using System.Drawing; | 30 | using System.Drawing; |
31 | using System.Drawing.Imaging; | ||
33 | 32 | ||
34 | namespace libTerrain | 33 | namespace libTerrain |
35 | { | 34 | { |
@@ -48,7 +47,7 @@ namespace libTerrain | |||
48 | for (y = 0; y < bit.Height; y++) | 47 | for (y = 0; y < bit.Height; y++) |
49 | { | 48 | { |
50 | Color val = bit.GetPixel(x, y); | 49 | Color val = bit.GetPixel(x, y); |
51 | chan.map[x, y] = (((double)val.R + (double)val.G + (double)val.B) / 3.0) / 255.0; | 50 | chan.map[x, y] = (((double) val.R + (double) val.G + (double) val.B)/3.0)/255.0; |
52 | } | 51 | } |
53 | } | 52 | } |
54 | 53 | ||
@@ -57,21 +56,21 @@ namespace libTerrain | |||
57 | 56 | ||
58 | public void SaveImage(string filename) | 57 | public void SaveImage(string filename) |
59 | { | 58 | { |
60 | Channel outmap = this.Copy(); | 59 | Channel outmap = Copy(); |
61 | outmap.Normalise(); | 60 | outmap.Normalise(); |
62 | 61 | ||
63 | Bitmap bit = new Bitmap(w, h, System.Drawing.Imaging.PixelFormat.Format24bppRgb); | 62 | Bitmap bit = new Bitmap(w, h, PixelFormat.Format24bppRgb); |
64 | int x, y; | 63 | int x, y; |
65 | for (x = 0; x < w; x++) | 64 | for (x = 0; x < w; x++) |
66 | { | 65 | { |
67 | for (y = 0; y < h; y++) | 66 | for (y = 0; y < h; y++) |
68 | { | 67 | { |
69 | int val = Math.Min(255, (int)(outmap.map[x,y] * 255)); | 68 | int val = Math.Min(255, (int) (outmap.map[x, y]*255)); |
70 | Color col = Color.FromArgb(val,val,val); | 69 | Color col = Color.FromArgb(val, val, val); |
71 | bit.SetPixel(x, y, col); | 70 | bit.SetPixel(x, y, col); |
72 | } | 71 | } |
73 | } | 72 | } |
74 | bit.Save(filename); | 73 | bit.Save(filename); |
75 | } | 74 | } |
76 | } | 75 | } |
77 | } | 76 | } \ No newline at end of file |
diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Fracture.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Fracture.cs index 3a9b7f7..65badd1 100644 --- a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Fracture.cs +++ b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Fracture.cs | |||
@@ -27,8 +27,6 @@ | |||
27 | */ | 27 | */ |
28 | 28 | ||
29 | using System; | 29 | using System; |
30 | using System.Collections.Generic; | ||
31 | using System.Text; | ||
32 | 30 | ||
33 | namespace libTerrain | 31 | namespace libTerrain |
34 | { | 32 | { |
@@ -60,19 +58,19 @@ namespace libTerrain | |||
60 | } | 58 | } |
61 | if (val < 512) | 59 | if (val < 512) |
62 | { | 60 | { |
63 | ret[0] = (val % 256); | 61 | ret[0] = (val%256); |
64 | ret[1] = 255; | 62 | ret[1] = 255; |
65 | return ret; | 63 | return ret; |
66 | } | 64 | } |
67 | if (val < 768) | 65 | if (val < 768) |
68 | { | 66 | { |
69 | ret[0] = 255; | 67 | ret[0] = 255; |
70 | ret[1] = 255 - (val % 256); | 68 | ret[1] = 255 - (val%256); |
71 | return ret; | 69 | return ret; |
72 | } | 70 | } |
73 | if (val < 1024) | 71 | if (val < 1024) |
74 | { | 72 | { |
75 | ret[0] = 255 - (val % 256); | 73 | ret[0] = 255 - (val%256); |
76 | ret[1] = 255; | 74 | ret[1] = 255; |
77 | return ret; | 75 | return ret; |
78 | } | 76 | } |
@@ -100,7 +98,7 @@ namespace libTerrain | |||
100 | { | 98 | { |
101 | for (int y = 0; y < h; y++) | 99 | for (int y = 0; y < h; y++) |
102 | { | 100 | { |
103 | double miny = Tools.LinearInterpolate(a[1], b[1], (double)x / (double)w); | 101 | double miny = Tools.LinearInterpolate(a[1], b[1], (double) x/(double) w); |
104 | 102 | ||
105 | if (v >= 0.5) | 103 | if (v >= 0.5) |
106 | { | 104 | { |
diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Gradient.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Gradient.cs index 8a1b048..b6e2491 100644 --- a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Gradient.cs +++ b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Gradient.cs | |||
@@ -26,15 +26,10 @@ | |||
26 | * | 26 | * |
27 | */ | 27 | */ |
28 | 28 | ||
29 | using System; | ||
30 | using System.Collections.Generic; | ||
31 | using System.Text; | ||
32 | |||
33 | namespace libTerrain | 29 | namespace libTerrain |
34 | { | 30 | { |
35 | partial class Channel | 31 | partial class Channel |
36 | { | 32 | { |
37 | |||
38 | public void GradientCube() | 33 | public void GradientCube() |
39 | { | 34 | { |
40 | SetDiff(); | 35 | SetDiff(); |
diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/HillPlanter.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/HillPlanter.cs index 7cea800..6806748 100644 --- a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/HillPlanter.cs +++ b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/HillPlanter.cs | |||
@@ -27,8 +27,6 @@ | |||
27 | */ | 27 | */ |
28 | 28 | ||
29 | using System; | 29 | using System; |
30 | using System.Collections.Generic; | ||
31 | using System.Text; | ||
32 | 30 | ||
33 | namespace libTerrain | 31 | namespace libTerrain |
34 | { | 32 | { |
@@ -44,7 +42,8 @@ namespace libTerrain | |||
44 | /// <param name="island">Whether to bias hills towards the center of the map</param> | 42 | /// <param name="island">Whether to bias hills towards the center of the map</param> |
45 | /// <param name="additive">Whether to add hills together or to pick the largest value</param> | 43 | /// <param name="additive">Whether to add hills together or to pick the largest value</param> |
46 | /// <param name="noisy">Generates hill-shaped noise instead of consistent hills</param> | 44 | /// <param name="noisy">Generates hill-shaped noise instead of consistent hills</param> |
47 | public void HillsSpheres(int number, double scale_min, double scale_range, bool island, bool additive, bool noisy) | 45 | public void HillsSpheres(int number, double scale_min, double scale_range, bool island, bool additive, |
46 | bool noisy) | ||
48 | { | 47 | { |
49 | SetDiff(); | 48 | SetDiff(); |
50 | 49 | ||
@@ -55,20 +54,20 @@ namespace libTerrain | |||
55 | 54 | ||
56 | for (i = 0; i < number; i++) | 55 | for (i = 0; i < number; i++) |
57 | { | 56 | { |
58 | double rx = Math.Min(255.0, random.NextDouble() * w); | 57 | double rx = Math.Min(255.0, random.NextDouble()*w); |
59 | double ry = Math.Min(255.0, random.NextDouble() * h); | 58 | double ry = Math.Min(255.0, random.NextDouble()*h); |
60 | double rand = random.NextDouble(); | 59 | double rand = random.NextDouble(); |
61 | 60 | ||
62 | if (island) | 61 | if (island) |
63 | { | 62 | { |
64 | // Move everything towards the center | 63 | // Move everything towards the center |
65 | rx -= w / 2; | 64 | rx -= w/2; |
66 | rx /= 2; | 65 | rx /= 2; |
67 | rx += w / 2; | 66 | rx += w/2; |
68 | 67 | ||
69 | ry -= h / 2; | 68 | ry -= h/2; |
70 | ry /= 2; | 69 | ry /= 2; |
71 | ry += h / 2; | 70 | ry += h/2; |
72 | } | 71 | } |
73 | 72 | ||
74 | for (x = 0; x < w; x++) | 73 | for (x = 0; x < w; x++) |
@@ -78,9 +77,9 @@ namespace libTerrain | |||
78 | if (noisy) | 77 | if (noisy) |
79 | rand = random.NextDouble(); | 78 | rand = random.NextDouble(); |
80 | 79 | ||
81 | double z = (scale_min + (scale_range * rand)); | 80 | double z = (scale_min + (scale_range*rand)); |
82 | z *= z; | 81 | z *= z; |
83 | z -= ((x - rx) * (x - rx)) + ((y - ry) * (y - ry)); | 82 | z -= ((x - rx)*(x - rx)) + ((y - ry)*(y - ry)); |
84 | 83 | ||
85 | if (z < 0) | 84 | if (z < 0) |
86 | z = 0; | 85 | z = 0; |
@@ -121,20 +120,20 @@ namespace libTerrain | |||
121 | 120 | ||
122 | for (i = 0; i < number; i++) | 121 | for (i = 0; i < number; i++) |
123 | { | 122 | { |
124 | double rx = Math.Min(255.0, random.NextDouble() * w); | 123 | double rx = Math.Min(255.0, random.NextDouble()*w); |
125 | double ry = Math.Min(255.0, random.NextDouble() * h); | 124 | double ry = Math.Min(255.0, random.NextDouble()*h); |
126 | double rand = random.NextDouble(); | 125 | double rand = random.NextDouble(); |
127 | 126 | ||
128 | if (island) | 127 | if (island) |
129 | { | 128 | { |
130 | // Move everything towards the center | 129 | // Move everything towards the center |
131 | rx -= w / 2; | 130 | rx -= w/2; |
132 | rx /= 2; | 131 | rx /= 2; |
133 | rx += w / 2; | 132 | rx += w/2; |
134 | 133 | ||
135 | ry -= h / 2; | 134 | ry -= h/2; |
136 | ry /= 2; | 135 | ry /= 2; |
137 | ry += h / 2; | 136 | ry += h/2; |
138 | } | 137 | } |
139 | 138 | ||
140 | for (x = 0; x < w; x++) | 139 | for (x = 0; x < w; x++) |
@@ -144,8 +143,8 @@ namespace libTerrain | |||
144 | if (noisy) | 143 | if (noisy) |
145 | rand = random.NextDouble(); | 144 | rand = random.NextDouble(); |
146 | 145 | ||
147 | double z = (scale_min + (scale_range * rand)); | 146 | double z = (scale_min + (scale_range*rand)); |
148 | z -= Math.Sqrt(((x - rx) * (x - rx)) + ((y - ry) * (y - ry))); | 147 | z -= Math.Sqrt(((x - rx)*(x - rx)) + ((y - ry)*(y - ry))); |
149 | 148 | ||
150 | if (z < 0) | 149 | if (z < 0) |
151 | z = 0; | 150 | z = 0; |
@@ -176,20 +175,20 @@ namespace libTerrain | |||
176 | 175 | ||
177 | for (i = 0; i < number; i++) | 176 | for (i = 0; i < number; i++) |
178 | { | 177 | { |
179 | double rx = Math.Min(255.0, random.NextDouble() * w); | 178 | double rx = Math.Min(255.0, random.NextDouble()*w); |
180 | double ry = Math.Min(255.0, random.NextDouble() * h); | 179 | double ry = Math.Min(255.0, random.NextDouble()*h); |
181 | double rand = random.NextDouble(); | 180 | double rand = random.NextDouble(); |
182 | 181 | ||
183 | if (island) | 182 | if (island) |
184 | { | 183 | { |
185 | // Move everything towards the center | 184 | // Move everything towards the center |
186 | rx -= w / 2; | 185 | rx -= w/2; |
187 | rx /= 2; | 186 | rx /= 2; |
188 | rx += w / 2; | 187 | rx += w/2; |
189 | 188 | ||
190 | ry -= h / 2; | 189 | ry -= h/2; |
191 | ry /= 2; | 190 | ry /= 2; |
192 | ry += h / 2; | 191 | ry += h/2; |
193 | } | 192 | } |
194 | 193 | ||
195 | for (x = 0; x < w; x++) | 194 | for (x = 0; x < w; x++) |
@@ -199,8 +198,8 @@ namespace libTerrain | |||
199 | if (noisy) | 198 | if (noisy) |
200 | rand = random.NextDouble(); | 199 | rand = random.NextDouble(); |
201 | 200 | ||
202 | double z = (scale_min + (scale_range * rand)); | 201 | double z = (scale_min + (scale_range*rand)); |
203 | z -= Math.Abs(x-rx) + Math.Abs(y-ry); | 202 | z -= Math.Abs(x - rx) + Math.Abs(y - ry); |
204 | //z -= Math.Sqrt(((x - rx) * (x - rx)) + ((y - ry) * (y - ry))); | 203 | //z -= Math.Sqrt(((x - rx) * (x - rx)) + ((y - ry) * (y - ry))); |
205 | 204 | ||
206 | if (z < 0) | 205 | if (z < 0) |
@@ -221,7 +220,8 @@ namespace libTerrain | |||
221 | Normalise(); | 220 | Normalise(); |
222 | } | 221 | } |
223 | 222 | ||
224 | public void HillsSquared(int number, double scale_min, double scale_range, bool island, bool additive, bool noisy) | 223 | public void HillsSquared(int number, double scale_min, double scale_range, bool island, bool additive, |
224 | bool noisy) | ||
225 | { | 225 | { |
226 | SetDiff(); | 226 | SetDiff(); |
227 | 227 | ||
@@ -232,20 +232,20 @@ namespace libTerrain | |||
232 | 232 | ||
233 | for (i = 0; i < number; i++) | 233 | for (i = 0; i < number; i++) |
234 | { | 234 | { |
235 | double rx = Math.Min(255.0, random.NextDouble() * w); | 235 | double rx = Math.Min(255.0, random.NextDouble()*w); |
236 | double ry = Math.Min(255.0, random.NextDouble() * h); | 236 | double ry = Math.Min(255.0, random.NextDouble()*h); |
237 | double rand = random.NextDouble(); | 237 | double rand = random.NextDouble(); |
238 | 238 | ||
239 | if (island) | 239 | if (island) |
240 | { | 240 | { |
241 | // Move everything towards the center | 241 | // Move everything towards the center |
242 | rx -= w / 2; | 242 | rx -= w/2; |
243 | rx /= 2; | 243 | rx /= 2; |
244 | rx += w / 2; | 244 | rx += w/2; |
245 | 245 | ||
246 | ry -= h / 2; | 246 | ry -= h/2; |
247 | ry /= 2; | 247 | ry /= 2; |
248 | ry += h / 2; | 248 | ry += h/2; |
249 | } | 249 | } |
250 | 250 | ||
251 | for (x = 0; x < w; x++) | 251 | for (x = 0; x < w; x++) |
@@ -255,11 +255,11 @@ namespace libTerrain | |||
255 | if (noisy) | 255 | if (noisy) |
256 | rand = random.NextDouble(); | 256 | rand = random.NextDouble(); |
257 | 257 | ||
258 | double z = (scale_min + (scale_range * rand)); | 258 | double z = (scale_min + (scale_range*rand)); |
259 | z *= z * z * z; | 259 | z *= z*z*z; |
260 | double dx = Math.Abs(x - rx); | 260 | double dx = Math.Abs(x - rx); |
261 | double dy = Math.Abs(y - ry); | 261 | double dy = Math.Abs(y - ry); |
262 | z -= (dx * dx * dx * dx) + (dy * dy * dy * dy); | 262 | z -= (dx*dx*dx*dx) + (dy*dy*dy*dy); |
263 | 263 | ||
264 | if (z < 0) | 264 | if (z < 0) |
265 | z = 0; | 265 | z = 0; |
@@ -278,6 +278,5 @@ namespace libTerrain | |||
278 | 278 | ||
279 | Normalise(); | 279 | Normalise(); |
280 | } | 280 | } |
281 | |||
282 | } | 281 | } |
283 | } | 282 | } \ No newline at end of file |
diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Noise.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Noise.cs index 43ae37a..5d39cd5 100644 --- a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Noise.cs +++ b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Noise.cs | |||
@@ -27,8 +27,6 @@ | |||
27 | */ | 27 | */ |
28 | 28 | ||
29 | using System; | 29 | using System; |
30 | using System.Collections.Generic; | ||
31 | using System.Text; | ||
32 | 30 | ||
33 | namespace libTerrain | 31 | namespace libTerrain |
34 | { | 32 | { |
@@ -53,4 +51,4 @@ namespace libTerrain | |||
53 | } | 51 | } |
54 | } | 52 | } |
55 | } | 53 | } |
56 | } | 54 | } \ No newline at end of file |
diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Spiral.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Spiral.cs index d7e0dcd..10eaf71 100644 --- a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Spiral.cs +++ b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Spiral.cs | |||
@@ -28,7 +28,6 @@ | |||
28 | 28 | ||
29 | using System; | 29 | using System; |
30 | using System.Collections.Generic; | 30 | using System.Collections.Generic; |
31 | using System.Text; | ||
32 | 31 | ||
33 | namespace libTerrain | 32 | namespace libTerrain |
34 | { | 33 | { |
@@ -36,10 +35,10 @@ namespace libTerrain | |||
36 | { | 35 | { |
37 | private double[] CoordinatesToPolar(int x, int y) | 36 | private double[] CoordinatesToPolar(int x, int y) |
38 | { | 37 | { |
39 | double theta = Math.Atan2(x - (w / 2), y - (h / 2)); | 38 | double theta = Math.Atan2(x - (w/2), y - (h/2)); |
40 | double rx = (double)x - ((double)w / 2); | 39 | double rx = (double) x - ((double) w/2); |
41 | double ry = (double)y - ((double)h / 2); | 40 | double ry = (double) y - ((double) h/2); |
42 | double r = Math.Sqrt((rx * rx) + (ry * ry)); | 41 | double r = Math.Sqrt((rx*rx) + (ry*ry)); |
43 | 42 | ||
44 | double[] coords = new double[2]; | 43 | double[] coords = new double[2]; |
45 | coords[0] = r; | 44 | coords[0] = r; |
@@ -47,15 +46,16 @@ namespace libTerrain | |||
47 | return coords; | 46 | return coords; |
48 | } | 47 | } |
49 | 48 | ||
50 | public int[] PolarToCoordinates(double r, double theta) { | 49 | public int[] PolarToCoordinates(double r, double theta) |
50 | { | ||
51 | double nx; | 51 | double nx; |
52 | double ny; | 52 | double ny; |
53 | 53 | ||
54 | nx = (double)r * Math.Cos(theta); | 54 | nx = (double) r*Math.Cos(theta); |
55 | ny = (double)r * Math.Sin(theta); | 55 | ny = (double) r*Math.Sin(theta); |
56 | 56 | ||
57 | nx += w / 2; | 57 | nx += w/2; |
58 | ny += h / 2; | 58 | ny += h/2; |
59 | 59 | ||
60 | if (nx >= w) | 60 | if (nx >= w) |
61 | nx = w - 1; | 61 | nx = w - 1; |
@@ -70,8 +70,8 @@ namespace libTerrain | |||
70 | ny = 0; | 70 | ny = 0; |
71 | 71 | ||
72 | int[] coords = new int[2]; | 72 | int[] coords = new int[2]; |
73 | coords[0] = (int)nx; | 73 | coords[0] = (int) nx; |
74 | coords[1] = (int)ny; | 74 | coords[1] = (int) ny; |
75 | return coords; | 75 | return coords; |
76 | } | 76 | } |
77 | 77 | ||
@@ -79,19 +79,19 @@ namespace libTerrain | |||
79 | { | 79 | { |
80 | SetDiff(); | 80 | SetDiff(); |
81 | 81 | ||
82 | Channel n = this.Copy(); | 82 | Channel n = Copy(); |
83 | 83 | ||
84 | int x, y; | 84 | int x, y; |
85 | for (x = 0; x < w; x++) | 85 | for (x = 0; x < w; x++) |
86 | { | 86 | { |
87 | for (y = 0; y < h; y++) | 87 | for (y = 0; y < h; y++) |
88 | { | 88 | { |
89 | double[] coords = CoordinatesToPolar(x,y); | 89 | double[] coords = CoordinatesToPolar(x, y); |
90 | 90 | ||
91 | coords[0] += w / 2.0; | 91 | coords[0] += w/2.0; |
92 | coords[1] += h / 2.0; | 92 | coords[1] += h/2.0; |
93 | 93 | ||
94 | map[x, y] = n.map[(int)coords[0] % n.w, (int)coords[1] % n.h]; | 94 | map[x, y] = n.map[(int) coords[0]%n.w, (int) coords[1]%n.h]; |
95 | } | 95 | } |
96 | } | 96 | } |
97 | } | 97 | } |
@@ -108,12 +108,13 @@ namespace libTerrain | |||
108 | r += incRadius; | 108 | r += incRadius; |
109 | theta += incAngle; | 109 | theta += incAngle; |
110 | 110 | ||
111 | int[] coords = PolarToCoordinates(r,theta); | 111 | int[] coords = PolarToCoordinates(r, theta); |
112 | Raise(coords[0], coords[1], 20, 1); | 112 | Raise(coords[0], coords[1], 20, 1); |
113 | } | 113 | } |
114 | } | 114 | } |
115 | 115 | ||
116 | public void SpiralCells(int steps, double incAngle, double incRadius, double offsetRadius, double offsetAngle, double[] c) | 116 | public void SpiralCells(int steps, double incAngle, double incRadius, double offsetRadius, double offsetAngle, |
117 | double[] c) | ||
117 | { | 118 | { |
118 | SetDiff(); | 119 | SetDiff(); |
119 | 120 | ||
@@ -128,7 +129,7 @@ namespace libTerrain | |||
128 | theta += incAngle; | 129 | theta += incAngle; |
129 | 130 | ||
130 | int[] coords = PolarToCoordinates(r, theta); | 131 | int[] coords = PolarToCoordinates(r, theta); |
131 | points.Add(new Point2D(coords[0],coords[1])); | 132 | points.Add(new Point2D(coords[0], coords[1])); |
132 | } | 133 | } |
133 | 134 | ||
134 | VoronoiDiagram(points, c); | 135 | VoronoiDiagram(points, c); |
@@ -145,9 +146,9 @@ namespace libTerrain | |||
145 | for (y = 0; y < h; y++) | 146 | for (y = 0; y < h; y++) |
146 | { | 147 | { |
147 | z++; | 148 | z++; |
148 | double dx = Math.Abs((w / 2) - x); | 149 | double dx = Math.Abs((w/2) - x); |
149 | double dy = Math.Abs((h / 2) - y); | 150 | double dy = Math.Abs((h/2) - y); |
150 | map[x, y] += Math.Sin(dx / wid) + Math.Cos(dy / hig); | 151 | map[x, y] += Math.Sin(dx/wid) + Math.Cos(dy/hig); |
151 | } | 152 | } |
152 | } | 153 | } |
153 | Normalise(); | 154 | Normalise(); |
diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Voronoi.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Voronoi.cs index e2f9560..0159b87 100644 --- a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Voronoi.cs +++ b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Voronoi.cs | |||
@@ -28,7 +28,6 @@ | |||
28 | 28 | ||
29 | using System; | 29 | using System; |
30 | using System.Collections.Generic; | 30 | using System.Collections.Generic; |
31 | using System.Text; | ||
32 | 31 | ||
33 | namespace libTerrain | 32 | namespace libTerrain |
34 | { | 33 | { |
@@ -57,8 +56,8 @@ namespace libTerrain | |||
57 | { | 56 | { |
58 | for (i = 0; i < pointsPerBlock; i++) | 57 | for (i = 0; i < pointsPerBlock; i++) |
59 | { | 58 | { |
60 | double pX = x + (generator.NextDouble() * (double)blockSize); | 59 | double pX = x + (generator.NextDouble()*(double) blockSize); |
61 | double pY = y + (generator.NextDouble() * (double)blockSize); | 60 | double pY = y + (generator.NextDouble()*(double) blockSize); |
62 | 61 | ||
63 | points.Add(new Point2D(pX, pY)); | 62 | points.Add(new Point2D(pX, pY)); |
64 | } | 63 | } |
@@ -75,10 +74,10 @@ namespace libTerrain | |||
75 | for (i = 0; i < points.Count; i++) | 74 | for (i = 0; i < points.Count; i++) |
76 | { | 75 | { |
77 | double dx, dy; | 76 | double dx, dy; |
78 | dx = Math.Abs((double)x - points[i].x); | 77 | dx = Math.Abs((double) x - points[i].x); |
79 | dy = Math.Abs((double)y - points[i].y); | 78 | dy = Math.Abs((double) y - points[i].y); |
80 | 79 | ||
81 | distances[i] = (dx * dx + dy * dy); | 80 | distances[i] = (dx*dx + dy*dy); |
82 | } | 81 | } |
83 | 82 | ||
84 | Array.Sort(distances); | 83 | Array.Sort(distances); |
@@ -92,7 +91,7 @@ namespace libTerrain | |||
92 | if (i >= points.Count) | 91 | if (i >= points.Count) |
93 | break; | 92 | break; |
94 | 93 | ||
95 | f += c[i] * distances[i]; | 94 | f += c[i]*distances[i]; |
96 | } | 95 | } |
97 | 96 | ||
98 | map[x, y] = f; | 97 | map[x, y] = f; |
@@ -119,10 +118,10 @@ namespace libTerrain | |||
119 | for (i = 0; i < points.Count; i++) | 118 | for (i = 0; i < points.Count; i++) |
120 | { | 119 | { |
121 | double dx, dy; | 120 | double dx, dy; |
122 | dx = Math.Abs((double)x - points[i].x); | 121 | dx = Math.Abs((double) x - points[i].x); |
123 | dy = Math.Abs((double)y - points[i].y); | 122 | dy = Math.Abs((double) y - points[i].y); |
124 | 123 | ||
125 | distances[i] = (dx * dx + dy * dy); | 124 | distances[i] = (dx*dx + dy*dy); |
126 | } | 125 | } |
127 | 126 | ||
128 | Array.Sort(distances); | 127 | Array.Sort(distances); |
@@ -136,7 +135,7 @@ namespace libTerrain | |||
136 | if (i >= points.Count) | 135 | if (i >= points.Count) |
137 | break; | 136 | break; |
138 | 137 | ||
139 | f += c[i] * distances[i]; | 138 | f += c[i]*distances[i]; |
140 | } | 139 | } |
141 | 140 | ||
142 | map[x, y] = f; | 141 | map[x, y] = f; |
@@ -162,8 +161,8 @@ namespace libTerrain | |||
162 | { | 161 | { |
163 | for (i = 0; i < pointsPerBlock; i++) | 162 | for (i = 0; i < pointsPerBlock; i++) |
164 | { | 163 | { |
165 | double pX = x + (generator.NextDouble() * (double)blockSize); | 164 | double pX = x + (generator.NextDouble()*(double) blockSize); |
166 | double pY = y + (generator.NextDouble() * (double)blockSize); | 165 | double pY = y + (generator.NextDouble()*(double) blockSize); |
167 | 166 | ||
168 | points.Add(new Point2D(pX, pY)); | 167 | points.Add(new Point2D(pX, pY)); |
169 | } | 168 | } |
@@ -180,10 +179,10 @@ namespace libTerrain | |||
180 | for (i = 0; i < points.Count; i++) | 179 | for (i = 0; i < points.Count; i++) |
181 | { | 180 | { |
182 | double dx, dy; | 181 | double dx, dy; |
183 | dx = Math.Abs((double)x - points[i].x); | 182 | dx = Math.Abs((double) x - points[i].x); |
184 | dy = Math.Abs((double)y - points[i].y); | 183 | dy = Math.Abs((double) y - points[i].y); |
185 | 184 | ||
186 | distances[i] = (dx * dx + dy * dy); | 185 | distances[i] = (dx*dx + dy*dy); |
187 | } | 186 | } |
188 | 187 | ||
189 | //Array.Sort(distances); | 188 | //Array.Sort(distances); |
@@ -191,7 +190,7 @@ namespace libTerrain | |||
191 | double f = 0.0; | 190 | double f = 0.0; |
192 | 191 | ||
193 | double min = double.MaxValue; | 192 | double min = double.MaxValue; |
194 | for (int j = 0; j < distances.Length;j++ ) | 193 | for (int j = 0; j < distances.Length; j++) |
195 | { | 194 | { |
196 | if (distances[j] < min) | 195 | if (distances[j] < min) |
197 | { | 196 | { |
@@ -211,4 +210,4 @@ namespace libTerrain | |||
211 | Normalise(); | 210 | Normalise(); |
212 | } | 211 | } |
213 | } | 212 | } |
214 | } | 213 | } \ No newline at end of file |
diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Worms.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Worms.cs index 788134d..deb2e0e 100644 --- a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Worms.cs +++ b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Worms.cs | |||
@@ -27,8 +27,6 @@ | |||
27 | */ | 27 | */ |
28 | 28 | ||
29 | using System; | 29 | using System; |
30 | using System.Collections.Generic; | ||
31 | using System.Text; | ||
32 | 30 | ||
33 | namespace libTerrain | 31 | namespace libTerrain |
34 | { | 32 | { |
@@ -54,18 +52,18 @@ namespace libTerrain | |||
54 | double rx, ry; | 52 | double rx, ry; |
55 | if (centerspawn) | 53 | if (centerspawn) |
56 | { | 54 | { |
57 | rx = w / 2.0; | 55 | rx = w/2.0; |
58 | ry = h / 2.0; | 56 | ry = h/2.0; |
59 | } | 57 | } |
60 | else | 58 | else |
61 | { | 59 | { |
62 | rx = random.NextDouble() * (w - 1); | 60 | rx = random.NextDouble()*(w - 1); |
63 | ry = random.NextDouble() * (h - 1); | 61 | ry = random.NextDouble()*(h - 1); |
64 | } | 62 | } |
65 | for (j = 0; j < rounds; j++) | 63 | for (j = 0; j < rounds; j++) |
66 | { | 64 | { |
67 | rx += (random.NextDouble() * movement) - (movement / 2.0); | 65 | rx += (random.NextDouble()*movement) - (movement/2.0); |
68 | ry += (random.NextDouble() * movement) - (movement / 2.0); | 66 | ry += (random.NextDouble()*movement) - (movement/2.0); |
69 | Raise(rx, ry, size, 1.0); | 67 | Raise(rx, ry, size, 1.0); |
70 | } | 68 | } |
71 | } | 69 | } |
diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Grid.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Grid.cs index 0155791..24df5b9 100644 --- a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Grid.cs +++ b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Grid.cs | |||
@@ -27,8 +27,6 @@ | |||
27 | */ | 27 | */ |
28 | 28 | ||
29 | using System; | 29 | using System; |
30 | using System.Collections.Generic; | ||
31 | using System.Text; | ||
32 | 30 | ||
33 | namespace libTerrain | 31 | namespace libTerrain |
34 | { | 32 | { |
@@ -49,13 +47,13 @@ namespace libTerrain | |||
49 | { | 47 | { |
50 | for (y = 0; y < h; y++) | 48 | for (y = 0; y < h; y++) |
51 | { | 49 | { |
52 | map[x, y] = (map[x, y] - min) * (1.0 / (max - min)); | 50 | map[x, y] = (map[x, y] - min)*(1.0/(max - min)); |
53 | } | 51 | } |
54 | } | 52 | } |
55 | } | 53 | } |
56 | else | 54 | else |
57 | { | 55 | { |
58 | this.Fill(0.5); | 56 | Fill(0.5); |
59 | } | 57 | } |
60 | 58 | ||
61 | return this; | 59 | return this; |
@@ -82,7 +80,7 @@ namespace libTerrain | |||
82 | { | 80 | { |
83 | if (min != max) | 81 | if (min != max) |
84 | { | 82 | { |
85 | double val = (map[x, y] - min) * (1.0 / max - min); | 83 | double val = (map[x, y] - min)*(1.0/max - min); |
86 | val *= maxv - minv; | 84 | val *= maxv - minv; |
87 | val += minv; | 85 | val += minv; |
88 | 86 | ||
@@ -179,9 +177,9 @@ namespace libTerrain | |||
179 | SetDiff(); | 177 | SetDiff(); |
180 | 178 | ||
181 | double area = amount; | 179 | double area = amount; |
182 | double step = amount / 4.0; | 180 | double step = amount/4.0; |
183 | 181 | ||
184 | double[,] manipulate = new double[w, h]; | 182 | double[,] manipulate = new double[w,h]; |
185 | int x, y; | 183 | int x, y; |
186 | double n, l; | 184 | double n, l; |
187 | for (x = 0; x < w; x++) | 185 | for (x = 0; x < w; x++) |
@@ -200,7 +198,7 @@ namespace libTerrain | |||
200 | } | 198 | } |
201 | } | 199 | } |
202 | 200 | ||
203 | manipulate[x, y] = average / avgsteps; | 201 | manipulate[x, y] = average/avgsteps; |
204 | } | 202 | } |
205 | } | 203 | } |
206 | map = manipulate; | 204 | map = manipulate; |
@@ -211,7 +209,7 @@ namespace libTerrain | |||
211 | SetDiff(); | 209 | SetDiff(); |
212 | 210 | ||
213 | // Simple pertubation filter | 211 | // Simple pertubation filter |
214 | double[,] manipulated = new double[w, h]; | 212 | double[,] manipulated = new double[w,h]; |
215 | Random generator = new Random(seed); // Seeds FTW! | 213 | Random generator = new Random(seed); // Seeds FTW! |
216 | //double amount = 8.0; | 214 | //double amount = 8.0; |
217 | 215 | ||
@@ -220,8 +218,8 @@ namespace libTerrain | |||
220 | { | 218 | { |
221 | for (y = 0; y < h; y++) | 219 | for (y = 0; y < h; y++) |
222 | { | 220 | { |
223 | double offset_x = (double)x + (generator.NextDouble() * amount) - (amount / 2.0); | 221 | double offset_x = (double) x + (generator.NextDouble()*amount) - (amount/2.0); |
224 | double offset_y = (double)y + (generator.NextDouble() * amount) - (amount / 2.0); | 222 | double offset_y = (double) y + (generator.NextDouble()*amount) - (amount/2.0); |
225 | double p = GetBilinearInterpolate(offset_x, offset_y); | 223 | double p = GetBilinearInterpolate(offset_x, offset_y); |
226 | manipulated[x, y] = p; | 224 | manipulated[x, y] = p; |
227 | } | 225 | } |
@@ -232,7 +230,7 @@ namespace libTerrain | |||
232 | public void PertubationMask(Channel mask) | 230 | public void PertubationMask(Channel mask) |
233 | { | 231 | { |
234 | // Simple pertubation filter | 232 | // Simple pertubation filter |
235 | double[,] manipulated = new double[w, h]; | 233 | double[,] manipulated = new double[w,h]; |
236 | Random generator = new Random(seed); // Seeds FTW! | 234 | Random generator = new Random(seed); // Seeds FTW! |
237 | //double amount = 8.0; | 235 | //double amount = 8.0; |
238 | 236 | ||
@@ -244,8 +242,8 @@ namespace libTerrain | |||
244 | for (y = 0; y < h; y++) | 242 | for (y = 0; y < h; y++) |
245 | { | 243 | { |
246 | amount = mask.map[x, y]; | 244 | amount = mask.map[x, y]; |
247 | double offset_x = (double)x + (generator.NextDouble() * amount) - (amount / 2.0); | 245 | double offset_x = (double) x + (generator.NextDouble()*amount) - (amount/2.0); |
248 | double offset_y = (double)y + (generator.NextDouble() * amount) - (amount / 2.0); | 246 | double offset_y = (double) y + (generator.NextDouble()*amount) - (amount/2.0); |
249 | 247 | ||
250 | if (offset_x > w) | 248 | if (offset_x > w) |
251 | offset_x = w - 1; | 249 | offset_x = w - 1; |
@@ -267,7 +265,7 @@ namespace libTerrain | |||
267 | public void Distort(Channel mask, double str) | 265 | public void Distort(Channel mask, double str) |
268 | { | 266 | { |
269 | // Simple pertubation filter | 267 | // Simple pertubation filter |
270 | double[,] manipulated = new double[w, h]; | 268 | double[,] manipulated = new double[w,h]; |
271 | 269 | ||
272 | double amount; | 270 | double amount; |
273 | 271 | ||
@@ -277,8 +275,8 @@ namespace libTerrain | |||
277 | for (y = 0; y < h; y++) | 275 | for (y = 0; y < h; y++) |
278 | { | 276 | { |
279 | amount = mask.map[x, y]; | 277 | amount = mask.map[x, y]; |
280 | double offset_x = (double)x + (amount * str) - (0.5 * str); | 278 | double offset_x = (double) x + (amount*str) - (0.5*str); |
281 | double offset_y = (double)y + (amount * str) - (0.5 * str); | 279 | double offset_y = (double) y + (amount*str) - (0.5*str); |
282 | 280 | ||
283 | if (offset_x > w) | 281 | if (offset_x > w) |
284 | offset_x = w - 1; | 282 | offset_x = w - 1; |
@@ -295,13 +293,12 @@ namespace libTerrain | |||
295 | } | 293 | } |
296 | } | 294 | } |
297 | map = manipulated; | 295 | map = manipulated; |
298 | |||
299 | } | 296 | } |
300 | 297 | ||
301 | public void Distort(Channel mask, Channel mask2, double str) | 298 | public void Distort(Channel mask, Channel mask2, double str) |
302 | { | 299 | { |
303 | // Simple pertubation filter | 300 | // Simple pertubation filter |
304 | double[,] manipulated = new double[w, h]; | 301 | double[,] manipulated = new double[w,h]; |
305 | 302 | ||
306 | double amountX; | 303 | double amountX; |
307 | double amountY; | 304 | double amountY; |
@@ -313,8 +310,8 @@ namespace libTerrain | |||
313 | { | 310 | { |
314 | amountX = mask.map[x, y]; | 311 | amountX = mask.map[x, y]; |
315 | amountY = mask2.map[x, y]; | 312 | amountY = mask2.map[x, y]; |
316 | double offset_x = (double)x + (amountX * str) - (0.5 * str); | 313 | double offset_x = (double) x + (amountX*str) - (0.5*str); |
317 | double offset_y = (double)y + (amountY * str) - (0.5 * str); | 314 | double offset_y = (double) y + (amountY*str) - (0.5*str); |
318 | 315 | ||
319 | if (offset_x > w) | 316 | if (offset_x > w) |
320 | offset_x = w - 1; | 317 | offset_x = w - 1; |
@@ -331,7 +328,6 @@ namespace libTerrain | |||
331 | } | 328 | } |
332 | } | 329 | } |
333 | map = manipulated; | 330 | map = manipulated; |
334 | |||
335 | } | 331 | } |
336 | 332 | ||
337 | public Channel Blend(Channel other, double amount) | 333 | public Channel Blend(Channel other, double amount) |
@@ -360,4 +356,4 @@ namespace libTerrain | |||
360 | return this; | 356 | return this; |
361 | } | 357 | } |
362 | } | 358 | } |
363 | } | 359 | } \ No newline at end of file |
diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Manipulators/AerobicErosion.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Manipulators/AerobicErosion.cs index ca93c25..c8584e8 100644 --- a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Manipulators/AerobicErosion.cs +++ b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Manipulators/AerobicErosion.cs | |||
@@ -27,8 +27,6 @@ | |||
27 | */ | 27 | */ |
28 | 28 | ||
29 | using System; | 29 | using System; |
30 | using System.Collections.Generic; | ||
31 | using System.Text; | ||
32 | 30 | ||
33 | namespace libTerrain | 31 | namespace libTerrain |
34 | { | 32 | { |
@@ -74,17 +72,18 @@ namespace libTerrain | |||
74 | /// <param name="carry">The percentage of rock which can be picked up to pickup 0..1</param> | 72 | /// <param name="carry">The percentage of rock which can be picked up to pickup 0..1</param> |
75 | /// <param name="rounds">The number of erosion rounds (recommended: 25+)</param> | 73 | /// <param name="rounds">The number of erosion rounds (recommended: 25+)</param> |
76 | /// <param name="lowest">Drop sediment at the lowest point?</param> | 74 | /// <param name="lowest">Drop sediment at the lowest point?</param> |
77 | public void AerobicErosion(double windspeed, double pickupTalusMinimum, double dropTalusMinimum, double carry, int rounds, bool lowest, bool usingFluidDynamics) | 75 | public void AerobicErosion(double windspeed, double pickupTalusMinimum, double dropTalusMinimum, double carry, |
76 | int rounds, bool lowest, bool usingFluidDynamics) | ||
78 | { | 77 | { |
79 | bool debugImages = false; | 78 | bool debugImages = false; |
80 | 79 | ||
81 | Channel wind = new Channel(w, h) ; | 80 | Channel wind = new Channel(w, h); |
82 | Channel sediment = new Channel(w, h); | 81 | Channel sediment = new Channel(w, h); |
83 | int x, y, i, j; | 82 | int x, y, i, j; |
84 | 83 | ||
85 | this.Normalise(); | 84 | Normalise(); |
86 | 85 | ||
87 | wind = this.Copy(); | 86 | wind = Copy(); |
88 | wind.Noise(); | 87 | wind.Noise(); |
89 | 88 | ||
90 | if (debugImages) | 89 | if (debugImages) |
@@ -120,7 +119,7 @@ namespace libTerrain | |||
120 | surfacearea += Math.Abs(target - me); | 119 | surfacearea += Math.Abs(target - me); |
121 | } | 120 | } |
122 | 121 | ||
123 | double amount = surfacearea * wind.map[x, y] * carry; | 122 | double amount = surfacearea*wind.map[x, y]*carry; |
124 | 123 | ||
125 | if (amount < 0) | 124 | if (amount < 0) |
126 | amount = 0; | 125 | amount = 0; |
@@ -147,7 +146,7 @@ namespace libTerrain | |||
147 | } | 146 | } |
148 | else | 147 | else |
149 | { | 148 | { |
150 | wind.Pertubation(15); // Can do better later | 149 | wind.Pertubation(15); // Can do better later |
151 | wind.seed++; | 150 | wind.seed++; |
152 | sediment.Pertubation(10); // Sediment is blown around a bit | 151 | sediment.Pertubation(10); // Sediment is blown around a bit |
153 | sediment.seed++; | 152 | sediment.seed++; |
@@ -175,12 +174,12 @@ namespace libTerrain | |||
175 | 174 | ||
176 | if (target < min && lowest) | 175 | if (target < min && lowest) |
177 | { | 176 | { |
178 | minside = (int[])coords.Clone(); | 177 | minside = (int[]) coords.Clone(); |
179 | min = target; | 178 | min = target; |
180 | } | 179 | } |
181 | } | 180 | } |
182 | 181 | ||
183 | double amount = surfacearea * (1.0 - wind.map[x, y]) * carry; | 182 | double amount = surfacearea*(1.0 - wind.map[x, y])*carry; |
184 | 183 | ||
185 | if (amount < 0) | 184 | if (amount < 0) |
186 | amount = 0; | 185 | amount = 0; |
@@ -199,7 +198,7 @@ namespace libTerrain | |||
199 | wind.Normalise(); | 198 | wind.Normalise(); |
200 | wind *= windspeed; | 199 | wind *= windspeed; |
201 | 200 | ||
202 | this.Normalise(); | 201 | Normalise(); |
203 | } | 202 | } |
204 | 203 | ||
205 | Channel myself = this; | 204 | Channel myself = this; |
@@ -207,7 +206,7 @@ namespace libTerrain | |||
207 | myself.Normalise(); | 206 | myself.Normalise(); |
208 | 207 | ||
209 | if (debugImages) | 208 | if (debugImages) |
210 | this.SaveImage("testimg/output.png"); | 209 | SaveImage("testimg/output.png"); |
211 | } | 210 | } |
212 | } | 211 | } |
213 | } \ No newline at end of file | 212 | } \ No newline at end of file |
diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Manipulators/HydraulicErosion.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Manipulators/HydraulicErosion.cs index 4f58f71..0e47e1b 100644 --- a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Manipulators/HydraulicErosion.cs +++ b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Manipulators/HydraulicErosion.cs | |||
@@ -27,8 +27,6 @@ | |||
27 | */ | 27 | */ |
28 | 28 | ||
29 | using System; | 29 | using System; |
30 | using System.Collections.Generic; | ||
31 | using System.Text; | ||
32 | 30 | ||
33 | namespace libTerrain | 31 | namespace libTerrain |
34 | { | 32 | { |
@@ -44,7 +42,7 @@ namespace libTerrain | |||
44 | Channel waterFlow = new Channel(w, h); | 42 | Channel waterFlow = new Channel(w, h); |
45 | 43 | ||
46 | NeighbourSystem type = NeighbourSystem.Moore; | 44 | NeighbourSystem type = NeighbourSystem.Moore; |
47 | int NEIGHBOUR_ME = 4; | 45 | int NEIGHBOUR_ME = 4; |
48 | 46 | ||
49 | int NEIGHBOUR_MAX = type == NeighbourSystem.Moore ? 9 : 5; | 47 | int NEIGHBOUR_MAX = type == NeighbourSystem.Moore ? 9 : 5; |
50 | 48 | ||
@@ -52,7 +50,7 @@ namespace libTerrain | |||
52 | { | 50 | { |
53 | water += rain; | 51 | water += rain; |
54 | 52 | ||
55 | sediment = terrain * water; | 53 | sediment = terrain*water; |
56 | terrain -= sediment; | 54 | terrain -= sediment; |
57 | 55 | ||
58 | for (int x = 1; x < w - 1; x++) | 56 | for (int x = 1; x < w - 1; x++) |
@@ -72,7 +70,8 @@ namespace libTerrain | |||
72 | coords[0] += x; | 70 | coords[0] += x; |
73 | coords[1] += y; | 71 | coords[1] += y; |
74 | 72 | ||
75 | heights[j] = map[coords[0], coords[1]] + water.map[coords[0], coords[1]] + sediment.map[coords[0], coords[1]]; | 73 | heights[j] = map[coords[0], coords[1]] + water.map[coords[0], coords[1]] + |
74 | sediment.map[coords[0], coords[1]]; | ||
76 | diffs[j] = heightCenter - heights[j]; | 75 | diffs[j] = heightCenter - heights[j]; |
77 | } | 76 | } |
78 | } | 77 | } |
@@ -97,13 +96,13 @@ namespace libTerrain | |||
97 | if (totalCellsCounted == 1) | 96 | if (totalCellsCounted == 1) |
98 | continue; | 97 | continue; |
99 | 98 | ||
100 | double averageHeight = totalHeight / totalCellsCounted; | 99 | double averageHeight = totalHeight/totalCellsCounted; |
101 | double waterAmount = Math.Min(water.map[x, y], heightCenter - averageHeight); | 100 | double waterAmount = Math.Min(water.map[x, y], heightCenter - averageHeight); |
102 | 101 | ||
103 | // TODO: Check this. | 102 | // TODO: Check this. |
104 | waterFlow.map[x, y] += waterFlow.map[x, y] - waterAmount; | 103 | waterFlow.map[x, y] += waterFlow.map[x, y] - waterAmount; |
105 | 104 | ||
106 | double totalInverseDiff = waterAmount / totalHeightDiff; | 105 | double totalInverseDiff = waterAmount/totalHeightDiff; |
107 | 106 | ||
108 | for (int j = 0; j < NEIGHBOUR_MAX; j++) | 107 | for (int j = 0; j < NEIGHBOUR_MAX; j++) |
109 | { | 108 | { |
@@ -115,7 +114,8 @@ namespace libTerrain | |||
115 | 114 | ||
116 | if (diffs[j] > 0) | 115 | if (diffs[j] > 0) |
117 | { | 116 | { |
118 | waterFlow.SetWrap(coords[0], coords[1], waterFlow.map[coords[0], coords[1]] + diffs[j] * totalInverseDiff); | 117 | waterFlow.SetWrap(coords[0], coords[1], |
118 | waterFlow.map[coords[0], coords[1]] + diffs[j]*totalInverseDiff); | ||
119 | } | 119 | } |
120 | } | 120 | } |
121 | } | 121 | } |
@@ -131,7 +131,7 @@ namespace libTerrain | |||
131 | { | 131 | { |
132 | for (int y = 0; y < h; y++) | 132 | for (int y = 0; y < h; y++) |
133 | { | 133 | { |
134 | double deposition = sediment.map[x, y] - water.map[x, y] * solubility; | 134 | double deposition = sediment.map[x, y] - water.map[x, y]*solubility; |
135 | if (deposition > 0) | 135 | if (deposition > 0) |
136 | { | 136 | { |
137 | sediment.map[x, y] -= deposition; | 137 | sediment.map[x, y] -= deposition; |
@@ -139,7 +139,6 @@ namespace libTerrain | |||
139 | } | 139 | } |
140 | } | 140 | } |
141 | } | 141 | } |
142 | |||
143 | } | 142 | } |
144 | } | 143 | } |
145 | } | 144 | } |
diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Manipulators/NavierStokes.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Manipulators/NavierStokes.cs index 401cf95..8c16d7c 100644 --- a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Manipulators/NavierStokes.cs +++ b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Manipulators/NavierStokes.cs | |||
@@ -26,10 +26,6 @@ | |||
26 | * | 26 | * |
27 | */ | 27 | */ |
28 | 28 | ||
29 | using System; | ||
30 | using System.Collections.Generic; | ||
31 | using System.Text; | ||
32 | |||
33 | namespace libTerrain | 29 | namespace libTerrain |
34 | { | 30 | { |
35 | partial class Channel | 31 | partial class Channel |
@@ -42,7 +38,7 @@ namespace libTerrain | |||
42 | 38 | ||
43 | private static int nsIX(int i, int j, int N) | 39 | private static int nsIX(int i, int j, int N) |
44 | { | 40 | { |
45 | return ((i) + (N + 2) * (j)); | 41 | return ((i) + (N + 2)*(j)); |
46 | } | 42 | } |
47 | 43 | ||
48 | private static void nsSwap(ref double x0, ref double x) | 44 | private static void nsSwap(ref double x0, ref double x) |
@@ -62,10 +58,10 @@ namespace libTerrain | |||
62 | private void nsAddSource(int N, ref double[] x, ref double[] s, double dt) | 58 | private void nsAddSource(int N, ref double[] x, ref double[] s, double dt) |
63 | { | 59 | { |
64 | int i; | 60 | int i; |
65 | int size = (N + 2) * (N + 2); | 61 | int size = (N + 2)*(N + 2); |
66 | for (i = 0; i < size; i++) | 62 | for (i = 0; i < size; i++) |
67 | { | 63 | { |
68 | x[i] += dt * s[i]; | 64 | x[i] += dt*s[i]; |
69 | } | 65 | } |
70 | } | 66 | } |
71 | 67 | ||
@@ -74,15 +70,15 @@ namespace libTerrain | |||
74 | int i; | 70 | int i; |
75 | for (i = 0; i <= N; i++) | 71 | for (i = 0; i <= N; i++) |
76 | { | 72 | { |
77 | x[nsIX(0, i, N)] = b == 1 ? -x[nsIX(1, i, N)] : x[nsIX(1, i, N)]; | 73 | x[nsIX(0, i, N)] = b == 1 ? -x[nsIX(1, i, N)] : x[nsIX(1, i, N)]; |
78 | x[nsIX(0, N + 1, N)] = b == 1 ? -x[nsIX(N, i, N)] : x[nsIX(N, i, N)]; | 74 | x[nsIX(0, N + 1, N)] = b == 1 ? -x[nsIX(N, i, N)] : x[nsIX(N, i, N)]; |
79 | x[nsIX(i, 0, N)] = b == 2 ? -x[nsIX(i, 1, N)] : x[nsIX(i, 1, N)]; | 75 | x[nsIX(i, 0, N)] = b == 2 ? -x[nsIX(i, 1, N)] : x[nsIX(i, 1, N)]; |
80 | x[nsIX(i, N + 1, N)] = b == 2 ? -x[nsIX(i, N, N)] : x[nsIX(i, N, N)]; | 76 | x[nsIX(i, N + 1, N)] = b == 2 ? -x[nsIX(i, N, N)] : x[nsIX(i, N, N)]; |
81 | } | 77 | } |
82 | x[nsIX(0, 0, N)] = 0.5f * (x[nsIX(1, 0, N)] + x[nsIX(0, 1, N)]); | 78 | x[nsIX(0, 0, N)] = 0.5f*(x[nsIX(1, 0, N)] + x[nsIX(0, 1, N)]); |
83 | x[nsIX(0, N + 1, N)] = 0.5f * (x[nsIX(1, N + 1, N)] + x[nsIX(0, N, N)]); | 79 | x[nsIX(0, N + 1, N)] = 0.5f*(x[nsIX(1, N + 1, N)] + x[nsIX(0, N, N)]); |
84 | x[nsIX(N + 1, 0, N)] = 0.5f * (x[nsIX(N, 0, N)] + x[nsIX(N + 1, 1, N)]); | 80 | x[nsIX(N + 1, 0, N)] = 0.5f*(x[nsIX(N, 0, N)] + x[nsIX(N + 1, 1, N)]); |
85 | x[nsIX(N + 1, N + 1, N)] = 0.5f * (x[nsIX(N, N + 1, N)] + x[nsIX(N + 1, N, N)]); | 81 | x[nsIX(N + 1, N + 1, N)] = 0.5f*(x[nsIX(N, N + 1, N)] + x[nsIX(N + 1, N, N)]); |
86 | } | 82 | } |
87 | 83 | ||
88 | private void nsLinSolve(int N, int b, ref double[] x, ref double[] x0, double a, double c) | 84 | private void nsLinSolve(int N, int b, ref double[] x, ref double[] x0, double a, double c) |
@@ -92,11 +88,11 @@ namespace libTerrain | |||
92 | { | 88 | { |
93 | for (j = 1; j <= N; j++) | 89 | for (j = 1; j <= N; j++) |
94 | { | 90 | { |
95 | x[nsIX(i, j, N)] = (x0[nsIX(i, j, N)] + a * | 91 | x[nsIX(i, j, N)] = (x0[nsIX(i, j, N)] + a* |
96 | (x[nsIX(i - 1, j, N)] + | 92 | (x[nsIX(i - 1, j, N)] + |
97 | x[nsIX(i + 1, j, N)] + | 93 | x[nsIX(i + 1, j, N)] + |
98 | x[nsIX(i, j - 1, N)] + x[nsIX(i, j + 1, N)]) | 94 | x[nsIX(i, j - 1, N)] + x[nsIX(i, j + 1, N)]) |
99 | ) / c; | 95 | )/c; |
100 | } | 96 | } |
101 | } | 97 | } |
102 | 98 | ||
@@ -105,8 +101,8 @@ namespace libTerrain | |||
105 | 101 | ||
106 | private void nsDiffuse(int N, int b, ref double[] x, ref double[] x0, double diff, double dt) | 102 | private void nsDiffuse(int N, int b, ref double[] x, ref double[] x0, double diff, double dt) |
107 | { | 103 | { |
108 | double a = dt * diff * N * N; | 104 | double a = dt*diff*N*N; |
109 | nsLinSolve(N, b, ref x, ref x0, a, 1 + 4 * a); | 105 | nsLinSolve(N, b, ref x, ref x0, a, 1 + 4*a); |
110 | } | 106 | } |
111 | 107 | ||
112 | private void nsAdvect(int N, int b, ref double[] d, ref double[] d0, ref double[] u, ref double[] v, double dt) | 108 | private void nsAdvect(int N, int b, ref double[] d, ref double[] d0, ref double[] u, ref double[] v, double dt) |
@@ -114,27 +110,27 @@ namespace libTerrain | |||
114 | int i, j, i0, j0, i1, j1; | 110 | int i, j, i0, j0, i1, j1; |
115 | double x, y, s0, t0, s1, t1, dt0; | 111 | double x, y, s0, t0, s1, t1, dt0; |
116 | 112 | ||
117 | dt0 = dt * N; | 113 | dt0 = dt*N; |
118 | 114 | ||
119 | for (i = 1; i <= N; i++) | 115 | for (i = 1; i <= N; i++) |
120 | { | 116 | { |
121 | for (j = 1; j <= N; j++) | 117 | for (j = 1; j <= N; j++) |
122 | { | 118 | { |
123 | x = i - dt0 * u[nsIX(i, j, N)]; | 119 | x = i - dt0*u[nsIX(i, j, N)]; |
124 | y = j - dt0 * v[nsIX(i, j, N)]; | 120 | y = j - dt0*v[nsIX(i, j, N)]; |
125 | 121 | ||
126 | if (x < 0.5) | 122 | if (x < 0.5) |
127 | x = 0.5; | 123 | x = 0.5; |
128 | if (x > N + 0.5) | 124 | if (x > N + 0.5) |
129 | x = N + 0.5; | 125 | x = N + 0.5; |
130 | i0 = (int)x; | 126 | i0 = (int) x; |
131 | i1 = i0 + 1; | 127 | i1 = i0 + 1; |
132 | 128 | ||
133 | if (y < 0.5) | 129 | if (y < 0.5) |
134 | y = 0.5; | 130 | y = 0.5; |
135 | if (y > N + 0.5) | 131 | if (y > N + 0.5) |
136 | y = N + 0.5; | 132 | y = N + 0.5; |
137 | j0 = (int)y; | 133 | j0 = (int) y; |
138 | j1 = j0 + 1; | 134 | j1 = j0 + 1; |
139 | 135 | ||
140 | s1 = x - i0; | 136 | s1 = x - i0; |
@@ -142,8 +138,8 @@ namespace libTerrain | |||
142 | t1 = y - j0; | 138 | t1 = y - j0; |
143 | t0 = 1 - t1; | 139 | t0 = 1 - t1; |
144 | 140 | ||
145 | d[nsIX(i, j, N)] = s0 * (t0 * d0[nsIX(i0, j0, N)] + t1 * d0[nsIX(i0, j1, N)]) + | 141 | d[nsIX(i, j, N)] = s0*(t0*d0[nsIX(i0, j0, N)] + t1*d0[nsIX(i0, j1, N)]) + |
146 | s1 * (t0 * d0[nsIX(i1, j0, N)] + t1 * d0[nsIX(i1, j1, N)]); | 142 | s1*(t0*d0[nsIX(i1, j0, N)] + t1*d0[nsIX(i1, j1, N)]); |
147 | } | 143 | } |
148 | } | 144 | } |
149 | 145 | ||
@@ -158,7 +154,9 @@ namespace libTerrain | |||
158 | { | 154 | { |
159 | for (j = 1; j <= N; j++) | 155 | for (j = 1; j <= N; j++) |
160 | { | 156 | { |
161 | div[nsIX(i, j, N)] = -0.5 * (u[nsIX(i + 1, j, N)] - u[nsIX(i - 1, j, N)] + v[nsIX(i, j + 1, N)] - v[nsIX(i, j - 1, N)]) / N; | 157 | div[nsIX(i, j, N)] = -0.5* |
158 | (u[nsIX(i + 1, j, N)] - u[nsIX(i - 1, j, N)] + v[nsIX(i, j + 1, N)] - | ||
159 | v[nsIX(i, j - 1, N)])/N; | ||
162 | p[nsIX(i, j, N)] = 0; | 160 | p[nsIX(i, j, N)] = 0; |
163 | } | 161 | } |
164 | } | 162 | } |
@@ -172,8 +170,8 @@ namespace libTerrain | |||
172 | { | 170 | { |
173 | for (j = 1; j <= N; j++) | 171 | for (j = 1; j <= N; j++) |
174 | { | 172 | { |
175 | u[nsIX(i, j, N)] -= 0.5 * N * (p[nsIX(i + 1, j, N)] - p[nsIX(i - 1, j, N)]); | 173 | u[nsIX(i, j, N)] -= 0.5*N*(p[nsIX(i + 1, j, N)] - p[nsIX(i - 1, j, N)]); |
176 | v[nsIX(i, j, N)] -= 0.5 * N * (p[nsIX(i, j + 1, N)] - p[nsIX(i, j - 1, N)]); | 174 | v[nsIX(i, j, N)] -= 0.5*N*(p[nsIX(i, j + 1, N)] - p[nsIX(i, j - 1, N)]); |
177 | } | 175 | } |
178 | } | 176 | } |
179 | 177 | ||
@@ -181,7 +179,8 @@ namespace libTerrain | |||
181 | nsSetBnd(N, 2, ref v); | 179 | nsSetBnd(N, 2, ref v); |
182 | } | 180 | } |
183 | 181 | ||
184 | private void nsDensStep(int N, ref double[] x, ref double[] x0, ref double[] u, ref double[] v, double diff, double dt) | 182 | private void nsDensStep(int N, ref double[] x, ref double[] x0, ref double[] u, ref double[] v, double diff, |
183 | double dt) | ||
185 | { | 184 | { |
186 | nsAddSource(N, ref x, ref x0, dt); | 185 | nsAddSource(N, ref x, ref x0, dt); |
187 | nsSwap(ref x0, ref x); | 186 | nsSwap(ref x0, ref x); |
@@ -190,7 +189,8 @@ namespace libTerrain | |||
190 | nsAdvect(N, 0, ref x, ref x0, ref u, ref v, dt); | 189 | nsAdvect(N, 0, ref x, ref x0, ref u, ref v, dt); |
191 | } | 190 | } |
192 | 191 | ||
193 | private void nsVelStep(int N, ref double[] u, ref double[] v, ref double[] u0, ref double[] v0, double visc, double dt) | 192 | private void nsVelStep(int N, ref double[] u, ref double[] v, ref double[] u0, ref double[] v0, double visc, |
193 | double dt) | ||
194 | { | 194 | { |
195 | nsAddSource(N, ref u, ref u0, dt); | 195 | nsAddSource(N, ref u, ref u0, dt); |
196 | nsAddSource(N, ref v, ref v0, dt); | 196 | nsAddSource(N, ref v, ref v0, dt); |
@@ -236,17 +236,17 @@ namespace libTerrain | |||
236 | 236 | ||
237 | private void nsSimulate(int N, int rounds, double dt, double diff, double visc) | 237 | private void nsSimulate(int N, int rounds, double dt, double diff, double visc) |
238 | { | 238 | { |
239 | int size = (N * 2) * (N * 2); | 239 | int size = (N*2)*(N*2); |
240 | 240 | ||
241 | double[] u = new double[size]; // Force, X axis | 241 | double[] u = new double[size]; // Force, X axis |
242 | double[] v = new double[size]; // Force, Y axis | 242 | double[] v = new double[size]; // Force, Y axis |
243 | double[] u_prev = new double[size]; | 243 | double[] u_prev = new double[size]; |
244 | double[] v_prev = new double[size]; | 244 | double[] v_prev = new double[size]; |
245 | double[] dens = new double[size]; | 245 | double[] dens = new double[size]; |
246 | double[] dens_prev = new double[size]; | 246 | double[] dens_prev = new double[size]; |
247 | 247 | ||
248 | nsDoublesToBuffer(this.map, N, ref dens); | 248 | nsDoublesToBuffer(map, N, ref dens); |
249 | nsDoublesToBuffer(this.map, N, ref dens_prev); | 249 | nsDoublesToBuffer(map, N, ref dens_prev); |
250 | 250 | ||
251 | for (int i = 0; i < rounds; i++) | 251 | for (int i = 0; i < rounds; i++) |
252 | { | 252 | { |
@@ -258,7 +258,7 @@ namespace libTerrain | |||
258 | nsDensStep(N, ref dens, ref dens_prev, ref u, ref v, diff, dt); | 258 | nsDensStep(N, ref dens, ref dens_prev, ref u, ref v, diff, dt); |
259 | } | 259 | } |
260 | 260 | ||
261 | nsBufferToDoubles(ref dens, N, ref this.map); | 261 | nsBufferToDoubles(ref dens, N, ref map); |
262 | } | 262 | } |
263 | 263 | ||
264 | /// <summary> | 264 | /// <summary> |
@@ -270,14 +270,14 @@ namespace libTerrain | |||
270 | /// <param name="visc">Fluid viscosity (Recommended: 0.0)</param> | 270 | /// <param name="visc">Fluid viscosity (Recommended: 0.0)</param> |
271 | public void navierStokes(int rounds, double dt, double diff, double visc) | 271 | public void navierStokes(int rounds, double dt, double diff, double visc) |
272 | { | 272 | { |
273 | nsSimulate(this.h, rounds, dt, diff, visc); | 273 | nsSimulate(h, rounds, dt, diff, visc); |
274 | } | 274 | } |
275 | 275 | ||
276 | public void navierStokes(int rounds, double dt, double diff, double visc, ref double[,] uret, ref double[,] vret) | 276 | public void navierStokes(int rounds, double dt, double diff, double visc, ref double[,] uret, ref double[,] vret) |
277 | { | 277 | { |
278 | int N = this.h; | 278 | int N = h; |
279 | 279 | ||
280 | int size = (N * 2) * (N * 2); | 280 | int size = (N*2)*(N*2); |
281 | 281 | ||
282 | double[] u = new double[size]; // Force, X axis | 282 | double[] u = new double[size]; // Force, X axis |
283 | double[] v = new double[size]; // Force, Y axis | 283 | double[] v = new double[size]; // Force, Y axis |
@@ -286,8 +286,8 @@ namespace libTerrain | |||
286 | double[] dens = new double[size]; | 286 | double[] dens = new double[size]; |
287 | double[] dens_prev = new double[size]; | 287 | double[] dens_prev = new double[size]; |
288 | 288 | ||
289 | nsDoublesToBuffer(this.map, N, ref dens); | 289 | nsDoublesToBuffer(map, N, ref dens); |
290 | nsDoublesToBuffer(this.map, N, ref dens_prev); | 290 | nsDoublesToBuffer(map, N, ref dens_prev); |
291 | 291 | ||
292 | for (int i = 0; i < rounds; i++) | 292 | for (int i = 0; i < rounds; i++) |
293 | { | 293 | { |
@@ -301,7 +301,7 @@ namespace libTerrain | |||
301 | 301 | ||
302 | nsBufferToDoubles(ref u, N, ref uret); | 302 | nsBufferToDoubles(ref u, N, ref uret); |
303 | nsBufferToDoubles(ref v, N, ref vret); | 303 | nsBufferToDoubles(ref v, N, ref vret); |
304 | nsBufferToDoubles(ref dens, N, ref this.map); | 304 | nsBufferToDoubles(ref dens, N, ref map); |
305 | } | 305 | } |
306 | } | 306 | } |
307 | } \ No newline at end of file | 307 | } \ No newline at end of file |
diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Manipulators/ThermalWeathering.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Manipulators/ThermalWeathering.cs index 9148c3c..0ca3d48 100644 --- a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Manipulators/ThermalWeathering.cs +++ b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Manipulators/ThermalWeathering.cs | |||
@@ -26,10 +26,6 @@ | |||
26 | * | 26 | * |
27 | */ | 27 | */ |
28 | 28 | ||
29 | using System; | ||
30 | using System.Collections.Generic; | ||
31 | using System.Text; | ||
32 | |||
33 | namespace libTerrain | 29 | namespace libTerrain |
34 | { | 30 | { |
35 | partial class Channel | 31 | partial class Channel |
@@ -47,10 +43,11 @@ namespace libTerrain | |||
47 | double[,] lastFrame; | 43 | double[,] lastFrame; |
48 | double[,] thisFrame; | 44 | double[,] thisFrame; |
49 | 45 | ||
50 | lastFrame = (double[,])map.Clone(); | 46 | lastFrame = (double[,]) map.Clone(); |
51 | thisFrame = (double[,])map.Clone(); | 47 | thisFrame = (double[,]) map.Clone(); |
52 | 48 | ||
53 | NeighbourSystem type = NeighbourSystem.Moore; // Using moore neighbourhood (twice as computationally expensive) | 49 | NeighbourSystem type = NeighbourSystem.Moore; |
50 | // Using moore neighbourhood (twice as computationally expensive) | ||
54 | int NEIGHBOUR_ME = 4; // I am always 4 in both systems. | 51 | int NEIGHBOUR_ME = 4; // I am always 4 in both systems. |
55 | 52 | ||
56 | int NEIGHBOUR_MAX = type == NeighbourSystem.Moore ? 9 : 5; | 53 | int NEIGHBOUR_MAX = type == NeighbourSystem.Moore ? 9 : 5; |
@@ -88,19 +85,18 @@ namespace libTerrain | |||
88 | 85 | ||
89 | if (target > heightF + talus) | 86 | if (target > heightF + talus) |
90 | { | 87 | { |
91 | double calc = c * ((target - heightF) - talus); | 88 | double calc = c*((target - heightF) - talus); |
92 | heightF += calc; | 89 | heightF += calc; |
93 | target -= calc; | 90 | target -= calc; |
94 | } | 91 | } |
95 | 92 | ||
96 | thisFrame[x, y] = heightF; | 93 | thisFrame[x, y] = heightF; |
97 | thisFrame[coords[0], coords[1]] = target; | 94 | thisFrame[coords[0], coords[1]] = target; |
98 | |||
99 | } | 95 | } |
100 | } | 96 | } |
101 | } | 97 | } |
102 | } | 98 | } |
103 | lastFrame = (double[,])thisFrame.Clone(); | 99 | lastFrame = (double[,]) thisFrame.Clone(); |
104 | } | 100 | } |
105 | 101 | ||
106 | map = thisFrame; | 102 | map = thisFrame; |
@@ -109,4 +105,4 @@ namespace libTerrain | |||
109 | return this; | 105 | return this; |
110 | } | 106 | } |
111 | } | 107 | } |
112 | } | 108 | } \ No newline at end of file |
diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Neighbours.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Neighbours.cs index 316bd9a..4004747 100644 --- a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Neighbours.cs +++ b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Neighbours.cs | |||
@@ -26,19 +26,15 @@ | |||
26 | * | 26 | * |
27 | */ | 27 | */ |
28 | 28 | ||
29 | using System; | ||
30 | using System.Collections.Generic; | ||
31 | using System.Text; | ||
32 | |||
33 | namespace libTerrain | 29 | namespace libTerrain |
34 | { | 30 | { |
35 | partial class Channel | 31 | partial class Channel |
36 | { | 32 | { |
37 | enum NeighbourSystem | 33 | private enum NeighbourSystem |
38 | { | 34 | { |
39 | Moore, | 35 | Moore, |
40 | VonNeumann | 36 | VonNeumann |
41 | }; | 37 | } ; |
42 | 38 | ||
43 | private int[] Neighbours(NeighbourSystem type, int index) | 39 | private int[] Neighbours(NeighbourSystem type, int index) |
44 | { | 40 | { |
@@ -138,4 +134,4 @@ namespace libTerrain | |||
138 | return coord; | 134 | return coord; |
139 | } | 135 | } |
140 | } | 136 | } |
141 | } | 137 | } \ No newline at end of file |
diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Operators.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Operators.cs index 0306e58..ae7530c 100644 --- a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Operators.cs +++ b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Operators.cs | |||
@@ -27,8 +27,6 @@ | |||
27 | */ | 27 | */ |
28 | 28 | ||
29 | using System; | 29 | using System; |
30 | using System.Collections.Generic; | ||
31 | using System.Text; | ||
32 | 30 | ||
33 | namespace libTerrain | 31 | namespace libTerrain |
34 | { | 32 | { |
@@ -138,7 +136,7 @@ namespace libTerrain | |||
138 | { | 136 | { |
139 | for (y = 0; y < A.h; y++) | 137 | for (y = 0; y < A.h; y++) |
140 | { | 138 | { |
141 | A.map[x, y] = Math.Pow(A.map[x,y],B.map[x, y]); | 139 | A.map[x, y] = Math.Pow(A.map[x, y], B.map[x, y]); |
142 | } | 140 | } |
143 | } | 141 | } |
144 | 142 | ||
@@ -230,7 +228,7 @@ namespace libTerrain | |||
230 | { | 228 | { |
231 | for (y = 0; y < A.h; y++) | 229 | for (y = 0; y < A.h; y++) |
232 | { | 230 | { |
233 | A.map[x, y] = Math.Pow(A.map[x,y],B); | 231 | A.map[x, y] = Math.Pow(A.map[x, y], B); |
234 | } | 232 | } |
235 | } | 233 | } |
236 | 234 | ||
@@ -238,6 +236,5 @@ namespace libTerrain | |||
238 | 236 | ||
239 | return A; | 237 | return A; |
240 | } | 238 | } |
241 | |||
242 | } | 239 | } |
243 | } | 240 | } \ No newline at end of file |