Ejemplo n.º 1
0
        /// <summary>
        /// 二维向量旋转
        /// </summary>
        /// <param name="v">向量</param>
        /// <param name="angle">旋转角度</param>
        /// <returns></returns>
        public static Vector2 Rotate(this Vector2 v, float angle)
        {
            var a = MathH.atan(v.x, v.y);

            a += angle;
            a %= 360;
            if (a < 0)
            {
                a += 360;
            }
            return(MathH.Tan2(a));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 检查点在弧形里面
        /// </summary>
        /// <param name="ori">弧形圆心</param>
        /// <param name="r">弧形半径</param>
        /// <param name="direct">弧形方向,0-360角度</param>
        /// <param name="scope">弧形范围0-180角度</param>
        /// <param name="dot">点</param>
        public static bool DotToArc(Vector2 ori, float r, float direct, float scope, Vector2 dot)
        {
            r *= r;
            float dx = dot.x - ori.x;
            float d  = dx * dx;
            float dy = dot.y - ori.y;

            d += dy * dy;
            if (d < r)//在半径内
            {
                float ta = MathH.atan(dx, dy);
                float a  = direct - scope;
                if (ta == a)
                {
                    return(true);
                }
                float b = direct + scope;
                if (ta == b)
                {
                    return(true);
                }
                if (a < 0)
                {
                    if (ta < b)
                    {
                        return(true);
                    }
                    a += 360;
                    if (ta > a)
                    {
                        return(true);
                    }
                }
                else if (b > 360)
                {
                    if (ta > a)
                    {
                        return(true);
                    }
                    b -= 360;
                    if (ta < b)
                    {
                        return(true);
                    }
                }
                else if (ta > a & ta < b)
                {
                    return(true);
                }
            }
            return(false);
        }
Ejemplo n.º 3
0
        void OnMove()
        {
            switch (pressCount)
            {
            case 1:
                if (Pressed)
                {
                    base.OnDrag(actions[0]);
                }
                else
                {
                    base.OnMouseMove(actions[0]);
                }
                break;

            case 2:
                var     d0 = actions[0].CanPosition;
                var     d1 = actions[1].CanPosition;
                Vector2 d  = d0 - d1;
                float   s  = d.x * d.x + d.y * d.y;
                s            = Mathf.Sqrt(s);
                DeltaPix     = s - CurrentScale;
                CurrentScale = s;
                DirPix       = s - StartScale;
                s           /= StartScale;
                CurScale     = s;
                var   v0 = RawPos0 - RawPos1;
                float a0 = MathH.atan(v0.x, v0.y); //原始角度
                var   a1 = MathH.atan(d.x, d.y);   //当前角度
                DirAngle   = a0 - a1;
                v0         = LastPos0 - LastPos1;
                a0         = MathH.atan(v0.x, v0.y);//上一帧角度
                DeltaAngle = a0 - a1;
                LastPos0   = d0;
                LastPos1   = d1;
                if (TowFingerMove != null)
                {
                    TowFingerMove(this);
                }
                break;

            case 3:
                LastPos0 = actions[0].CanPosition;
                LastPos1 = actions[1].CanPosition;
                LastPos2 = actions[2].CanPosition;
                if (ThreeFingerMove != null)
                {
                    ThreeFingerMove(this);
                }
                break;

            case 4:
                LastPos0 = actions[0].CanPosition;
                LastPos1 = actions[1].CanPosition;
                LastPos2 = actions[2].CanPosition;
                LastPos3 = actions[3].CanPosition;
                if (FourFingerMove != null)
                {
                    FourFingerMove(this);
                }
                break;

            case 5:
                LastPos0 = actions[0].CanPosition;
                LastPos1 = actions[1].CanPosition;
                LastPos2 = actions[2].CanPosition;
                LastPos3 = actions[3].CanPosition;
                LastPos4 = actions[4].CanPosition;
                if (FiveFingerMove != null)
                {
                    FiveFingerMove(this);
                }
                break;
            }
        }