diff options
Diffstat (limited to 'OpenSim/Region/CoreModules/World/Wind/Plugins/ConfigurableWind.cs')
-rw-r--r-- | OpenSim/Region/CoreModules/World/Wind/Plugins/ConfigurableWind.cs | 422 |
1 files changed, 211 insertions, 211 deletions
diff --git a/OpenSim/Region/CoreModules/World/Wind/Plugins/ConfigurableWind.cs b/OpenSim/Region/CoreModules/World/Wind/Plugins/ConfigurableWind.cs index 2f5cc31..2a0bb73 100644 --- a/OpenSim/Region/CoreModules/World/Wind/Plugins/ConfigurableWind.cs +++ b/OpenSim/Region/CoreModules/World/Wind/Plugins/ConfigurableWind.cs | |||
@@ -1,211 +1,211 @@ | |||
1 | using System; | 1 | using System; |
2 | using System.Collections.Generic; | 2 | using System.Collections.Generic; |
3 | using System.Reflection; | 3 | using System.Reflection; |
4 | 4 | ||
5 | using log4net; | 5 | using log4net; |
6 | using OpenMetaverse; | 6 | using OpenMetaverse; |
7 | 7 | ||
8 | using OpenSim.Region.CoreModules.World.Wind; | 8 | using OpenSim.Region.CoreModules.World.Wind; |
9 | 9 | ||
10 | namespace OpenSim.Region.CoreModules.World.Wind.Plugins | 10 | namespace OpenSim.Region.CoreModules.World.Wind.Plugins |
11 | { | 11 | { |
12 | class ConfigurableWind : Mono.Addins.TypeExtensionNode, IWindModelPlugin | 12 | class ConfigurableWind : Mono.Addins.TypeExtensionNode, IWindModelPlugin |
13 | { | 13 | { |
14 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 14 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
15 | 15 | ||
16 | private Vector2[] m_windSpeeds = new Vector2[16 * 16]; | 16 | private Vector2[] m_windSpeeds = new Vector2[16 * 16]; |
17 | private Random m_rndnums = new Random(Environment.TickCount); | 17 | private Random m_rndnums = new Random(Environment.TickCount); |
18 | 18 | ||
19 | private float m_avgStrength = 5.0f; // Average magnitude of the wind vector | 19 | private float m_avgStrength = 5.0f; // Average magnitude of the wind vector |
20 | private float m_avgDirection = 0.0f; // Average direction of the wind in degrees | 20 | private float m_avgDirection = 0.0f; // Average direction of the wind in degrees |
21 | private float m_varStrength = 5.0f; // Max Strength Variance | 21 | private float m_varStrength = 5.0f; // Max Strength Variance |
22 | private float m_varDirection = 30.0f;// Max Direction Variance | 22 | private float m_varDirection = 30.0f;// Max Direction Variance |
23 | private float m_rateChange = 1.0f; // | 23 | private float m_rateChange = 1.0f; // |
24 | 24 | ||
25 | private Vector2 m_curPredominateWind = new Vector2(); | 25 | private Vector2 m_curPredominateWind = new Vector2(); |
26 | 26 | ||
27 | 27 | ||
28 | 28 | ||
29 | #region IPlugin Members | 29 | #region IPlugin Members |
30 | 30 | ||
31 | public string Version | 31 | public string Version |
32 | { | 32 | { |
33 | get { return "1.0.0.0"; } | 33 | get { return "1.0.0.0"; } |
34 | } | 34 | } |
35 | 35 | ||
36 | public string Name | 36 | public string Name |
37 | { | 37 | { |
38 | get { return "ConfigurableWind"; } | 38 | get { return "ConfigurableWind"; } |
39 | } | 39 | } |
40 | 40 | ||
41 | public void Initialise() | 41 | public void Initialise() |
42 | { | 42 | { |
43 | 43 | ||
44 | } | 44 | } |
45 | 45 | ||
46 | #endregion | 46 | #endregion |
47 | 47 | ||
48 | #region IDisposable Members | 48 | #region IDisposable Members |
49 | 49 | ||
50 | public void Dispose() | 50 | public void Dispose() |
51 | { | 51 | { |
52 | m_windSpeeds = null; | 52 | m_windSpeeds = null; |
53 | } | 53 | } |
54 | 54 | ||
55 | #endregion | 55 | #endregion |
56 | 56 | ||
57 | #region IWindModelPlugin Members | 57 | #region IWindModelPlugin Members |
58 | 58 | ||
59 | public void WindConfig(OpenSim.Region.Framework.Scenes.Scene scene, Nini.Config.IConfig windConfig) | 59 | public void WindConfig(OpenSim.Region.Framework.Scenes.Scene scene, Nini.Config.IConfig windConfig) |
60 | { | 60 | { |
61 | if( windConfig != null ) | 61 | if( windConfig != null ) |
62 | { | 62 | { |
63 | // Uses strength value if avg_strength not specified | 63 | // Uses strength value if avg_strength not specified |
64 | m_avgStrength = windConfig.GetFloat("strength", 5.0F); | 64 | m_avgStrength = windConfig.GetFloat("strength", 5.0F); |
65 | m_avgStrength = windConfig.GetFloat("avg_strength", 5.0F); | 65 | m_avgStrength = windConfig.GetFloat("avg_strength", 5.0F); |
66 | 66 | ||
67 | m_avgDirection = windConfig.GetFloat("avg_direction", 0.0F); | 67 | m_avgDirection = windConfig.GetFloat("avg_direction", 0.0F); |
68 | m_varStrength = windConfig.GetFloat("var_strength", 5.0F); | 68 | m_varStrength = windConfig.GetFloat("var_strength", 5.0F); |
69 | m_varDirection = windConfig.GetFloat("var_direction", 30.0F); | 69 | m_varDirection = windConfig.GetFloat("var_direction", 30.0F); |
70 | m_rateChange = windConfig.GetFloat("rate_change", 1.0F); | 70 | m_rateChange = windConfig.GetFloat("rate_change", 1.0F); |
71 | 71 | ||
72 | LogSettings(); | 72 | LogSettings(); |
73 | } | 73 | } |
74 | } | 74 | } |
75 | 75 | ||
76 | public void WindUpdate(uint frame) | 76 | public void WindUpdate(uint frame) |
77 | { | 77 | { |
78 | double avgAng = m_avgDirection * (Math.PI/180.0f); | 78 | double avgAng = m_avgDirection * (Math.PI/180.0f); |
79 | double varDir = m_varDirection * (Math.PI/180.0f); | 79 | double varDir = m_varDirection * (Math.PI/180.0f); |
80 | 80 | ||
81 | // Prevailing wind algorithm | 81 | // Prevailing wind algorithm |
82 | // Inspired by Kanker Greenacre | 82 | // Inspired by Kanker Greenacre |
83 | 83 | ||
84 | // TODO: | 84 | // TODO: |
85 | // * This should probably be based on in-world time. | 85 | // * This should probably be based on in-world time. |
86 | // * should probably move all these local variables to class members and constants | 86 | // * should probably move all these local variables to class members and constants |
87 | double time = DateTime.Now.TimeOfDay.Seconds / 86400; | 87 | double time = DateTime.Now.TimeOfDay.Seconds / 86400; |
88 | 88 | ||
89 | double theta = time * (2 * Math.PI) * m_rateChange; | 89 | double theta = time * (2 * Math.PI) * m_rateChange; |
90 | 90 | ||
91 | double offset = Math.Sin(theta) * Math.Sin(theta*2) * Math.Sin(theta*9) * Math.Cos(theta*4); | 91 | double offset = Math.Sin(theta) * Math.Sin(theta*2) * Math.Sin(theta*9) * Math.Cos(theta*4); |
92 | 92 | ||
93 | double windDir = avgAng + (varDir * offset); | 93 | double windDir = avgAng + (varDir * offset); |
94 | 94 | ||
95 | offset = Math.Sin(theta) * Math.Sin(theta*4) + (Math.Sin(theta*13) / 3); | 95 | offset = Math.Sin(theta) * Math.Sin(theta*4) + (Math.Sin(theta*13) / 3); |
96 | double windSpeed = m_avgStrength + (m_varStrength * offset); | 96 | double windSpeed = m_avgStrength + (m_varStrength * offset); |
97 | 97 | ||
98 | if (windSpeed<0) | 98 | if (windSpeed<0) |
99 | windSpeed=0; | 99 | windSpeed=0; |
100 | 100 | ||
101 | 101 | ||
102 | 102 | ||
103 | m_curPredominateWind.X = (float)Math.Cos(windDir); | 103 | m_curPredominateWind.X = (float)Math.Cos(windDir); |
104 | m_curPredominateWind.Y = (float)Math.Sin(windDir); | 104 | m_curPredominateWind.Y = (float)Math.Sin(windDir); |
105 | 105 | ||
106 | m_curPredominateWind.Normalize(); | 106 | m_curPredominateWind.Normalize(); |
107 | m_curPredominateWind.X *= (float)windSpeed; | 107 | m_curPredominateWind.X *= (float)windSpeed; |
108 | m_curPredominateWind.Y *= (float)windSpeed; | 108 | m_curPredominateWind.Y *= (float)windSpeed; |
109 | 109 | ||
110 | for (int y = 0; y < 16; y++) | 110 | for (int y = 0; y < 16; y++) |
111 | { | 111 | { |
112 | for (int x = 0; x < 16; x++) | 112 | for (int x = 0; x < 16; x++) |
113 | { | 113 | { |
114 | m_windSpeeds[y * 16 + x] = m_curPredominateWind; | 114 | m_windSpeeds[y * 16 + x] = m_curPredominateWind; |
115 | } | 115 | } |
116 | } | 116 | } |
117 | } | 117 | } |
118 | 118 | ||
119 | public Vector3 WindSpeed(float fX, float fY, float fZ) | 119 | public Vector3 WindSpeed(float fX, float fY, float fZ) |
120 | { | 120 | { |
121 | return new Vector3(m_curPredominateWind, 0.0f); | 121 | return new Vector3(m_curPredominateWind, 0.0f); |
122 | } | 122 | } |
123 | 123 | ||
124 | public Vector2[] WindLLClientArray() | 124 | public Vector2[] WindLLClientArray() |
125 | { | 125 | { |
126 | return m_windSpeeds; | 126 | return m_windSpeeds; |
127 | } | 127 | } |
128 | 128 | ||
129 | public string Description | 129 | public string Description |
130 | { | 130 | { |
131 | get | 131 | get |
132 | { | 132 | { |
133 | return "Provides a predominate wind direction that can change within configured variances for direction and speed."; | 133 | return "Provides a predominate wind direction that can change within configured variances for direction and speed."; |
134 | } | 134 | } |
135 | } | 135 | } |
136 | 136 | ||
137 | public System.Collections.Generic.Dictionary<string, string> WindParams() | 137 | public System.Collections.Generic.Dictionary<string, string> WindParams() |
138 | { | 138 | { |
139 | Dictionary<string, string> Params = new Dictionary<string, string>(); | 139 | Dictionary<string, string> Params = new Dictionary<string, string>(); |
140 | 140 | ||
141 | Params.Add("avgStrength", "average wind strength"); | 141 | Params.Add("avgStrength", "average wind strength"); |
142 | Params.Add("avgDirection", "average wind direction in degrees"); | 142 | Params.Add("avgDirection", "average wind direction in degrees"); |
143 | Params.Add("varStrength", "allowable variance in wind strength"); | 143 | Params.Add("varStrength", "allowable variance in wind strength"); |
144 | Params.Add("varDirection", "allowable variance in wind direction in +/- degrees"); | 144 | Params.Add("varDirection", "allowable variance in wind direction in +/- degrees"); |
145 | Params.Add("rateChange", "rate of change"); | 145 | Params.Add("rateChange", "rate of change"); |
146 | 146 | ||
147 | return Params; | 147 | return Params; |
148 | } | 148 | } |
149 | 149 | ||
150 | public void WindParamSet(string param, float value) | 150 | public void WindParamSet(string param, float value) |
151 | { | 151 | { |
152 | switch (param) | 152 | switch (param) |
153 | { | 153 | { |
154 | case "avgStrength": | 154 | case "avgStrength": |
155 | m_avgStrength = value; | 155 | m_avgStrength = value; |
156 | break; | 156 | break; |
157 | case "avgDirection": | 157 | case "avgDirection": |
158 | m_avgDirection = value; | 158 | m_avgDirection = value; |
159 | break; | 159 | break; |
160 | case "varStrength": | 160 | case "varStrength": |
161 | m_varStrength = value; | 161 | m_varStrength = value; |
162 | break; | 162 | break; |
163 | case "varDirection": | 163 | case "varDirection": |
164 | m_varDirection = value; | 164 | m_varDirection = value; |
165 | break; | 165 | break; |
166 | case "rateChange": | 166 | case "rateChange": |
167 | m_rateChange = value; | 167 | m_rateChange = value; |
168 | break; | 168 | break; |
169 | } | 169 | } |
170 | } | 170 | } |
171 | 171 | ||
172 | public float WindParamGet(string param) | 172 | public float WindParamGet(string param) |
173 | { | 173 | { |
174 | switch (param) | 174 | switch (param) |
175 | { | 175 | { |
176 | case "avgStrength": | 176 | case "avgStrength": |
177 | return m_avgStrength; | 177 | return m_avgStrength; |
178 | case "avgDirection": | 178 | case "avgDirection": |
179 | return m_avgDirection; | 179 | return m_avgDirection; |
180 | case "varStrength": | 180 | case "varStrength": |
181 | return m_varStrength; | 181 | return m_varStrength; |
182 | case "varDirection": | 182 | case "varDirection": |
183 | return m_varDirection; | 183 | return m_varDirection; |
184 | case "rateChange": | 184 | case "rateChange": |
185 | return m_rateChange; | 185 | return m_rateChange; |
186 | default: | 186 | default: |
187 | throw new Exception(String.Format("Unknown {0} parameter {1}", this.Name, param)); | 187 | throw new Exception(String.Format("Unknown {0} parameter {1}", this.Name, param)); |
188 | 188 | ||
189 | } | 189 | } |
190 | } | 190 | } |
191 | 191 | ||
192 | 192 | ||
193 | 193 | ||
194 | #endregion | 194 | #endregion |
195 | 195 | ||
196 | 196 | ||
197 | private void LogSettings() | 197 | private void LogSettings() |
198 | { | 198 | { |
199 | m_log.InfoFormat("[ConfigurableWind] Average Strength : {0}", m_avgStrength); | 199 | m_log.InfoFormat("[ConfigurableWind] Average Strength : {0}", m_avgStrength); |
200 | m_log.InfoFormat("[ConfigurableWind] Average Direction : {0}", m_avgDirection); | 200 | m_log.InfoFormat("[ConfigurableWind] Average Direction : {0}", m_avgDirection); |
201 | m_log.InfoFormat("[ConfigurableWind] Varience Strength : {0}", m_varStrength); | 201 | m_log.InfoFormat("[ConfigurableWind] Varience Strength : {0}", m_varStrength); |
202 | m_log.InfoFormat("[ConfigurableWind] Varience Direction : {0}", m_varDirection); | 202 | m_log.InfoFormat("[ConfigurableWind] Varience Direction : {0}", m_varDirection); |
203 | m_log.InfoFormat("[ConfigurableWind] Rate Change : {0}", m_rateChange); | 203 | m_log.InfoFormat("[ConfigurableWind] Rate Change : {0}", m_rateChange); |
204 | } | 204 | } |
205 | 205 | ||
206 | #region IWindModelPlugin Members | 206 | #region IWindModelPlugin Members |
207 | 207 | ||
208 | 208 | ||
209 | #endregion | 209 | #endregion |
210 | } | 210 | } |
211 | } | 211 | } |