Raise.cs 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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 OpenSim 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. namespace libTerrain
  30. {
  31. partial class Channel
  32. {
  33. /// <summary>
  34. /// Raises land around the selection
  35. /// </summary>
  36. /// <param name="rx">The center the X coordinate of where you wish to raise the land</param>
  37. /// <param name="ry">The center the Y coordinate of where you wish to raise the land</param>
  38. /// <param name="size">The radius of the dimple</param>
  39. /// <param name="amount">How much impact to add to the terrain (0..2 usually)</param>
  40. public void Raise(double rx, double ry, double size, double amount)
  41. {
  42. RaiseSphere(rx, ry, size, amount);
  43. }
  44. /// <summary>
  45. /// Raises land in a sphere around the selection
  46. /// </summary>
  47. /// <param name="rx">The center the X coordinate of where you wish to raise the land</param>
  48. /// <param name="ry">The center the Y coordinate of where you wish to raise the land</param>
  49. /// <param name="size">The radius of the sphere dimple</param>
  50. /// <param name="amount">How much impact to add to the terrain (0..2 usually)</param>
  51. public void RaiseSphere(double rx, double ry, double size, double amount)
  52. {
  53. int x, y;
  54. for (x = 0; x < w; x++)
  55. {
  56. for (y = 0; y < h; y++)
  57. {
  58. double z = size;
  59. z *= z;
  60. z -= ((x - rx)*(x - rx)) + ((y - ry)*(y - ry));
  61. if (z > 0.0)
  62. Set(x, y, map[x, y] + (z * amount));
  63. }
  64. }
  65. }
  66. /// <summary>
  67. /// Raises land in a cone around the selection
  68. /// </summary>
  69. /// <param name="rx">The center the X coordinate of where you wish to raise the land</param>
  70. /// <param name="ry">The center the Y coordinate of where you wish to raise the land</param>
  71. /// <param name="size">The radius of the cone</param>
  72. /// <param name="amount">How much impact to add to the terrain (0..2 usually)</param>
  73. public void RaiseCone(double rx, double ry, double size, double amount)
  74. {
  75. int x, y;
  76. for (x = 0; x < w; x++)
  77. {
  78. for (y = 0; y < h; y++)
  79. {
  80. double z = size;
  81. z -= Math.Sqrt(((x - rx)*(x - rx)) + ((y - ry)*(y - ry)));
  82. if (z > 0.0)
  83. Set(x, y, map[x, y] + (z * amount));
  84. }
  85. }
  86. }
  87. /// <summary>
  88. /// Lowers land in a sphere around the selection
  89. /// </summary>
  90. /// <param name="rx">The center the X coordinate of where you wish to lower the land</param>
  91. /// <param name="ry">The center the Y coordinate of where you wish to lower the land</param>
  92. /// <param name="size">The radius of the sphere dimple</param>
  93. /// <param name="amount">How much impact to remove from the terrain (0..2 usually)</param>
  94. public void Lower(double rx, double ry, double size, double amount)
  95. {
  96. LowerSphere(rx, ry, size, amount);
  97. }
  98. /// <summary>
  99. /// Lowers land in a sphere around the selection
  100. /// </summary>
  101. /// <param name="rx">The center the X coordinate of where you wish to lower the land</param>
  102. /// <param name="ry">The center the Y coordinate of where you wish to lower the land</param>
  103. /// <param name="size">The radius of the sphere dimple</param>
  104. /// <param name="amount">How much impact to remove from the terrain (0..2 usually)</param>
  105. public void LowerSphere(double rx, double ry, double size, double amount)
  106. {
  107. int x, y;
  108. for (x = 0; x < w; x++)
  109. {
  110. for (y = 0; y < h; y++)
  111. {
  112. double z = size;
  113. z *= z;
  114. z -= ((x - rx)*(x - rx)) + ((y - ry)*(y - ry));
  115. if (z > 0.0)
  116. Set(x, y, map[x, y] - (z * amount));
  117. }
  118. }
  119. }
  120. }
  121. }