Border.cs 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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. using System;
  28. using System.Collections.Generic;
  29. using System.Text;
  30. using OpenMetaverse;
  31. namespace OpenSim.Region.Framework.Scenes
  32. {
  33. public class Border
  34. {
  35. /// <summary>
  36. /// Line perpendicular to the Direction Cardinal. Z value is the
  37. /// </summary>
  38. public Vector3 BorderLine = Vector3.Zero;
  39. /// <summary>
  40. /// Direction cardinal of the border, think, 'which side of the region this is'. EX South border: Cardinal.S
  41. /// </summary>
  42. public Cardinals CrossDirection = Cardinals.N;
  43. public uint TriggerRegionX = 0;
  44. public uint TriggerRegionY = 0;
  45. public Border()
  46. {
  47. }
  48. /// <summary>
  49. /// Creates a Border. The line is perpendicular to the direction cardinal.
  50. /// IE: if the direction cardinal is South, the line is West->East
  51. /// </summary>
  52. /// <param name="lineStart">The starting point for the line of the border.
  53. /// The position of an object must be greater then this for this border to trigger.
  54. /// Perpendicular to the direction cardinal</param>
  55. /// <param name="lineEnd">The ending point for the line of the border.
  56. /// The position of an object must be less then this for this border to trigger.
  57. /// Perpendicular to the direction cardinal</param>
  58. /// <param name="triggerCoordinate">The position that triggers border the border
  59. /// cross parallel to the direction cardinal. On the North cardinal, this
  60. /// normally 256. On the South cardinal, it's normally 0. Any position past this
  61. /// point on the cartesian coordinate will trigger the border cross as long as it
  62. /// falls within the line start and the line end.</param>
  63. /// <param name="triggerRegionX">When this border triggers, teleport to this regionX
  64. /// in the grid</param>
  65. /// <param name="triggerRegionY">When this border triggers, teleport to this regionY
  66. /// in the grid</param>
  67. /// <param name="direction">Cardinal for border direction. Think, 'which side of the
  68. /// region is this'</param>
  69. public Border(float lineStart, float lineEnd, float triggerCoordinate, uint triggerRegionX,
  70. uint triggerRegionY, Cardinals direction)
  71. {
  72. BorderLine = new Vector3(lineStart,lineEnd,triggerCoordinate);
  73. CrossDirection = direction;
  74. TriggerRegionX = triggerRegionX;
  75. TriggerRegionY = triggerRegionY;
  76. }
  77. public bool TestCross(Vector3 position)
  78. {
  79. bool result = false;
  80. switch (CrossDirection)
  81. {
  82. case Cardinals.N: // x+0, y+1
  83. if (position.X >= BorderLine.X && position.X <= BorderLine.Y && position.Y > BorderLine.Z)
  84. {
  85. return true;
  86. }
  87. break;
  88. case Cardinals.NE: // x+1, y+1
  89. break;
  90. case Cardinals.E: // x+1, y+0
  91. if (position.Y >= BorderLine.X && position.Y <= BorderLine.Y && position.X > BorderLine.Z)
  92. {
  93. return true;
  94. }
  95. break;
  96. case Cardinals.SE: // x+1, y-1
  97. break;
  98. case Cardinals.S: // x+0, y-1
  99. if (position.X >= BorderLine.X && position.X <= BorderLine.Y && position.Y < BorderLine.Z)
  100. {
  101. return true;
  102. }
  103. break;
  104. case Cardinals.SW: // x-1, y-1
  105. break;
  106. case Cardinals.W: // x-1, y+0
  107. if (position.Y >= BorderLine.X && position.Y <= BorderLine.Y && position.X < BorderLine.Z)
  108. {
  109. return true;
  110. }
  111. break;
  112. case Cardinals.NW: // x-1, y+1
  113. break;
  114. }
  115. return result;
  116. }
  117. public float Extent
  118. {
  119. get
  120. {
  121. switch (CrossDirection)
  122. {
  123. case Cardinals.N:
  124. break;
  125. case Cardinals.S:
  126. break;
  127. case Cardinals.W:
  128. break;
  129. case Cardinals.E:
  130. break;
  131. }
  132. return 0;
  133. }
  134. }
  135. }
  136. }