예제 #1
0
    /// <summary>
    /// End of gesture movement callback.
    /// </summary>
    /// <param name='data'>
    /// Data of the gesture gathered.
    /// </param>
    public void endOfGestureCallback(GestureData data)
    {
        GestureUtils.EnumGestures gResult;

        Debug.Log("Gesture ended!");
        List <Vector2> pointList      = new List <Vector2>();
        GestureData    normalizedData = data.getNormalizedGestureData(CANVAS_SIZE);

        GestureFrame previousFrame = (GestureFrame)normalizedData.frames[0];

        pointList.Add(new Vector2(previousFrame.position.x, previousFrame.position.y));
        for (int i = 1; i < normalizedData.frames.Count; i++)
        {
            GestureFrame currentFrame = (GestureFrame)normalizedData.frames[i];

            if ((Math.Abs(currentFrame.position.x - previousFrame.position.x) < NORMAL_FRAME_VARIATION) &&
                (Math.Abs(currentFrame.position.y - previousFrame.position.y) < NORMAL_FRAME_VARIATION))
            {
                pointList.Add(new Vector2(currentFrame.position.x, currentFrame.position.y));
                previousFrame = currentFrame;
            }
        }

        //At gesture end, draw the normalized data.
        Vector2 previousPoint = pointList[0];

        for (int i = 1; i < pointList.Count; i++)
        {
            Vector2 currentPoint = pointList[i];
            DrawLine(canvas, previousPoint.x, previousPoint.y, currentPoint.x, currentPoint.y, Color.black);
            previousPoint = currentPoint;
        }

        canvas.Apply();

        //The checker method only receives canvas if you want the points used drawn on the screen,
        //can just receive a points list otherwise.
        gResult = gu.GestureChecker(pointList, canvas, CANVAS_SIZE);

        switch (gResult)
        {
        case GestureUtils.EnumGestures.DownZigZag:
            Debug.Log("Downwards Zig Zag!");
            status = "Downwards Zig Zag!";
            break;

        case GestureUtils.EnumGestures.RightZigZag:
            Debug.Log("Rightwards Zig Zag!");
            status = "Rightwards Zig Zag!";
            break;

        case GestureUtils.EnumGestures.Square:
            Debug.Log("Square!");
            status = "Square!";
            break;

        default:
            Debug.Log("No Gesture found.");
            status = "Nothing.";
            break;
        }
    }
예제 #2
0
    /// <summary>
    /// End of gesture movement callback.
    /// </summary>
    /// <param name='data'>
    /// Data of the gesture gathered.
    /// </param>
    public void endOfGestureCallback(GestureData data)
    {
        GestureUtils.EnumGestures gResult;

        Debug.Log("Gesture ended!");
        List<Vector2> pointList = new List<Vector2>();
        GestureData normalizedData = data.getNormalizedGestureData(CANVAS_SIZE);

        GestureFrame previousFrame = (GestureFrame)normalizedData.frames[0];
        pointList.Add(new Vector2(previousFrame.position.x, previousFrame.position.y));
        for (int i = 1; i < normalizedData.frames.Count; i++) {
            GestureFrame currentFrame = (GestureFrame)normalizedData.frames[i];

            if ((Math.Abs(currentFrame.position.x - previousFrame.position.x) < NORMAL_FRAME_VARIATION) &&
                (Math.Abs(currentFrame.position.y - previousFrame.position.y) < NORMAL_FRAME_VARIATION)) {

                pointList.Add(new Vector2(currentFrame.position.x, currentFrame.position.y));
                previousFrame = currentFrame;
            }

        }

        //At gesture end, draw the normalized data.
        Vector2 previousPoint = pointList[0];
        for (int i = 1; i < pointList.Count; i++) {
            Vector2 currentPoint = pointList[i];
            DrawLine(canvas, previousPoint.x, previousPoint.y, currentPoint.x, currentPoint.y, Color.black);
            previousPoint = currentPoint;
        }

        canvas.Apply();

        //The checker method only receives canvas if you want the points used drawn on the screen,
        //can just receive a points list otherwise.
        gResult = gu.GestureChecker(pointList, canvas, CANVAS_SIZE);

        switch(gResult) {
        case GestureUtils.EnumGestures.DownZigZag:
            Debug.Log("Downwards Zig Zag!");
            status = "Downwards Zig Zag!";
            break;
        case GestureUtils.EnumGestures.RightZigZag:
            Debug.Log("Rightwards Zig Zag!");
            status = "Rightwards Zig Zag!";
            break;
        case GestureUtils.EnumGestures.Square:
            Debug.Log("Square!");
            status = "Square!";
            break;
        default:
            Debug.Log("No Gesture found.");
            status = "Nothing.";
            break;
        }
    }