Example #1
0
    private PointerEventData getLeapPointerEventData(LeapTouch input, out bool pressed, out bool released)
    {
        PointerEventData pointerData;
        bool created = GetPointerData(input.fingerId, out pointerData, true);

        pointerData.Reset();

        pressed = created || (input.phase == TouchPhase.Began);
        released = (input.phase == TouchPhase.Canceled) || (input.phase == TouchPhase.Ended);

        Vector2 screenSpace = _guiCamera.WorldToScreenPoint(input.position);

        if (created)
            pointerData.position = screenSpace;

        if (pressed)
            pointerData.delta = Vector2.zero;
        else
            pointerData.delta = screenSpace - pointerData.position;

        pointerData.position = screenSpace;
        pointerData.button = PointerEventData.InputButton.Left;

        eventSystem.RaycastAll(pointerData, m_RaycastResultCache);

        var raycast = FindFirstRaycast(m_RaycastResultCache);
        pointerData.pointerCurrentRaycast = raycast;
        m_RaycastResultCache.Clear();
        return pointerData;
    }
Example #2
0
    private void updateLeapTouches()
    {
        Frame frame = HandControllerUtil.handController.GetFrame();

        Dictionary <int, LeapTouch> newTouches = new Dictionary <int, LeapTouch>();

        foreach (Hand hand in frame.Hands)
        {
            foreach (Finger finger in hand.Fingers)
            {
                LeapTouch leapTouch = new LeapTouch();
                leapTouch.fingerId = finger.Id;

                leapTouch.position = HandControllerUtil.toUnitySpace(finger.TipPosition);

                if (!doesTouch(leapTouch))
                {
                    continue;
                }

                if (finger.Type != Finger.FingerType.TYPE_INDEX)
                {
                    continue;
                }

                LeapTouch previousTouch;
                if (!_leapTouches.TryGetValue(finger.Id, out previousTouch))
                {
                    leapTouch.phase = TouchPhase.Began;
                }
                else
                {
                    leapTouch.phase = TouchPhase.Moved;
                }

                newTouches[finger.Id] = leapTouch;
            }
        }

        foreach (var pair in _leapTouches)
        {
            //If we have been tracking a non-ended touch and it is not present in the new frame, generate a touch-ended touch
            if (pair.Value.phase != TouchPhase.Ended && !newTouches.ContainsKey(pair.Key))
            {
                LeapTouch endingTouch = new LeapTouch();
                endingTouch.fingerId = pair.Key;
                endingTouch.position = pair.Value.position;
                endingTouch.phase    = TouchPhase.Ended;
                newTouches[pair.Key] = endingTouch;
            }
        }

        _leapTouches = newTouches;
    }
Example #3
0
    private PointerEventData getLeapPointerEventData(LeapTouch input, out bool pressed, out bool released)
    {
        PointerEventData pointerData;
        bool             created = GetPointerData(input.fingerId, out pointerData, true);

        pointerData.Reset();

        pressed  = created || (input.phase == TouchPhase.Began);
        released = (input.phase == TouchPhase.Canceled) || (input.phase == TouchPhase.Ended);

        Vector2 screenSpace = _guiCamera.WorldToScreenPoint(input.position);

        if (created)
        {
            pointerData.position = screenSpace;
        }

        if (pressed)
        {
            pointerData.delta = Vector2.zero;
        }
        else
        {
            pointerData.delta = screenSpace - pointerData.position;
        }

        pointerData.position = screenSpace;
        pointerData.button   = PointerEventData.InputButton.Left;

        eventSystem.RaycastAll(pointerData, m_RaycastResultCache);

        var raycast = FindFirstRaycast(m_RaycastResultCache);

        pointerData.pointerCurrentRaycast = raycast;
        m_RaycastResultCache.Clear();
        return(pointerData);
    }
Example #4
0
 private bool doesTouch(LeapTouch leapTouch)
 {
     return(relativeTo.transform.InverseTransformPoint(leapTouch.position).z > 0);
 }
Example #5
0
 private bool doesTouch(LeapTouch leapTouch)
 {
     return relativeTo.transform.InverseTransformPoint(leapTouch.position).z > 0;
 }
Example #6
0
    private void updateLeapTouches()
    {
        Frame frame = HandControllerUtil.handController.GetFrame();

        Dictionary<int, LeapTouch> newTouches = new Dictionary<int, LeapTouch>();
        foreach (Hand hand in frame.Hands) {
            foreach (Finger finger in hand.Fingers) {
                LeapTouch leapTouch = new LeapTouch();
                leapTouch.fingerId = finger.Id;

                leapTouch.position = HandControllerUtil.toUnitySpace(finger.TipPosition);

                if (!doesTouch(leapTouch)) {
                    continue;
                }

                if (finger.Type != Finger.FingerType.TYPE_INDEX) {
                    continue;
                }

                LeapTouch previousTouch;
                if (!_leapTouches.TryGetValue(finger.Id, out previousTouch)) {
                    leapTouch.phase = TouchPhase.Began;
                } else {
                    leapTouch.phase = TouchPhase.Moved;
                }

                newTouches[finger.Id] = leapTouch;
            }
        }

        foreach (var pair in _leapTouches) {
            //If we have been tracking a non-ended touch and it is not present in the new frame, generate a touch-ended touch
            if (pair.Value.phase != TouchPhase.Ended && !newTouches.ContainsKey(pair.Key)) {
                LeapTouch endingTouch = new LeapTouch();
                endingTouch.fingerId = pair.Key;
                endingTouch.position = pair.Value.position;
                endingTouch.phase = TouchPhase.Ended;
                newTouches[pair.Key] = endingTouch;
            }
        }

        _leapTouches = newTouches;
    }