Exemplo n.º 1
0
    private char DoASLTest_B(Leap.Hand hand)
    {
        float fingerThreshold = 1400;

        Leap.FingerList fingers = hand.Fingers;

        Leap.Finger pinky  = fingers[(int)Leap.Finger.FingerType.TYPE_PINKY];
        Leap.Finger ring   = fingers[(int)Leap.Finger.FingerType.TYPE_RING];
        Leap.Finger middle = fingers[(int)Leap.Finger.FingerType.TYPE_MIDDLE];
        Leap.Finger index  = fingers[(int)Leap.Finger.FingerType.TYPE_INDEX];
        Leap.Finger thumb  = fingers[(int)Leap.Finger.FingerType.TYPE_THUMB];

        Vector3 pinkyPos  = ToVector3(pinky.Bone(Leap.Bone.BoneType.TYPE_INTERMEDIATE).NextJoint);
        Vector3 ringPos   = ToVector3(ring.Bone(Leap.Bone.BoneType.TYPE_INTERMEDIATE).NextJoint);
        Vector3 middlePos = ToVector3(middle.Bone(Leap.Bone.BoneType.TYPE_INTERMEDIATE).NextJoint);
        Vector3 indexPos  = ToVector3(index.Bone(Leap.Bone.BoneType.TYPE_INTERMEDIATE).NextJoint);

        if ((pinkyPos - ringPos).sqrMagnitude < fingerThreshold &&
            (ringPos - middlePos).sqrMagnitude < fingerThreshold &&
            (middlePos - indexPos).sqrMagnitude < fingerThreshold)
        {
            return('B');
        }
        return(INVALID_ASL_LETTER);
    }
Exemplo n.º 2
0
        public Hand TransformedCopy(Matrix trs)
        {
            FingerList transformedFingers = new FingerList(5);

            for (int f = 0; f < this.Fingers.Count; f++)
            {
                transformedFingers.Add(Fingers[f].TransformedCopy(trs));
            }

            float hScale = trs.xBasis.Magnitude;

            return(new Hand(_frameId,
                            _id,
                            _confidence,
                            _grabStrength,
                            _grabAngle,
                            _pinchStrength,
                            _pinchDistance,
                            _palmWidth * hScale,
                            _isLeft,
                            _timeVisible,
                            _arm.TransformedCopy(trs),
                            transformedFingers,
                            trs.TransformPoint(_palmPosition),
                            trs.TransformPoint(_stabilizedPalmPosition),
                            trs.TransformPoint(_palmVelocity),
                            trs.TransformDirection(_palmNormal).Normalized,
                            trs.TransformDirection(_direction).Normalized,
                            trs.TransformPoint(_wristPosition)
                            ));
        }
Exemplo n.º 3
0
 public Frame(long id, long timestamp, float fps, InteractionBox interactionBox)
 {
     _id            = id;
     _timestamp     = timestamp;
     _fps           = fps;
     _isValid       = true;
     _fingers       = new FingerList(15);
     _hands         = new HandList(3);
     _trackedQuad   = new TrackedQuad();
     InteractionBox = interactionBox;
 }
Exemplo n.º 4
0
    private bool AreTwoFingersInContact(MyFingerType firstFingerType, MyFingerType secondFingerType, Leap.Hand hand, float threshold)
    {
        Leap.FingerList fingers      = hand.Fingers;
        Leap.Finger     firstFinger  = fingers[(int)firstFingerType];
        Leap.Finger     secondFinger = fingers[(int)secondFingerType];

        Vector3 firstFingerPos  = ToVector3(firstFinger.TipPosition);
        Vector3 secondFingerPos = ToVector3(secondFinger.TipPosition);

        float twoFingerDist = Vector3.Distance(firstFingerPos, secondFingerPos);

        return(twoFingerDist <= threshold);
    }
Exemplo n.º 5
0
    private char DoASLTest_CO(Leap.Hand hand)
    {
        float threshold = 40;

        Leap.FingerList fingers   = hand.Fingers;
        Leap.Finger     middle    = fingers[(int)Leap.Finger.FingerType.TYPE_MIDDLE];
        Leap.Finger     thumb     = fingers[(int)Leap.Finger.FingerType.TYPE_THUMB];
        Vector3         middlePos = ToVector3(middle.TipPosition);
        Vector3         thumbPos  = ToVector3(thumb.TipPosition);

        float dist = Vector3.Distance(middlePos, thumbPos);

        //Debug.Log("hey " + dist);

        return((dist < threshold) ? 'O' : 'C');
    }
Exemplo n.º 6
0
        public static Hand MakeTestHand(int frameId, int handId, bool isLeft)
        {
            FingerList fingers = new FingerList(5);

            fingers.Add(MakeThumb(frameId, handId));
            fingers.Add(MakeIndexFinger(frameId, handId));
            fingers.Add(MakeMiddleFinger(frameId, handId));
            fingers.Add(MakeRingFinger(frameId, handId));
            fingers.Add(MakePinky(frameId, handId));

            Vector armWrist = new Vector(-7.05809944059f, 4.0f, 50.0f);
            Vector elbow    = armWrist + 250f * Vector.Backward;
            Matrix armBasis = new Matrix(Vector.Right, Vector.Down, Vector.Forward);
            Arm    arm      = new Arm(elbow, armWrist, (elbow + armWrist) / 2, Vector.Forward, 250f, 41f, Bone.BoneType.TYPE_DISTAL, armBasis);
            Hand   testHand = new Hand(frameId,
                                       handId,
                                       1.0f,
                                       0.0f,
                                       0.0f,
                                       0.0f,
                                       0.0f,
                                       85f,
                                       isLeft,
                                       0.0f,
                                       arm,
                                       fingers,
                                       new Vector(0, 0, 0),
                                       new Vector(0, 0, 0),
                                       new Vector(0, 0, 0),
                                       Vector.Down,
                                       Vector.Backward,
                                       new Vector(-4.36385750984f, 6.5f, 31.0111342526f)
                                       );

            if (isLeft)
            {
                return(testHand);
            }
            else
            {
                Matrix leftToRight = new Matrix(Vector.Right, Vector.Up, Vector.Forward);
                return(testHand.TransformedCopy(leftToRight));
            }
        }
Exemplo n.º 7
0
    //1,DISTAL(tip) 2,INTERMEDIATE 3,PROXIMAL
    // Update is called once per frame
    void Update()
    {
        Leap.Frame frame = controller.GetFrame();
        if (gestureOption == 0)
        {
            hands = frame.Hands;
            Leap.Hand hand = hands.Leftmost;
            //Debug.Log ("here");
            if (hand.IsValid && hand.IsLeft)
            {
                Leap.FingerList fingers = hand.Fingers;
                Leap.Vector     tipV    = fingers[0].TipVelocity;
                float           tipVmag = tipV.Magnitude;
                //Leap.Vector tipV2 = fingers[1].TipVelocity;
                Leap.Bone bone = fingers[0].Bone(Leap.Bone.BoneType.TYPE_DISTAL);
                //Leap.Bone bone2 = fingers[1].Bone (Leap.Bone.BoneType.TYPE_DISTAL);

                float distFromBoneToPalm = bone.Center.DistanceTo(hand.PalmPosition);
                float palmDirectionSign  = hand.PalmNormal.Dot(vecUpInLeapForm);

                //Debug.Log (distFromBoneToPalm + " " + palmDirectionSign + " " + tipVmag + " " + hand.Confidence);
                //Debug.Log (bone.Direction.Pitch);
                if (distFromBoneToPalm < 70 && palmDirectionSign > 0.5 && tipVmag > 30 && hand.Confidence > 0.7)
                {
                    getCollidersInARangeAndSendMessage();
                }
            }
        }
        else if (gestureOption == 1)
        {
            Leap.GestureList gestures = frame.Gestures();
            for (int i = 0; i < gestures.Count; i++)
            {
                if (gestures[i].Type == Leap.Gesture.GestureType.TYPESWIPE)
                {
                    if (gestures[i].IsValid && gestures[i].State == Leap.Gesture.GestureState.STATESTOP)
                    {
                        Debug.Log("Yes");
                        getCollidersInARangeAndSendMessage();
                    }
                }
            }
        }
    }
Exemplo n.º 8
0
        public void AddHand(Hand hand)
        {
            if (_hands == null)
            {
                _hands = new HandList(3);
            }

            _hands.Add(hand);
            if (_fingers == null)
            {
                _fingers = new FingerList(15);
            }


            for (int f = 0; f < hand.Fingers.Count; f++)
            {
                _fingers.Add(hand.Fingers [f]);
            }
        }
Exemplo n.º 9
0
 public Hand(int frameID,
             int id,
             float confidence,
             float grabStrength,
             float grabAngle,
             float pinchStrength,
             float pinchDistance,
             float palmWidth,
             bool isLeft,
             float timeVisible,
             Arm arm,
             FingerList fingers,
             Vector palmPosition,
             Vector stabilizedPalmPosition,
             Vector palmVelocity,
             Vector palmNormal,
             Vector direction,
             Vector wristPosition)
 {
     _frameId                = frameID;
     _id                     = id;
     _confidence             = confidence;
     _grabStrength           = grabStrength;
     _grabAngle              = grabAngle;
     _pinchStrength          = pinchStrength;
     _pinchDistance          = pinchDistance;
     _palmWidth              = palmWidth;
     _isLeft                 = isLeft;
     _isRight                = !isLeft;
     _timeVisible            = timeVisible;
     _arm                    = arm;
     _fingers                = fingers;
     _palmPosition           = palmPosition;
     _stabilizedPalmPosition = stabilizedPalmPosition;
     _palmVelocity           = palmVelocity;
     _palmNormal             = palmNormal;
     _direction              = direction;
     _wristPosition          = wristPosition;
 }
Exemplo n.º 10
0
    private char DoASLTest_AEMNST(Leap.Hand hand)
    {
        // TODO: Add The Proper Letter Detection Here
        // Would be doing this if Leap Motion proved accurate enough...

        //float fingerThreshold = 30;
        //float angleAlignmentThreshold = 15;
        //float pinkyThreshold = 15;
        //float closestFingerThreshold = 10;


        Leap.FingerList fingers = hand.Fingers;
        //Leap.Finger pinky = fingers[(int)Leap.Finger.FingerType.TYPE_PINKY];
        //Leap.Finger ring = fingers[(int)Leap.Finger.FingerType.TYPE_RING];
        //Leap.Finger middle = fingers[(int)Leap.Finger.FingerType.TYPE_MIDDLE];
        Leap.Finger index = fingers[(int)Leap.Finger.FingerType.TYPE_INDEX];
        Leap.Finger thumb = fingers[(int)Leap.Finger.FingerType.TYPE_THUMB];

        {         // Test For 'A'
            float   distance;
            Vector3 point1  = ToVector3(index.TipPosition);
            Vector3 point2  = ToVector3(index.Bone(Leap.Bone.BoneType.TYPE_INTERMEDIATE).PrevJoint);
            Vector3 point3  = ToVector3(index.Bone(Leap.Bone.BoneType.TYPE_METACARPAL).PrevJoint);
            Vector3 vector1 = point1 - point2;
            Vector3 vector2 = point3 - point2;
            Vector3 N       = Vector3.Cross(vector1, vector2);
            Vector3 w       = ToVector3(thumb.TipPosition) - point2;

            Vector3 projection = Vector3.Project(w, N);

            distance  = projection.magnitude;
            distance *= (projection.normalized == N.normalized) ? 1.0f : -1.0f;
            distance *= (hand.IsRight) ? 1.0f : -1.0f;

            if (distance > 0)
            {
                return('A');
            }
        }

        // Test for 'O'
        float theO_Threshold = 40;

        Leap.Finger middle    = fingers[(int)Leap.Finger.FingerType.TYPE_MIDDLE];
        Vector3     middlePos = ToVector3(middle.TipPosition);
        Vector3     thumbPos  = ToVector3(thumb.TipPosition);
        float       dist      = Vector3.Distance(middlePos, thumbPos);

        if (dist < theO_Threshold)
        {
            return('O');
        }
        else
        {
            // Otherwise, not worth getting the rest. . .
            return(INVALID_ASL_LETTER);
        }

        /*
         * Vector3 pinkyPos = ToVector3(pinky.Bone(Leap.Bone.BoneType.TYPE_INTERMEDIATE).NextJoint);
         * Vector3 ringPos = ToVector3(ring.Bone(Leap.Bone.BoneType.TYPE_INTERMEDIATE).NextJoint);
         * Vector3 middlePos = ToVector3(middle.Bone(Leap.Bone.BoneType.TYPE_INTERMEDIATE).NextJoint);
         * Vector3 indexPos = ToVector3(index.Bone(Leap.Bone.BoneType.TYPE_INTERMEDIATE).NextJoint);
         * Vector3 thumbPos = ToVector3(thumb.TipPosition);
         * Vector3 palmPos = ToVector3(hand.PalmPosition);
         *
         * Vector3 middleToThumb = thumbPos - middlePos;
         * Vector3 indexToThumb = thumbPos - indexPos;
         * Vector3 indexToMiddle = middlePos - indexPos;
         *
         * float middleToThumbDist = middleToThumb.sqrMagnitude;
         *
         * if (AreTwoFingersInContact(MyFingerType.TYPE_PINKY, MyFingerType.TYPE_THUMB, hand, pinkyThreshold))
         * {
         *      return 'E';
         * }
         *
         * // Check Based on distance from Bone
         * float pinkyToThumbDist = Vector3.Distance(pinkyPos, thumbPos);
         * float ringToThumbDist = Vector3.Distance(ringPos, thumbPos);
         * middleToThumbDist = Mathf.Sqrt(middleToThumbDist);
         * float indexToThumbDist = indexToThumb.magnitude;
         *
         * // Test for what the thumb is closest to
         * MyFingerType fingerClosest = MyFingerType.TYPE_PINKY;
         * float currentClosest = pinkyToThumbDist;
         * if (ringToThumbDist < currentClosest)
         * {
         *      fingerClosest = MyFingerType.TYPE_RING;
         *      currentClosest = ringToThumbDist;
         * }
         * if (middleToThumbDist < currentClosest)
         * {
         *      fingerClosest = MyFingerType.TYPE_MIDDLE;
         *      currentClosest = middleToThumbDist;
         * }
         * if (indexToThumbDist < currentClosest)
         * {
         *      fingerClosest = MyFingerType.TYPE_INDEX;
         *      currentClosest = indexToThumbDist;
         * }
         *
         * // Near Pinky = E
         * // Near Ring = M
         * // Near Middle = N, S
         * // Near Index = T, A
         * if (currentClosest < closestFingerThreshold)
         * {
         *      switch (fingerClosest)
         *      {
         *              case MyFingerType.TYPE_PINKY:	return 'E';
         *              case MyFingerType.TYPE_RING:
         *              case MyFingerType.TYPE_MIDDLE:
         *              case MyFingerType.TYPE_INDEX:	return 'O';
         *      }
         * }
         * return INVALID_ASL_LETTER;*/
    }
Exemplo n.º 11
0
    private char DoASLTest_HKRUV(Leap.Hand hand)
    {
        float equalDistanceThreshold = 7;
        float fingerPointThreshold   = 12;
        float fingersApartThreshold  = 25;
        float angleThreshold         = 45;

        Leap.FingerList fingers = hand.Fingers;
        Leap.Finger     index   = fingers[(int)Leap.Finger.FingerType.TYPE_INDEX];
        Leap.Finger     middle  = fingers[(int)Leap.Finger.FingerType.TYPE_MIDDLE];
        Leap.Finger     ring    = fingers[(int)Leap.Finger.FingerType.TYPE_RING];
        Leap.Finger     thumb   = fingers[(int)Leap.Finger.FingerType.TYPE_THUMB];

        Vector3 indexPos      = ToVector3(index.Bone(Leap.Bone.BoneType.TYPE_PROXIMAL).Center);
        Vector3 middlePos     = ToVector3(middle.Bone(Leap.Bone.BoneType.TYPE_PROXIMAL).Center);
        Vector3 thumbPos      = ToVector3(thumb.StabilizedTipPosition);
        float   thumbToIndex  = Vector3.Distance(indexPos, thumbPos);
        float   thumbToMiddle = Vector3.Distance(middlePos, thumbPos);

        Vector3 indexDir  = ToVector3(index.Direction);
        Vector3 middleDir = ToVector3(middle.Direction);
        Vector3 thumbDir  = ToVector3(thumb.Direction);

        Vector3 palmDirection  = ToVector3(hand.Direction);
        Vector3 palmNormal     = ToVector3(hand.PalmNormal);
        Vector3 sidePalmFacing = Vector3.Cross(palmNormal, palmDirection);
        float   angleTestH     = Vector3.Angle((hand.IsLeft) ? Vector3.up : Vector3.down, sidePalmFacing);
        float   indexAngle     = Vector3.Angle(middleDir, indexDir);
        float   thumbAngle     = Vector3.Angle(Vector3.up, thumbDir);

        Debug.Log(thumbAngle + " " + indexAngle + " (" + thumbToIndex + ", " + thumbToMiddle + ")");

        // HRU test - Index and Middle are touching
        if (AreTwoFingersInContact(MyFingerType.TYPE_INDEX, MyFingerType.TYPE_MIDDLE, hand, fingersApartThreshold))
        {
            // H Test - Hand is tilted
            if (angleTestH < angleThreshold)
            {
                return('H');
            }

            // R Test - Index crosses Middle
            else if (indexAngle > fingerPointThreshold)
            {
                return('R');
            }

            // Otherwise, it must be U
            else
            {
                return('U');
            }
        }

        // K Test - Index apart from Middle, and Thumb equidistant to Index and Middle
        //else if (thumbAngle < angleThreshold * 0.5f)
        else if (Mathf.Abs(thumbToIndex - thumbToMiddle) < equalDistanceThreshold)
        {
            return('K');
        }

        // V Test - Index apart from Middle, Thumb not pointing up
        //          *Note, Thumb is not UP according to First-Pass
        return('V');
    }
    // Update is called once per frame
    void Update()
    {
        Leap.Frame frame = controller.Frame();
        guiFrame = frame;

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

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

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

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

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

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

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

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



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

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

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

                float sweptAngle = 0;

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

                break;

            case Leap.Gesture.GestureType.TYPESWIPE:
                Leap.SwipeGesture swipe = new Leap.SwipeGesture(gesture);
                globalInfo = ("Swipe id: " + swipe.Id
                              + ", " + swipe.State
                              + ", position: " + swipe.Position
                              + ", direction: " + swipe.Direction
                              + ", speed: " + swipe.Speed);
                break;

            case Leap.Gesture.GestureType.TYPEKEYTAP:
                Leap.KeyTapGesture keytap = new Leap.KeyTapGesture(gesture);
                globalInfo = ("Tap id: " + keytap.Id
                              + ", " + keytap.State
                              + ", position: " + keytap.Position
                              + ", direction: " + keytap.Direction);
                break;

            case Leap.Gesture.GestureType.TYPESCREENTAP:
                Leap.ScreenTapGesture screentap = new Leap.ScreenTapGesture(gesture);
                globalInfo = ("Tap id: " + screentap.Id
                              + ", " + screentap.State
                              + ", position: " + screentap.Position
                              + ", direction: " + screentap.Direction);
                break;

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


        if (!frame.Hands.Empty)
        {
            hand0ID = hand0.Id;
            if (hand1.Id != -1)
            {
                hand1ID = hand1.Id;                           // since when u take away your first hand,the second one becomes the first one on the list (with ID = 1),I want to remember its value
            }
        }
        else
        {
            hand0ID = -1;
        }
    }
Exemplo n.º 13
0
 /**
  * Constructs a Frame object.
  *
  * Frame instances created with this constructor are invalid.
  * Get valid Frame objects by calling the Controller::frame() function.
  *
  * \include Frame_Frame.txt
  *
  * The only time you should use this constructor is before deserializing
  * serialized frame data. Call ``Frame::deserialize(string)`` to recreate
  * a saved Frame.
  *
  * @since 1.0
  */
 public Frame()
 {
     _fingers     = new FingerList(15);
     _hands       = new HandList(3);
     _trackedQuad = new TrackedQuad();
 }