Ejemplo n.º 1
0
    /*
     * This method checks whether a given plane meets the Platform Requirement.
     * It could be improved a lot, current implementation is more like a workaround ¯\_(ツ)_/¯
     */
    public bool IsMetBy(DetectedPlane plane)
    {
        float[] boxDimensions = DetectedPlaneHelper.CalculateBoxDimensions(plane);
        bool    fits          = boxDimensions[0] > 8 * PlatformBoardBehaviour.SQUARE_LENGTH * EXTRA_SPACE &&
                                boxDimensions[1] > 8 * PlatformBoardBehaviour.SQUARE_LENGTH * EXTRA_SPACE;
        bool fitsRotated = boxDimensions[1] > 8 * PlatformBoardBehaviour.SQUARE_LENGTH * EXTRA_SPACE &&
                           boxDimensions[0] > 8 * PlatformBoardBehaviour.SQUARE_LENGTH * EXTRA_SPACE;

        return(fits || fitsRotated);
    }
Ejemplo n.º 2
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);
                }
            }
        }
    }