1
0

Border.cs 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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. /// <summary>
  78. /// Tests to see if the given position would cross this border.
  79. /// </summary>
  80. /// <returns></returns>
  81. public bool TestCross(Vector3 position)
  82. {
  83. bool result = false;
  84. switch (CrossDirection)
  85. {
  86. case Cardinals.N: // x+0, y+1
  87. if (position.X >= BorderLine.X && position.X <= BorderLine.Y && position.Y > BorderLine.Z)
  88. {
  89. return true;
  90. }
  91. break;
  92. case Cardinals.NE: // x+1, y+1
  93. break;
  94. case Cardinals.E: // x+1, y+0
  95. if (position.Y >= BorderLine.X && position.Y <= BorderLine.Y && position.X > BorderLine.Z)
  96. {
  97. return true;
  98. }
  99. break;
  100. case Cardinals.SE: // x+1, y-1
  101. break;
  102. case Cardinals.S: // x+0, y-1
  103. if (position.X >= BorderLine.X && position.X <= BorderLine.Y && position.Y < BorderLine.Z)
  104. {
  105. return true;
  106. }
  107. break;
  108. case Cardinals.SW: // x-1, y-1
  109. break;
  110. case Cardinals.W: // x-1, y+0
  111. if (position.Y >= BorderLine.X && position.Y <= BorderLine.Y && position.X < BorderLine.Z)
  112. {
  113. return true;
  114. }
  115. break;
  116. case Cardinals.NW: // x-1, y+1
  117. break;
  118. }
  119. return result;
  120. }
  121. public float Extent
  122. {
  123. get
  124. {
  125. switch (CrossDirection)
  126. {
  127. case Cardinals.N:
  128. break;
  129. case Cardinals.S:
  130. break;
  131. case Cardinals.W:
  132. break;
  133. case Cardinals.E:
  134. break;
  135. }
  136. return 0;
  137. }
  138. }
  139. }
  140. }