Collider.cs 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using CommonAI.RTS;
  5. using CommonLang.Vector;
  6. using CommonLang;
  7. namespace CommonAI.Zone.Instance
  8. {
  9. public static class Collider
  10. {
  11. /// <summary>
  12. /// 单位和【圆形】碰撞
  13. /// </summary>
  14. /// <param name="o"></param>
  15. /// <param name="x"></param>
  16. /// <param name="y"></param>
  17. /// <param name="r"></param>
  18. /// <returns></returns>
  19. public delegate bool ObjectBodyTouchRound(InstanceZoneObject o, float x, float y, float r);
  20. /// <summary>
  21. /// 单位和【扇形】碰撞
  22. /// </summary>
  23. /// <param name="o"></param>
  24. /// <param name="x"></param>
  25. /// <param name="y"></param>
  26. /// <param name="r"></param>
  27. /// <param name="sa"></param>
  28. /// <param name="ea"></param>
  29. /// <returns></returns>
  30. public delegate bool ObjectBodyTouchFan(InstanceZoneObject o, float x, float y, float r, float sa, float ea);
  31. /// <summary>
  32. /// 单位和【直线】碰撞(粗线段)
  33. /// </summary>
  34. /// <param name="o"></param>
  35. /// <param name="x1"></param>
  36. /// <param name="y1"></param>
  37. /// <param name="x2"></param>
  38. /// <param name="y2"></param>
  39. /// <param name="line_r"></param>
  40. /// <returns></returns>
  41. public delegate bool ObjectBodyTouchRectLine(InstanceZoneObject o, float x1, float y1, float x2, float y2, float line_r);
  42. /// <summary>
  43. /// 单位【运动轨迹】从A点移动到B点经过的碰撞(圆角粗线段)
  44. /// </summary>
  45. /// <param name="o"></param>
  46. /// <param name="sx"></param>
  47. /// <param name="sy"></param>
  48. /// <param name="dx"></param>
  49. /// <param name="dy"></param>
  50. /// <param name="line_r">粗度</param>
  51. /// <returns></returns>
  52. public delegate bool ObjectBodyTouchRoundLine(InstanceZoneObject o, float sx, float sy, float dx, float dy, float line_r);
  53. /// <summary>
  54. /// 单位和【矩形】碰撞
  55. /// </summary>
  56. /// <param name="o"></param>
  57. /// <param name="x1"></param>
  58. /// <param name="y1"></param>
  59. /// <param name="x2"></param>
  60. /// <param name="y2"></param>
  61. /// <returns></returns>
  62. public delegate bool ObjectBodyTouchRect(InstanceZoneObject o, float x1, float y1, float x2, float y2);
  63. //---------------------------------------------------------------------------------------------
  64. public static bool Object_Pos_IncludeInRound(InstanceZoneObject o, float x, float y, float r)
  65. {
  66. return CMath.includeRoundPoint(x, y, r, o.X, o.Y);
  67. }
  68. public static bool Object_BlockBody_TouchRound(InstanceZoneObject o, float x, float y, float r)
  69. {
  70. return CMath.intersectRound(x, y, r, o.X, o.Y, o.BodyBlockSize);
  71. }
  72. public static bool Object_HitBody_TouchRound(InstanceZoneObject o, float x, float y, float r)
  73. {
  74. return CMath.intersectRound(x, y, r, o.X, o.Y, o.BodyHitSize);
  75. }
  76. public static bool Object_Pos_IncludeInFan(InstanceZoneObject o, float x, float y, float distance, float startAngle, float endAngle)
  77. {
  78. return CMath.includeFanPoint(x, y, distance, o.X, o.Y, startAngle, endAngle);
  79. }
  80. public static bool Object_BlockBody_TouchFan(InstanceZoneObject o, float x, float y, float distance, float startAngle, float endAngle)
  81. {
  82. return CMath.intersectFanRound(x, y, distance, o.X, o.Y, o.BodyBlockSize, startAngle, endAngle);
  83. }
  84. public static bool Object_HitBody_TouchFan(InstanceZoneObject o, float x, float y, float distance, float startAngle, float endAngle)
  85. {
  86. return CMath.intersectFanRound(x, y, distance, o.X, o.Y, o.BodyHitSize, startAngle, endAngle);
  87. }
  88. public static bool Object_Pos_IncludeInRect(InstanceZoneObject o, float x1, float y1, float x2, float y2)
  89. {
  90. return CMath.includeRectPoint(x1, y1, x2, y2, o.X, o.Y);
  91. }
  92. public static bool Object_BlockBody_TouchRect(InstanceZoneObject o, float x1, float y1, float x2, float y2)
  93. {
  94. float b = o.BodyBlockSize;
  95. return (CMath.intersectRect(o.X - b, o.Y - b, b * 2, b * 2, x1, y1, x2, y2));
  96. }
  97. public static bool Object_HitBody_TouchRect(InstanceZoneObject o, float x1, float y1, float x2, float y2)
  98. {
  99. float b = o.BodyHitSize;
  100. return (CMath.intersectRect(o.X - b, o.Y - b, b * 2, b * 2, x1, y1, x2, y2));
  101. }
  102. /// <summary>
  103. /// 圆角粗线段
  104. /// </summary>
  105. public static bool Object_BlockBody_TouchRoundLine(InstanceZoneObject o, float sx, float sy, float dx, float dy, float line_r)
  106. {
  107. float body_r = o.BodyBlockSize;
  108. float body_x = o.X;
  109. float body_y = o.Y;
  110. if (CMath.intersectRound(sx, sy, line_r, body_x, body_y, body_r))
  111. {
  112. return true;
  113. }
  114. if (CMath.intersectRound(dx, dy, line_r, body_x, body_y, body_r))
  115. {
  116. return true;
  117. }
  118. return (CMath.intersectLineRound(sx, sy, dx, dy, body_x, body_y, body_r + line_r));
  119. }
  120. /// <summary>
  121. /// 圆角粗线段
  122. /// </summary>
  123. public static bool Object_HitBody_TouchRoundLine(InstanceZoneObject o, float sx, float sy, float dx, float dy, float line_r)
  124. {
  125. float body_r = o.BodyHitSize;
  126. float body_x = o.X;
  127. float body_y = o.Y;
  128. if (CMath.intersectRound(sx, sy, line_r, body_x, body_y, body_r))
  129. {
  130. return true;
  131. }
  132. if (CMath.intersectRound(dx, dy, line_r, body_x, body_y, body_r))
  133. {
  134. return true;
  135. }
  136. return (CMath.intersectLineRound(sx, sy, dx, dy, body_x, body_y, body_r + line_r));
  137. }
  138. /// <summary>
  139. /// 方角粗线段
  140. /// </summary>
  141. public static bool Object_BlockBody_TouchRectLine(InstanceZoneObject o, float x1, float y1, float x2, float y2, float line_r)
  142. {
  143. return CMath.intersectRoundStripWidth(o.X, o.Y, o.BodyBlockSize , x1, y1, x2, y2, line_r);
  144. }
  145. /// <summary>
  146. /// 方角粗线段
  147. /// </summary>
  148. public static bool Object_HitBody_TouchRectLine(InstanceZoneObject o, float x1, float y1, float x2, float y2, float line_r)
  149. {
  150. return CMath.intersectRoundStripWidth(o.X, o.Y, o.BodyHitSize, x1, y1, x2, y2, line_r);
  151. }
  152. }
  153. }