RaiseLower.cs 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. namespace OpenSim.Terrain.BasicTerrain
  5. {
  6. static class RaiseLower
  7. {
  8. /// <summary>
  9. /// Raises land around the selection
  10. /// </summary>
  11. /// <param name="rx">The center the X coordinate of where you wish to raise the land</param>
  12. /// <param name="ry">The center the Y coordinate of where you wish to raise the land</param>
  13. /// <param name="size">The radius of the dimple</param>
  14. /// <param name="amount">How much impact to add to the terrain (0..2 usually)</param>
  15. public static void raise(float[,] map, double rx, double ry, double size, double amount)
  16. {
  17. raiseSphere(map, rx, ry, size, amount);
  18. }
  19. /// <summary>
  20. /// Raises land in a sphere around the selection
  21. /// </summary>
  22. /// <param name="rx">The center the X coordinate of where you wish to raise the land</param>
  23. /// <param name="ry">The center the Y coordinate of where you wish to raise the land</param>
  24. /// <param name="size">The radius of the sphere dimple</param>
  25. /// <param name="amount">How much impact to add to the terrain (0..2 usually)</param>
  26. public static void raiseSphere(float[,] map, double rx, double ry, double size, double amount)
  27. {
  28. int x, y;
  29. int w = map.GetLength(0);
  30. int h = map.GetLength(1);
  31. for (x = 0; x < w; x++)
  32. {
  33. for (y = 0; y < h; y++)
  34. {
  35. double z = size;
  36. z *= z;
  37. z -= ((x - rx) * (x - rx)) + ((y - ry) * (y - ry));
  38. if (z < 0)
  39. z = 0;
  40. map[x, y] += (float)(z * amount);
  41. }
  42. }
  43. }
  44. /// <summary>
  45. /// Lowers land in a sphere around the selection
  46. /// </summary>
  47. /// <param name="rx">The center the X coordinate of where you wish to lower the land</param>
  48. /// <param name="ry">The center the Y coordinate of where you wish to lower the land</param>
  49. /// <param name="size">The radius of the sphere dimple</param>
  50. /// <param name="amount">How much impact to remove from the terrain (0..2 usually)</param>
  51. public static void lower(float[,] map, double rx, double ry, double size, double amount)
  52. {
  53. lowerSphere(map, rx, ry, size, amount);
  54. }
  55. /// <summary>
  56. /// Lowers land in a sphere around the selection
  57. /// </summary>
  58. /// <param name="rx">The center the X coordinate of where you wish to lower the land</param>
  59. /// <param name="ry">The center the Y coordinate of where you wish to lower the land</param>
  60. /// <param name="size">The radius of the sphere dimple</param>
  61. /// <param name="amount">How much impact to remove from the terrain (0..2 usually)</param>
  62. public static void lowerSphere(float[,] map, double rx, double ry, double size, double amount)
  63. {
  64. int x, y;
  65. int w = map.GetLength(0);
  66. int h = map.GetLength(1);
  67. for (x = 0; x < w; x++)
  68. {
  69. for (y = 0; y < h; y++)
  70. {
  71. double z = size;
  72. z *= z;
  73. z -= ((x - rx) * (x - rx)) + ((y - ry) * (y - ry));
  74. if (z < 0)
  75. z = 0;
  76. map[x, y] -= (float)(z * amount);
  77. }
  78. }
  79. }
  80. }
  81. }