Ejemplo n.º 1
0
        void listener_OnFrameUpdate(object sender, LeapListenerArgs e)
        {
            Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.High, () =>
            {
                TextBlock_HandCount.Text   = e.currentframe.Hands.Count.ToString();
                TextBlock_FingerCount.Text = e.currentframe.Fingers.Count.ToString();

                var frame = e.currentframe;

                switch (frame.Hands.Count)
                {
                case 1: circle_left.Visibility = Visibility.Visible;
                    circle_right.Visibility    = Visibility.Collapsed;
                    break;

                case 2: circle_left.Visibility = Visibility.Visible;
                    circle_right.Visibility    = Visibility.Visible;
                    break;

                case 0:
                    circle_left.Visibility = Visibility.Collapsed;
                    circle_left.Visibility = Visibility.Collapsed;
                    break;
                }
            });
        }
Ejemplo n.º 2
0
        private void UpdateDeviceStatus(LeapDeviceState status)
        {
            lock (thisLock)
            {
                //fires the event only in the case of an event handler being present
                if (OnDeviceStatusUpdate == null)
                {
                    return;
                }

                LeapListenerArgs args = new LeapListenerArgs(status);
                OnDeviceStatusUpdate(this, args);
            }
        }
Ejemplo n.º 3
0
        private void UpdateFrame(Frame frame)
        {
            lock (thisLock)
            {
                //fires the event only in the case of an event handler being present
                if (OnFrameUpdate == null)
                {
                    return;
                }

                LeapListenerArgs args = new LeapListenerArgs(frame);
                OnFrameUpdate(this, args);
            }
        }
Ejemplo n.º 4
0
        private void SafeWriteLine(String line)
        {
            lock (thisLock)
            {
                // System.Diagnostics.Debug.WriteLine(line);

                System.Diagnostics.Debug.WriteLine("Leap Output:" + line);

                //fires the event only in the case of an event handler being present
                if (OnLogUpdate == null)
                {
                    return;
                }

                LeapListenerArgs args = new LeapListenerArgs(line);
                OnLogUpdate(this, args);
            }
        }
Ejemplo n.º 5
0
        void listener_OnDeviceStatusUpdate(object sender, LeapListenerArgs e)
        {
            Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.High, () =>
            {
                string texttodisplay = "";

                switch (e.devicestatus)
                {
                case LeapDeviceState.connected: texttodisplay = "Connected"; break;

                case LeapDeviceState.disconnected: texttodisplay = "Disconnected"; break;

                case LeapDeviceState.exited: texttodisplay = "Exited"; break;

                case LeapDeviceState.initialized: texttodisplay = "Initialized"; break;
                }

                TextBlock_DeviceStatus.Text = texttodisplay;
            });
        }
Ejemplo n.º 6
0
        public override void OnFrame(Controller controller)
        {
            // Get the most recent frame and report some basic information
            Frame frame = controller.Frame();

            SafeWriteLine("Frame id: " + frame.Id
                          + ", timestamp: " + frame.Timestamp
                          + ", hands: " + frame.Hands.Count
                          + ", fingers: " + frame.Fingers.Count
                          + ", tools: " + frame.Tools.Count
                          + ", gestures: " + frame.Gestures().Count);

            UpdateFrame(frame);

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

                // Check if the hand has any fingers
                FingerList fingers = hand.Fingers;
                if (!fingers.Empty)
                {
                    // Calculate the hand's average finger tip position
                    Vector avgPos = Vector.Zero;
                    foreach (Finger finger in fingers)
                    {
                        avgPos += finger.TipPosition;
                    }
                    avgPos /= fingers.Count;
                    //SafeWriteLine("Hand has " + fingers.Count
                    //            + " fingers, average finger tip position: " + avgPos);
                }

                // Get the hand's sphere radius and palm position
                //SafeWriteLine("Hand sphere radius: " + hand.SphereRadius.ToString("n2")
                //            + " mm, palm position: " + hand.PalmPosition);

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

                // Calculate the hand's pitch, roll, and yaw angles
                //SafeWriteLine("Hand pitch: " + direction.Pitch * 180.0f / (float)Math.PI + " degrees, "
                //            + "roll: " + normal.Roll * 180.0f / (float)Math.PI + " degrees, "
                //            + "yaw: " + direction.Yaw * 180.0f / (float)Math.PI + " degrees");
            }

            // Get gestures


            GestureList gestures = frame.Gestures();

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

                switch (gesture.Type)
                {
                case Gesture.GestureType.TYPECIRCLE:

                    if (OnCircleGesture == null)
                    {
                        break;
                    }

                    CircleGesture circle = new CircleGesture(gesture);

                    // Calculate clock direction using the angle between circle normal and pointable
                    String clockwiseness;
                    if (circle.Pointable.Direction.AngleTo(circle.Normal) <= Math.PI / 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 != Gesture.GestureState.STATESTART)
                    {
                        CircleGesture previousUpdate = new CircleGesture(controller.Frame(1).Gesture(circle.Id));
                        sweptAngle = (circle.Progress - previousUpdate.Progress) * 360;
                    }

                    var cargs = new LeapListenerArgs(circle);

                    cargs.logdata = "Circle id: " + circle.Id
                                    + ", " + circle.State
                                    + ", progress: " + circle.Progress
                                    + ", radius: " + circle.Radius
                                    + ", angle: " + sweptAngle
                                    + ", " + clockwiseness;

                    OnCircleGesture(this, cargs);

                    //SafeWriteLine("Circle id: " + circle.Id
                    //               + ", " + circle.State
                    //               + ", progress: " + circle.Progress
                    //               + ", radius: " + circle.Radius
                    //               + ", angle: " + sweptAngle
                    //               + ", " + clockwiseness);


                    break;

                case Gesture.GestureType.TYPESWIPE:

                    if (OnSwipeGesture == null)
                    {
                        break;
                    }

                    SwipeGesture swipe = new SwipeGesture(gesture);

                    var sargs = new LeapListenerArgs(swipe);

                    sargs.logdata = "Swipe id: " + swipe.Id
                                    + ", " + swipe.State
                                    + ", position: " + swipe.Position
                                    + ", direction: " + swipe.Direction
                                    + ", speed: " + swipe.Speed;



                    OnSwipeGesture(this, sargs);

                    //SafeWriteLine("Swipe id: " + swipe.Id
                    //               + ", " + swipe.State
                    //               + ", position: " + swipe.Position
                    //               + ", direction: " + swipe.Direction
                    //               + ", speed: " + swipe.Speed);
                    break;

                case Gesture.GestureType.TYPEKEYTAP:

                    if (OnKeyTapGesture == null)
                    {
                        break;
                    }

                    KeyTapGesture keytap = new KeyTapGesture(gesture);

                    var kargs = new LeapListenerArgs(keytap);

                    kargs.logdata = "Tap id: " + keytap.Id
                                    + ", " + keytap.State
                                    + ", position: " + keytap.Position
                                    + ", direction: " + keytap.Direction;

                    OnKeyTapGesture(this, kargs);

                    //SafeWriteLine("Tap id: " + keytap.Id
                    //               + ", " + keytap.State
                    //               + ", position: " + keytap.Position
                    //               + ", direction: " + keytap.Direction);
                    break;

                case Gesture.GestureType.TYPESCREENTAP:

                    if (OnScreenTapGesture == null)
                    {
                        break;
                    }

                    ScreenTapGesture screentap = new ScreenTapGesture(gesture);

                    var targs = new LeapListenerArgs(screentap);

                    targs.logdata = "Tap id: " + screentap.Id
                                    + ", " + screentap.State
                                    + ", position: " + screentap.Position
                                    + ", direction: " + screentap.Direction;

                    OnScreenTapGesture(this, targs);

                    //SafeWriteLine("Tap id: " + screentap.Id
                    //               + ", " + screentap.State
                    //               + ", position: " + screentap.Position
                    //               + ", direction: " + screentap.Direction);
                    break;

                default:
                    //SafeWriteLine("Unknown gesture type.");
                    break;
                }
            }

            if (!frame.Hands.Empty || !frame.Gestures().Empty)
            {
                //SafeWriteLine("");
            }
        }
Ejemplo n.º 7
0
        private void UpdateDeviceStatus(LeapDeviceState status)
        {
            lock (thisLock)
            {

                //fires the event only in the case of an event handler being present
                if (OnDeviceStatusUpdate == null) return;

                LeapListenerArgs args = new LeapListenerArgs(status);
                OnDeviceStatusUpdate(this, args);
            }
        }
Ejemplo n.º 8
0
 void listener_OnKeyTapGesture(object sender, LeapListenerArgs e)
 {
     PrintLog(e);
 }
Ejemplo n.º 9
0
 void listener_OnCircleGesture(object sender, LeapListenerArgs e)
 {
     PrintLog(e);
 }
Ejemplo n.º 10
0
 private void PrintLog(LeapListenerArgs e)
 {
     Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.High, () => { TextBlock_log.Text += "\n" + e.logdata; });
 }
Ejemplo n.º 11
0
 void ll_OnLogUpdate(object sender, LeapListenerArgs e)
 {
     //throw new NotImplementedException();
     PrintLog(e);
 }
Ejemplo n.º 12
0
 void listener_OnScreenTapGesture(object sender, LeapListenerArgs e)
 {
     PrintLog(e);
 }
Ejemplo n.º 13
0
        void listener_OnFrameUpdate(object sender, LeapListenerArgs e)
        {
            Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.High, () =>
            {
                TextBlock_HandCount.Text = e.currentframe.Hands.Count.ToString();
                TextBlock_FingerCount.Text = e.currentframe.Fingers.Count.ToString();

                var frame = e.currentframe;

                switch (frame.Hands.Count)
                {
                    case 1: circle_left.Visibility = Visibility.Visible;
                        circle_right.Visibility = Visibility.Collapsed;
                        break;

                    case 2: circle_left.Visibility = Visibility.Visible;
                        circle_right.Visibility = Visibility.Visible;
                        break;

                    case 0:
                        circle_left.Visibility = Visibility.Collapsed;
                        circle_left.Visibility = Visibility.Collapsed;
                        break;
                }
            });
        }
Ejemplo n.º 14
0
        public override void OnFrame(Controller controller)
        {
            // Get the most recent frame and report some basic information
            Frame frame = controller.Frame();

            SafeWriteLine("Frame id: " + frame.Id
                        + ", timestamp: " + frame.Timestamp
                        + ", hands: " + frame.Hands.Count
                        + ", fingers: " + frame.Fingers.Count
                        + ", tools: " + frame.Tools.Count
                        + ", gestures: " + frame.Gestures().Count);

            UpdateFrame(frame);

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

                // Check if the hand has any fingers
                FingerList fingers = hand.Fingers;
                if (!fingers.Empty)
                {
                    // Calculate the hand's average finger tip position
                    Vector avgPos = Vector.Zero;
                    foreach (Finger finger in fingers)
                    {
                        avgPos += finger.TipPosition;
                    }
                    avgPos /= fingers.Count;
                    //SafeWriteLine("Hand has " + fingers.Count
                    //            + " fingers, average finger tip position: " + avgPos);
                }

                // Get the hand's sphere radius and palm position
                //SafeWriteLine("Hand sphere radius: " + hand.SphereRadius.ToString("n2")
                //            + " mm, palm position: " + hand.PalmPosition);

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

                // Calculate the hand's pitch, roll, and yaw angles
                //SafeWriteLine("Hand pitch: " + direction.Pitch * 180.0f / (float)Math.PI + " degrees, "
                //            + "roll: " + normal.Roll * 180.0f / (float)Math.PI + " degrees, "
                //            + "yaw: " + direction.Yaw * 180.0f / (float)Math.PI + " degrees");
            }

            // Get gestures


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

                switch (gesture.Type)
                {
                    case Gesture.GestureType.TYPECIRCLE:

                        if (OnCircleGesture == null) break;

                        CircleGesture circle = new CircleGesture(gesture);

                        // Calculate clock direction using the angle between circle normal and pointable
                        String clockwiseness;
                        if (circle.Pointable.Direction.AngleTo(circle.Normal) <= Math.PI / 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 != Gesture.GestureState.STATESTART)
                        {
                            CircleGesture previousUpdate = new CircleGesture(controller.Frame(1).Gesture(circle.Id));
                            sweptAngle = (circle.Progress - previousUpdate.Progress) * 360;
                        }

                        var cargs = new LeapListenerArgs(circle);
                        
                        cargs.logdata = "Circle id: " + circle.Id
                                       + ", " + circle.State
                                       + ", progress: " + circle.Progress
                                       + ", radius: " + circle.Radius
                                       + ", angle: " + sweptAngle
                                       + ", " + clockwiseness;

                        OnCircleGesture(this, cargs);

                        //SafeWriteLine("Circle id: " + circle.Id
                        //               + ", " + circle.State
                        //               + ", progress: " + circle.Progress
                        //               + ", radius: " + circle.Radius
                        //               + ", angle: " + sweptAngle
                        //               + ", " + clockwiseness);


                        break;
                    case Gesture.GestureType.TYPESWIPE:

                        if (OnSwipeGesture == null) break;

                        SwipeGesture swipe = new SwipeGesture(gesture);

                        var sargs = new LeapListenerArgs(swipe);
                        
                         sargs.logdata = "Swipe id: " + swipe.Id
                                       + ", " + swipe.State
                                       + ", position: " + swipe.Position
                                       + ", direction: " + swipe.Direction
                                       + ", speed: " + swipe.Speed;

                         

                        OnSwipeGesture(this, sargs);

                        //SafeWriteLine("Swipe id: " + swipe.Id
                        //               + ", " + swipe.State
                        //               + ", position: " + swipe.Position
                        //               + ", direction: " + swipe.Direction
                        //               + ", speed: " + swipe.Speed);
                        break;
                    case Gesture.GestureType.TYPEKEYTAP:

                        if (OnKeyTapGesture == null) break;

                        KeyTapGesture keytap = new KeyTapGesture(gesture);

                        var kargs = new LeapListenerArgs(keytap);

                        kargs.logdata = "Tap id: " + keytap.Id
                                       + ", " + keytap.State
                                       + ", position: " + keytap.Position
                                       + ", direction: " + keytap.Direction;

                        OnKeyTapGesture(this, kargs);

                        //SafeWriteLine("Tap id: " + keytap.Id
                        //               + ", " + keytap.State
                        //               + ", position: " + keytap.Position
                        //               + ", direction: " + keytap.Direction);
                        break;
                    case Gesture.GestureType.TYPESCREENTAP:

                        if (OnScreenTapGesture == null) break;

                        ScreenTapGesture screentap = new ScreenTapGesture(gesture);

                        var targs = new LeapListenerArgs(screentap);

                        targs.logdata = "Tap id: " + screentap.Id
                                       + ", " + screentap.State
                                       + ", position: " + screentap.Position
                                       + ", direction: " + screentap.Direction;

                        OnScreenTapGesture(this, targs);

                        //SafeWriteLine("Tap id: " + screentap.Id
                        //               + ", " + screentap.State
                        //               + ", position: " + screentap.Position
                        //               + ", direction: " + screentap.Direction);
                        break;
                    default:
                        //SafeWriteLine("Unknown gesture type.");
                        break;
                }
            }

            if (!frame.Hands.Empty || !frame.Gestures().Empty)
            {
                //SafeWriteLine("");
            }
        }
Ejemplo n.º 15
0
        private void UpdateFrame(Frame frame)
        {
            lock (thisLock)
            {
                //fires the event only in the case of an event handler being present
                if (OnFrameUpdate == null) return;

                LeapListenerArgs args = new LeapListenerArgs(frame);
                OnFrameUpdate(this, args);
            }
        }
Ejemplo n.º 16
0
 void ll_OnLogUpdate(object sender, LeapListenerArgs e)
 {
     //throw new NotImplementedException();
     PrintLog(e);
 }
Ejemplo n.º 17
0
 private void PrintLog(LeapListenerArgs e)
 {
     Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.High, () => { TextBlock_log.Text += "\n" + e.logdata; });
 }
Ejemplo n.º 18
0
        void listener_OnDeviceStatusUpdate(object sender, LeapListenerArgs e)
        {
            Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.High, () =>
            {

                string texttodisplay = "";

                switch (e.devicestatus)
                {
                    case LeapDeviceState.connected: texttodisplay = "Connected"; break;
                    case LeapDeviceState.disconnected: texttodisplay = "Disconnected"; break;
                    case LeapDeviceState.exited: texttodisplay = "Exited"; break;
                    case LeapDeviceState.initialized: texttodisplay = "Initialized"; break;
                }

                TextBlock_DeviceStatus.Text = texttodisplay;
            });
        }
Ejemplo n.º 19
0
 void listener_OnCircleGesture(object sender, LeapListenerArgs e)
 {
     PrintLog(e);
 }
Ejemplo n.º 20
0
        private void SafeWriteLine(String line)
        {
            lock (thisLock)
            {
                // System.Diagnostics.Debug.WriteLine(line);

                System.Diagnostics.Debug.WriteLine("Leap Output:" + line);

                //fires the event only in the case of an event handler being present
                if (OnLogUpdate == null) return;

                LeapListenerArgs args = new LeapListenerArgs(line);
                OnLogUpdate(this, args);
            }
        }