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