Пример #1
0
 // Update is called once per frame
 void Update()
 {
     if (Lclic)Lclic = false;
     frame = a.frame;
     t    += Time.deltaTime;
     if (manager != null && manager.IsLeapInitialized ()) {
         switch (step) {
         case 0:
             t = 0;
             if(frame.Pointables.Count==2)step++; //double pinch
         break;
         case 1:
             if(frame.Pointables.Count==0)step++;
         break;
         case 2:
             if(frame.Pointables.Count==2)step++;
         break;
         case 3:
             if(frame.Pointables.Count==0)step++;
         break;
         }
     }
     if (t > 1)step = 0;
     if (step == 4) {
         Lclic = true;
         t     = 0;
         step  = 0;
     }
 }
        private void btnChooseFile_Click(object sender, RoutedEventArgs e)
        {
            // Create OpenFileDialog
            Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();

            // Set filter for file extension and default file extension
            dlg.DefaultExt = ".data";
            dlg.Filter = "Frame data (*.data)|*.data";

            // Display OpenFileDialog by calling ShowDialog method
            Nullable<bool> result = dlg.ShowDialog();

            // Get the selected file name and display in a TextBox
            if (result == true)
            {
                frameList.Clear();
                // Open document
                string filename = dlg.FileName;
                using (System.IO.BinaryReader br =
                    new System.IO.BinaryReader(System.IO.File.Open(filename, System.IO.FileMode.Open)))
                {
                    while (br.BaseStream.Position < br.BaseStream.Length)
                    {
                        //deserialises and reads the binary file
                        DateTime date = new DateTime();
                        date = DateTime.FromBinary(br.ReadInt64());
                        // Console.WriteLine(date.ToString());

                        Int32 stimCode = br.ReadInt32();

                        Int32 nextBlock = br.ReadInt32();
                        byte[] frameData = br.ReadBytes(nextBlock);
                        Leap.Frame newFrame = new Leap.Frame();
                        newFrame.Deserialize(frameData);

                        if (stimCode == 5443)
                        {
                            Debug.WriteLine("5443 detected: " + newFrame.Id);
                        }
                        frameList.Add(newFrame);
                        //Console.WriteLine(newFrame.CurrentFramesPerSecond);

                    }
                    br.Close();
                    br.Dispose();
                }
                /* WRITE CODE HERE TO EXTRACT DATA FROM FILE
                foreach (Leap.Frame frame in frameList)
                {
                    //Console.WriteLine(frame.Id);
                }
                */

            }
        }
Пример #3
0
        private void onProviderFixedFrame(Leap.Frame frame)
        {
            _hand = handAccessorFunc(frame);

            if (_hand != null)
            {
                _handData.CopyFrom(_hand);
                _unwarpedHandData.CopyFrom(_handData);

                refreshPointDataFromHand();
                _lastCustomHandWasLeft = _unwarpedHandData.IsLeft;
            }
        }
Пример #4
0
        private void onProviderFixedFrame(Leap.Frame frame)
        {
            _hand = handAccessorFunc(frame);

            if (_hand != null)
            {
                _handData.CopyFrom(_hand);
                _unwarpedHandData.CopyFrom(_handData);

                _unwarpedHandData.SetTransform(forcedPosition.transform.position, _unwarpedHandData.Rotation.ToQuaternion()); //WRITTEN BY CAL

                refreshPointDataFromHand();
                _lastCustomHandWasLeft = _unwarpedHandData.IsLeft;
            }
        }
Пример #5
0
 //we flagged Leap.Frame as an immutable type
 //However, Leap.Frame.Deserialize returns void
 //Therefore it cannot be used like the method of an immutable type, so here's the workaround:
 public static Leap.Frame Deserialize(IEnumerable <byte> data, out String errorMessage, out bool error)
 {
     error        = false;
     errorMessage = "";
     Leap.Frame frame = new Leap.Frame();
     try
     {
         frame.Deserialize(data.ToArray());
     }
     catch (Exception e)
     {
         error        = true;
         errorMessage = e.ToString();
     }
     return(frame);
 }
Пример #6
0
 // Update is called once per frame
 void Update()
 {
     mFrame = leapController.Frame ();
     if(mFrame.Hands.Count >= 1) {
         // deal with position
         float sphereRadius = mFrame.Hands[0].SphereRadius;
         Leap.Vector sphereCentre = mFrame.Hands[0].StabilizedPalmPosition;
         transform.position = Vector3.Slerp (transform.position,new Vector3(-sphereCentre.x,sphereCentre.y,sphereCentre.z),Time.deltaTime*10f);
         transform.localScale = Vector3.one*sphereRadius;
         //Deal with rotation
         Leap.Vector forward = mFrame.Hands[0].Direction;
         Leap.Vector up = mFrame.Hands[0].PalmNormal;
         Vector3 rotation = new Vector3(forward.Pitch*Mathf.Rad2Deg,forward.Yaw*Mathf.Rad2Deg,-up.Roll*Mathf.Rad2Deg);
         transform.localEulerAngles = Vector3.Slerp (transform.localEulerAngles,rotation,Time.deltaTime*80f);
     }
 }
Пример #7
0
        public void DoPulse()
        {
            if (m_controller.IsConnected)
            {
                bool l_leftFound  = false;
                bool l_rightFound = false;

                Leap.Frame l_frame = m_controller.Frame();
                if (l_frame != null)
                {
                    foreach (Leap.Hand l_hand in l_frame.Hands)
                    {
                        if (l_hand.IsLeft && !l_leftFound)
                        {
                            l_leftFound = true;
                            foreach (Leap.Finger l_finger in l_hand.Fingers)
                            {
                                if (l_finger.Type == Leap.Finger.FingerType.TYPE_INDEX)
                                {
                                    l_finger.TipPosition.Convert(ref m_leftTipPosition);
                                    ConvertOrientation(ref m_leftTipPosition);
                                    break;
                                }
                            }
                            continue;
                        }
                        if (l_hand.IsRight && !l_rightFound)
                        {
                            l_rightFound = true;
                            foreach (Leap.Finger l_finger in l_hand.Fingers)
                            {
                                if (l_finger.Type == Leap.Finger.FingerType.TYPE_INDEX)
                                {
                                    l_finger.TipPosition.Convert(ref m_rightTipPosition);
                                    ConvertOrientation(ref m_rightTipPosition);
                                    break;
                                }
                            }
                        }
                    }
                }

                m_core.GetControlManager().SetHandPresence(ControlManager.Hand.Left, l_rightFound, l_rightFound ? m_rightTipPosition : ms_zeroPoint);
                m_core.GetControlManager().SetHandPresence(ControlManager.Hand.Right, l_leftFound, l_leftFound ? m_leftTipPosition : ms_zeroPoint);
            }
        }
Пример #8
0
 public Frame(Leap.Frame frame)
 {
     this.Id         = frame.Id;
     this.Timestamp  = frame.Timestamp;
     this.Hands      = new List <Hand>();
     this.Pointables = new List <Pointable>();
     this.Fingers    = new List <Finger>();
     this.Tools      = new List <Tool>();
     foreach (Leap.Hand lh in frame.Hands)
     {
         Hand h = new Hand(lh, this);
         this.Hands.Add(h);
         this.Pointables.AddRange(h.Pointables);
         this.Fingers.AddRange(h.Fingers);
         this.Tools.AddRange(h.Tools);
     }
 }
Пример #9
0
    // Update is called once per frame
    void Update()
    {
        transform.RotateAround(new Vector3(0.0f,1.0f,0.0f),angle);
        Leap.Frame frame = controller.Frame();
        guiFrame=frame;
        if (!frame.Hands.Empty)
        {
            hand0 = frame.Hands[0];
            hand1 = frame.Hands[1];
            Leap.FingerList fingers = hand0.Fingers;
            if (!fingers.Empty)
            {
                Leap.Finger firstfinger = fingers[0];
                if ((hand1.Fingers.Count) >=3 ){
                    mustPause=true;
                }
                    mustPause=false;
                    if (!hand1.IsValid ||(hand1.IsValid && hand1.Fingers.Count<=2) ){
                            if (mustPause==false && frame.Hands[0].Id != hand1ID){  // (*)<--

                                //if (scratch==true) if (audio.pitch > 0.0f)  audio.pitch-=0.010f;

                                if (hand0.PalmPosition.x>0 ){
                                float moveStraightY = hand0.PalmPosition.y;
                                    if (moveStraightY >190) angle = 2.0f;
                                    if (moveStraightY >=130 && moveStraightY<190) {
                                            moveStraightY/=180;
                                            if (moveStraightY>1) moveStraightY=1;
                                            angle = moveStraightY;
                                            }
                                    else {
                                        if (angle > 0.0f) angle -=0.30f;
                                        if (angle <= 0.0f) angle =0.0f;

                                        }
                                }
                            }
                }
            }
        }
        else {
            if (angle<2.0f) angle +=0.086f;
        }
    }
Пример #10
0
        public static void GetGestures(ref Leap.Frame f_frame, ref GesturesData f_data)
        {
            // Fill as default
            for (int i = 0; i < GesturesData.gc_handCount; i++)
            {
                f_data.m_handsPresenses[i] = false;
            }
            for (int i = 0; i < GesturesData.gc_fingersCount; i++)
            {
                f_data.m_leftFingersBends[i]   = 0f;
                f_data.m_leftFingersSpreads[i] = 0f;
                f_data.m_rightFingersBends[i]  = 0f;
                f_data.m_leftFingersSpreads[i] = 0f;
            }

            // Fill hands data
            foreach (var l_hand in f_frame.Hands)
            {
                int l_sideID = (l_hand.IsLeft ? 0 : 1);
                if (!f_data.m_handsPresenses[l_sideID])
                {
                    f_data.m_handsPresenses[l_sideID] = true;
                    FillHandPosition(l_hand, ref f_data.m_handsPositons[l_sideID]);
                    FillHandRotation(l_hand, ref f_data.m_handsRotations[l_sideID]);
                    switch (l_sideID)
                    {
                    case 0:
                    {
                        FillHandBends(l_hand, ref f_data.m_leftFingersBends);
                        FillHandSpreads(l_hand, ref f_data.m_leftFingersBends, ref f_data.m_leftFingersSpreads);
                    }
                    break;

                    case 1:
                    {
                        FillHandBends(l_hand, ref f_data.m_rightFingersBends);
                        FillHandSpreads(l_hand, ref f_data.m_rightFingersBends, ref f_data.m_rightFingersSpreads);
                    }
                    break;
                    }
                }
            }
        }
Пример #11
0
        public ZoomIn(CustomGestureType type, Leap.Frame frame)
            : base(type, frame)
        {
            if (other != null)
            {
                if (other.State.Equals(GestureState.NA))
                {
                    _state = GestureState.START;
                }
                else if (other.State.Equals(GestureState.END))
                {
                    _state = GestureState.NA;
                }
                else
                {
                    _state = GestureState.MIDDLE;
                }
            }

            other = this;
        }
Пример #12
0
 void MoveHands(Leap.Frame frame)
 {
     for (int i = 0; i < frame.Hands.Count; i++)
     {
         Leap.Hand hand = frame.Hands[i];
         if (i < hands.Length)
         {
             Point position = GetCanvasPosition(hand.PalmPosition);
             Canvas.SetLeft(hands[i], position.X);
             Canvas.SetTop(hands[i], position.Y);
             float scale       = Math.Abs((backMostZ - hand.PalmPosition.z) / (backMostZ - forwardMostZ));
             float newDiameter = 100 * scale + 40;
             hands[i].Width  = newDiameter;
             hands[i].Height = newDiameter;
         }
         //foreach (Leap.Finger finger in hand.Fingers)
         //{
         //	AnalyzeBounds(finger.TipPosition);
         //}
     }
 }
Пример #13
0
        /// <summary>
        /// The conversion changes the Leap Motion space into a set of cubes.
        /// It then calculates the average of the finger tips detected by the
        /// Leap Motion.  The cube that contains that average position is
        /// located, and used to determine a note to send to the Arduino.
        /// </summary>
        /// <param name="frame">The leap motion data containing the finger
        /// information.</param>
        /// <returns>A note to send to the Arduino.  This will always return a
        /// <c>Note</c>.</returns>
        public override Data.TxMessage Convert(Leap.Frame frame)
        {
            TxMessage result = null;

            if (frame.Fingers.Any())
            {
                #region FIGURES OUT STEP
                var avgX = frame.Fingers.Average(x => x.TipPosition.x);
                var avgY = frame.Fingers.Average(x => x.TipPosition.y);
                var avgZ = frame.Fingers.Average(x => x.TipPosition.z);

                var unitX = (avgX - MIN_X) / (MAX_X - MIN_X);
                var unitY = (avgY - MIN_Y) / (MAX_Y - MIN_Y);
                var unitZ = (avgZ - MIN_Z) / (MAX_Z - MIN_Z);

                var scaledX = Math.Round(unitX * RESOLUTION_X, 0) * ScaleX;
                var scaledY = Math.Round(unitY * RESOLUTION_Y, 0) * ScaleY;
                var scaledZ = Math.Round(unitZ * RESOLUTION_Z, 0) * ScaleZ;

                var step = (byte)(scaledX + scaledY + scaledZ);
                #endregion

                // Saves the step.
                result = new Note()
                {
                    Pin          = 8,
                    NoteLength   = 1,
                    RepeatLength = 1,
                    Step         = step
                };
            }
            else
            {
                result = Last ?? DEFAULT_LAST;
            }

            return(Last = result);
        }
Пример #14
0
        private void OnUpdateFrame(Leap.Frame frame)
        {
            if (frame == null)
            {
                return;
            }

            humanoid.leftHandTarget.leap.SetHand(null);
            humanoid.rightHandTarget.leap.SetHand(null);

            for (int i = 0; i < frame.Hands.Count; i++)
            {
                Leap.Hand curHand = frame.Hands[i];
                if (curHand.IsLeft)
                {
                    humanoid.leftHandTarget.leap.SetHand(curHand);
                }
                if (curHand.IsRight)
                {
                    humanoid.rightHandTarget.leap.SetHand(curHand);
                }
            }
        }
Пример #15
0
 // Update is called once per frame
 void Update()
 {
     if (Rclic)Rclic = false;
     frame = a.frame;
     if (manager != null && manager.IsLeapInitialized ()) {
         Debug.Log ("ello");
         spector = frame.RotationAxis(frame).ToFloatArray();
         switch(step){
         case 0:t =0;
             if(frame.Pointables.Count==2){
                 step++;
             }
             break;
         case 1:t += Time.deltaTime;
             if(frame.Pointables.Count==0){
                 step++;
             }
             break;
         case 2:t += Time.deltaTime;												// prevents multiple unintentional gestures.
             if(frame.Pointables.Count<=2){
                 if(frame.RotationAxis(frame).z>0.5){
                     k++;
                 }
             }
             if(k>15){
                 step++;															//This is the "objective" of the gesture.
                 k=0;
                 t=0;
             }
         break;
         }
         if(step==3){
             Rclic=true;
             step=0;
         }
     }
 }
    // Update is called once per frame
    void Update()
    {
        Leap.Frame frame = controller.Frame();
        guiFrame=frame;

        if (!frame.Hands.Empty)
        {
            // Get the first hand
            hand0 = frame.Hands[0];
            hand1 = frame.Hands[1];

            // Check if the hand has any fingers
            Leap.FingerList fingers = hand0.Fingers;

            if (!fingers.Empty)
            {
                Leap.Finger firstfinger = fingers[0];

                // If at leasts 3 fingers are valid on the second hand (remember that when you take away your hand from leap,the second hand becomes the first on the HandsList) (*)<--
                if ((hand1.Fingers.Count) >=3 ){
                    hasPaused=true;
                }
                if (firstfinger.IsValid){
                    hasPaused=false;
                    if (!hand1.IsValid ||(hand1.IsValid && hand1.Fingers.Count<=2) ){
                            if (hasPaused==false && frame.Hands[0].Id != hand1ID){  // (*)<--
                                float moveInputX = firstfinger.TipVelocity.x /600;
                                transform.position += new Vector3(moveInputX, 0, 0);

                                float moveInputY = firstfinger.TipVelocity.y /600;
                                transform.position += new Vector3(0, moveInputY, 0);

                                float moveInputZ = firstfinger.TipVelocity.z /600;
                                transform.position -= new Vector3(0, 0 , moveInputZ);
                            }
                    }
                }

                // Calculate the hand's average finger tip position
                Leap.Vector avgPos = Leap.Vector.Zero;
                foreach (Leap.Finger finger in fingers)
                {
                    avgPos += finger.TipPosition;
                }
                avgPos /= fingers.Count;
                print("Hand has " + fingers.Count
                            + " fingers, average finger tip position: " + avgPos);
            }

        //            // Get the hand's sphere radius and palm position
        //            print("Hand sphere radius: " + hand0.SphereRadius.ToString("n2")
        //                        + " mm, palm position: " + hand0.PalmPosition);
        //
        //            // Get the hand's normal vector and direction
        //            Leap.Vector normal = hand0.PalmNormal;
        //            Leap.Vector direction = hand0.Direction;
        //
        //            // Calculate the hand's pitch, roll, and yaw angles
        //            print("Hand pitch: " + direction.Pitch * 180.0f / (float)3.14 + " degrees, "
        //                        + "roll: " + normal.Roll * 180.0f / (float)3.14 + " degrees, "
        //                        + "yaw: " + direction.Yaw * 180.0f / (float)3.14 + " degrees");
        }

        Leap.GestureList gestures = frame.Gestures();
        for (int i = 0; i < gestures.Count; i++)
        {
            Leap.Gesture gesture = gestures[i];

            switch (gesture.Type)
            {
                case Leap.Gesture.GestureType.TYPECIRCLE:
                    Leap.CircleGesture circle = new Leap.CircleGesture(gesture);

                    // Calculate clock direction using the angle between circle normal and pointable
                    string clockwiseness;
                    if (circle.Pointable.Direction.AngleTo(circle.Normal) <= 3.1487 / 4)
                    {
                        //Clockwise if angle is less than 90 degrees
                        clockwiseness = "clockwise";
                    }
                    else
                    {
                        clockwiseness = "counterclockwise";
                    }

                    float sweptAngle = 0;

                    // Calculate angle swept since last frame
                    if (circle.State != Leap.Gesture.GestureState.STATESTART)
                    {
                        Leap.CircleGesture previousUpdate = new Leap.CircleGesture(controller.Frame(1).Gesture(circle.Id));
                        sweptAngle = (circle.Progress - previousUpdate.Progress) * 360;
                    }
                    globalInfo = ("Circle id: " + circle.Id
                                   + ", " + circle.State
                                   + ", progress: " + circle.Progress
                                   + ", radius: " + circle.Radius
                                   + ", angle: " + sweptAngle
                                   + ", " + clockwiseness);

                    break;
                case Leap.Gesture.GestureType.TYPESWIPE:
                    Leap.SwipeGesture swipe = new Leap.SwipeGesture(gesture);
                    globalInfo = ("Swipe id: " + swipe.Id
                                   + ", " + swipe.State
                                   + ", position: " + swipe.Position
                                   + ", direction: " + swipe.Direction
                                   + ", speed: " + swipe.Speed);
                    break;
                case Leap.Gesture.GestureType.TYPEKEYTAP:
                    Leap.KeyTapGesture keytap = new Leap.KeyTapGesture(gesture);
                    globalInfo = ("Tap id: " + keytap.Id
                                   + ", " + keytap.State
                                   + ", position: " + keytap.Position
                                   + ", direction: " + keytap.Direction);
                    break;
                case Leap.Gesture.GestureType.TYPESCREENTAP:
                    Leap.ScreenTapGesture screentap = new Leap.ScreenTapGesture(gesture);
                    globalInfo = ("Tap id: " + screentap.Id
                                   + ", " + screentap.State
                                   + ", position: " + screentap.Position
                                   + ", direction: " + screentap.Direction);
                    break;
                default:
                    print("Unknown gesture type.");
                    break;
            }
        }

        if (!frame.Hands.Empty) {
            hand0ID = hand0.Id;
            if ( hand1.Id != -1 ) hand1ID = hand1.Id; // since when u take away your first hand,the second one becomes the first one on the list (with ID = 1),I want to remember its value
        }
        else{
            hand0ID = -1;
        }
    }
Пример #17
0
    // Update is called once per frame
    void Update()
    {
        transform.RotateAround(new Vector3(0.0f,1.0f,0.0f),angle);
        Leap.Frame frame = controller.Frame();
        guiFrame=frame;
        if (!frame.Hands.Empty)
        {
            hand0 = frame.Hands[0];
            hand1 = frame.Hands[1];
            Leap.FingerList fingers = hand0.Fingers;
            if (!fingers.Empty)
            {
                Leap.Finger firstfinger = fingers[0];
                if ((hand1.Fingers.Count) >=3 ){
                    mustPause=true;
                }
                    mustPause=false;
                    if (!hand1.IsValid ||(hand1.IsValid && hand1.Fingers.Count<=2) ){
                            if (mustPause==false && frame.Hands[0].Id != hand1ID){  // (*)<--

                                //if (scratch==true) if (audio.pitch > 0.0f)  audio.pitch-=0.010f;

                                    moveStraightY = hand0.PalmPosition.y;
                                    if (moveStraightY >190) angle = 0.0683f;  //-
                                    if (moveStraightY >=160 && moveStraightY<190) {
                                            moveStraightY/=5000;
                                            if (moveStraightY>1) {moveStraightY=1;}
                                            angle = moveStraightY;
                                    }else { //disco fermo
                                        if (angle > 0.0f) angle -=0.004f;
                                        if (angle <= 0.0f) angle =0.0f;

                                    //if (audio.pitch > 0.0f ) {audio.pitch -=0.115f;} //disco fermo ----

                                    //se velocità troppo bassa azzera pitch <<-------------------------------------------------------
                                    ///////////////////////////////////////////////////////////////
                                    float fingerTemp = hand0.Fingers[0].TipVelocity.z;
                                    float zPosition = hand0.Fingers[0].TipPosition.z/20;

                                            if (zPosition <10 ){ //se non sono in zona morta
                                                fingerTemp /= 18000;

                                                if (fingerTemp>0 ){
                                                    angle = -fingerTemp;
                                                }else if (fingerTemp<0 ){
                                                    angle = -fingerTemp;
                                                } else{
                                                    angle = 0.0f;
                                                }
                                            }
                                    }//-------

                    }
                }
            }
        }
        else {
            if (angle<0.0683f) angle +=0.0030f;
            if (angle>0.0683f) angle -=0.0030f;
            if (angle < 0.0716f && angle >0.0650f) angle= 0.0683f;
        }
    }
Пример #18
0
        //============================
        // this is run once per frame
        //============================
        void Update()
        {
            if (!leapProvider || !leftTargetHand || !rightTargetHand || targetCapturyActorId == -1)
            {
                return;
            }

            Leap.Frame frame = leapProvider.CurrentFrame;
            if (frame.Hands.Count == 0)
            {
                return;
            }

            bool leftSet  = false;
            bool rightSet = false;

            foreach (Leap.Hand hand in frame.Hands)
            {
                Transform    targetHand;
                Transform[]  targetFingers;
                Quaternion[] initRot;
                Quaternion   rot;
                if (hand.IsLeft)
                {
                    targetHand    = leftTargetHand;
                    targetFingers = leftFingers;
                    initRot       = leftFingersInit;
                    rot           = leftHandInit;
                    leftSet       = true;
                }
                else
                {
                    targetHand    = rightTargetHand;
                    targetFingers = rightFingers;
                    initRot       = rightFingersInit;
                    rot           = rightHandInit;
                    rightSet      = true;
                }

                if (moveWrists)
                {
                    targetHand.position = hand.WristPosition.ToVector3();
                }
                targetHand.rotation = hand.Basis.rotation.ToQuaternion() * rot;
                Debug.Log(frame.Id + " leap hand rot " + hand.Basis.rotation.ToQuaternion());
                foreach (Leap.Finger finger in hand.Fingers)
                {
                    int       i            = (int)finger.Type;
                    Transform targetFinger = targetFingers[i * 3];

                    //				Quaternion q = initRot[i*3];// * finger.Bone(Leap.Bone.BoneType.TYPE_PROXIMAL).Rotation.ToQuaternion();
                    //				if (i == 1)
                    //					Debug.Log(frame.Id + " leap hand has " + targetFinger.name + " " + finger.Bone(Leap.Bone.BoneType.TYPE_INTERMEDIATE).Rotation.ToQuaternion());

                    //				targetFinger.position                         = finger.Bone(Leap.Bone.BoneType.TYPE_PROXIMAL).PrevJoint.ToVector3();
                    //				targetFinger.GetChild(0).position             = finger.Bone(Leap.Bone.BoneType.TYPE_INTERMEDIATE).PrevJoint.ToVector3();
                    //				targetFinger.GetChild(0).GetChild(0).position = finger.Bone(Leap.Bone.BoneType.TYPE_DISTAL).PrevJoint.ToVector3();
                    targetFinger.rotation                         = finger.Bone(Leap.Bone.BoneType.TYPE_PROXIMAL).Rotation.ToQuaternion() * initRot[i * 3];
                    targetFinger.GetChild(0).rotation             = finger.Bone(Leap.Bone.BoneType.TYPE_INTERMEDIATE).Rotation.ToQuaternion() * initRot[i * 3 + 1];
                    targetFinger.GetChild(0).GetChild(0).rotation = finger.Bone(Leap.Bone.BoneType.TYPE_DISTAL).Rotation.ToQuaternion() * initRot[i * 3 + 2];
                }
            }
            if (!leftSet)
            {
                leftTargetHand.localRotation = Quaternion.identity;
                leftTargetHand.localPosition = leftHandInitOffset;
                foreach (Transform fingerBone in leftFingers)
                {
                    fingerBone.localRotation = Quaternion.identity;
                }
            }
            else if (networkPlugin)
            {
                networkPlugin.setRotationConstraint(targetCapturyActorId, leftTargetHand.name, leftTargetHand);
                foreach (Transform finger in leftFingers)
                {
                    networkPlugin.setRotationConstraint(targetCapturyActorId, finger.name, finger);
                }
            }
            if (!rightSet)
            {
                rightTargetHand.localRotation = Quaternion.identity;
                rightTargetHand.localPosition = rightHandInitOffset;
                foreach (Transform fingerBone in rightFingers)
                {
                    fingerBone.localRotation = Quaternion.identity;
                }
            }
            else if (networkPlugin)
            {
                networkPlugin.setRotationConstraint(targetCapturyActorId, rightTargetHand.name, rightTargetHand);
                foreach (Transform finger in rightFingers)
                {
                    networkPlugin.setRotationConstraint(targetCapturyActorId, finger.name, finger);
                }
            }
        }
Пример #19
0
    // Update is called once per frame
    void Update()
    {
        mFrame = leapController.Frame ();
        int fingerCount = 0;
        if(numbersGestureRegistered || closeFistRegistered || openFistRegistered ||
                keytapGestureRegistered || twoFingerKeytapRegistered || threeFingerKeytapRegistered ||
                screentapGestureRegistered || twoFingerScreentapRegistered || threeFingerScreentapRegistered || steeringWheelRegistered)
            fingerCount = GetFingerCount();

        foreach(Leap.Gesture gesture in mFrame.Gestures ()) {
            switch(gesture.Type) {
                case Leap.Gesture.GestureType.TYPECIRCLE:
                    if(circleGestureRegistered) BuiltInGestureRecognised(gesture,EasyLeapGestureType.TYPECIRCLE);
                    break;
                case Leap.Gesture.GestureType.TYPESWIPE:
                    if(swipeGestureRegistered) BuiltInGestureRecognised(gesture,EasyLeapGestureType.TYPESWIPE);
                    break;
                case Leap.Gesture.GestureType.TYPEKEYTAP:
                    if(keytapGestureRegistered && fingerCount == 1) BuiltInGestureRecognised(gesture,EasyLeapGestureType.TYPEKEYTAP);
                    if(twoFingerKeytapRegistered && fingerCount == 2) BuiltInImprovedGestureRecognised(gesture,EasyLeapGestureType.TWO_FINGERS_KEYTAP);
                    if(threeFingerKeytapRegistered && fingerCount == 3) BuiltInImprovedGestureRecognised(gesture,EasyLeapGestureType.THREE_FINGERS_KEYTAP);
                    break;
                case Leap.Gesture.GestureType.TYPESCREENTAP:
                    if(screentapGestureRegistered && fingerCount == 1) BuiltInGestureRecognised(gesture,EasyLeapGestureType.TYPESCREENTAP);
                    if(twoFingerScreentapRegistered && fingerCount == 2) BuiltInImprovedGestureRecognised(gesture,EasyLeapGestureType.TWO_FINGERS_SCREENTAP);
                    if(threeFingerScreentapRegistered && fingerCount == 3) BuiltInImprovedGestureRecognised(gesture,EasyLeapGestureType.THREE_FINGERS_SCREENTAP);
                    break;
            }

        }
        if(mFrame.Gestures ().Count == 0) ClearDraggingGestures();

        if(numbersGestureRegistered || closeFistRegistered || openFistRegistered) {
            switch(fingerCount) {
                case 0:
                    // NO FINGERS
                    if(numbersGestureRegistered) NumbersGestureRecognised(EasyLeapGestureType.DEFAULT);
                    if(closeFistRegistered) {
                        if(mFrame.Hands.Count == 1) {
                            if(PalmIsHorizontal(mFrame.Hands[0])) CloseFistGestureRecognised(EasyLeapGestureState.STATESTOP);
                        }
                        else CloseFistGestureRecognised(EasyLeapGestureState.STATEINVALID);
                    }
                    if(openFistRegistered) {
                        if(mFrame.Hands.Count == 1) {
                            if(PalmIsHorizontal(mFrame.Hands[0])) OpenFistGestureRecognised(EasyLeapGestureState.STATESTART);
                        }
                        else OpenFistGestureRecognised(EasyLeapGestureState.STATEINVALID);
                    }
                    break;
                case 1:
                    if(numbersGestureRegistered) NumbersGestureRecognised(EasyLeapGestureType.ONE);
                    break;
                case 2:
                    if(numbersGestureRegistered) NumbersGestureRecognised(EasyLeapGestureType.TWO);
                    break;
                case 3:
                    if(numbersGestureRegistered) NumbersGestureRecognised(EasyLeapGestureType.THREE);
                    break;
                case 4:
                    if(numbersGestureRegistered) NumbersGestureRecognised(EasyLeapGestureType.FOUR);
                    break;
                case 5:
                    if(numbersGestureRegistered) NumbersGestureRecognised(EasyLeapGestureType.FIVE);
                    if(closeFistRegistered && mFrame.Hands.Count == 1) CloseFistGestureRecognised(EasyLeapGestureState.STATESTART);
                    if(openFistRegistered) OpenFistGestureRecognised(EasyLeapGestureState.STATESTOP);
                    break;
                case 6:
                    if(numbersGestureRegistered) NumbersGestureRecognised(EasyLeapGestureType.SIX);
                    break;
                case 7:
                    if(numbersGestureRegistered) NumbersGestureRecognised(EasyLeapGestureType.SEVEN);
                    break;
                case 8:
                    if(numbersGestureRegistered) NumbersGestureRecognised(EasyLeapGestureType.EIGHT);
                    break;
                case 9:
                    if(numbersGestureRegistered) NumbersGestureRecognised(EasyLeapGestureType.NINE);
                    break;
                case 10:
                    if(numbersGestureRegistered) NumbersGestureRecognised(EasyLeapGestureType.TEN);
                    break;
            }
        }

        if(pushGestureRegistered || pullGestureRegistered) {
            if(mFrame.Hands.Count == 1) {
                if(pushGestureRegistered) {
                    if(mFrame.Hands[0].PalmVelocity.y < -EasyLeapGesture.MinPushPullVelocity) PushGestureRecognised(EasyLeapGestureState.STATESTART);
                    else PushGestureRecognised(EasyLeapGestureState.STATEINVALID);
                }
                if(pullGestureRegistered) {
                    if(mFrame.Hands[0].PalmVelocity.y > EasyLeapGesture.MinPushPullVelocity) PullGestureRecognised(EasyLeapGestureState.STATESTART);
                    else PullGestureRecognised(EasyLeapGestureState.STATEINVALID);
                }
            } else {
                PushGestureRecognised(EasyLeapGestureState.STATEINVALID);
                PullGestureRecognised(EasyLeapGestureState.STATEINVALID);
            }
        }

        if(doubleInwardsSwipeGestureRegistered || doubleOutwardsSwipeGestureRegistered) {
            if(mFrame.Hands.Count == 2) {
                bool leftHandSwipeIn = (PalmIsHorizontal(mFrame.Hands.Leftmost)) && mFrame.Hands.Leftmost.PalmVelocity.x > EasyLeapGesture.MinSwipeVelocity;
                bool rightHandSwipeIn = (PalmIsHorizontal(mFrame.Hands.Rightmost)) && mFrame.Hands.Rightmost.PalmVelocity.x < -EasyLeapGesture.MinSwipeVelocity;
                if(doubleInwardsSwipeGestureRegistered && (leftHandSwipeIn && rightHandSwipeIn)) {
                    if(mFrame.Hands[0].StabilizedPalmPosition.DistanceTo(mFrame.Hands[1].StabilizedPalmPosition) < EasyLeapGesture.MaxPalmDistance) DoubleInwardsSwipeRecognised(EasyLeapGestureState.STATESTART);
                } else DoubleInwardsSwipeRecognised(EasyLeapGestureState.STATEINVALID);
                bool leftHandSwipeOut = (PalmIsHorizontal(mFrame.Hands.Leftmost)) && mFrame.Hands.Leftmost.PalmVelocity.x < -EasyLeapGesture.MinSwipeVelocity;
                bool rightHandSwipeOut = (PalmIsHorizontal(mFrame.Hands.Rightmost)) && mFrame.Hands.Rightmost.PalmVelocity.x > EasyLeapGesture.MinSwipeVelocity;
                if(doubleOutwardsSwipeGestureRegistered && leftHandSwipeOut && rightHandSwipeOut) {
                    if(mFrame.Hands[0].StabilizedPalmPosition.DistanceTo(mFrame.Hands[1].StabilizedPalmPosition) > EasyLeapGesture.MaxPalmDistance) DoubleOutwardsSwipeRecognised(EasyLeapGestureState.STATESTART);
                } else DoubleOutwardsSwipeRecognised(EasyLeapGestureState.STATEINVALID);
            }
        }

        if(clapGestureRegistered) {
            if(mFrame.Hands.Count == 2) {
                bool leftHandSwipeIn = (!PalmIsHorizontal(mFrame.Hands.Leftmost)) && mFrame.Hands.Leftmost.PalmVelocity.x > EasyLeapGesture.MinClapVelocity;
                bool rightHandSwipeIn = (!PalmIsHorizontal(mFrame.Hands.Rightmost)) && mFrame.Hands.Rightmost.PalmVelocity.x < -EasyLeapGesture.MinClapVelocity;
                if(leftHandSwipeIn && rightHandSwipeIn) {
                    if(mFrame.Hands[0].StabilizedPalmPosition.DistanceTo(mFrame.Hands[1].StabilizedPalmPosition) < EasyLeapGesture.MaxPalmClapDistance) ClapRecognised(EasyLeapGestureState.STATESTART);
                } else ClapRecognised(EasyLeapGestureState.STATEINVALID);
            }
        }

        if(steeringWheelRegistered) {
            float palmsAngle = (mFrame.Hands.Leftmost.PalmNormal.AngleTo(mFrame.Hands.Rightmost.PalmNormal)*Mathf.Rad2Deg);
            if(mFrame.Hands.Count >= 1 && fingerCount < 2 && (palmsAngle > 110 || palmsAngle < 70)) {
                Leap.Vector leftMost = mFrame.Hands.Leftmost.StabilizedPalmPosition;
                Leap.Vector rightMost = mFrame.Hands.Rightmost.StabilizedPalmPosition;
                Leap.Vector steerVector = (leftMost - rightMost).Normalized;
                //steerVector.z = 0;
                float angle = steerVector.AngleTo(Leap.Vector.Left)*Mathf.Rad2Deg * (leftMost.y > rightMost.y ? 1 : -1);
                SteeringWheelRecognised(angle, Mathf.Abs (leftMost.z) - Mathf.Abs (rightMost.z));
            }
        }

        // Send gestures detected to all registered gesture listeners
        SendGesturesToListeners();
    }
Пример #20
0
        private bool IsLeapMotionTrackingBone(HumanBodyBones bone)
        {
            Leap.Controller  lc    = IKDataSourceManager.Instance.LeapController;
            Leap.Frame       frame = lc.Frame();
            List <Leap.Hand> hands = frame.Hands;

            bool leftHandTracked  = false;
            bool rightHandTracked = false;

            int numHands = hands.Count;

            for (int i = 0; i < numHands; ++i)
            {
                if (hands[i].IsLeft)
                {
                    leftHandTracked = true;
                }
                else if (hands[i].IsRight)
                {
                    rightHandTracked = true;
                }
            }

            switch (bone)
            {
            // Left hand bones
            case HumanBodyBones.LeftHand:
            case HumanBodyBones.LeftIndexDistal:
            case HumanBodyBones.LeftIndexIntermediate:
            case HumanBodyBones.LeftIndexProximal:
            case HumanBodyBones.LeftLittleDistal:
            case HumanBodyBones.LeftLittleIntermediate:
            case HumanBodyBones.LeftLittleProximal:
            case HumanBodyBones.LeftLowerArm:
            case HumanBodyBones.LeftMiddleDistal:
            case HumanBodyBones.LeftMiddleIntermediate:
            case HumanBodyBones.LeftMiddleProximal:
            case HumanBodyBones.LeftRingDistal:
            case HumanBodyBones.LeftRingIntermediate:
            case HumanBodyBones.LeftRingProximal:
            case HumanBodyBones.LeftThumbDistal:
            case HumanBodyBones.LeftThumbIntermediate:
            case HumanBodyBones.LeftThumbProximal:
                return(leftHandTracked);

            // Right hand bones
            case HumanBodyBones.RightHand:
            case HumanBodyBones.RightIndexDistal:
            case HumanBodyBones.RightIndexIntermediate:
            case HumanBodyBones.RightIndexProximal:
            case HumanBodyBones.RightLittleDistal:
            case HumanBodyBones.RightLittleIntermediate:
            case HumanBodyBones.RightLittleProximal:
            case HumanBodyBones.RightLowerArm:
            case HumanBodyBones.RightMiddleDistal:
            case HumanBodyBones.RightMiddleIntermediate:
            case HumanBodyBones.RightMiddleProximal:
            case HumanBodyBones.RightRingDistal:
            case HumanBodyBones.RightRingIntermediate:
            case HumanBodyBones.RightRingProximal:
            case HumanBodyBones.RightThumbDistal:
            case HumanBodyBones.RightThumbIntermediate:
            case HumanBodyBones.RightThumbProximal:
                return(rightHandTracked);

            // Leap only tracks hands
            default:
                Debug.LogWarningFormat("IKTarget IsLeapMotionTrackingBone: Invalid bone for Leap Motion: {0} - returning false", bone);
                return(false);
            }
        }
Пример #21
0
        public static void Update(GameTime gameTime, Leap.Frame frame)
        {
            Leap.Pointable currentPointer = null;
            foreach (Leap.Hand hand in frame.Hands)
            {
                Vector3 furthest = new Vector3(0, 0, 1000);
                foreach (Leap.Pointable p in hand.Pointables)
                {
                    if (p.IsExtended)
                    {
                        Vector3 worldPos = Util.toWorldNoTransform(p.StabilizedTipPosition) - new Vector3(0, Main.handOffset, 0);
                        if (worldPos.Z < furthest.Z)
                        {
                            furthest       = worldPos;
                            currentPointer = p;
                        }
                    }
                }
                Vector3 screenPos = Main.main.GraphicsDevice.Viewport.Project(furthest, Main.main.handCamera.projection, Main.main.handCamera.view, Matrix.Identity);
                screenFingerPos = new Vector2((screenPos.X - Main.screenWidth / 2) * 2f + (Main.screenWidth / 2), screenPos.Y);
                if (screenFingerPos.Y > Main.screenHeight * .5f)
                {
                    screenFingerPos.Y += (screenFingerPos.Y - Main.screenHeight / 2) * 1.5f;
                }
            }

            int   w      = Main.screenWidth;
            int   h      = Main.screenHeight;
            Point finger = new Point((int)screenFingerPos.X, (int)screenFingerPos.Y);

            foreach (Screen screen in screens)
            {
                if (screen.visible)
                {
                    float sw = screen.Size.calc(w, h).X;
                    float sh = screen.Size.calc(w, h).Y;
                    foreach (UIElement e in screen.elements)
                    {
                        if (e is Button)
                        {
                            Button    btn = e as Button;
                            Rectangle r   = new Rectangle((int)btn.Position.calc(sw, sh).X, (int)btn.Position.calc(sw, sh).Y, (int)btn.Size.calc(sw, sh).X + (int)btn.selOffset.X + (int)btn.selOffset.X, (int)btn.Size.calc(sw, sh).Y);
                            if (r.Contains(finger))
                            {
                                btn.hover       = true;
                                btn.selOffset.X = MathHelper.Lerp(btn.selOffset.X, 50, .2f);
                                if (currentPointer != null)
                                {
                                    if (currentPointer.TipVelocity.x > 200 && finger.X > r.Right - 40)
                                    {
                                        if (btn.onClick != null)
                                        {
                                            btn.onClick.Invoke();
                                        }
                                    }
                                }
                            }
                            else
                            {
                                btn.hover       = false;
                                btn.selOffset.X = MathHelper.Lerp(btn.selOffset.X, 0, .2f);
                            }
                        }
                        else if (e is RadioList)
                        {
                            RadioList rl = e as RadioList;
                            for (int i = 0; i < rl.items.Count; i++)
                            {
                                RadioListElement item = rl.items[i];

                                int       yoffset = (int)(i * rl.Size.calc(sw, sh).Y + i * 5);
                                Rectangle r       = new Rectangle((int)rl.Position.calc(sw, sh).X, (int)rl.Position.calc(sw, sh).Y + yoffset, (int)rl.Size.calc(sw, sh).X, (int)rl.Size.calc(sw, sh).Y);
                                if (r.Contains(finger) && !item.disabled)
                                {
                                    item.hover  = true;
                                    item.offset = MathHelper.Lerp(item.offset, i == rl.selected ? 50 : 25, .2f);
                                    if (currentPointer != null)
                                    {
                                        if (currentPointer.TipVelocity.x > 150 && finger.X > r.Center.X)
                                        {
                                            rl.selected = i;
                                            if (item.onSelected != null)
                                            {
                                                item.onSelected.Invoke();
                                            }
                                        }
                                    }
                                }
                                else
                                {
                                    item.hover = false;
                                    if (i != rl.selected)
                                    {
                                        item.offset = MathHelper.Lerp(item.offset, 0, .2f);
                                    }
                                    else
                                    {
                                        item.offset = MathHelper.Lerp(item.offset, 50, .2f);
                                        if (item.disabled)
                                        {
                                            rl.selected = -1;
                                        }
                                    }
                                }
                                rl.items[i] = item;
                            }
                        }
                    }
                }
            }
        }
Пример #22
0
    // Update is called once per frame
    void Update()
    {
        Leap.Frame frame = controller.Frame();
        guiFrame=frame;

        if (!frame.Hands.Empty)
        {
            // Get the first hand
            hand0 = frame.Hands[0];
            hand1 = frame.Hands[1];

            // Check if the hand has any fingers
            Leap.FingerList fingers = hand0.Fingers;

            if (!fingers.Empty)
            {
                Leap.Finger firstfinger = fingers[0];

                // If at leasts 3 fingers are valid on the second hand (remember that when you take away your hand from leap,the second hand becomes the first on the HandsList) (*)<--
                if ((hand1.Fingers.Count) >=3 ){
                    mustPause=true;
                }

                    mustPause=false;
                    if (!hand1.IsValid ||(hand1.IsValid && hand1.Fingers.Count<=2) ){
                            if (mustPause==false && frame.Hands[0].Id != hand1ID){  // (*)<--

                                // first navigation type

        //								if (hand0.Fingers.Count<=2){

        //								float moveInputX = firstfinger.TipVelocity.x /400;
        //						        transform.position += new Vector3(moveInputX, 0, 0);

        //								float moveInputY = firstfinger.TipVelocity.y /400;
        //						        transform.position += new Vector3(0, moveInputY, 0);

        //								float moveInputZ = firstfinger.TipVelocity.z /400;
        //						        if (moveInputZ >=0) transform.position -= new Vector3(0, 0 , moveInputZ*2);
        //								else transform.position -= new Vector3(0, 0 , moveInputZ*2);

        //							}else{
        //								// second navigation type
        //								float moveStraightX = hand0.PalmPosition.x;
        //						        if (moveStraightX>25) transform.position += new Vector3(moveStraightX/45, 0 , 0);
        //								else if (moveStraightX<-25) transform.position -= new Vector3(5, 0 , 0);
        //
        //								float moveStraightZ = hand0.PalmPosition.z;
        //						        if (moveStraightZ>25) transform.position -= new Vector3(0, 0 , 1);
        //								else if (moveStraightZ<-2) transform.position += new Vector3(0, 0 , 1);
        //
                                ///////////////////////////////////////////////////////////////

                                float moveStraightY = hand0.PalmPosition.y;
                                if (moveStraightY >=160) {
                                    moveStraightY/=460;
                                    if (moveStraightY>1) {moveStraightY=1; }
                                    audio.pitch = moveStraightY;
                                }else{
                                    //if (audio.pitch > 0.0f ) {audio.pitch -=0.115f;} //disco fermo ----

                                //se velocità troppo bassa azzera pitch <<-------------------------------------------------------
                                ///////////////////////////////////////////////////////////////
                                fingerTemp = hand0.Fingers[0].TipVelocity.z;
                                float zPosition = hand0.Fingers[0].TipPosition.z/20;

                                        if (zPosition <10 ){ //se non sono in zona morta
                                            fingerTemp /= 250;

                                            if (fingerTemp>0 ){
                                                audio.pitch = -fingerTemp;
                                            }else if (fingerTemp<0 ){
                                                audio.pitch = -fingerTemp;
                                            } else{
                                                audio.pitch=0.0f;
                                            }
                                        }
                                }//-------
        //							}
                            }
                    }

                // Calculate the hand's average finger tip position
                Leap.Vector avgPos = Leap.Vector.Zero;
                foreach (Leap.Finger finger in fingers)
                {
                    avgPos += finger.TipPosition;
                }
                avgPos /= fingers.Count;
                //print("Hand has " + fingers.Count + " fingers, average finger tip position: " + avgPos);
            }

            //Ok no figners,but there's at least a hand,so a palm

            // Get the hand's normal vector and direction
            Leap.Vector normal = hand0.PalmNormal;
            Leap.Vector direction = hand0.Direction;

        //			float HandRoll = hand1.PalmNormal.Roll * 180.0f / (float)3.14 ;
        //			if (HandRoll > 100) HandRoll = 100;
        //			if (HandRoll < -100) HandRoll = -100;

            // Calculate the hand's pitch, roll, and yaw angles
            print ("Hand pitch: " + direction.Pitch * 180.0f / (float)3.14 + " degrees, "
                        /*+ "roll: " + HandRoll + " degrees, "*/
                        + "yaw: " + direction.Yaw * 180.0f / (float)3.14 + " degrees"
                        + "Hand sphere radius: " + hand0.SphereRadius.ToString("n2")
                        + " mm, palm position: " + hand0.PalmPosition);
        //
        //			if (hand1.IsValid) if (HandRoll > 25 || HandRoll < -25)  transform.Rotate(new Vector3(0, 1 , 0),HandRoll/100);

        }
        else {
            if (audio.pitch<0.95f) audio.pitch +=0.145f;
            if (audio.pitch>1.12f) audio.pitch -=0.145f;
            if (audio.pitch>0.95 && audio.pitch<1.12) audio.pitch = 1.0f;
            scratch= false;

        }

        counter= counter+1;
        if (counter>=19) {
            temp = hand0.Fingers[0].TipPosition.z/20;
            counter=0;
        }

        Leap.GestureList gestures = frame.Gestures();
        for (int i = 0; i < gestures.Count; i++)
        {
            Leap.Gesture gesture = gestures[i];

            switch (gesture.Type)
            {
                case Leap.Gesture.GestureType.TYPECIRCLE:
                    Leap.CircleGesture circle = new Leap.CircleGesture(gesture);

                    // Calculate clock direction using the angle between circle normal and pointable
                    string clockwiseness;
                    if (circle.Pointable.Direction.AngleTo(circle.Normal) <= 3.1487 / 4)
                    {
                        //Clockwise if angle is less than 90 degrees
                        clockwiseness = "clockwise";
                    }
                    else
                    {
                        clockwiseness = "counterclockwise";
                    }

                    float sweptAngle = 0;

                    // Calculate angle swept since last frame
                    if (circle.State != Leap.Gesture.GestureState.STATESTART)
                    {
                        Leap.CircleGesture previousUpdate = new Leap.CircleGesture(controller.Frame(1).Gesture(circle.Id));
                        sweptAngle = (circle.Progress - previousUpdate.Progress) * 360;
                    }
                    globalInfo = ("Circle id: " + circle.Id
                                   + ", " + circle.State
                                   + ", progress: " + circle.Progress
                                   + ", radius: " + circle.Radius
                                   + ", angle: " + sweptAngle
                                   + ", " + clockwiseness);

                    break;
                case Leap.Gesture.GestureType.TYPESWIPE:
                    Leap.SwipeGesture swipe = new Leap.SwipeGesture(gesture);
                    globalInfo = ("Swipe id: " + swipe.Id
                                   + ", " + swipe.State
                                   + ", position: " + swipe.Position
                                   + ", direction: " + swipe.Direction
                                   + ", speed: " + swipe.Speed);
                    break;
                case Leap.Gesture.GestureType.TYPEKEYTAP:
                    Leap.KeyTapGesture keytap = new Leap.KeyTapGesture(gesture);
                    globalInfo = ("Tap id: " + keytap.Id
                                   + ", " + keytap.State
                                   + ", position: " + keytap.Position
                                   + ", direction: " + keytap.Direction);
                    break;
                case Leap.Gesture.GestureType.TYPESCREENTAP:
                    Leap.ScreenTapGesture screentap = new Leap.ScreenTapGesture(gesture);
                    globalInfo = ("Tap id: " + screentap.Id
                                   + ", " + screentap.State
                                   + ", position: " + screentap.Position
                                   + ", direction: " + screentap.Direction);
                    break;
                default:
                    print("Unknown gesture type.");
                    break;
            }
        }

        if (!frame.Hands.Empty) {
            hand0ID = hand0.Id;
            if ( hand1.Id != -1 ) hand1ID = hand1.Id; // when first hand disappears,the second one becomes the first one on the list (with ID = 1).So before losing its ID,I want to remember its value
        }
        else hand0ID = -1; // if here no Hands on the scene. Hand1ID can be a dirty value.

        if (Input.GetKey (KeyCode.G)){
            float moveInputz = Time.deltaTime * 3;
            transform.position = new Vector3(0, 50, -50);
        }
    }
        public override void OnFrame(Leap.Controller controller)
        {
            Leap.Frame frame = controller.Frame();

            Leap.InteractionBox interactionBox = frame.InteractionBox;
            _pointerPosition =
                interactionBox.NormalizePoint(frame.Pointables.Frontmost.TipPosition);

            _standardGestures = frame.Gestures();

            foreach (Leap.Gesture gesture in _standardGestures)
            {
                if (gesture.State.Equals(Leap.Gesture.GestureState.STATESTOP))
                {
                    if (gesture.Type.Equals(Leap.Gesture.GestureType.TYPESWIPE))
                    {
                        Print("Finger Swipe Detected");
                        Leap.SwipeGesture       swipe      = new Leap.SwipeGesture(gesture);
                        Events.FingerSwipeEvent swipeEvent = new Events.FingerSwipeEvent(swipe);
                        OnFingerSwipeDetected(swipeEvent);
                    }

                    if (gesture.Type.Equals(Leap.Gesture.GestureType.TYPE_CIRCLE))
                    {
                        Print("Circle Gesture Detected");
                        Leap.CircleGesture circle      = new Leap.CircleGesture(gesture);
                        Events.CircleEvent circleEvent = new Events.CircleEvent(circle);
                        OnCircleDetected(circleEvent);
                    }

                    if (gesture.Type.Equals(Leap.Gesture.GestureType.TYPE_SCREEN_TAP))
                    {
                        Print("Screen Tap Detected");
                        Leap.ScreenTapGesture screenTap      = new Leap.ScreenTapGesture(gesture);
                        Events.ScreenTapEvent screenTapEvent = new Events.ScreenTapEvent(screenTap);
                        OnScreenTapDetected(screenTapEvent);
                    }
                }
            }

            Gestures.HandSwipe handSwipe = Gestures.HandSwipe.IsHandSwipe(frame);
            if (handSwipe != null)
            {
                if (handSwipe.State.Equals(Gestures.GestureState.END))
                {
                    Print("Hand Swipe Detected");

                    Events.HandSwipeEvent swipeEvent = new Events.HandSwipeEvent(handSwipe);
                    OnHandSwipeDetected(swipeEvent);
                }
            }

            Gestures.ZoomIn zoomIn = Gestures.ZoomIn.IsZoomIn(frame);
            if (zoomIn != null)
            {
                if (zoomIn.State.Equals(Gestures.GestureState.END))
                {
                    Print("ZoomIn Detected");

                    Events.ZoomInEvent zoomInEvent = new Events.ZoomInEvent(zoomIn);
                    OnZoomInDetected(zoomInEvent);
                }
            }

            Gestures.ZoomOut zoomOut = Gestures.ZoomOut.IsZoomOut(frame);
            if (zoomOut != null)
            {
                if (zoomOut.State.Equals(Gestures.GestureState.END))
                {
                    Print("ZoomOut Detected");

                    Events.ZoomOutEvent zoomOutEvent = new Events.ZoomOutEvent(zoomOut);
                    OnZoomOutDetected(zoomOutEvent);
                }
            }
        }
Пример #24
0
 public void Detect(Leap.Frame frame)
 {
     _frameBuffer.Add(new Frame(frame));
     Detect();
 }