diff options
author | Adam Frisby | 2008-03-12 11:02:30 +0000 |
---|---|---|
committer | Adam Frisby | 2008-03-12 11:02:30 +0000 |
commit | 8e27656fcc0331c8521e4ef8e8ece4495f1f32ae (patch) | |
tree | 560a7511ec1a7a7e26c540d7ca042825b2f10e1e /OpenSim/Region/Environment/Modules/Terrain/PaintBrushes/SmoothSphere.cs | |
parent | * Renamed Main.cs to GridServerBase.cs (diff) | |
download | opensim-SC-8e27656fcc0331c8521e4ef8e8ece4495f1f32ae.zip opensim-SC-8e27656fcc0331c8521e4ef8e8ece4495f1f32ae.tar.gz opensim-SC-8e27656fcc0331c8521e4ef8e8ece4495f1f32ae.tar.bz2 opensim-SC-8e27656fcc0331c8521e4ef8e8ece4495f1f32ae.tar.xz |
* Refactored some terrain brushes to move out some common functions into TerrainUtil class. More needs doing.
* Adjusted strength of brushes to Math.Pow(2,size), this should in theory work closer to how it was before.
Diffstat (limited to 'OpenSim/Region/Environment/Modules/Terrain/PaintBrushes/SmoothSphere.cs')
-rw-r--r-- | OpenSim/Region/Environment/Modules/Terrain/PaintBrushes/SmoothSphere.cs | 47 |
1 files changed, 5 insertions, 42 deletions
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 | { |