Ejemplo n.º 1
0
 public BimanualData(Hand l, Hand r, UnimanualGestureType lg, UnimanualGestureType rg, BimanualGestureType g)
 {
     leftHand         = l;
     rightHand        = r;
     leftHandGesture  = lg;
     rightHandGesture = rg;
     gesture          = g;
 }
Ejemplo n.º 2
0
        public BimanualGestureType GetBimanualGesture(UnimanualGestureType l, UnimanualGestureType r)
        {
            BimanualGestureType gesture = BimanualGestureType.Unknown;

            foreach (SimpleBimanualGestureTemplate template in simpleBimanualGestures)
            {
                if (template.IsMatch(l, r))
                {
                    gesture = template.gestureType;
                }
            }
            return(gesture);
        }
 void BimanualUntracked()
 {
     bimanualGesture = BimanualGestureType.Unknown;
     bimanualData    = null;
 }
        void PoseGestureUpdate()
        {
            Frame       frame = leapServiceProvider.CurrentFrame;
            List <Hand> hands = frame.Hands;

            if (hands.Count > 0)
            {
                switch (hands.Count)
                {
                case 1:
                    if (hands[0].IsLeft)
                    {
                        leftHand  = hands[0];
                        rightHand = null;
                    }
                    else
                    {
                        leftHand  = null;
                        rightHand = hands[0];
                    }
                    break;

                case 2:
                    if (hands[0].IsRight)
                    {
                        leftHand  = hands[1];
                        rightHand = hands[0];
                    }
                    else
                    {
                        leftHand  = hands[0];
                        rightHand = hands[1];
                    }
                    break;
                }

                if (leftHand != null && leftHand.Id != 0)
                {
                    if (leftHand.IsPinching())
                    {
                        if (!isLeftHandPinching)
                        {
                            leftHandPinchStart = leftHand.PalmPosition.ToVector3();
                        }

                        if (overridePinchStatus)
                        {
                            isLeftHandPinching = (leftHand.PinchStrength <= maxPinchStrength && leftHand.PinchStrength >= minPinchStrength) ? true : false;
                        }
                        else
                        {
                            isLeftHandPinching = true;
                        }
                    }
                    else if (!leftHand.IsPinching())
                    {
                        isLeftHandPinching = false;
                        leftHandPinchStart = Vector3.negativeInfinity;
                    }
                    isLeftHandTracked = true;
                    leftHandPose      = handPoseRecognition.GetHandPose(leftHand);
                    leftHandGesture   = leftGestureRecognition.GetUnimanualGesture(leftHandPose);

                    if (!leftHandGesture.Equals(UnimanualGestureType.Unknown.ToString()))
                    {
                        if (leftUnimanualData == null || leftUnimanualData.gesture != leftHandGesture)
                        {
                            Hand h = new Hand();
                            h = h.CopyFrom(leftHand);
                            leftUnimanualData = new UnimanualData(leftHandGesture, h);
                        }
                    }
                    else
                    {
                        leftUnimanualData = null;
                    }
                }
                else
                {
                    LeftUntracked();
                }

                if (rightHand != null && rightHand.Id != 0)
                {
                    if (rightHand.IsPinching())
                    {
                        if (!isRightHandPinching)
                        {
                            righHandPinchStart = rightHand.PalmPosition.ToVector3();
                        }

                        if (overridePinchStatus)
                        {
                            isRightHandPinching = (rightHand.PinchStrength <= maxPinchStrength && rightHand.PinchStrength >= minPinchStrength) ? true : false;
                        }
                        else
                        {
                            isRightHandPinching = true;
                        }
                    }
                    else if (!rightHand.IsPinching())
                    {
                        isRightHandPinching = false;
                        righHandPinchStart  = Vector3.negativeInfinity;
                    }

                    isRightHandTracked = true;
                    rightHandPose      = handPoseRecognition.GetHandPose(rightHand);
                    rightHandGesture   = rightGestureRecognition.GetUnimanualGesture(rightHandPose);
                    if (!rightHandGesture.Equals(UnimanualGestureType.Unknown.ToString()))
                    {
                        if (rightUnimanualData == null || rightUnimanualData.gesture != rightHandGesture)
                        {
                            Hand h = new Hand();
                            h = h.CopyFrom(rightHand);
                            rightUnimanualData = new UnimanualData(rightHandGesture, h);
                        }
                    }
                    else
                    {
                        rightUnimanualData = null;
                    }

                    //EventUpdate
                    UpdatePoseEvents();
                }
                else
                {
                    RightUntracked();
                }

                if (hands.Count == 2 && leftHand != null && rightHand != null)
                {
                    bimanualGesture = bimanualRecognition.GetBimanualGesture(leftHandGesture, rightHandGesture);
                    if (!bimanualGesture.Equals(BimanualGestureType.Unknown.ToString()))
                    {
                        if (bimanualData == null || bimanualGesture != bimanualData.gesture)
                        {
                            Hand l = new Hand();
                            l = l.CopyFrom(leftHand);
                            Hand r = new Hand();
                            r            = r.CopyFrom(rightHand);
                            bimanualData = new BimanualData(l, r, leftHandGesture, rightHandGesture, bimanualGesture);
                        }
                    }
                    else
                    {
                        bimanualData = null;
                    }
                }
                else
                {
                    bimanualGesture = BimanualGestureType.Unknown;
                }
            }
            else
            {
                LeftUntracked();
                RightUntracked();
                BimanualUntracked();
            }
        }
Ejemplo n.º 5
0
 public SimpleBimanualGestureTemplate(UnimanualGestureType l, UnimanualGestureType r, BimanualGestureType t)
 {
     leftHand    = l;
     rigthHand   = r;
     gestureType = t;
 }