diff options
Diffstat (limited to 'OpenSim/Region/Environment/Modules/Terrain/TerrainUtil.cs')
-rw-r--r-- | OpenSim/Region/Environment/Modules/Terrain/TerrainUtil.cs | 51 |
1 files changed, 51 insertions, 0 deletions
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 @@ | |||
1 | using System; | ||
2 | using OpenSim.Region.Environment.Interfaces; | ||
3 | |||
4 | namespace 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 | } | ||