/Aurora/Modules/World/Terrain/PaintBrushes/WeatherSphere.cs

https://bitbucket.org/VirtualReality/async-sim-testing-depracated · C# · 215 lines · 149 code · 37 blank · 29 comment · 15 complexity · 0ceb89b42f270d32e580aaacb0c74dec MD5 · raw file

  1. /*
  2. * Copyright (c) Contributors, http://aurora-sim.org/, 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 Aurora-Sim 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. using System.Collections.Generic;
  28. using Aurora.Framework.Modules;
  29. using Aurora.Framework.SceneInfo;
  30. using OpenMetaverse;
  31. using Aurora.Framework;
  32. namespace Aurora.Modules.Terrain.PaintBrushes
  33. {
  34. /// <summary>
  35. /// Thermal Weathering Paint Brush
  36. /// </summary>
  37. public class WeatherSphere : ITerrainPaintableEffect
  38. {
  39. private const float talus = 0.2f;
  40. private const NeighbourSystem type = NeighbourSystem.Moore;
  41. #region Supporting Functions
  42. private static int[] Neighbours(NeighbourSystem neighbourType, int index)
  43. {
  44. int[] coord = new int[2];
  45. index++;
  46. switch (neighbourType)
  47. {
  48. case NeighbourSystem.Moore:
  49. switch (index)
  50. {
  51. case 1:
  52. coord[0] = -1;
  53. coord[1] = -1;
  54. break;
  55. case 2:
  56. coord[0] = -0;
  57. coord[1] = -1;
  58. break;
  59. case 3:
  60. coord[0] = +1;
  61. coord[1] = -1;
  62. break;
  63. case 4:
  64. coord[0] = -1;
  65. coord[1] = -0;
  66. break;
  67. case 5:
  68. coord[0] = -0;
  69. coord[1] = -0;
  70. break;
  71. case 6:
  72. coord[0] = +1;
  73. coord[1] = -0;
  74. break;
  75. case 7:
  76. coord[0] = -1;
  77. coord[1] = +1;
  78. break;
  79. case 8:
  80. coord[0] = -0;
  81. coord[1] = +1;
  82. break;
  83. case 9:
  84. coord[0] = +1;
  85. coord[1] = +1;
  86. break;
  87. default:
  88. break;
  89. }
  90. break;
  91. case NeighbourSystem.VonNeumann:
  92. switch (index)
  93. {
  94. case 1:
  95. coord[0] = 0;
  96. coord[1] = -1;
  97. break;
  98. case 2:
  99. coord[0] = -1;
  100. coord[1] = 0;
  101. break;
  102. case 3:
  103. coord[0] = +1;
  104. coord[1] = 0;
  105. break;
  106. case 4:
  107. coord[0] = 0;
  108. coord[1] = +1;
  109. break;
  110. case 5:
  111. coord[0] = -0;
  112. coord[1] = -0;
  113. break;
  114. default:
  115. break;
  116. }
  117. break;
  118. }
  119. return coord;
  120. }
  121. private enum NeighbourSystem
  122. {
  123. Moore,
  124. VonNeumann
  125. };
  126. #endregion
  127. #region ITerrainPaintableEffect Members
  128. public void PaintEffect(ITerrainChannel map, UUID userID, float rx, float ry, float rz, float strength,
  129. float duration, float BrushSize, List<IScene> scene)
  130. {
  131. strength = TerrainUtil.MetersToSphericalStrength(strength);
  132. int x;
  133. for (x = 0; x < map.Width; x++)
  134. {
  135. int y;
  136. for (y = 0; y < map.Height; y++)
  137. {
  138. if (!map.Scene.Permissions.CanTerraformLand(userID, new Vector3(x, y, 0)))
  139. continue;
  140. float z = TerrainUtil.SphericalFactor(x, y, rx, ry, strength);
  141. if (z > 0) // add in non-zero amount
  142. {
  143. const int NEIGHBOUR_ME = 4;
  144. const int NEIGHBOUR_MAX = 9;
  145. for (int j = 0; j < NEIGHBOUR_MAX; j++)
  146. {
  147. if (j != NEIGHBOUR_ME)
  148. {
  149. int[] coords = Neighbours(type, j);
  150. coords[0] += x;
  151. coords[1] += y;
  152. if (coords[0] > map.Width - 1)
  153. continue;
  154. if (coords[1] > map.Height - 1)
  155. continue;
  156. if (coords[0] < 0)
  157. continue;
  158. if (coords[1] < 0)
  159. continue;
  160. float heightF = map[x, y];
  161. float target = map[coords[0], coords[1]];
  162. if (target > heightF + talus)
  163. {
  164. float calc = duration*((target - heightF) - talus)*z;
  165. heightF += calc;
  166. target -= calc;
  167. }
  168. map[x, y] = heightF;
  169. map[coords[0], coords[1]] = target;
  170. }
  171. }
  172. }
  173. }
  174. }
  175. }
  176. #endregion
  177. }
  178. }