示例#1
0
    //stores the grid coodinates of the lower left square. This is needed to properly map a grid's face to a matrix entry. First we find out its world coordinates,
    // then we translate then to grid cordinates.
    public static void SetOriginSquare()
    {
        //get the grid coordinates of the box (see GetBoxCoordinates in documentation); we get three coordinates, but we only use X and Y
        //we add 0.1f * Vector3.one to avoid unexpected behaviour for edge cases dues to rounding and float (in)accuracy
        Vector3 box = movementGrid.useCustomRenderRange? movementGrid.NearestBoxG(movementGrid.transform.position + movementGrid.renderFrom + 0.1f * Vector3.one):
                      movementGrid.NearestBoxG(movementGrid.transform.position - movementGrid.size + 0.1f * Vector3.one);

        originSquare = new int[2] {
            Mathf.RoundToInt(box.x), Mathf.RoundToInt(box.y)
        };
    }
    //stores the grid coodinates of the lower left square. This is needed to properly map a grid's face to a matrix entry. First we find out its world coordinates,
    // then we translate then to grid cordinates.
    public static void SetOriginSquare()
    {
        //get the grid coordinates of the box (see GetBoxCoordinates in documentation); we get three coordinates, but we only use X and Y
        //we add 0.1f * Vector3.one to avoid unexpected behaviour for edge cases dues to rounding and float (in)accuracy, we subtract 0.5f * Vector3.one to get whole numbers
        Vector3 box = movementGrid.useCustomRenderRange ? movementGrid.NearestBoxG(movementGrid.transform.position + Vector3.Scale(movementGrid.renderFrom, movementGrid.spacing) + 0.1f * Vector3.one) - 0.5f * Vector3.one :
                      movementGrid.NearestBoxG(movementGrid.transform.position - Vector3.Scale(movementGrid.size, movementGrid.spacing) + 0.1f * Vector3.one) - 0.5f * Vector3.one;

        originSquare = new int[2] {
            Mathf.RoundToInt(box.x), Mathf.RoundToInt(box.y)
        };
        // Debug.Log (originSquare [0] + "/" + originSquare [1]);
    }
示例#3
0
 // take world coodinates and find the corresponding square. The result is returned as an int array that contains that square's position in the matrix
 private static int[] GetSquare(Vector3 vec)
 {
     int[] square = new int [2];
     for (int i = 0; i < 2; i++)
     {
         square[i] = Mathf.RoundToInt(_grid.NearestBoxG(vec)[i]);
     }
     return(square);
 }
示例#4
0
 ///<summary>Take world coodinates and find the corresponding square. The result is returned as an int array that contains that square's position in the matrix.</summary>
 private static int[] GetSquare(Vector3 vec)
 {
     int[] square = new int [2];
     for (int i = 0; i < 2; i++)
     {
         // remember, boxes dont have whole coordiantes, that's why we use a little shift to turn e.g. (3.5, 2.5, 1.5) into (3, 2, 1)
         square[i] = Mathf.RoundToInt((_grid.NearestBoxG(vec) - 0.5f * Vector3.one)[i]);
     }
     return(square);
 }