Exemple #1
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);
        }
Exemple #2
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);
        }