Beispiel #1
0
        public void detectGesture(Leap.Frame frame)                                    //Función publica de detección de gesto con los frames recibidos del Leap Motion
        {
            GestureList gestures = frame.Gestures();                                   //Intanciación del objeto gestos con la llamada de frames

            for (int i = 0; i < gestures.Count(); i++)                                 //Bucle for para recorrer la cantidad de gestos recibidos
            {
                Gesture gesture = gestures[i];                                         //Aignación de las posiciones del array segun se recorre el array de  gestos
                switch (gesture.Type)                                                  //Switch de caos del tipo de gesto
                {
                case Gesture.GestureType.TYPE_CIRCLE:                                  //Si se recibe el gesto de circulo
                    richTextBox1.AppendText("Circle detected!" + Environment.NewLine); //Se muestra el texto por pantalla y se pasa a la siguiente linea del cuadro de muestras de texto por pantalla
                    break;                                                             //Salida

                case Gesture.GestureType.TYPE_SCREEN_TAP:                              //Si se recibe el gesto de screen tap
                    richTextBox1.AppendText("Screen tap!" + Environment.NewLine);      //Se muestra el texto por pantalla y se pasa a la siguiente linea del cuadro de muestras de texto por pantalla
                    break;                                                             //Salida

                case Gesture.GestureType.TYPE_KEY_TAP:                                 //Si se recibe el gesto de key tap
                    richTextBox1.AppendText("Key tap!" + Environment.NewLine);         //Se muestra el texto por pantalla y se pasa a la siguiente linea del cuadro de muestras de texto por pantalla
                    break;                                                             //Salida

                case Gesture.GestureType.TYPE_SWIPE:                                   //Si se recibe el gesto de swipe
                    richTextBox1.AppendText("Swipe detected!" + Environment.NewLine);  //Se muestra el texto por pantalla y se pasa a la siguiente linea del cuadro de muestras de texto por pantalla
                    break;                                                             //Salida
                }
            }
        }
Beispiel #2
0
      private void detectGesture(Leap.Frame frame)
      {
          GestureList gestures = frame.Gestures();

          for (int i = 0; i < gestures.Count(); i++)
          {
              Gesture gesture = gestures[i];
              switch (gesture.Type)
              {
              case Gesture.GestureType.TYPE_CIRCLE:
                  //richTextBox1.AppendText("Movement detected!" + Environment.NewLine);
                  break;

              case Gesture.GestureType.TYPE_KEY_TAP:
                  //richTextBox1.AppendText("Movement detected!" + Environment.NewLine);

                  break;

              case Gesture.GestureType.TYPE_SWIPE:
                  // richTextBox1.AppendText("Translation detected!" + Environment.NewLine);

                  break;

              case Gesture.GestureType.TYPE_INVALID:
                  //richTextBox1.AppendText("NO MOVEMENT ");
                  break;
              }
          }
      }
Beispiel #3
0
        //method to detect hand and creates the frame object
        public void detectGesture(Leap.Frame frame)
        {
            // creates an object
            GestureList gestures = frame.Gestures(); //returns list of gestures

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

                //switch using gesture.type as a flag, when it gets the type of gesture it will go to its respective case
                switch (gesture.Type)
                {
                //these are the cases and prints out the detected gesture

                case Gesture.GestureType.TYPE_CIRCLE:
                    Debug.WriteLine("Circle");
                    break;

                case Gesture.GestureType.TYPE_KEY_TAP:
                    Debug.WriteLine("Key Tap");
                    break;

                case Gesture.GestureType.TYPE_SWIPE:
                    Debug.WriteLine("Swipe");
                    break;

                case Gesture.GestureType.TYPE_SCREEN_TAP:
                    Debug.WriteLine("Screen Tap");
                    break;
                }
            }
        }
Beispiel #4
0
 void newFrameHandler(Leap.Frame frame)
 {
     LeapInfo.X = (int)frame.Pointables.Frontmost.TipPosition.x;
     LeapInfo.Y = (int)frame.Pointables.Frontmost.TipPosition.y;
     LeapInfo.Z = (int)frame.Pointables.Frontmost.TipPosition.z;
     Console.WriteLine(LeapInfo);
 }
Beispiel #5
0
        protected void DrawLeapTouch(Leap.Frame frame)
        {
            InteractionBox interactionBox = frame.InteractionBox;

            if (frame.Pointables.Extended().Count != 1)
            {
                return;
            }

            Pointable pointable = frame.Pointables.Extended()[0];

            // InteractionBox を利用した座標変換
            Leap.Vector normalizedPosition = interactionBox.NormalizePoint(pointable.StabilizedTipPosition);

            double                tx         = normalizedPosition.x * windowWidth;
            double                ty         = windowHeight - normalizedPosition.y * windowHeight;
            StylusPoint           touchPoint = new StylusPoint(tx, ty);
            StylusPointCollection tips       = new StylusPointCollection(new StylusPoint[] { touchPoint });

            // タッチ状態
            if (normalizedPosition.z <= TouchBorder)
            {
                Stroke touchStroke = new Stroke(tips, touchIndicator);
                this.InkCanvas_LeapPaintLine.Strokes.Add(touchStroke.Clone());
            }
        }
Beispiel #6
0
        private void TransformModulationFraction(Leap.Frame frameData)
        {
            foreach (var hand in frameData.Hands)
            {
                if (hand.IsLeft)
                {
                    float yPosition = hand.PalmPosition.y;

                    if (yPosition < 500 && yPosition >= 0)
                    {
                        for (int i = 0; i < yPartition.Length; ++i)
                        {
                            if (i < yPartition.Length - 1)
                            {
                                if (yPosition >= yPartition[i] && yPosition < yPartition[i + 1])
                                {
                                    pmProvider.LerpModulationFraction(modulationFractions[i], InterpolationSpeed);
                                    return;
                                }
                            }
                            else
                            {
                                pmProvider.CarrierFrequency = noteFrequencies[yPartition.Length - 1];
                            }
                        }
                    }
                }
            }
        }
Beispiel #7
0
 // Update is called once per frame
 void Update()
 {
     frame = a.frame;
     if(t<1.5)
         t += Time.deltaTime; 													//This prevents multiple unintentional gestures.
     Debug.Log (manager != null);
     Debug.Log (manager.IsLeapInitialized ());
     if (manager != null && manager.IsLeapInitialized ()) {
         if(t>=1.5){																// prevents multiple unintentional gestures.
             if(frame.Pointables.Count>=5){
                 k++;
                 /*if(frame.RotationAngle(frame)<=0){
                     k++;
                 }
                 else{
                     k=0;
                 }*/
             }
         }
         if(k>15){//Debug.Log ("BditVICTORY");
             isDT=!isDT;															//This is the "objective" of the gesture.
             k=0;
             t=0;
         }
         if(isDT){transform.GetChild(0).gameObject.SetActive(false);}
         else{transform.GetChild(0).gameObject.SetActive(true);}
     }
 }
Beispiel #8
0
        protected void DrawLeapPoint(Leap.Frame frame)
        {
            this.InkCanvas_LeapPaint.Strokes.Clear();
            windowHeight = (float)this.MainWindow1.Height;
            windowWidth  = (float)this.MainWindow1.Width;

            InteractionBox interactionBox = frame.InteractionBox;

            foreach (Pointable pointable in frame.Pointables.Extended())
            {
                // InteractionBox を利用した座標変換
                Leap.Vector normalizedPosition = interactionBox.NormalizePoint(pointable.StabilizedTipPosition);

                double                tx         = normalizedPosition.x * windowWidth;
                double                ty         = windowHeight - normalizedPosition.y * windowHeight;
                StylusPoint           touchPoint = new StylusPoint(tx, ty);
                StylusPointCollection tips       = new StylusPointCollection(new StylusPoint[] { touchPoint });

                // ホバー状態
                if (normalizedPosition.z > TouchBorder)
                {
                    Stroke touchStroke = new Stroke(tips, pointIndicator);
                    this.InkCanvas_LeapPaint.Strokes.Add(touchStroke);
                }
            }
        }
        public override void OnFrame(Controller controller)
        {
            Leap.Frame frame = controller.Frame();
            if (!frame.Hands.IsEmpty)
            {
                var screen = controller.LocatedScreens.FirstOrDefault();
                if (screen != null && screen.IsValid)
                {
                    if (frame.Fingers.Count > 0)
                    {
                        _now            = frame.Timestamp;
                        _timeDifference = _now - _previous;
                        _previous       = frame.Timestamp;
                        if (_timeDifference >= 1000)
                        {
                            Finger oFinger    = frame.Fingers[0];
                            var    coordinate = GetNormalizedXAndY(oFinger, screen);

                            if (this.OnFingerLocationChanged != null)
                            {
                                Task.Factory.StartNew(() => OnFingerLocationChanged(coordinate.X, coordinate.Y));
                            }
                        }
                    }

                    var pos = FindCursorPosition(frame.Hands[0], screen);
                    if (this.OnHandLocationChanged != null)
                    {
                        Task.Factory.StartNew(() => OnHandLocationChanged(pos.x, pos.y));
                    }
                }
            }
        }
Beispiel #10
0
        protected void DrawLeapLine(Controller leap, Leap.Frame frame)
        {
            FingerList allFingers = frame.Fingers.Extended();

            if (allFingers.Count != 2 || leap.Frame(10).Fingers.Extended().Count != 2)
            {
                return;
            }

            Finger finger1 = allFingers.Leftmost;
            Finger finger2 = allFingers.Rightmost;

            InteractionBox interactionBox = frame.InteractionBox;

            Leap.Vector normalizedPosition1 = interactionBox.NormalizePoint(finger1.StabilizedTipPosition);
            Leap.Vector normalizedPosition2 = interactionBox.NormalizePoint(finger2.StabilizedTipPosition);

            double tx1 = normalizedPosition1.x * windowWidth;
            double ty1 = windowHeight - normalizedPosition1.y * windowHeight;
            double tx2 = normalizedPosition2.x * windowWidth;
            double ty2 = windowHeight - normalizedPosition2.y * windowHeight;

            StylusPointCollection tips = new StylusPointCollection();

            tips.Add(new StylusPoint(tx1, ty1));
            tips.Add(new StylusPoint(tx2, ty2));
            Stroke stroke = new Stroke(tips, lineIndicator);

            this.InkCanvas_LeapPaint.Strokes.Add(stroke);
        }
Beispiel #11
0
        protected void DetectLeapGesture(Controller leap, Leap.Frame frame)
        {
            GestureList gestures = frame.Gestures();

            foreach (Gesture gesture in gestures)
            {
                if (gesture.State != Gesture.GestureState.STATESTOP)
                {
                    continue;
                }

                switch (gesture.Type)
                {
                case Gesture.GestureType.TYPESWIPE:
                    SwipeGesture swipe = new SwipeGesture(gesture);

                    if (swipe.StartPosition.x < 0 && swipe.Direction.x > 0)
                    {
                        TurnSlide(-1);
                    }
                    else if (swipe.StartPosition.x > 0 && swipe.Direction.x < 0)
                    {
                        TurnSlide(+1);
                    }
                    break;

                default: break;
                }
            }
        }
Beispiel #12
0
        public void detectGesture(Leap.Frame frame)
        {
            GestureList gestures = frame.Gestures();   //Return a list of gestures

            for (int i = 0; i < gestures.Count(); i++) // enumerate all the gestures detected in a frame
            {
                Gesture gesture = gestures[i];
                switch (gesture.Type)
                {
                case Gesture.GestureType.TYPE_CIRCLE:
                    richTextBox1.AppendText("Circle detected!" + Environment.NewLine);
                    break;

                case Gesture.GestureType.TYPE_KEY_TAP:
                    richTextBox1.AppendText("Key Tap detected!" + Environment.NewLine);
                    break;

                case Gesture.GestureType.TYPE_SWIPE:
                    richTextBox1.AppendText("Swipe detected!" + Environment.NewLine);
                    break;

                case Gesture.GestureType.TYPE_SCREEN_TAP:
                    richTextBox1.AppendText("Screen Tap detected!" + Environment.NewLine);
                    break;
                }
            }
        }
Beispiel #13
0
        private void TransformModulationIndex(Leap.Frame frameData)
        {
            foreach (var hand in frameData.Hands)
            {
                if (hand.IsRight)
                {
                    float xPosition = hand.PalmPosition.x;

                    if (xPosition >= xMin && xPosition <= xMax)
                    {
                        for (int i = 0; i < xPartition.Length; ++i)
                        {
                            if (i < xPartition.Length - 1)
                            {
                                if (xPosition >= xPartition[i] && xPosition < xPartition[i + 1])
                                {
                                    pmProvider.LerpModulationIndex(modulationIndices[i], InterpolationSpeed);
                                    return;
                                }
                            }
                            else
                            {
                                pmProvider.LerpModulationIndex(modulationIndices[xPartition.Length - 1], InterpolationSpeed);
                            }
                        }
                    }
                }
            }
        }
        public override void Init()
        {
            try
            {
                headDistance           = new JSONStorableFloat("Camera to head distance required", 0.2f, 0f, 0.5f, true);
                headDistance.storeType = JSONStorableParam.StoreType.Full;
                RegisterFloat(headDistance);
                CreateSlider(headDistance, false);

                xOffsetSlider           = new JSONStorableFloat("X Offset", 0.045f, -0.1f, 0.1f, true);
                xOffsetSlider.storeType = JSONStorableParam.StoreType.Full;
                RegisterFloat(xOffsetSlider);
                CreateSlider(xOffsetSlider, false);

                provider = FindObjectOfType <LeapProvider>() as LeapProvider;
                frame    = provider.CurrentFrame;
                hands    = frame.Hands;

                if (SuperController.singleton.isOVR)
                {
                    mainCamera = SuperController.singleton.ViveCenterCamera;
                }
                else
                {
                    mainCamera = SuperController.singleton.lookCamera;
                }
            }
            catch (Exception e)
            {
                SuperController.LogError("Exception caught: " + e);
            }
        }
Beispiel #15
0
        public void detectGesture(Leap.Frame frame)
        {
            GestureList gestures = frame.Gestures();   //Return a list of gestures

            for (int i = 0; i < gestures.Count(); i++) // enumerate all the gestures detected in a frame
            {
                Gesture gesture = gestures[i];
                switch (gesture.Type)
                {
                case Gesture.GestureType.TYPE_CIRCLE:
                    richTextBox1.AppendText("Circle detected!" + Environment.NewLine);
                    this.Unlocked = true;
                    this.UnlockGestureTimer.Stop();
                    this.UnlockGestureTimer.Start();
                    break;

                case Gesture.GestureType.TYPE_KEY_TAP:
                    FanController.WindLevel();
                    richTextBox1.AppendText("Key Tap detected!" + Environment.NewLine);
                    break;

                case Gesture.GestureType.TYPE_SWIPE:
                    FanController.PowerOff();
                    richTextBox1.AppendText("Swipe detected!" + Environment.NewLine);
                    break;

                case Gesture.GestureType.TYPE_SCREEN_TAP:
                    FanController.LightOn();
                    richTextBox1.AppendText("Screen Tap detected!" + Environment.NewLine);
                    break;
                }
            }
        }
Beispiel #16
0
 // Update is called once per frame
 void Update()
 {
     if(controller.IsConnected)//controller is a Controller object
     {
         frame = controller.Frame();												//Puts the controler information into the frame for export
     }																			//to other scripts
 }
        void newFrameHandler(Leap.Frame frame)
        {
            while (LeftHandModelGroup.Children.Count > 0)
            {
                LeftHandModelGroup.Children.RemoveAt(0);
            }
            while (RightHandModelGroup.Children.Count > 0)
            {
                RightHandModelGroup.Children.RemoveAt(0);
            }


            List <GeometryModel3D> leftList  = new List <GeometryModel3D>();
            List <GeometryModel3D> rightList = new List <GeometryModel3D>();

            if (!frame.IsValid)
            {
                return;
            }

            if (frame.Hands.Count == 2)
            {
                Hand hand  = frame.Hands[0];
                Hand hand2 = frame.Hands[1];
                if (hand.IsLeft)
                {
                    leftList  = visualizer.drawLeftHand(hand);
                    rightList = visualizer.drawRightHand(hand2);
                }
                else
                {
                    leftList  = visualizer.drawLeftHand(hand2);
                    rightList = visualizer.drawRightHand(hand);
                }
            }
            else if (frame.Hands.Count == 1)
            {
                Hand hand = frame.Hands[0];
                if (hand.IsLeft)
                {
                    leftList = visualizer.drawLeftHand(hand);
                }
                else
                {
                    rightList = visualizer.drawRightHand(hand);
                }
            }
            else
            {
            }
            leftList.ForEach(delegate(GeometryModel3D m)
            {
                LeftHandModelGroup.Children.Add(m);
            });
            rightList.ForEach(delegate(GeometryModel3D m)
            {
                RightHandModelGroup.Children.Add(m);
            });
        }
Beispiel #18
0
 // 实时采集信息显示
 private void ShowGeneralInfo(Leap.Frame frame)
 {
     this.TbkFrameId.Text       = "Frame ID: " + frame.Id;
     this.TbkTimestamp.Text     = "Timestamp: " + frame.Timestamp;
     this.TbkGesturesCount.Text = "Gestures Count: " + frame.Gestures().Count;
     this.TbkHandsCount.Text    = "Hands Count: " + frame.Hands.Count;
     this.TbkFingersCount.Text  = "Fingers Count: " + frame.Fingers.Count;
     this.TbkToolsCount.Text    = "Tools Count: " + frame.Tools.Count;
 }
        void newFrameHandler(object sender, FrameEventArgs eventArgs)
        {
            Leap.Frame frame = eventArgs.frame;

            this.fpsDisplay.Content = frame.CurrentFramesPerSecond.ToString();
            if (frame.Hands.Count > 0)
            {
                Hand hand = frame.Hands[0];

                // determine if hand is left or right hand
                string handType = hand.IsLeft ? "Left" : "Right";
                this.handTypeDisplay.Content = handType;

                // fingers
                Finger thumb   = hand.Fingers[0];
                Finger pointer = hand.Fingers[1];
                Finger middle  = hand.Fingers[2];
                Finger ring    = hand.Fingers[3];
                Finger pinky   = hand.Fingers[4];

                // thumb abduction
                Leap.Vector thumbDirection   = thumb.Direction;
                Leap.Vector pointerDirection = pointer.Direction;
                Leap.Vector handDirection    = hand.Direction;

                double angleRadians = thumbDirection.AngleTo(pointerDirection);
                double angleDegrees = Math.Round(angleRadians * 180 / Math.PI, 1);
                currentAngle = angleDegrees;
                calculateAverageAngle();
                this.angleDisplay.Content = currentAverageAngle.ToString();

                if (recording == true)
                {
                    DateTime currentTime = DateTime.Now;
                    int      elapsedTime = Convert.ToInt32(((TimeSpan)(currentTime - startRecording)).TotalMilliseconds);
                    timeDisplay.Content = elapsedTime.ToString();
                    string line = "timestamp: " + elapsedTime.ToString() + " | hand: " + handType + " | angle: " + currentAverageAngle.ToString();
                    if (firstFrame == true)
                    {
                        using (StreamWriter recordFile = new StreamWriter(@"C:\Users\casch\Documents\Work\Uni\Studienarbeit\Implementierung\C#\abd.txt"))
                        {
                            recordFile.WriteLine(line);
                        };

                        firstFrame = false;
                    }
                    else
                    {
                        using (StreamWriter recordFile = new StreamWriter(@"C:\Users\casch\Documents\Work\Uni\Studienarbeit\Implementierung\C#\abd.txt", true)) {
                            recordFile.WriteLine(line);
                        };
                    }
                }
            }

            controller.RequestImages(frame.Id, Leap.Image.ImageType.DEFAULT, imagedata);
        }
 void newFrameHandler(Leap.Frame frame)
 {
     displayID.Text = frame.Id.ToString();
     //this.displayTimestamp.Content = frame.Timestamp.ToString();
     //this.displayFPS.Content = frame.CurrentFramesPerSecond.ToString();
     //this.displayIsValid.Content = frame.IsValid.ToString();
     displayGestureCount.Text = frame.Gestures().Count.ToString();
     //this.displayImageCount.Content = frame.Images.Count.ToString();
 }
        protected virtual void StartZoom(Leap.Frame frame)
        {
            IsZooming  = true;
            StartFrame = frame;

            if (ZoomStarted != null)
            {
                ZoomStarted();
            }
        }
Beispiel #22
0
    public static void Update()
    {
        if (m_controller != null)
        {
            Frame lastFrame = m_Frame == null ? Frame.Invalid : m_Frame;
            m_Frame = m_controller.Frame();

            DispatchLostEvents(Frame, lastFrame);
            DispatchFoundEvents(Frame, lastFrame);
            DispatchUpdatedEvents(Frame, lastFrame);
        }
    }
Beispiel #23
0
 // Render
 private void NewFrameHandler(Leap.Frame frame)
 {
     try
     {
         this.ShowRawImages(frame);
         this.ShowGeneralInfo(frame);
         this.ShowFingerPoints(frame);
     }
     catch (Exception ex)
     {
         Debug.WriteLine(ex.Message);
     }
 }
Beispiel #24
0
        public bool Update(Leap.Frame frame)
        {
            var s = _HandManager.Dump();

            if (!String.IsNullOrWhiteSpace(s))
            {
                if (frame.Timestamp > _LastLogTime + 0)
                {
                    _LastLogTime = frame.Timestamp;
                    _LogAction(s);
                }
            }
            return(true);
        }
Beispiel #25
0
        //====================================================================
        //  Leap Motion
        //====================================================================

        protected void LeapUpdate(object sender, EventArgs e)
        {
            Leap.Frame frame = leap.Frame();

            DetectLeapGesture(leap, frame);
            DrawLeapPoint(frame);
            DrawLeapTouch(frame);
            DrawLeapLine(leap, frame);

            if (frame.Fingers.Extended().Count == 5 && leap.Frame(10).Fingers.Extended().Count <= 1)
            {
                this.InkCanvas_LeapPaintLine.Strokes.Clear();
            }
        }
        void newFrameHandler(Leap.Frame frame)
        {
            HandList hands = frame.Hands;


            this.handCountValue.Content = hands.Count;
            //get the front most hand
            if (hands.Count > 0 && hands[0] != null)
            {
                Hand firstHand = hands[0];

                Leap.Vector direction  = firstHand.Direction;
                Leap.Vector PalmNormal = firstHand.PalmNormal;
                Leap.Vector center     = firstHand.PalmPosition;
                Leap.Vector moveRate   = firstHand.PalmVelocity;


                this.directionValue.Content    = direction;
                this.palmPositionValue.Content = center;
                this.normalValue.Content       = PalmNormal;

                FingerList fingers = firstHand.Fingers;
                this.fingerCountValue.Content = fingers.Count();
            }

            if (hands.Count > 1 && hands[1] != null)
            {
                Hand secondHand = hands[1];

                Leap.Vector direction  = secondHand.Direction;
                Leap.Vector PalmNormal = secondHand.PalmNormal;
                Leap.Vector center     = secondHand.PalmPosition;
                Leap.Vector moveRate   = secondHand.PalmVelocity;


                this.secondDirectionValue.Content    = direction;
                this.secondPalmPositionValue.Content = center;
                this.secondNormalValue.Content       = PalmNormal;

                //pass finger number in front hand to label( it is always five, with the new Leap Motion Hand model)
                FingerList fingers = secondHand.Fingers;
                this.secondFingerCountValue.Content = fingers.Count();
            }


            this.idValue.Content        = frame.Id.ToString();
            this.frameRateValue.Content = frame.CurrentFramesPerSecond.ToString();
            this.isValidValue.Content   = frame.IsValid.ToString();
        }
Beispiel #27
0
 private void detectFingers(Leap.Frame frame)
 {
     foreach (Finger finger in frame.Fingers)
     {
         // richTextBox2.AppendText("Finger Type:" + finger.Id + Environment.NewLine +
         //  "Finger position:" + finger.TipPosition + Environment.NewLine+
         // "Finger stabilized position "+ finger.StabilizedTipPosition);
         foreach (Bone.BoneType boneType in (Bone.BoneType[])Enum.GetValues(typeof(Bone.BoneType)))
         {
             Bone bone = finger.Bone(boneType);
             //richTextBox3.AppendText("Bone Type:" + bone.Type + Environment.NewLine + "Bone Direction" +
             //   bone.Direction);
         }
     }
 }
Beispiel #28
0
 //get latest frame called each second
 public static void Update()
 {
     if(_controller != null)
     {
         Frame lastFrame = _frame == null ? Frame.Invalid : _frame;
         _frame = _controller.Frame();
         if(_frame != null)
         {
             if(_frame.Hands.Count > 0)
             {
                 _hand = _frame.Hands[0];
             }
         }
     }
 }
        void newFrameHandler(Leap.Frame frameAv)
        {
            if (send)
            {
                long id     = -1;
                long lHands = -1;
                long rHands = -1;

                if (senderTimer.ElapsedMilliseconds > timeThreshold)
                {
                    id     = frameAv.Id;
                    lHands = 0;
                    rHands = 0;

                    if (frameAv.Hands.Count > 0)
                    {
                        foreach (Leap.Hand hand in frameAv.Hands)
                        {
                            if (hand.IsLeft)
                            {
                                lHands += 1;
                            }
                            else
                            {
                                rHands += 1;
                            }
                        }
                        LeapFrameYarpSender frameSender = new LeapFrameYarpSender(frameAv, new ManualResetEvent(false));
                        ThreadPool.QueueUserWorkItem(frameSender.ThreadPoolCallback, yarpPort);

                        frameCounter += 1;
                        // reset timer, start again
                        senderTimer.Reset();
                        senderTimer.Start();
                    }
                    else
                    {
                        skippedFrame += 1;// frame without hands += 1
                    }
                }
                else
                {
                    skippedFrame += 1;
                }

                ThreadPool.QueueUserWorkItem(UpdateLabels, new long[] { id, lHands, rHands });
            }
        }
        protected void Update(object sender, EventArgs e)
        {
            paintCanvas.Strokes.Clear();

            windowWidth  = (float)this.Width;
            windowHeight = (float)this.Height;

            Leap.Frame     frame          = leap.Frame();
            InteractionBox interactionBox = leap.Frame().InteractionBox;

            try
            {
                Leap.Image image = frame.Images[0];
                this.DrawRawImages_WriteableBitmap(image.Data, image.Width, image.Height);
            }
            catch { }

            foreach (Pointable pointable in leap.Frame().Pointables)
            {
                Finger      oFinger            = new Finger(pointable);
                Leap.Vector normalizedPosition =
                    interactionBox.NormalizePoint(pointable.StabilizedTipPosition);
                float tx = normalizedPosition.x * windowWidth;
                float ty = windowHeight - normalizedPosition.y * windowHeight;

                int alpha = 255;
                if (pointable.TouchDistance > 0 && pointable.TouchZone != Pointable.Zone.ZONENONE)
                {
                    alpha = 255 - (int)(255 * pointable.TouchDistance);
                    touchIndicator.Color = Color.FromArgb((byte)alpha, 0x0, 0xff, 0x0);
                }
                else if (pointable.TouchDistance <= 0)
                {
                    alpha = -(int)(255 * pointable.TouchDistance);
                    touchIndicator.Color = Color.FromArgb((byte)alpha, 0xff, 0x0, 0x0);
                }
                else
                {
                    alpha = 50;
                    touchIndicator.Color = Color.FromArgb((byte)alpha, 0x0, 0x0, 0xff);
                }
                StylusPoint           touchPoint = new StylusPoint(tx, ty);
                StylusPointCollection tips       =
                    new StylusPointCollection(new StylusPoint[] { touchPoint });
                Stroke touchStroke = new Stroke(tips, touchIndicator);
                paintCanvas.Strokes.Add(touchStroke);
            }
        }
        void listener_FrameArrived(Leap.Frame frame)
        {
            FrameRate = frame.CurrentFramesPerSecond;

            TipPositions = frame.Pointables
                           .Where(p => p.IsValid)
                           .Where(p => p.TipPosition.IsValid())
                           .Select(p => ToScreenPoint(p.TipPosition))
                           .ToArray();

            StabilizedTipPositions = frame.Pointables
                                     .Where(p => p.IsValid)
                                     .Where(p => p.StabilizedTipPosition.IsValid())
                                     .Select(p => ToScreenPoint(p.StabilizedTipPosition))
                                     .ToArray();
        }
Beispiel #32
0
 public void wheel(Leap.Frame frame)
 {
     if (roll_ready == 0 && !setPTmode)
     {
         if (frame.Hands[0].PalmNormal.z < -0.65)
         {
             // 150 = 스크롤 업
             mouse_event((uint)MotionEnum.MOUSE.MouseWheel, 0, 0, 150, 0);
         }
         else if (frame.Hands[0].PalmNormal.z > 0.35)
         {
             // -150 = 스크롤 다운
             mouse_event((uint)MotionEnum.MOUSE.MouseWheel, 0, 0, -150, 0);
         }
     }
 }
        protected void Update(object sender, EventArgs e)
        {
            paintCanvas.Strokes.Clear();
            windowWidth  = (float)this.Width;
            windowHeight = (float)this.Height;

            Leap.Frame     frame          = leap.Frame();
            InteractionBox interactionBox = leap.Frame().InteractionBox;

            foreach (Pointable pointable in leap.Frame().Pointables)
            {
                // ここから追加
                // 伸びている指、ツール以外は無視する
                //if ( !pointable.IsExtended ) {
                //    continue;
                //}
                // ここまで追加

                Leap.Vector normalizedPosition =
                    interactionBox.NormalizePoint(pointable.StabilizedTipPosition);
                float tx = normalizedPosition.x * windowWidth;
                float ty = windowHeight - normalizedPosition.y * windowHeight;

                int alpha = 255;
                if ((pointable.TouchDistance > 0 && pointable.TouchZone != Pointable.Zone.ZONENONE))
                {
                    alpha = 255 - (int)(255 * pointable.TouchDistance);
                    touchIndicator.Color = Color.FromArgb((byte)alpha, 0x0, 0xff, 0x0);
                }
                else if (pointable.TouchDistance <= 0)
                {
                    alpha = -(int)(255 * pointable.TouchDistance);
                    touchIndicator.Color = Color.FromArgb((byte)alpha, 0xff, 0x0, 0x0);
                }
                else
                {
                    alpha = 50;
                    touchIndicator.Color = Color.FromArgb((byte)alpha, 0x0, 0x0, 0xff);
                }

                StylusPoint           touchPoint = new StylusPoint(tx, ty);
                StylusPointCollection tips       =
                    new StylusPointCollection(new StylusPoint[] { touchPoint });
                Stroke touchStroke = new Stroke(tips, touchIndicator);
                paintCanvas.Strokes.Add(touchStroke);
            }
        }
Beispiel #34
0
	public static void Update() 
	{	
		if( m_controller != null )
		{
			
			Frame lastFrame = m_Frame == null ? Frame.Invalid : m_Frame;
			m_Frame	= m_controller.Frame();
			if (m_Frame != null)
			{
				if (m_Frame.Hands.Count > 0)
				{
					m_Hand = m_Frame.Hands[0];
				}
				fingerCount = m_Frame.Fingers.Count;
			}
		}
	}
    public Frame makeFrame(ref LEAP_TRACKING_EVENT trackingMsg)
    {
      Frame newFrame = new Leap.Frame((long)trackingMsg.info.frame_id,
                           (long)trackingMsg.info.timestamp,
                           trackingMsg.framerate,
                           new InteractionBox(trackingMsg.interaction_box_center.ToLeapVector(),
                               trackingMsg.interaction_box_size.ToLeapVector()),
                           new List<Hand>((int)trackingMsg.nHands)
            );

      for (int h = 0; h < trackingMsg.nHands; h++)
      {
        LEAP_HAND hand = StructMarshal<LEAP_HAND>.ArrayElementToStruct(trackingMsg.pHands, h);
        newFrame.Hands.Add(makeHand(ref hand, newFrame));
      }
      return newFrame;
    }
Beispiel #36
0
	public static void Update() 
	{	
		if( m_controller != null )
		{
			
			Frame lastFrame = m_Frame == null ? Frame.Invalid : m_Frame;
			m_Frame	= m_controller.Frame();
			if (m_Frame != null)
			{
				if (m_Frame.Hands.Count > 0)
				{
					m_Hand = m_Frame.Hands[0];
					normal = m_Hand.PalmNormal;
					direction = m_Hand.Direction;
				}
			}
		}
	}
    public Frame makeFrame(ref LEAP_TRACKING_EVENT trackingMsg)
    {
      Frame newFrame = new Leap.Frame((long)trackingMsg.info.frame_id,
                           (long)trackingMsg.info.timestamp,
                           trackingMsg.framerate,
                           new InteractionBox(trackingMsg.interaction_box_center.ToLeapVector(),
                               trackingMsg.interaction_box_size.ToLeapVector()),
                           new List<Hand>((int)trackingMsg.nHands)
            );

      int pHandArrayOffset = 0;
      for (int h = 0; h < trackingMsg.nHands; h++)
      {
        LEAP_HAND hand = LeapC.PtrToStruct<LEAP_HAND>(new IntPtr(trackingMsg.pHands.ToInt64() + pHandArrayOffset));
        pHandArrayOffset += handStructSize;
        newFrame.Hands.Add(makeHand(ref hand, newFrame));
      }
      return newFrame;
    }
Beispiel #38
0
    public static void Update()
    {
        if( m_controller != null )
        {
            if(!GesturesEnabled) {
                m_controller.EnableGesture(Gesture.GestureType.TYPEKEYTAP);
            }
            Frame lastFrame = m_Frame == null ? Frame.Invalid : m_Frame;
            m_Frame	= m_controller.Frame();

            DispatchGestures (Frame);
            DispatchLostEvents(Frame, lastFrame);
            DispatchFoundEvents(Frame, lastFrame);
            DispatchUpdatedEvents(Frame, lastFrame);

        }
    }
Beispiel #39
0
    void OnApplicationQuit()
    {
        leapPointable = null;
        leapFrame = null;

        if(leapController != null)
        {
            leapController.Dispose();
            leapController = null;
        }

        leapInitialized = false;
        instance = null;
    }
Beispiel #40
0
    void Update()
    {
        if(leapInitialized && leapController != null)
        {
            Leap.Frame frame = leapController.Frame();

            if(frame.IsValid && (frame.Id != lastFrameID))
            {
                leapFrame = frame;
                lastFrameID = leapFrame.Id;
                leapFrameCounter++;

                // fix unfinished leap gesture progress
                if(fCircleProgress > 0f && fCircleProgress < 1f)
                    fCircleProgress = 0f;
                if(fSwipeProgress > 0f && fSwipeProgress < 1f)
                    fSwipeProgress = 0f;
                if(fKeyTapProgress > 0f && fKeyTapProgress < 1f)
                    fKeyTapProgress = 0f;
                if(fScreenTapProgress > 0f && fScreenTapProgress < 1f)
                    fScreenTapProgress = 0f;

                // get a suitable pointable
                leapPointable = leapFrame.Pointable(leapPointableID);

                if(!leapPointable.IsValid)
                    leapPointable = leapFrame.Pointables.Frontmost;

                Leap.Vector stabilizedPosition = Leap.Vector.Zero;
                Leap.Hand handPrim = leapFrame.Hands.Count > 0 ? leapFrame.Hands[leapFrame.Hands.Count - 1] : null;

                if(leapPointable != null && leapPointable.IsValid &&
                    leapPointable.Hand != null && leapPointable.Hand.IsValid &&
                    handPrim != null && leapPointable.Hand.Id == handPrim.Id)
                {
                    leapPointableID = leapPointable.Id;
                    leapPointableHandID = leapPointable.Hand != null && leapPointable.Hand.IsValid ? leapPointable.Hand.Id : 0;

                    leapPointablePos = LeapToUnity(leapPointable.StabilizedTipPosition, true);
                    leapPointableDir = LeapToUnity(leapPointable.Direction, false);
                    //leapPointableQuat = Quaternion.LookRotation(leapPointableDir);

                    leapPointableZone = leapPointable.TouchZone;
                    //stabilizedPosition = leapPointable.StabilizedTipPosition;

                    leapHand = leapPointable.Hand;
                    leapHandID = leapHand.Id;
                }
                else
                {
                    leapPointableID = 0;
                    leapPointable = null;

                    // get leap hand
                    leapHand = leapFrame.Hand(leapHandID);
                    if(leapHand == null || !leapHand.IsValid)
                    {
                        leapHandID = 0;

                        if(leapFrame.Hands.Count > 0)
                        {
                            for(int i = leapFrame.Hands.Count - 1; i >= 0; i--)
                            {
                                leapHand = leapFrame.Hands[i];

                                if(leapHand.IsValid /**&& leapHand.Fingers.Count > 0*/)
                                {
                                    leapHandID = leapHand.Id;
                                    break;
                                }
                            }
                        }
                    }

                }

                if(leapHandID != 0)
                {
                    leapHandPos = LeapToUnity(leapHand.StabilizedPalmPosition, true);
                    stabilizedPosition = leapHand.StabilizedPalmPosition;
                    leapHandFingersCount = leapHand.Fingers.Count;
                }

                // estimate the cursor coordinates
                if(stabilizedPosition != Leap.Vector.Zero)
                {
                    Leap.InteractionBox iBox = frame.InteractionBox;
                    Leap.Vector normalizedPosition = iBox.NormalizePoint(stabilizedPosition);

                    cursorNormalPos.x = normalizedPosition.x;
                    cursorNormalPos.y = normalizedPosition.y;
                    cursorScreenPos.x = cursorNormalPos.x * UnityEngine.Screen.width;
                    cursorScreenPos.y = cursorNormalPos.y * UnityEngine.Screen.height;
                }

                // do fingers count filter
                if(leapHandID != fingersCountHandID)
                {
                    fingersCountHandID = leapHandID;
                    fingersCountPrev = -1;
                    fingersCountPrevPrev = -1;

                    handGripDetected = false;
                    fingersCountFilter.Reset();
                }

                if(leapHandID != 0)
                {
                    fingersCountFiltered = leapHandFingersCount;
                    fingersCountFilter.UpdateFilter(ref fingersCountFiltered);

                    if((leapFrameCounter - handGripFrameCounter) >= FramesToSkip)
                    {
                        handGripFrameCounter = leapFrameCounter;
                        int fingersCountNow = (int)(fingersCountFiltered + 0.5f);
                        //int fingersCountNow = leapHandFingersCount;

                        if(fingersCountPrev == fingersCountPrevPrev)
                        {
                            if(!handGripDetected)
                            {
                                if(fingersCountNow < fingersCountPrev)
                                {
                                    Finger leftFinger = leapHand.Finger(leapHandLFingerId);
                                    Finger rightFinger = leapHand.Finger(leapHandRFingerId);
                                    bool bThumbOff = !LeftHandedUser ? leapHandLFingerId != 0 && (leftFinger == null || !leftFinger.IsValid) :
                                        leapHandRFingerId != 0 && (rightFinger == null || !rightFinger.IsValid);

                                    if(bThumbOff)
                                    {
                                        handGripDetected = true;
                                        handGripFingersCount = fingersCountPrev;
                                    }
                                }
                                else
                                {
                                    leapHandLFingerId = leapHand != null && leapHand.Fingers.Count > 0 ? leapHand.Fingers.Leftmost.Id : 0;
                                    leapHandRFingerId = leapHand != null && leapHand.Fingers.Count > 0 ? leapHand.Fingers.Rightmost.Id : 0;
                                }
                            }
                            else
                            {
                                if(fingersCountNow >= fingersCountPrev/**handGripFingersCount*/)
                                {
                                    Finger leftFinger = leapHand.Finger(leapHandLFingerId);
                                    Finger rightFinger = leapHand.Finger(leapHandRFingerId);

                                    bool bThumbOn = !LeftHandedUser ? (leftFinger != null && leftFinger.IsValid) :
                                        (rightFinger != null && rightFinger.IsValid);

                                    if(bThumbOn || fingersCountNow >= handGripFingersCount)
                                    {
                                        handGripDetected = false;
                                    }
                                }
                                else if(leapHand == null || !leapHand.IsValid)
                                {
                                    // stop pinching if the hand is lost
                                    handGripDetected = false;
                                }
                            }
                        }

                        fingersCountPrevPrev = fingersCountPrev;
                        fingersCountPrev = fingersCountNow;
                    }
                }

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

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

                                if((leapFrameCounter - iCircleFrameCounter) >= FramesToSkip &&
                                    iCircleGestureID != circle.Id &&
                                    circle.State == Gesture.GestureState.STATESTOP)
                                {
                                    iCircleFrameCounter = leapFrameCounter;
                                    iCircleGestureID = circle.Id;
                                    fCircleProgress = 1f;

                                    gestureTrackingAtTime = Time.realtimeSinceStartup + MinTimeBetweenGestures;
                                }
                                else if(circle.Progress < 1f)
                                {
                                    fCircleProgress = circle.Progress;
                                }
                                break;

                            case Gesture.GestureType.TYPESWIPE:
                                SwipeGesture swipe = new SwipeGesture(gesture);

                                if((leapFrameCounter - iSwipeFrameCounter) >= FramesToSkip &&
                                    iSwipeGestureID != swipe.Id &&
                                    swipe.State == Gesture.GestureState.STATESTOP)
                                {
                                    iSwipeFrameCounter = leapFrameCounter;
                                    iSwipeGestureID = swipe.Id;
                                    fSwipeProgress = 1f;  // swipe.Progress

                                    gestureTrackingAtTime = Time.realtimeSinceStartup + MinTimeBetweenGestures;

                                    leapSwipeDir = LeapToUnity(swipe.Direction, false);
                                    leapSwipeSpeed = LeapToUnity(swipe.Position - swipe.StartPosition, true);

                                    if(swipe.DurationSeconds != 0)
                                        leapSwipeSpeed /= swipe.DurationSeconds;
                                    else
                                        leapSwipeSpeed = Vector3.zero;
                                }
                                else if(swipe.State != Gesture.GestureState.STATESTOP)
                                {
                                    fSwipeProgress = 0.5f;
                                }
                                break;

                            case Gesture.GestureType.TYPEKEYTAP:
                                KeyTapGesture keytap = new KeyTapGesture (gesture);

                                if((leapFrameCounter - iKeyTapFrameCounter) >= FramesToSkip &&
                                    iKeyTapGestureID != keytap.Id &&
                                    keytap.State == Gesture.GestureState.STATESTOP)
                                {
                                    iKeyTapFrameCounter = leapFrameCounter;
                                    iKeyTapGestureID = keytap.Id;
                                    fKeyTapProgress = 1f;

                                    gestureTrackingAtTime = Time.realtimeSinceStartup + MinTimeBetweenGestures;
                                }
                                else if(keytap.Progress < 1f)
                                {
                                    fKeyTapProgress = keytap.Progress;
                                }
                                break;

                            case Gesture.GestureType.TYPESCREENTAP:
                                ScreenTapGesture screentap = new ScreenTapGesture (gesture);

                                if((leapFrameCounter - iScreenTapFrameCounter) >= FramesToSkip &&
                                    iScreenTapGestureID != screentap.Id &&
                                    screentap.State == Gesture.GestureState.STATESTOP)
                                {
                                    iScreenTapFrameCounter = leapFrameCounter;
                                    iScreenTapGestureID = screentap.Id;
                                    fScreenTapProgress = 1f;

                                    gestureTrackingAtTime = Time.realtimeSinceStartup + MinTimeBetweenGestures;
                                }
                                else if(screentap.Progress < 1f)
                                {
                                    fScreenTapProgress = screentap.Progress;
                                }
                                break;

                            default:
                                Debug.LogError("Unknown gesture type.");
                                break;
                        }
                    }

                    // check for extra gestures
                    int listGestureSize = extraGesturesData.Count;
                    float timestampNow = Time.realtimeSinceStartup;

                    for(int g = 0; g < listGestureSize; g++)
                    {
                        LeapExtraGestures.ExtraGestureData gestureData = extraGesturesData[g];

                        if(timestampNow >= gestureData.startTrackingAtTime)
                        {
                            LeapExtraGestures.CheckForGesture(ref gestureData, Time.realtimeSinceStartup, this);
                            extraGesturesData[g] = gestureData;

                            if(gestureData.complete)
                            {
                                gestureTrackingAtTime = Time.realtimeSinceStartup + MinTimeBetweenGestures;
                            }
                        }
                    }
                }

                if(DebugCamera)
                {
                    DoDisplayFingers();
                }
            }
        }
    }
Beispiel #41
0
    void Update()
    {
        if(leapInitialized && leapController != null)
        {
            Leap.Frame frame = leapController.Frame();

            if(frame.IsValid && (frame.Id != lastFrameID))
            {
                leapFrame = frame;
                lastFrameID = leapFrame.Id;
                leapFrameCounter++;

        //				// fix unfinished leap gesture progress
        //				if(fCircleProgress > 0f && fCircleProgress < 1f)
        //					fCircleProgress = 0f;
        //				if(fSwipeProgress > 0f && fSwipeProgress < 1f)
        //					fSwipeProgress = 0f;
        //				if(fKeyTapProgress > 0f && fKeyTapProgress < 1f)
        //					fKeyTapProgress = 0f;
        //				if(fScreenTapProgress > 0f && fScreenTapProgress < 1f)
        //					fScreenTapProgress = 0f;

                // get the prime hand
                leapHand = leapFrame.Hand(leapHandID);
                if(leapHand == null || !leapHand.IsValid)
                {
                    leapHand = GetFrontmostHand();
                    leapHandID = leapHand != null && leapHand.IsValid ? leapHand.Id : 0;
                }

                // get the prime pointable
                leapPointable = leapFrame.Pointable(leapPointableID);
                if(leapPointable == null || !leapPointable.IsValid)
                {
                    leapPointable = leapHand.IsValid ? GetPointingFigner(leapHand) : leapFrame.Pointables.Frontmost;

                    leapPointableID = leapPointable != null && leapPointable.IsValid ? leapPointable.Id : 0;
                    leapPointableHandID = leapPointable != null && leapPointable.IsValid && leapPointable.Hand.IsValid ? leapPointable.Hand.Id : 0;
                }

                if(leapPointable != null && leapPointable.IsValid &&
                    leapPointable.Hand != null && leapPointable.Hand.IsValid &&
                    leapHand != null && leapHand.IsValid && leapPointable.Hand.Id == leapHand.Id)
                {
                    leapPointablePos = LeapToUnity(leapPointable.StabilizedTipPosition, true);
                    leapPointableDir = LeapToUnity(leapPointable.Direction, false);
                    //leapPointableQuat = Quaternion.LookRotation(leapPointableDir);
                }
                else
                {
                    leapPointable = null;

                    leapPointableID = 0;
                    leapPointableHandID = 0;
                }

                Leap.Vector stabilizedPosition = Leap.Vector.Zero;
                if(leapHandID != 0)
                {
                    leapHandPos = LeapToUnity(leapHand.StabilizedPalmPosition, true);
                    stabilizedPosition = leapHand.StabilizedPalmPosition;

                    leapHandFingersCount = leapHand.Fingers.Count;

                    bool bCurrentHandGrip = handGripDetected;
                    handGripDetected = !isHandOpen(leapHand);
                    handReleaseDetected = !handGripDetected;

                    if(controlMouseCursor)
                    {
                        if(!bCurrentHandGrip && handGripDetected)
                        {
                            MouseControl.MouseDrag();
                        }
                        else if(bCurrentHandGrip && handReleaseDetected)
                        {
                            MouseControl.MouseRelease();
                        }
                    }
                }
                else
                {
                    if(controlMouseCursor && handGripDetected)
                    {
                        MouseControl.MouseRelease();
                    }

                    leapHandFingersCount = 0;
                    handGripDetected = false;
                    handReleaseDetected = false;
                }

                // estimate the cursor coordinates
                if(stabilizedPosition.MagnitudeSquared != 0f)
                {
                    Leap.InteractionBox iBox = frame.InteractionBox;
                    Leap.Vector normalizedPosition = iBox.NormalizePoint(stabilizedPosition);

                    cursorNormalPos.x = normalizedPosition.x;
                    cursorNormalPos.y = normalizedPosition.y;
                    cursorScreenPos.x = cursorNormalPos.x * UnityEngine.Screen.width;
                    cursorScreenPos.y = cursorNormalPos.y * UnityEngine.Screen.height;

                    if(controlMouseCursor)
                    {
                        MouseControl.MouseMove(cursorNormalPos);
                    }
                }

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

                    if(Time.realtimeSinceStartup < gestureTrackingAtTime)
                        continue;

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

                            if(iCircleGestureID != circle.Id &&
                                circle.State == Gesture.GestureState.STATESTOP)
                            {
                                iCircleGestureID = circle.Id;
                                fCircleProgress = 1f;

                                gestureTrackingAtTime = Time.realtimeSinceStartup + MinTimeBetweenGestures;
                            }
                            else if(circle.Progress < 1f)
                            {
                                fCircleProgress = circle.Progress;
                            }
                            break;

                        case Gesture.GestureType.TYPESWIPE:
                            SwipeGesture swipe = new SwipeGesture(gesture);

                            if(iSwipeGestureID != swipe.Id &&
                                swipe.State == Gesture.GestureState.STATESTOP)
                            {
                                iSwipeGestureID = swipe.Id;
                                fSwipeProgress = 1f;  // swipe.Progress

                                gestureTrackingAtTime = Time.realtimeSinceStartup + MinTimeBetweenGestures;

                                leapSwipeDir = LeapToUnity(swipe.Direction, false);
                                leapSwipeSpeed = LeapToUnity(swipe.Position - swipe.StartPosition, true);

                                if(swipe.DurationSeconds != 0)
                                    leapSwipeSpeed /= swipe.DurationSeconds;
                                else
                                    leapSwipeSpeed = Vector3.zero;
                            }
                            else if(swipe.State != Gesture.GestureState.STATESTOP)
                            {
                                fSwipeProgress = 0.5f;
                            }
                            break;

                        case Gesture.GestureType.TYPEKEYTAP:
                            KeyTapGesture keytap = new KeyTapGesture (gesture);

        //							if(iKeyTapGestureID != keytap.Id &&
        //								keytap.State == Gesture.GestureState.STATESTOP)
                            {
                                iKeyTapGestureID = keytap.Id;
                                fKeyTapProgress = 1f;

                                gestureTrackingAtTime = Time.realtimeSinceStartup + MinTimeBetweenGestures;
                            }
        //							else if(keytap.Progress < 1f)
        //							{
        //								fKeyTapProgress = keytap.Progress;
        //							}
                            break;

                        case Gesture.GestureType.TYPESCREENTAP:
                            ScreenTapGesture screentap = new ScreenTapGesture (gesture);

        //							if(iScreenTapGestureID != screentap.Id &&
        //								screentap.State == Gesture.GestureState.STATESTOP)
                            {
                                iScreenTapGestureID = screentap.Id;
                                fScreenTapProgress = 1f;

                                gestureTrackingAtTime = Time.realtimeSinceStartup + MinTimeBetweenGestures;
                            }
        //							else if(screentap.Progress < 1f)
        //							{
        //								fScreenTapProgress = screentap.Progress;
        //							}
                            break;

                        default:
                            Debug.LogError("Unknown gesture type.");
                            break;
                    }
                }

                if(DebugCamera)
                {
                    DoDisplayFingers();
                }
            }
        }
    }
Beispiel #42
0
    public static void Update()
    {
        // If there is a controller currently connected
        if( m_controller != null )
        {
            // If the frame null, set lastFrame to Frame.Invalid,
            // otherwise set it to the current value of m_Frame.
            Frame lastFrame = m_Frame == null ? Frame.Invalid : m_Frame;
            // Get a Frame from the Controller:
            m_Frame	= m_controller.Frame();

            // Process all events for the new Frame
            DispatchLostEvents(Frame, lastFrame);
            DispatchFoundEvents(Frame, lastFrame);
            DispatchUpdatedEvents(Frame, lastFrame);
        }
    }
    public static void Update()
    {
        m_Hand = null;
        m_Frame = null;
        m_FingersCount = 0;
        if( m_controller != null )
        {
            m_Frame	= m_controller.Frame();
            if (m_Frame != null)
            {
                if (m_Frame.Hands.Count > 0)
                {
                    m_Hand = m_Frame.Hands[0];
                }

                if (m_Frame.Fingers.Count > 0)
                {
                    m_FingersCount = m_Frame.Fingers.Count;
                }
            }
        }
    }
Beispiel #44
0
    void Update()
    {
        if(leapInitialized && leapController != null)
        {
            Leap.Frame frame = leapController.Frame();

            if(frame.IsValid && (frame.Id != lastFrameID))
            {
                leapFrame = frame;
                lastFrameID = leapFrame.Id;
                leapFrameCounter++;

                // get the prime hand
                leapHand = leapFrame.Hand(leapHandID);
                if(leapHand == null || !leapHand.IsValid)
                {
                    leapHand = GetFrontmostHand();
                    leapHandID = leapHand != null && leapHand.IsValid ? leapHand.Id : 0;
                }

                leapPointable = leapFrame.Pointable(leapPointableID);
                if(leapPointable == null || !leapPointable.IsValid)
                {
                    leapPointable = leapHand.IsValid ? GetPointingFigner(leapHand) : leapFrame.Pointables.Frontmost;

                    leapPointableID = leapPointable != null && leapPointable.IsValid ? leapPointable.Id : 0;
                    leapPointableHandID = leapPointable != null && leapPointable.IsValid && leapPointable.Hand.IsValid ? leapPointable.Hand.Id : 0;
                }

                if(leapPointable != null && leapPointable.IsValid &&
                   leapPointable.Hand != null && leapPointable.Hand.IsValid &&
                   leapHand != null && leapHand.IsValid && leapPointable.Hand.Id == leapHand.Id)
                {
                    leapPointablePos = LeapToUnity(leapPointable.StabilizedTipPosition, true);
                    leapPointableDir = LeapToUnity(leapPointable.Direction, false);
                }
                else
                {
                    leapPointable = null;

                    leapPointableID = 0;
                    leapPointableHandID = 0;
                }

                Leap.Vector stabilizedPosition = Leap.Vector.Zero;
                if(leapHandID != 0)
                {
                    leapHandPos = LeapToUnity(leapHand.StabilizedPalmPosition, true);
                    stabilizedPosition = leapHand.StabilizedPalmPosition;

                    leapHandFingersCount = leapHand.Fingers.Count;

                    bool bCurrentHandGrip = handGripDetected;
                    handGripDetected = !isHandOpen(leapHand);
                    handReleaseDetected = !handGripDetected;

                }
                else
                {
                    leapHandFingersCount = 0;
                    handGripDetected = false;
                    handReleaseDetected = false;
                }

                if(stabilizedPosition.MagnitudeSquared != 0f)
                {
                    Leap.InteractionBox iBox = frame.InteractionBox;
                    Leap.Vector normalizedPosition = iBox.NormalizePoint(stabilizedPosition);

                    cursorNormalPos.x = normalizedPosition.x;
                    cursorNormalPos.y = normalizedPosition.y;
                    cursorScreenPos.x = cursorNormalPos.x * UnityEngine.Screen.width;
                    cursorScreenPos.y = cursorNormalPos.y * UnityEngine.Screen.height;

                }
            }
        }
    }
        private void btnRead_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);
                }
                */

            }
        }
    public static void Update()
    {
        if( m_controller != null )
        {

            Frame lastFrame = m_Frame == null ? Frame.Invalid : m_Frame;
            m_Frame	= m_controller.Frame();

            DispatchLostEvents(Frame, lastFrame);
            DispatchFoundEvents(Frame, lastFrame);
            DispatchUpdatedEvents(Frame, lastFrame);
        }
    }
    void Update()
    {
        Leap.Frame thisFrame = LeapManager.frame;
        if( thisFrame == null )
            return;

        //Remove fingers which have been disabled
        int index;
        while( (index = m_Touching.FindIndex(i => i.collider && i.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;
        }
    }