OpenSim
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros
SimpleRandomWind.cs
Go to the documentation of this file.
1 /*
2  * Copyright (c) Contributors, http://opensimulator.org/
3  * See CONTRIBUTORS.TXT for a full list of copyright holders.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  * * Redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer.
9  * * Redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution.
12  * * Neither the name of the OpenSimulator Project nor the
13  * names of its contributors may be used to endorse or promote products
14  * derived from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19  * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
27 
28 using System;
29 using System.Collections.Generic;
30 
31 using OpenMetaverse;
32 using Mono.Addins;
33 
34 using OpenSim.Region.Framework.Interfaces;
35 
36 namespace OpenSim.Region.CoreModules.World.Wind.Plugins
37 {
38  [Extension(Path = "/OpenSim/WindModule", NodeName = "WindModel", Id = "SimpleRandomWind")]
39  class SimpleRandomWind : Mono.Addins.TypeExtensionNode, IWindModelPlugin
40  {
41  private Vector2[] m_windSpeeds = new Vector2[16 * 16];
42  private float m_strength = 1.0f;
43  private Random m_rndnums = new Random(Environment.TickCount);
44 
45  #region IPlugin Members
46 
47  public string Version
48  {
49  get { return "1.0.0.0"; }
50  }
51 
52  public string Name
53  {
54  get { return "SimpleRandomWind"; }
55  }
56 
57  public void Initialise()
58  {
59  }
60 
61  #endregion
62 
63  #region IDisposable Members
64 
65  public void Dispose()
66  {
67  m_windSpeeds = null;
68  }
69 
70  #endregion
71 
72  #region IWindModelPlugin Members
73 
74  public void WindConfig(OpenSim.Region.Framework.Scenes.Scene scene, Nini.Config.IConfig windConfig)
75  {
76  if (windConfig != null)
77  {
78  if (windConfig.Contains("strength"))
79  {
80  m_strength = windConfig.GetFloat("strength", 1.0F);
81  }
82  }
83  }
84 
85  public void WindUpdate(uint frame)
86  {
87  //Make sure our object is valid (we haven't been disposed of yet)
88  if (m_windSpeeds != null)
89  {
90  for (int y = 0; y < 16; y++)
91  {
92  for (int x = 0; x < 16; x++)
93  {
94  m_windSpeeds[y * 16 + x].X = (float)(m_rndnums.NextDouble() * 2d - 1d); // -1 to 1
95  m_windSpeeds[y * 16 + x].Y = (float)(m_rndnums.NextDouble() * 2d - 1d); // -1 to 1
96  m_windSpeeds[y * 16 + x].X *= m_strength;
97  m_windSpeeds[y * 16 + x].Y *= m_strength;
98  }
99  }
100  }
101  }
102 
103  public Vector3 WindSpeed(float fX, float fY, float fZ)
104  {
105  Vector3 windVector = new Vector3(0.0f, 0.0f, 0.0f);
106 
107  int x = (int)fX / 16;
108  int y = (int)fY / 16;
109 
110  if (x < 0) x = 0;
111  if (x > 15) x = 15;
112  if (y < 0) y = 0;
113  if (y > 15) y = 15;
114 
115  if (m_windSpeeds != null)
116  {
117  windVector.X = m_windSpeeds[y * 16 + x].X;
118  windVector.Y = m_windSpeeds[y * 16 + x].Y;
119  }
120 
121  return windVector;
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 simple wind model that creates random wind of a given strength in 16m x 16m patches.";
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("strength", "wind strength");
142 
143  return Params;
144  }
145 
146  public void WindParamSet(string param, float value)
147  {
148  switch (param)
149  {
150  case "strength":
151  m_strength = value;
152  break;
153  }
154  }
155 
156  public float WindParamGet(string param)
157  {
158  switch (param)
159  {
160  case "strength":
161  return m_strength;
162  default:
163  throw new Exception(String.Format("Unknown {0} parameter {1}", this.Name, param));
164  }
165  }
166 
167  #endregion
168 
169  }
170 }
Vector3 WindSpeed(float fX, float fY, float fZ)
Returns the wind vector at the given local region coordinates.
float WindParamGet(string param)
Get the specified parameter
void WindParamSet(string param, float value)
Set the specified parameter
System.Collections.Generic.Dictionary< string, string > WindParams()
Retrieve a list of parameter/description pairs.
Vector2[] WindLLClientArray()
Generate a 16 x 16 Vector2 array of wind speeds for LL* based viewers
void WindConfig(OpenSim.Region.Framework.Scenes.Scene scene, Nini.Config.IConfig windConfig)
Interactive OpenSim region server
Definition: OpenSim.cs:55