aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Editing/Flatten.cs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Editing/Flatten.cs296
1 files changed, 148 insertions, 148 deletions
diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Editing/Flatten.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Editing/Flatten.cs
index 48f02e8..713ae23 100644
--- a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Editing/Flatten.cs
+++ b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Editing/Flatten.cs
@@ -1,149 +1,149 @@
1/* 1/*
2* Copyright (c) Contributors, http://www.openmetaverse.org/ 2* Copyright (c) Contributors, http://www.openmetaverse.org/
3* See CONTRIBUTORS.TXT for a full list of copyright holders. 3* See CONTRIBUTORS.TXT for a full list of copyright holders.
4* 4*
5* Redistribution and use in source and binary forms, with or without 5* Redistribution and use in source and binary forms, with or without
6* modification, are permitted provided that the following conditions are met: 6* modification, are permitted provided that the following conditions are met:
7* * Redistributions of source code must retain the above copyright 7* * Redistributions of source code must retain the above copyright
8* notice, this list of conditions and the following disclaimer. 8* notice, this list of conditions and the following disclaimer.
9* * Redistributions in binary form must reproduce the above copyright 9* * Redistributions in binary form must reproduce the above copyright
10* notice, this list of conditions and the following disclaimer in the 10* notice, this list of conditions and the following disclaimer in the
11* documentation and/or other materials provided with the distribution. 11* documentation and/or other materials provided with the distribution.
12* * Neither the name of the OpenSim Project nor the 12* * Neither the name of the OpenSim Project nor the
13* names of its contributors may be used to endorse or promote products 13* names of its contributors may be used to endorse or promote products
14* derived from this software without specific prior written permission. 14* derived from this software without specific prior written permission.
15* 15*
16* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY 16* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
17* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY 19* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 22* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26* 26*
27*/ 27*/
28 28
29 29
30using System; 30using System;
31using System.Collections.Generic; 31using System.Collections.Generic;
32using System.Text; 32using System.Text;
33 33
34namespace libTerrain 34namespace libTerrain
35{ 35{
36 partial class Channel 36 partial class Channel
37 { 37 {
38 /// <summary> 38 /// <summary>
39 /// Flattens the area underneath rx,ry by moving it to the average of the area. Uses a spherical mask provided by the raise() function. 39 /// Flattens the area underneath rx,ry by moving it to the average of the area. Uses a spherical mask provided by the raise() function.
40 /// </summary> 40 /// </summary>
41 /// <param name="rx">The X coordinate of the terrain mask</param> 41 /// <param name="rx">The X coordinate of the terrain mask</param>
42 /// <param name="ry">The Y coordinate of the terrain mask</param> 42 /// <param name="ry">The Y coordinate of the terrain mask</param>
43 /// <param name="size">The size of the terrain mask</param> 43 /// <param name="size">The size of the terrain mask</param>
44 /// <param name="amount">The scale of the terrain mask</param> 44 /// <param name="amount">The scale of the terrain mask</param>
45 public void Flatten(double rx, double ry, double size, double amount) 45 public void Flatten(double rx, double ry, double size, double amount)
46 { 46 {
47 FlattenSlow(rx, ry, size, amount); 47 FlattenSlow(rx, ry, size, amount);
48 } 48 }
49 49
50 private void FlattenSlow(double rx, double ry, double size, double amount) 50 private void FlattenSlow(double rx, double ry, double size, double amount)
51 { 51 {
52 // Generate the mask 52 // Generate the mask
53 Channel temp = new Channel(w, h); 53 Channel temp = new Channel(w, h);
54 temp.Fill(0); 54 temp.Fill(0);
55 temp.Raise(rx, ry, size, amount); 55 temp.Raise(rx, ry, size, amount);
56 temp.Normalise(); 56 temp.Normalise();
57 double total_mod = temp.Sum(); 57 double total_mod = temp.Sum();
58 58
59 // Establish the average height under the area 59 // Establish the average height under the area
60 Channel newmap = new Channel(w, h); 60 Channel newmap = new Channel(w, h);
61 newmap.map = (double[,])map.Clone(); 61 newmap.map = (double[,])map.Clone();
62 62
63 newmap *= temp; 63 newmap *= temp;
64 64
65 double total_terrain = newmap.Sum(); 65 double total_terrain = newmap.Sum();
66 double avg_height = total_terrain / total_mod; 66 double avg_height = total_terrain / total_mod;
67 67
68 // Create a flat terrain using the average height 68 // Create a flat terrain using the average height
69 Channel flat = new Channel(w, h); 69 Channel flat = new Channel(w, h);
70 flat.Fill(avg_height); 70 flat.Fill(avg_height);
71 71
72 // Blend the current terrain with the average height terrain 72 // Blend the current terrain with the average height terrain
73 // using the "raised" empty terrain as a mask 73 // using the "raised" empty terrain as a mask
74 Blend(flat, temp); 74 Blend(flat, temp);
75 75
76 } 76 }
77 77
78 private void FlattenFast(double rx, double ry, double size, double amount) 78 private void FlattenFast(double rx, double ry, double size, double amount)
79 { 79 {
80 int x, y; 80 int x, y;
81 double avg = 0; 81 double avg = 0;
82 double div = 0; 82 double div = 0;
83 83
84 int minX = Math.Max(0, (int)(rx - (size + 1))); 84 int minX = Math.Max(0, (int)(rx - (size + 1)));
85 int maxX = Math.Min(w, (int)(rx + (size + 1))); 85 int maxX = Math.Min(w, (int)(rx + (size + 1)));
86 int minY = Math.Max(0, (int)(ry - (size + 1))); 86 int minY = Math.Max(0, (int)(ry - (size + 1)));
87 int maxY = Math.Min(h, (int)(ry + (size + 1))); 87 int maxY = Math.Min(h, (int)(ry + (size + 1)));
88 88
89 for (x = minX; x < maxX; x++) 89 for (x = minX; x < maxX; x++)
90 { 90 {
91 for (y = minY; y < maxY; y++) 91 for (y = minY; y < maxY; y++)
92 { 92 {
93 double z = size; 93 double z = size;
94 z *= z; 94 z *= z;
95 z -= ((x - rx) * (x - rx)) + ((y - ry) * (y - ry)); 95 z -= ((x - rx) * (x - rx)) + ((y - ry) * (y - ry));
96 96
97 if (z < 0) 97 if (z < 0)
98 z = 0; 98 z = 0;
99 99
100 avg += z * amount; 100 avg += z * amount;
101 div += z; 101 div += z;
102 } 102 }
103 } 103 }
104 104
105 double height = avg / div; 105 double height = avg / div;
106 106
107 for (x = minX; x < maxX; x++) 107 for (x = minX; x < maxX; x++)
108 { 108 {
109 for (y = minY; y < maxY; y++) 109 for (y = minY; y < maxY; y++)
110 { 110 {
111 double z = size; 111 double z = size;
112 z *= z; 112 z *= z;
113 z -= ((x - rx) * (x - rx)) + ((y - ry) * (y - ry)); 113 z -= ((x - rx) * (x - rx)) + ((y - ry) * (y - ry));
114 114
115 if (z < 0) 115 if (z < 0)
116 z = 0; 116 z = 0;
117 117
118 Set(x, y, Tools.linearInterpolate(map[x, y], height, z)); 118 Set(x, y, Tools.linearInterpolate(map[x, y], height, z));
119 } 119 }
120 } 120 }
121 } 121 }
122 122
123 public void Flatten(Channel mask, double amount) 123 public void Flatten(Channel mask, double amount)
124 { 124 {
125 // Generate the mask 125 // Generate the mask
126 Channel temp = mask * amount; 126 Channel temp = mask * amount;
127 temp.Clip(0, 1); // Cut off out-of-bounds values 127 temp.Clip(0, 1); // Cut off out-of-bounds values
128 128
129 double total_mod = temp.Sum(); 129 double total_mod = temp.Sum();
130 130
131 // Establish the average height under the area 131 // Establish the average height under the area
132 Channel map = new Channel(w, h); 132 Channel map = new Channel(w, h);
133 map.map = (double[,])this.map.Clone(); 133 map.map = (double[,])this.map.Clone();
134 134
135 map *= temp; 135 map *= temp;
136 136
137 double total_terrain = map.Sum(); 137 double total_terrain = map.Sum();
138 double avg_height = total_terrain / total_mod; 138 double avg_height = total_terrain / total_mod;
139 139
140 // Create a flat terrain using the average height 140 // Create a flat terrain using the average height
141 Channel flat = new Channel(w, h); 141 Channel flat = new Channel(w, h);
142 flat.Fill(avg_height); 142 flat.Fill(avg_height);
143 143
144 // Blend the current terrain with the average height terrain 144 // Blend the current terrain with the average height terrain
145 // using the "raised" empty terrain as a mask 145 // using the "raised" empty terrain as a mask
146 Blend(flat, temp); 146 Blend(flat, temp);
147 } 147 }
148 } 148 }
149} \ No newline at end of file 149} \ No newline at end of file