123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171 |
- using System;
- using System.Collections.Generic;
- using System.Text;
- using CommonAI.RTS;
- using CommonLang.Vector;
- using CommonLang;
- namespace CommonAI.Zone.Instance
- {
- public static class Collider
- {
- /// <summary>
- /// 单位和【圆形】碰撞
- /// </summary>
- /// <param name="o"></param>
- /// <param name="x"></param>
- /// <param name="y"></param>
- /// <param name="r"></param>
- /// <returns></returns>
- public delegate bool ObjectBodyTouchRound(InstanceZoneObject o, float x, float y, float r);
- /// <summary>
- /// 单位和【扇形】碰撞
- /// </summary>
- /// <param name="o"></param>
- /// <param name="x"></param>
- /// <param name="y"></param>
- /// <param name="r"></param>
- /// <param name="sa"></param>
- /// <param name="ea"></param>
- /// <returns></returns>
- public delegate bool ObjectBodyTouchFan(InstanceZoneObject o, float x, float y, float r, float sa, float ea);
- /// <summary>
- /// 单位和【直线】碰撞(粗线段)
- /// </summary>
- /// <param name="o"></param>
- /// <param name="x1"></param>
- /// <param name="y1"></param>
- /// <param name="x2"></param>
- /// <param name="y2"></param>
- /// <param name="line_r"></param>
- /// <returns></returns>
- public delegate bool ObjectBodyTouchRectLine(InstanceZoneObject o, float x1, float y1, float x2, float y2, float line_r);
- /// <summary>
- /// 单位【运动轨迹】从A点移动到B点经过的碰撞(圆角粗线段)
- /// </summary>
- /// <param name="o"></param>
- /// <param name="sx"></param>
- /// <param name="sy"></param>
- /// <param name="dx"></param>
- /// <param name="dy"></param>
- /// <param name="line_r">粗度</param>
- /// <returns></returns>
- public delegate bool ObjectBodyTouchRoundLine(InstanceZoneObject o, float sx, float sy, float dx, float dy, float line_r);
- /// <summary>
- /// 单位和【矩形】碰撞
- /// </summary>
- /// <param name="o"></param>
- /// <param name="x1"></param>
- /// <param name="y1"></param>
- /// <param name="x2"></param>
- /// <param name="y2"></param>
- /// <returns></returns>
- public delegate bool ObjectBodyTouchRect(InstanceZoneObject o, float x1, float y1, float x2, float y2);
- //---------------------------------------------------------------------------------------------
- public static bool Object_Pos_IncludeInRound(InstanceZoneObject o, float x, float y, float r)
- {
- return CMath.includeRoundPoint(x, y, r, o.X, o.Y);
- }
- public static bool Object_BlockBody_TouchRound(InstanceZoneObject o, float x, float y, float r)
- {
- return CMath.intersectRound(x, y, r, o.X, o.Y, o.BodyBlockSize);
- }
- public static bool Object_HitBody_TouchRound(InstanceZoneObject o, float x, float y, float r)
- {
- return CMath.intersectRound(x, y, r, o.X, o.Y, o.BodyHitSize);
- }
- public static bool Object_Pos_IncludeInFan(InstanceZoneObject o, float x, float y, float distance, float startAngle, float endAngle)
- {
- return CMath.includeFanPoint(x, y, distance, o.X, o.Y, startAngle, endAngle);
- }
- public static bool Object_BlockBody_TouchFan(InstanceZoneObject o, float x, float y, float distance, float startAngle, float endAngle)
- {
- return CMath.intersectFanRound(x, y, distance, o.X, o.Y, o.BodyBlockSize, startAngle, endAngle);
- }
- public static bool Object_HitBody_TouchFan(InstanceZoneObject o, float x, float y, float distance, float startAngle, float endAngle)
- {
- return CMath.intersectFanRound(x, y, distance, o.X, o.Y, o.BodyHitSize, startAngle, endAngle);
- }
- public static bool Object_Pos_IncludeInRect(InstanceZoneObject o, float x1, float y1, float x2, float y2)
- {
- return CMath.includeRectPoint(x1, y1, x2, y2, o.X, o.Y);
- }
- public static bool Object_BlockBody_TouchRect(InstanceZoneObject o, float x1, float y1, float x2, float y2)
- {
- float b = o.BodyBlockSize;
- return (CMath.intersectRect(o.X - b, o.Y - b, b * 2, b * 2, x1, y1, x2, y2));
- }
- public static bool Object_HitBody_TouchRect(InstanceZoneObject o, float x1, float y1, float x2, float y2)
- {
- float b = o.BodyHitSize;
- return (CMath.intersectRect(o.X - b, o.Y - b, b * 2, b * 2, x1, y1, x2, y2));
- }
- /// <summary>
- /// 圆角粗线段
- /// </summary>
- public static bool Object_BlockBody_TouchRoundLine(InstanceZoneObject o, float sx, float sy, float dx, float dy, float line_r)
- {
- float body_r = o.BodyBlockSize;
- float body_x = o.X;
- float body_y = o.Y;
- if (CMath.intersectRound(sx, sy, line_r, body_x, body_y, body_r))
- {
- return true;
- }
- if (CMath.intersectRound(dx, dy, line_r, body_x, body_y, body_r))
- {
- return true;
- }
- return (CMath.intersectLineRound(sx, sy, dx, dy, body_x, body_y, body_r + line_r));
- }
- /// <summary>
- /// 圆角粗线段
- /// </summary>
- public static bool Object_HitBody_TouchRoundLine(InstanceZoneObject o, float sx, float sy, float dx, float dy, float line_r)
- {
- float body_r = o.BodyHitSize;
- float body_x = o.X;
- float body_y = o.Y;
- if (CMath.intersectRound(sx, sy, line_r, body_x, body_y, body_r))
- {
- return true;
- }
- if (CMath.intersectRound(dx, dy, line_r, body_x, body_y, body_r))
- {
- return true;
- }
- return (CMath.intersectLineRound(sx, sy, dx, dy, body_x, body_y, body_r + line_r));
- }
- /// <summary>
- /// 方角粗线段
- /// </summary>
- public static bool Object_BlockBody_TouchRectLine(InstanceZoneObject o, float x1, float y1, float x2, float y2, float line_r)
- {
- return CMath.intersectRoundStripWidth(o.X, o.Y, o.BodyBlockSize , x1, y1, x2, y2, line_r);
- }
- /// <summary>
- /// 方角粗线段
- /// </summary>
- public static bool Object_HitBody_TouchRectLine(InstanceZoneObject o, float x1, float y1, float x2, float y2, float line_r)
- {
- return CMath.intersectRoundStripWidth(o.X, o.Y, o.BodyHitSize, x1, y1, x2, y2, line_r);
- }
- }
- }
|