aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/CoreModules/World/Wind/Plugins/SimpleRandomWind.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/CoreModules/World/Wind/Plugins/SimpleRandomWind.cs')
-rw-r--r--OpenSim/Region/CoreModules/World/Wind/Plugins/SimpleRandomWind.cs139
1 files changed, 139 insertions, 0 deletions
diff --git a/OpenSim/Region/CoreModules/World/Wind/Plugins/SimpleRandomWind.cs b/OpenSim/Region/CoreModules/World/Wind/Plugins/SimpleRandomWind.cs
new file mode 100644
index 0000000..040a3c4
--- /dev/null
+++ b/OpenSim/Region/CoreModules/World/Wind/Plugins/SimpleRandomWind.cs
@@ -0,0 +1,139 @@
1using System;
2using System.Collections.Generic;
3
4using OpenMetaverse;
5
6
7namespace OpenSim.Region.CoreModules.World.Wind.Plugins
8{
9 class SimpleRandomWind : Mono.Addins.TypeExtensionNode, IWindModelPlugin
10 {
11 private Vector2[] m_windSpeeds = new Vector2[16 * 16];
12 private float m_strength = 1.0f;
13 private Random m_rndnums = new Random(Environment.TickCount);
14
15
16 #region IPlugin Members
17
18 public string Version
19 {
20 get { return "1.0.0.0"; }
21 }
22
23 public string Name
24 {
25 get { return "SimpleRandomWind"; }
26 }
27
28 public void Initialise()
29 {
30
31 }
32
33 #endregion
34
35 #region IDisposable Members
36
37 public void Dispose()
38 {
39 m_windSpeeds = null;
40 }
41
42 #endregion
43
44 #region IWindModelPlugin Members
45
46 public void WindConfig(OpenSim.Region.Framework.Scenes.Scene scene, Nini.Config.IConfig windConfig)
47 {
48 if( windConfig != null )
49 {
50 if( windConfig.Contains("strength") )
51 {
52 m_strength = windConfig.GetFloat("strength", 1.0F);
53 }
54 }
55 }
56
57 public void WindUpdate(uint frame)
58 {
59 for (int y = 0; y < 16; y++)
60 {
61 for (int x = 0; x < 16; x++)
62 {
63 m_windSpeeds[y * 16 + x].X = (float)(m_rndnums.NextDouble() * 2d - 1d); // -1 to 1
64 m_windSpeeds[y * 16 + x].Y = (float)(m_rndnums.NextDouble() * 2d - 1d); // -1 to 1
65 m_windSpeeds[y * 16 + x].X *= m_strength;
66 m_windSpeeds[y * 16 + x].Y *= m_strength;
67 }
68 }
69 }
70
71 public Vector3 WindSpeed(float fX, float fY, float fZ)
72 {
73 Vector3 windVector = new Vector3(0.0f, 0.0f, 0.0f);
74
75 int x = (int)fX / 16;
76 int y = (int)fY / 16;
77
78 if (x < 0) x = 0;
79 if (x > 15) x = 15;
80 if (y < 0) y = 0;
81 if (y > 15) y = 15;
82
83 if (m_windSpeeds != null)
84 {
85 windVector.X = m_windSpeeds[y * 16 + x].X;
86 windVector.Y = m_windSpeeds[y * 16 + x].Y;
87 }
88
89 return windVector;
90
91 }
92
93 public Vector2[] WindLLClientArray()
94 {
95 return m_windSpeeds;
96 }
97
98 public string Description
99 {
100 get
101 {
102 return "Provides a simple wind model that creates random wind of a given strength in 16m x 16m patches.";
103 }
104 }
105
106 public System.Collections.Generic.Dictionary<string, string> WindParams()
107 {
108 Dictionary<string, string> Params = new Dictionary<string, string>();
109
110 Params.Add("strength", "wind strength");
111
112 return Params;
113 }
114
115 public void WindParamSet(string param, float value)
116 {
117 switch (param)
118 {
119 case "strength":
120 m_strength = value;
121 break;
122 }
123 }
124
125 public float WindParamGet(string param)
126 {
127 switch (param)
128 {
129 case "strength":
130 return m_strength;
131 default:
132 throw new Exception(String.Format("Unknown {0} parameter {1}", this.Name, param));
133 }
134 }
135
136 #endregion
137
138 }
139}