Beispiel #1
0
 public RayShap ResetDirection(Fixed2 origin, Fixed2 direction, FixedNumber length)
 {
     position   = origin;
     _points[1] = direction * length;
     ResetSize();
     return(this);
 }
Beispiel #2
0
        public static RayShap GetRay(Fixed2 origin, Fixed2 direction, FixedNumber length)
        {
            var shap = new RayShap(direction.normalized * length);

            shap._position = origin;
            return(shap);
        }
Beispiel #3
0
 public ShapBase(Fixed2[] points, Fixed2 position, Fixed rotation)
 {
     _points        = points;
     this._position = position;
     this._rotation = rotation;
     ResetSize();
 }
Beispiel #4
0
 public RayShap(Fixed2 direction)
 {
     Fixed2[] v2s = new Fixed2[2];
     v2s[0] = Fixed2.zero;
     v2s[1] = direction;
     Points = v2s;
 }
Beispiel #5
0
        public static bool DistanceLess(Fixed2 a, Fixed2 b, Fixed len)
        {
            var xLen = a.x - b.x;
            var yLen = a.y - b.y;

            return((xLen * xLen + yLen * yLen) < len * len);
        }
Beispiel #6
0
        /// <summary>
        /// GJK算法的多边形碰撞检测
        /// </summary>
        /// <param name="a">形状a</param>
        /// <param name="b">形状b</param>
        /// <returns>是否碰撞</returns>
        public static bool GJKCheck(ShapBase a, ShapBase b)
        {
            Fixed2 direction = a.position - b.position;

            Simplex s = new Simplex();

            s.Push(ShapBase.Support(a, b, direction));
            direction = -direction;
            while (true)        //迭代
            {
                s.Push(ShapBase.Support(a, b, direction));
                if (s.GetA().Dot(direction) < 0)
                {
                    return(false);
                }
                else
                {
                    if (s.ContainsOrigin())
                    {
                        return(true);
                    }
                    else
                    {
                        direction = s.GetDirection();
                    }
                }
            }
        }
Beispiel #7
0
 public RayShap(Fixed2 origin, Fixed2 direction, Fixed length)
 {
     Fixed2[] v2s = new Fixed2[2];
     v2s[0]    = Fixed2.zero;
     v2s[1]    = direction.normalized * length;
     Points    = v2s;
     _position = origin;
 }
Beispiel #8
0
        /// <summary>
        /// 给定方向 给定两个凸体 该函数返回这两个凸体明可夫斯基差形状中的一个点
        /// </summary>
        /// <param name="a">形状a</param>
        /// <param name="b">形状b</param>
        /// <param name="direction">迭代方向</param>
        /// <returns>指定方向内的一点</returns>
        public static Fixed2 Support(ShapBase a, ShapBase b, Fixed2 direction)
        {
            Fixed2 p1 = a.Support(direction);
            Fixed2 p2 = b.Support(-direction);

            //Debug.Log("Support{ p1:" + p1 + "p2:" + p2 + "p3:" + (p1 - p2));
            return(p1 - p2);
        }
Beispiel #9
0
 public BoxShap(FixedNumber x, FixedNumber y)
 {
     Fixed2[] v2s = new Fixed2[4];
     v2s[0] = new Fixed2(x / 2, y / 2);
     v2s[1] = new Fixed2(-x / 2, y / 2);
     v2s[2] = new Fixed2(x / 2, -y / 2);
     v2s[3] = new Fixed2(-x / 2, -y / 2);
     Points = v2s;
 }
Beispiel #10
0
        public void SetShap(Vector2[] points)
        {
            var ps = new Fixed2[points.Length];

            for (int i = 0; i < ps.Length; i++)
            {
                ps[i] = points[i].ToFixed2();
            }
            Shap = new ShapBase(ps);
        }
Beispiel #11
0
 private Fixed2 SetScale(Fixed2 point)
 {
     if (data != null)
     {
         return(new Fixed2(point.x * data.transform.Scale.x, point.y * data.transform.Scale.y));
     }
     else
     {
         return(point);
     }
 }
Beispiel #12
0
 public BoxShap(Fixed x, Fixed y, Fixed2 pos, Fixed rot)
 {
     Fixed2[] v2s = new Fixed2[4];
     v2s[0]    = new Fixed2(x / 2, y / 2);
     v2s[1]    = new Fixed2(-x / 2, y / 2);
     v2s[2]    = new Fixed2(-x / 2, -y / 2);
     v2s[3]    = new Fixed2(x / 2, -y / 2);
     Points    = v2s;
     _position = pos;
     _rotation = rot;
 }
Beispiel #13
0
 public void SetJoyStickDirection(KeyNum key, Fixed2 direction)
 {
     if (joySticks.ContainsKey(key))
     {
         joySticks[key].direction = direction;
     }
     else
     {
         joySticks.Add(key, new JoyStickKey(key, direction));
     }
     Key.SetKey(true, key);
 }
Beispiel #14
0
        public CircleShap(FixedNumber r, int num)
        {
            FixedNumber t360 = new FixedNumber(360);
            FixedNumber tmp  = t360 / num;

            Fixed2[] v2s = new Fixed2[num];
            int      i   = 0;

            for (FixedNumber tr = new FixedNumber(0); tr < t360 && i < num; tr += tmp, i++)
            {
                v2s[i] = Fixed2.Parse(tr) * r;
            }

            Points = v2s;
        }
Beispiel #15
0
        /// <summary>
        /// 给定两个凸体 给定迭代方向 该函数返回这两个凸体明可夫斯基差形状中的一个点
        /// </summary>
        /// <param name="direction">迭代方向</param>
        /// <returns>点</returns>
        public Fixed2 Support(Fixed2 direction)
        {
            int         index = 0;
            FixedNumber maxDot, t;
            Fixed2      p;

            p      = GetPoint(index);
            maxDot = Fixed2.Dot(p, direction);
            for (; index < PointsCount; index++)
            {
                t = Fixed2.Dot(GetPoint(index), direction);
                //Debug.Log(_points[index] + "dot" + direction + "=" + t);
                if (t > maxDot)
                {
                    maxDot = t;
                    p      = GetPoint(index);
                }
            }
            return(p + position);
        }
Beispiel #16
0
        /// <summary>
        /// 检测是否包含原点 包含原点就发生了碰撞
        /// </summary>
        /// <returns>是否包含原点</returns>
        public bool ContainsOrigin()
        {
            Fixed2 A  = GetA();
            Fixed2 AO = -A;
            Fixed2 B  = GetB();
            Fixed2 AB = B - A;

            if (points.Count == 3)
            {
                Fixed2 C = GetC();

                Fixed2 AC       = C - A;
                Fixed2 ABnormal = AC * AB * AB;
                Fixed2 ACnormal = AB * AC * AC;
                if (ABnormal.Dot(AO) > 0)
                {
                    points.Remove(C);
                    d = ABnormal;
                }
                else
                {
                    if (ACnormal.Dot(AO) > 0)
                    {
                        points.Remove(B);
                        d = ACnormal;
                    }
                    else
                    {
                        return(true);
                    }
                }
            }
            else
            {
                d = AB * AO * AB;
            }
            return(false);
        }
Beispiel #17
0
        public void PhysicsEffect()
        {
            if (data.Shap == null)
            {
                return;
            }
            if (data.isTrigger || !data.rigibody.CheckCollision(data))
            {
                if (_position != _lastPos || _rotation != _lastRota)
                {
                    _lastPos  = _position;
                    _lastRota = _rotation;
                    data.Shap.ResetSize();

                    Tree4.Move(data);
                }
            }
            else
            {
                _rotation = _lastRota;
                _position = _lastPos;
            }
        }
Beispiel #18
0
 public void Push(Fixed2 point)
 {
     points.Add(point);
 }
Beispiel #19
0
 public List <NetData> OverlapShap(ShapBase shap, Fixed2 position)
 {
     shap.position = position;
     return(OverlapShap(shap));
 }
Beispiel #20
0
 public static Fixed Dot(Fixed2 a, Fixed2 b)
 {
     return(a.x * b.x + b.y * a.y);
 }
Beispiel #21
0
        //public static V3 operator +(V3 v3,Ratio ratio)
        //{

        //}
        public Fixed Dot(Fixed2 b)
        {
            return(Dot(this, b));
        }
Beispiel #22
0
        //public static V3 operator +(V3 v3,Ratio ratio)
        //{

        //}
        public FixedNumber Dot(Fixed2 b)
        {
            return(Dot(this, b));
        }
Beispiel #23
0
 public void LookAt(Fixed2 target)
 {
     Rotation = (target - Position).ToRotation();
 }
Beispiel #24
0
 public void Reset(Fixed2 position, Fixed rotation)
 {
     _position = position;
     _lastPos  = position;
     _rotation = rotation;
 }
 public abstract void push(Fixed2 v2);
 public override void push(Fixed2 v2)
 {
     push(v2.x.GetValue());
     push(v2.y.GetValue());
 }
Beispiel #27
0
 public Tree4Border(Fixed2 center, Fixed size)
 {
     this.center = center;
     this.size   = size;
 }
Beispiel #28
0
 public void Reset(Fixed2 position, Fixed rotation)
 {
     transform.Reset(position, rotation);
 }
Beispiel #29
0
 public JoyStickKey(KeyNum key, Fixed2 direction)
 {
     this.key       = key;
     this.direction = direction;
 }
Beispiel #30
0
 public void Reset(Fixed2 position, FixedNumber rotation)
 {
     _position = position;
     _rotation = rotation;
 }