Exemple #1
0
    private void GenerateCoordinates(DetectedPlatform platform)
    {
        // Variables initialization
        Vector3[] boundingBox = DetectedPlaneHelper.CalculateBoundingBox(platform);
        Vector3   startPoint = boundingBox[0], finishPoint = boundingBox[1];
        float     boxWidth = finishPoint.x - startPoint.x;
        float     boxDepth = finishPoint.z - startPoint.z;

        rowsCount    = (int)Mathf.Floor(boxWidth / SQUARE_LENGTH);
        columnsCount = (int)Mathf.Floor(boxDepth / SQUARE_LENGTH);
        boardSquares = new BoardSquareBehaviour[rowsCount, columnsCount];

        List <Vector3> platformPolygon = new List <Vector3>();

        platform.GetBoundaryPolygon(platformPolygon);

        float planeHeight = platformPolygon[0].y;

        // We iterate over the bounding box collecting the points that belong to the platform
        for (int colNum = 0; colNum < columnsCount; colNum++)
        {
            float zValue = startPoint.z + SQUARE_LENGTH * (colNum + 1);
            for (int rowNum = 0; rowNum < rowsCount; rowNum++)
            {
                float   xValue = startPoint.x + SQUARE_LENGTH * (rowNum + 1);
                Vector3 point  = new Vector3(xValue, planeHeight, zValue);
                if (GeometryUtils.PolyContainsPoint(platformPolygon, point))
                {
                    GameObject square = Instantiate(BoardSquarePrefab, transform);
                    square.transform.position    = point;
                    boardSquares[rowNum, colNum] = square.GetComponent <BoardSquareBehaviour>();
                    boardSquares[rowNum, colNum].DebugText.text = String.Format("({0}; {1})", rowNum, colNum);
                }
            }
        }
    }
 public bool VisualizesPlatform(DetectedPlatform platform)
 {
     return(platform.EqualsPlane(DetectedPlane));
 }