Exemplo n.º 1
0
    public BoundStatus GetBoundsStatus(Vector3 pos)
    {
        BoundStatus bs     = BoundStatus.UnChecked;
        float       width  = numCols * cellSize;
        float       height = numRows * cellSize;

        if (pos.x < origin.x)
        {
            bs |= BoundStatus.OutLeft;
        }
        if (pos.x > origin.x + width)
        {
            bs |= BoundStatus.OutRight;
        }
        if (pos.z < origin.z)
        {
            bs |= BoundStatus.OutDown;
        }
        if (pos.z > origin.z + height)
        {
            bs |= BoundStatus.OutUp;
        }
        if (bs == BoundStatus.UnChecked)
        {
            bs = BoundStatus.In;
        }
        return(bs);
    }
Exemplo n.º 2
0
        public static IEnumerable <string> writeBound(string word, int actCount, BoundStatus st)
        {
            yield return(word);

            if (st.boundsCount == null)
            {
                st.boundsCount = bounds.Select(i => 0).ToArray();
            }
            var idx = getBoundIdx(actCount);

            st.boundsCount[idx]++;
            if (idx == st.actIdx)
            {
                yield break;
            }
            st.actIdx = idx;
            yield return("#####        >=" + bounds[idx].ToString());
        }
Exemplo n.º 3
0
    private int[] GetGridIndexesInBounds(Bounds bnd)
    {
        List <int> indexList = new List <int>();

        Vector3 blVector = new Vector3(bnd.min.x, bnd.min.y, bnd.min.z);

        //blVector *= obstaclePadding;
        blVector = bnd.center + (blVector - bnd.center) * obstaclePadding;
        //Debug.Log(GetBoundsStatus(blVector));
        BoundStatus boundStatus = GetBoundsStatus(blVector);

        if (boundStatus != BoundStatus.In)
        {
            ClampPosToBounds(ref blVector, boundStatus);
        }
        int blIndex = GetGridIndex(blVector);

        Vector3 trVector = new Vector3(bnd.max.x, bnd.max.y, bnd.max.z);

        //trVector *= obstaclePadding;
        trVector = bnd.center + (trVector - bnd.center) * obstaclePadding;
        //Debug.Log(GetBoundsStatus(trVector));
        boundStatus = GetBoundsStatus(trVector);
        if (boundStatus != BoundStatus.In)
        {
            ClampPosToBounds(ref trVector, boundStatus);
        }
        int trIndex = GetGridIndex(trVector);

        for (int i = GetRow(blIndex); i <= GetRow(trIndex); i++)
        {
            for (int j = GetColumn(blIndex); j <= GetColumn(trIndex); j++)
            {
                if (IsInBounds(nodes[i, j].position))
                {
                    indexList.Add(GetGridIndex(nodes[i, j].position));
                }
            }
        }
        return(indexList.ToArray());
    }
Exemplo n.º 4
0
    private void ClampPosToBounds(ref Vector3 pos, BoundStatus bs)
    {
        float width  = numCols * cellSize;
        float height = numRows * cellSize;

        if ((bs & BoundStatus.OutDown) != 0)
        {
            pos.z = origin.z;
        }
        if ((bs & BoundStatus.OutLeft) != 0)
        {
            pos.x = origin.x;
        }
        if ((bs & BoundStatus.OutUp) != 0)
        {
            pos.z = origin.z + height - cellSize;
        }
        if ((bs & BoundStatus.OutRight) != 0)
        {
            pos.x = origin.x + width - cellSize;
        }
    }