diff options
Diffstat (limited to 'libraries/libTerrain/libTerrain/Channel/Editing/Raise.cs')
-rw-r--r-- | libraries/libTerrain/libTerrain/Channel/Editing/Raise.cs | 117 |
1 files changed, 117 insertions, 0 deletions
diff --git a/libraries/libTerrain/libTerrain/Channel/Editing/Raise.cs b/libraries/libTerrain/libTerrain/Channel/Editing/Raise.cs new file mode 100644 index 0000000..ce1ce98 --- /dev/null +++ b/libraries/libTerrain/libTerrain/Channel/Editing/Raise.cs | |||
@@ -0,0 +1,117 @@ | |||
1 | /* | ||
2 | Redistribution and use in source and binary forms, with or without | ||
3 | modification, are permitted provided that the following conditions are | ||
4 | met: | ||
5 | |||
6 | * Redistributions of source code must retain the above copyright | ||
7 | notice, this list of conditions and the following disclaimer. | ||
8 | |||
9 | * Redistributions in binary form must reproduce the above | ||
10 | copyright notice, this list of conditions and the following | ||
11 | disclaimer in the documentation and/or other materials provided | ||
12 | with the distribution. | ||
13 | |||
14 | * Neither the name of libTerrain nor the names of | ||
15 | its contributors may be used to endorse or promote products | ||
16 | derived from this software without specific prior written | ||
17 | permission. | ||
18 | |||
19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
20 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
21 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
22 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
23 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
24 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
25 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
26 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
27 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
28 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
29 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
30 | */ | ||
31 | |||
32 | |||
33 | using System; | ||
34 | using System.Collections.Generic; | ||
35 | using System.Text; | ||
36 | |||
37 | namespace libTerrain | ||
38 | { | ||
39 | partial class Channel | ||
40 | { | ||
41 | /// <summary> | ||
42 | /// Raises land around the selection | ||
43 | /// </summary> | ||
44 | /// <param name="rx">The center the X coordinate of where you wish to raise the land</param> | ||
45 | /// <param name="ry">The center the Y coordinate of where you wish to raise the land</param> | ||
46 | /// <param name="size">The radius of the dimple</param> | ||
47 | /// <param name="amount">How much impact to add to the terrain (0..2 usually)</param> | ||
48 | public void raise(double rx, double ry, double size, double amount) | ||
49 | { | ||
50 | raiseSphere(rx, ry, size, amount); | ||
51 | } | ||
52 | |||
53 | /// <summary> | ||
54 | /// Raises land in a sphere around the selection | ||
55 | /// </summary> | ||
56 | /// <param name="rx">The center the X coordinate of where you wish to raise the land</param> | ||
57 | /// <param name="ry">The center the Y coordinate of where you wish to raise the land</param> | ||
58 | /// <param name="size">The radius of the sphere dimple</param> | ||
59 | /// <param name="amount">How much impact to add to the terrain (0..2 usually)</param> | ||
60 | public void raiseSphere(double rx, double ry, double size, double amount) | ||
61 | { | ||
62 | int x, y; | ||
63 | for (x = 0; x < w; x++) | ||
64 | { | ||
65 | for (y = 0; y < h; y++) | ||
66 | { | ||
67 | double z = size; | ||
68 | z *= z; | ||
69 | z -= ((x - rx) * (x - rx)) + ((y - ry) * (y - ry)); | ||
70 | |||
71 | if (z < 0) | ||
72 | z = 0; | ||
73 | |||
74 | map[x, y] += z * amount; | ||
75 | } | ||
76 | } | ||
77 | } | ||
78 | |||
79 | /// <summary> | ||
80 | /// Lowers land in a sphere around the selection | ||
81 | /// </summary> | ||
82 | /// <param name="rx">The center the X coordinate of where you wish to lower the land</param> | ||
83 | /// <param name="ry">The center the Y coordinate of where you wish to lower the land</param> | ||
84 | /// <param name="size">The radius of the sphere dimple</param> | ||
85 | /// <param name="amount">How much impact to remove from the terrain (0..2 usually)</param> | ||
86 | public void lower(double rx, double ry, double size, double amount) | ||
87 | { | ||
88 | lowerSphere(rx, ry, size, amount); | ||
89 | } | ||
90 | |||
91 | /// <summary> | ||
92 | /// Lowers land in a sphere around the selection | ||
93 | /// </summary> | ||
94 | /// <param name="rx">The center the X coordinate of where you wish to lower the land</param> | ||
95 | /// <param name="ry">The center the Y coordinate of where you wish to lower the land</param> | ||
96 | /// <param name="size">The radius of the sphere dimple</param> | ||
97 | /// <param name="amount">How much impact to remove from the terrain (0..2 usually)</param> | ||
98 | public void lowerSphere(double rx, double ry, double size, double amount) | ||
99 | { | ||
100 | int x, y; | ||
101 | for (x = 0; x < w; x++) | ||
102 | { | ||
103 | for (y = 0; y < h; y++) | ||
104 | { | ||
105 | double z = size; | ||
106 | z *= z; | ||
107 | z -= ((x - rx) * (x - rx)) + ((y - ry) * (y - ry)); | ||
108 | |||
109 | if (z < 0) | ||
110 | z = 0; | ||
111 | |||
112 | map[x, y] -= z * amount; | ||
113 | } | ||
114 | } | ||
115 | } | ||
116 | } | ||
117 | } \ No newline at end of file | ||