コード例 #1
0
    public static void GetEdge(IRect rect, int index, out Vector3 from, out Vector3 to)
    {
        var point = rect.GetRectInfo();

        switch (index)
        {
        case 0:
            from = point[0];
            to   = point[1];
            break;

        case 1:
            from = point[1];
            to   = point[2];
            break;

        case 2:
            from = point[2];
            to   = point[3];
            break;

        default:
            from = point[3];
            to   = point[0];
            break;
        }
    }
コード例 #2
0
    public bool IsContainRectVertex(IRect rect)
    {
        var testPoints = rect.GetRectInfo();

        for (var i = 0; i < testPoints.Length; ++i)
        {
            var nowPoint = testPoints[i];
            if (IsContainPoint(nowPoint))
            {
                return(true);
            }
        }
        return(false);
    }
コード例 #3
0
    static void DrawRect(IRect rect, Color color)
    {
        var point = rect.GetRectInfo();

        if (point == null)
        {
            return;
        }

        Gizmos.color = color;
        for (var i = 0; i <= 2; ++i)
        {
            Gizmos.DrawLine(point[i], point[i + 1]);
        }
        Gizmos.DrawLine(point[3], point[0]);
    }
コード例 #4
0
    //b是不是被a包住
    //(用在a的軸向沒有和世界對齊的情況)
    //(另1種作法是把b的4個點轉換到a的local,之後就可以用軸對齊的判定)
    public static bool IsContainCenterPoint(IRect a, IRect b)
    {
        var point = a.GetRectInfo();
        var p1    = point[1];
        var p2    = point[2];
        var p3    = point[3];

        var xDir = (p3 - p2);
        var zDir = (p1 - p2);

        var width  = xDir.magnitude;
        var height = zDir.magnitude;

        var xNormalDir = xDir / width;
        var zNormalDir = zDir / height;

        //只判斷中心點
        var center = b.GetCenter();

        var vec    = center - p2;
        var xValue = Vector3.Dot(vec, xNormalDir);
        var zValue = Vector3.Dot(vec, zNormalDir);

        bool test = xValue > 0 && xValue < width && zValue > 0 && zValue < height;

        return(test);

        /*
         * foreach (var tPoint in testPoint)
         * {
         *  var vec = tPoint - p2;
         *  var xValue = Vector3.Dot(vec, xNormalDir);
         *  var zValue = Vector3.Dot(vec, zNormalDir);
         *
         *  bool test = xValue > 0 && xValue < width && zValue > 0 && zValue < height;
         *  if (!test)
         *      return false;
         * }
         *
         * return true;
         */
    }