예제 #1
0
        // Poke gesture
        void PokeGesture(Leap.Controller controller)
        {
            Leap.Frame frame = controller.Frame();
            Hand       hand  = frame.Hands[0];

            // Initiate Poke gesture if Index finger is extended
            if (!poke.gestureOn)
            {
                foreach (Finger finger in hand.Fingers)
                {
                    if (finger.Type == Finger.FingerType.TYPE_INDEX && ((Pointable)finger).IsExtended)
                    {
                        Debug.WriteLine("Poke Started");
                        poke.gestureOn = true;
                    }
                }
            }

            // Perform Poke gesture if Index finger moves forward & back
            if (poke.gestureOn)
            {
                Leap.Vector motion = frame.Translation(controller.Frame(1));

                if (motion.y < -5.0f)
                {
                    poke.forwardMotion++;
                }
                else if (motion.y > 5.0f)
                {
                    poke.backwardMotion++;
                }

                // Turn off gesture and set cooldown timer to .5 sec
                if (poke.forwardMotion > 5 && poke.backwardMotion > 5)
                {
                    Debug.WriteLine("Poke!");
                    poke.forwardMotion   = 0;
                    poke.backwardMotion  = 0;
                    poke.gestureOn       = false;
                    poke.gestureFinished = true;
                    System.Timers.Timer timer = new System.Timers.Timer();
                    timer.Elapsed += new ElapsedEventHandler(PokeSetFinished);
                    timer.Interval = 500;
                    timer.Start();
                }
            }
        }
예제 #2
0
        // Wave Gesture
        void WaveGesture(Leap.Controller controller)
        {
            Leap.Frame frame = controller.Frame();
            Hand       hand  = frame.Hands[0];

            // Initiate Wave gesture if all 5 fingers are extended
            if (hand.Pointables.Count == 5 && !wave.gestureOn)
            {
                if (GetNumFingersExtended(hand) == 5)
                {
                    Debug.WriteLine("5 Fingers!");
                    wave.gestureOn = true;
                }
            }

            // Perform wave gesture if hand moves back and forth laterally
            if (wave.gestureOn)
            {
                Leap.Vector motion = frame.Translation(controller.Frame(1));

                if (motion.x > 7.0f)
                {
                    wave.rightMotion++;
                }
                else if (motion.x < -7.0f)
                {
                    wave.leftMotion++;
                }

                if (wave.rightMotion > 5 && wave.leftMotion > 5)
                {
                    Debug.WriteLine("Wave!");
                    wave.rightMotion     = 0;
                    wave.leftMotion      = 0;
                    wave.gestureOn       = false;
                    wave.gestureFinished = true;
                }
            }
        }
    void Update()
    {
        Leap.Frame thisFrame = LeapInput.Frame;
        if (thisFrame == null)
        {
            return;
        }

        //Remove fingers which have been disabled
        int index;

        while ((index = m_Touching.FindIndex(i => i.GetComponent <Collider>() && i.GetComponent <Collider>().enabled == false)) != -1)
        {
            m_Touching.RemoveAt(index);
            m_LastPos.RemoveAt(index);
        }

        if (m_LastFrame != null && thisFrame != null && m_Selected)
        {
            float transMagnitude = thisFrame.Translation(m_LastFrame).MagnitudeSquared;
            if (transMagnitude > kMovementThreshold)
            {
                m_LastMovedTime = Time.time;
            }
        }

        //Set selection after the time has elapsed
        if (!m_Selected && m_FocusedObject && (Time.fixedTime - m_FirstTouchedTime) >= kSelectionTime)
        {
            m_Selected = true;
        }

        //Update the focused object's color
        float selectedT = m_FocusedObject != null ? (Time.time - m_FirstTouchedTime) / kSelectionTime : 0.0f;

        //If we have passed the minimum deselection threshold and are past the minimum time to start deselecting...
        if (m_Selected && Time.time - m_FirstTouchedTime > kIdleStartDeselectTime + kSelectionTime)
        {
            selectedT = 1.3f - (((Time.time - m_LastMovedTime) - kIdleStartDeselectTime) / kSelectionTime);
        }
        SetHighlightColor(Color.Lerp(kBlankColor, m_HighlightMaterial.color, selectedT));

        //Process the movement of the selected object.
        if (m_Selected && thisFrame != m_LastFrame)
        {
            //End selection if we don't see any fingers or the scaling factor is going down quickly ( indicating we are making a fist )
            if (CheckEndSelection(thisFrame))
            {
                ClearFocus();
            }
            else
            {
                if (CheckShouldMove(thisFrame))
                {
                    DoMovement(thisFrame);
                }
                if (CheckShouldRotate(thisFrame))
                {
                    DoRotation(thisFrame);
                }
                if (CheckShouldScale(thisFrame))
                {
                    DoScaling(thisFrame);
                }
            }
        }


        m_LastFrame = thisFrame;
        for (int i = 0; i < m_Touching.Count; ++i)
        {
            m_LastPos[i] = m_Touching[i].transform.position;
        }
    }
    void Update()
    {
        Leap.Frame thisFrame = LeapInput.Frame;
        if (thisFrame == null)
        {
            return;
        }

        if (LeapInput.NumberOfFingers[0] + LeapInput.NumberOfFingers[1] == 10)
        {
            //Application.LoadLevel(Application.loadedLevel);

            foreach (objectTouched touchedObject in m_ObjectTouched)
            {
                touchedObject.finger.collider.isTrigger = false;
            }

            ClearFocus();

            GameObject[] allTouchable = GameObject.FindGameObjectsWithTag("Touchable");

            foreach (GameObject obj in allTouchable)
            {
                LeapTouchable tcb = (LeapTouchable)obj.GetComponent(typeof(LeapTouchable));
                if (tcb != null)
                {
                    tcb.reset();
                }
            }
            return;
        }

        //Remove fingers which have been disabled
        int index;

        while ((index = m_Touching.FindIndex(i => i.collider && i.collider.enabled == false)) != -1)
        {
            m_Touching[index].collider.isTrigger = false;
            m_Touching.RemoveAt(index);
            m_LastPos.RemoveAt(index);
        }

        while ((index = m_ObjectTouched.FindIndex(i => i.finger.collider && i.finger.collider.enabled == false)) != -1)
        {
            m_ObjectTouched[index].finger.collider.isTrigger = false;
            m_ObjectTouched.RemoveAt(index);
        }

        while ((index = m_ObjectTouched.FindIndex(i => i.finger.collider && i.finger.collider.enabled == false)) != -1)
        {
            m_ObjectTouched.RemoveAt(index);
        }

        if (m_LastFrame != null && thisFrame != null && m_Selected)
        {
            float transMagnitude = thisFrame.Translation(m_LastFrame).MagnitudeSquared;
            if (transMagnitude > kMovementThreshold)
            {
                m_LastMovedTime = Time.time;
            }
        }

        //Set selection after the time has elapsed
        if (!m_Selected && m_FocusedObject && (Time.fixedTime - m_FirstTouchedTime) >= kSelectionTime)
        {
            m_Selected = true;
        }

        //Update the focused object's color
        float selectedT = m_FocusedObject != null ? (Time.time - m_FirstTouchedTime) / kSelectionTime : 0.0f;


        //If we have passed the minimum deselection threshold and are past the minimum time to start deselecting...
        if (m_Selected && Time.time - m_FirstTouchedTime > kIdleStartDeselectTime + kSelectionTime)
        {
            selectedT = 1.3f - (((Time.time - m_LastMovedTime) - kIdleStartDeselectTime) / kSelectionTime);
        }
        SetHighlightColor(Color.Lerp(kBlankColor, m_HighlightMaterial.color, selectedT));

        //Process the movement of the selected object.
        if (m_Selected && thisFrame != m_LastFrame)
        {
            //End selection if we don't see any fingers or the scaling factor is going down quickly ( indicating we are making a fist )
            if (CheckEndSelection(thisFrame))
            {
                foreach (objectTouched touchedObject in m_ObjectTouched)
                {
                    touchedObject.finger.collider.isTrigger = false;
                }

                ClearFocus();
            }
            else
            {
                if (CheckShouldMove(thisFrame))
                {
                    DoMovement(thisFrame);
                }
                if (CheckShouldRotate(thisFrame))
                {
                    DoRotation(thisFrame);
                }
                if (CheckShouldScale(thisFrame))
                {
                    DoScaling(thisFrame);
                }
            }
        }


        m_LastFrame = thisFrame;
        for (int i = 0; i < m_Touching.Count; ++i)
        {
            m_LastPos[i] = m_Touching[i].transform.position;
        }
    }
예제 #5
0
        // Perform swipe gesture
        void SwipeGesturePerform(Leap.Controller controller, Leap.Frame frame, int numFingers)
        {
            Leap.Vector motion = frame.Translation(controller.Frame(1));

            // Increment/reset directional motion counters according to direction of swipe
            swipe.rightMotion = (motion.x > 12.0f) ? swipe.rightMotion + 1 : 0;
            swipe.leftMotion  = (motion.x < -12.0f) ? swipe.leftMotion + 1 : 0;
            swipe.upMotion    = (motion.z < -12.0f) ? swipe.upMotion + 1 : 0;
            swipe.downMotion  = (motion.z > 12.0f) ? swipe.downMotion + 1 : 0;

            if (swipe.rightMotion > 5 || swipe.leftMotion > 5 || swipe.upMotion > 5 || swipe.downMotion > 5)
            {
                if (swipe.rightMotion > 5)
                {
                    switch (numFingers)
                    {
                    case 1:
                        Debug.WriteLine("Swipe Right 1!");
                        break;

                    case 2:
                        Debug.WriteLine("Swipe Right 2!");
                        break;

                    case 5:
                        Debug.WriteLine("Swipe Right 5!");
                        break;
                    }
                    swipe.rightMotion = 0;
                }
                else if (swipe.leftMotion > 5)
                {
                    switch (numFingers)
                    {
                    case 1:
                        Debug.WriteLine("Swipe Left 1!");
                        break;

                    case 2:
                        Debug.WriteLine("Swipe Left 2!");
                        break;

                    case 5:
                        Debug.WriteLine("Swipe Left 5!");
                        break;
                    }
                    swipe.leftMotion = 0;
                }
                else if (swipe.upMotion > 5)
                {
                    switch (numFingers)
                    {
                    case 1:
                        Debug.WriteLine("Swipe Up 1!");
                        break;

                    case 2:
                        Debug.WriteLine("Swipe Up 2!");
                        break;

                    case 5:
                        Debug.WriteLine("Swipe Up 5!");
                        break;
                    }
                    swipe.upMotion = 0;
                }
                else
                {
                    switch (numFingers)
                    {
                    case 1:
                        Debug.WriteLine("Swipe Down 1!");
                        break;

                    case 2:
                        Debug.WriteLine("Swipe Down 2!");
                        break;

                    case 5:
                        Debug.WriteLine("Swipe Down 5!");
                        break;
                    }
                    swipe.downMotion = 0;
                }

                // Turn off gesture and set cooldown timer to .5 sec
                swipe.gestureOn       = false;
                swipe.gestureFinished = true;
                System.Timers.Timer timer = new System.Timers.Timer();
                timer.Elapsed += new ElapsedEventHandler(SwipeSetFinished);
                timer.Interval = 500;
                timer.Start();
            }
        }