Esempio n. 1
0
        public static string IsLeftFingerFlicked(Finger finger,long frame_id)
        {
            float finger_velocity = finger.TipVelocity.Magnitude;

            string finger_direction = get_finger_direction(finger.TipVelocity.y);

            if (finger_is_flicked == "yes")
            {
                finger_is_flicked = "no";
            }

            if (finger_direction == "up" && finger_velocity > finger_up_velocity)
            {
                finger_is_flicked = "in_progress";
                flick_start_frame_id = frame_id;
            }
            else if (finger_direction == "down" && (finger.TipVelocity.y < -100) && finger_is_flicked == "in_progress")
            {
                finger_is_flicked = "yes";
            }

            //Reset if taking too long
            if (finger_is_flicked == "in_progress" && (frame_id - flick_start_frame_id > 30))
            {
                finger_is_flicked = "no";
            }

            return finger_is_flicked;
        }
Esempio n. 2
0
        public static string IsLeftFingerDragged(Finger finger, long frame_id)
        {
            float finger_velocity = finger.TipVelocity.Magnitude;
            string finger_direction = get_finger_direction(finger.TipVelocity.y);

            long time_difference = frame_id - drag_start_frame_id;

            //Console.WriteLine("Before IsLeftFingerDragged, finger_is_dragged: " + finger_is_dragged + ", frame_id: " + frame_id + ",gesture_start_frame_id: " + drag_start_frame_id);

            if (finger_is_dragged == "no" && finger_direction == "up" && finger_velocity > 400)
            {
                finger_is_dragged = "in_progress";
                drag_start_frame_id = frame_id;
                //Console.WriteLine("Start Finger Drag Gesture...");
            }
            else if (finger_is_dragged == "in_progress" && (time_difference > 15))
            {
                finger_is_dragged = "yes";
                //Console.WriteLine("Finger is dragged is yes...");
            }
            else if (finger_is_dragged == "in_progress" && finger_direction == "down" && finger_velocity > finger_down_velocity)
            {
                //finger_is_dragged = "no";
            }

            Console.WriteLine("Inside IsLeftFingerDragged, finger_is_dragged: " + finger_is_dragged + ", frame_id: " + frame_id + ",gesture_start_frame_id: " + drag_start_frame_id + ", difference: "+ (frame_id - drag_start_frame_id));

            return finger_is_dragged;
        }
Esempio n. 3
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);
    }
Esempio n. 4
0
        private static JointType FingerType2JointType(Finger.FingerType ft, int side)
        {
            JointType jt;

            switch (ft)
            {
                case Finger.FingerType.TYPE_INDEX:
                    jt = (side == 1) ? JointType.INDEX_FINGER_LEFT : JointType.INDEX_FINGER_RIGHT;
                    break;
                case Finger.FingerType.TYPE_MIDDLE:
                    jt = (side == 1) ? JointType.MIDDLE_FINGER_LEFT : JointType.MIDDLE_FINGER_RIGHT;
                    break;
                case Finger.FingerType.TYPE_PINKY:
                    jt = (side == 1) ? JointType.LITTLE_FINGER_LEFT : JointType.LITTLE_FINGER_RIGHT;
                    break;
                case Finger.FingerType.TYPE_RING:
                    jt = (side == 1) ? JointType.RING_FINGER_LEFT : JointType.RING_FINGER_RIGHT;
                    break;
                case Finger.FingerType.TYPE_THUMB:
                    jt = (side == 1) ? JointType.THUMB_LEFT : JointType.THUMB_RIGHT;
                    break;
                default:
                    jt = JointType.UNSPECIFIED;
                    break;
            }

            return jt;
        }
Esempio n. 5
0
 /**
  * Constructs a finger.
  *
  * Generally, you should not create your own finger objects. Such objects will not
  * have valid tracking data. Get valid finger objects from a hand in a frame
  * received from the service.
  *
  * @param frameId The id of the frame this finger appears in.
  * @param handId The id of the hand this finger belongs to.
  * @param fingerId The id of this finger (handId + 0-4 for finger position).
  * @param timeVisible How long this instance of the finger has been visible.
  * @param tipPosition The position of the finger tip.
  * @param tipVelocity The velocity of the finger tip.
  * @param direction The pointing direction of the finger.
  * @param stabilizedTipPosition The stabilized tip position.
  * @param width The average width of the finger.
  * @param length The length of the finger.
  * @param isExtended Whether the finger is more-or-less straight.
  * @param type The finger name.
  * @param metacarpal The first bone of the finger (inside the hand).
  * @param proximal The second bone of the finger
  * @param intermediate The third bone of the finger.
  * @param distal The end bone.
  * @since 3.0
  */
 public Finger(long frameId,
               int handId,
               int fingerId,
               float timeVisible,
               Vector tipPosition,
               Vector tipVelocity,
               Vector direction,
               Vector stabilizedTipPosition,
               float width,
               float length,
               bool isExtended,
               Finger.FingerType type,
               Bone metacarpal,
               Bone proximal,
               Bone intermediate,
               Bone distal)
 {
   Type = type;
   _bones[0] = metacarpal;
   _bones[1] = proximal;
   _bones[2] = intermediate;
   _bones[3] = distal;
   _frameId = frameId;
   Id = (handId * 10) + fingerId;
   HandId = handId;
   TipPosition = tipPosition;
   TipVelocity = tipVelocity;
   Direction = direction;
   Width = width;
   Length = length;
   IsExtended = isExtended;
   StabilizedTipPosition = stabilizedTipPosition;
   TimeVisible = timeVisible;
 }
    Vector3 GetFingerCollision(Leap.Finger finger)
    {
        for (int i = 0; i < finger.bones.Length; i++)
        {
            var bone   = finger.bones[i];
            var origin = bone.PrevJoint.ToVector3();
            var dir    = bone.Direction.ToVector3();
            if (dir == Vector3.zero)
            {
                continue;
            }
            var        ray = new Ray(origin, dir);
            RaycastHit hit;
            if (_collider.Raycast(ray, out hit, bone.Length))
            {
                return(hit.point);
            }
        }

        {
            var tip   = finger.TipPosition.ToVector3();
            var point = _collider.ClosestPoint(tip);
            var dir   = point - tip;
            var min   = _distanceClamp.keys[0].time;
            var max   = _distanceClamp.keys[_distanceClamp.keys.Length - 1].time;
            var len   = _distanceClamp.Evaluate(Mathf.Clamp(dir.magnitude, min, max));
            dir = Vector3.ClampMagnitude(dir, len);
            return(tip + dir);
        }
    }
Esempio n. 7
0
 public Finger(int frameId,
                    int handId, 
                    int fingerId,
                    float timeVisible,
                    Vector tipPosition,
                    Vector tipVelocity,
                    Vector direction,
                    Vector stabilizedTipPosition,
                    float width,
                    float length,
                    bool isExtended,
                    Finger.FingerType type,
                    Bone metacarpal,
                    Bone proximal,
                    Bone intermediate,
                    Bone distal)
 {
     _type = type;
     _bones [0] = metacarpal;
     _bones [1] = proximal;
     _bones [2] = intermediate;
     _bones [3] = distal;
     _frameId = frameId;
     _id = (handId * 10) + fingerId;
     _handID = handId;
     _tipPosition = tipPosition;
     _tipVelocity = tipVelocity;
     _direction = direction;
     _width = width;
     _length = length;
     _isExtended = isExtended;
     _isValid = false;
     _stabilizedTipPosition = stabilizedTipPosition;
     _timeVisible = timeVisible;
 }
Esempio n. 8
0
 public override void OnInputDisconnected(NodeBase src, string srcSlotName, string targetSlotName)
 {
     base.OnInputDisconnected(src, srcSlotName, targetSlotName);
     if (targetSlotName == "set_Finger")
     {
         Finger = null;
     }
 }
Esempio n. 9
0
 //Constructor for LeapFrame
 public FingerData(Finger finger)
 {
     m_id = finger.Id;
     m_isFrontmost = (finger.Id == finger.Frame.Fingers.Frontmost.Id);
     m_tipPosition = finger.TipPosition;
     m_length = finger.Length;
     m_isValid = finger.IsValid;
 }
 protected Finger FindFingerByType(Hand hand, Finger.FingerType type)
 {
     foreach (var finger in hand.Fingers)
     {
         if (finger.Type() == type)
         return finger;
     }
     return null;
 }
Esempio n. 11
0
    private void Awake()
    {
        lineRenderer = gameObject.AddComponent <LineRenderer>();

        leftIndicator  = leftHand.leapHand.Fingers[1];
        rightIndicator = rightHand.leapHand.Fingers[1];

        InitializeLineRenderer();
    }
Esempio n. 12
0
 private Finger FindFingerByType(FingerList fingers, Finger.FingerType type)
 {
     foreach (var finger in fingers)
     {
         if (finger.Type () == type)
         return finger;
     }
     return null;
 }
Esempio n. 13
0
        // Return true if the finger and the thumb's tip are near.
        private bool IsNearFromThumb(Finger finger, Finger thumb)
        {
            Vector fingerBase = finger.Bone(Bone.BoneType.TYPE_METACARPAL).Center;
            Vector baseToFingerTip = finger.TipPosition - fingerBase;
            Vector baseToThumbTip = thumb.TipPosition - fingerBase;

            float distance =
                baseToFingerTip.Cross(baseToThumbTip).Magnitude / baseToFingerTip.Magnitude;
            return distance < 40F;
        }
Esempio n. 14
0
    //Gets the distance between the thumb and a finger. Has leapmotion leniency
    public float getPinchDistance(Leap.Finger finger, Leap.Finger thumb)
    {
        // Gets the distance between two fingers, determines if they are close in any direction.
        Vector3 diff         = thumb.TipPosition.ToVector3() - finger.TipPosition.ToVector3();
        float   dist         = diff.magnitude;
        Vector3 padDirection = Vector3.Cross(finger.Direction.ToVector3(), Vector3.Cross(finger.Direction.ToVector3(), finger.bones[1].Direction.ToVector3()));

        return(dist * Mathf.Sign(Vector3.Dot(diff, padDirection)));
        //return dist;
    }
        private void setFingerBasePositions_Relative(Hand hand)
        {
            Leap.Finger index  = hand.Fingers.Where(f => f.Type == Finger.FingerType.TYPE_INDEX).FirstOrDefault();
            Leap.Finger middle = hand.Fingers.Where(f => f.Type == Finger.FingerType.TYPE_MIDDLE).FirstOrDefault();
            Leap.Finger ring   = hand.Fingers.Where(f => f.Type == Finger.FingerType.TYPE_RING).FirstOrDefault();
            Leap.Finger pinky  = hand.Fingers.Where(f => f.Type == Finger.FingerType.TYPE_PINKY).FirstOrDefault();

            IndexBasePos_Relative  = new Vec3(HandTransform.TransformPoint(index.Bone(Bone.BoneType.TYPE_METACARPAL).PrevJoint)) / FingerLengths[Finger.FingerType.TYPE_INDEX];
            MiddleBasePos_Relative = new Vec3(HandTransform.TransformPoint(middle.Bone(Bone.BoneType.TYPE_METACARPAL).PrevJoint)) / FingerLengths[Finger.FingerType.TYPE_MIDDLE];
            RingBasePos_Relative   = new Vec3(HandTransform.TransformPoint(ring.Bone(Bone.BoneType.TYPE_METACARPAL).PrevJoint)) / FingerLengths[Finger.FingerType.TYPE_RING];
            PinkyBasePos_Relative  = new Vec3(HandTransform.TransformPoint(pinky.Bone(Bone.BoneType.TYPE_METACARPAL).PrevJoint)) / FingerLengths[Finger.FingerType.TYPE_PINKY];
        }
Esempio n. 16
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);
    }
		/*--------------------------------------------------------------------------------------------*/
		public void Rebuild(Finger pLeapFinger) {
			if ( pLeapFinger == null ) {
				IsAvailable = false;
				Position = Vector3.zero;
				Rotation = Quaternion.identity;
				return;
			}

			Bone bone = pLeapFinger.Bone(Bone.BoneType.TYPE_DISTAL);

			IsAvailable = true;
			Position = pLeapFinger.TipPosition.ToUnityScaled();
			Rotation = LeapInputMenu.CalcQuaternion(bone.Basis);
		}
Esempio n. 18
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');
    }
		/*--------------------------------------------------------------------------------------------*/
		private void UpdateForFinger(Hand pLeapHand, Finger.FingerType pLeapFingerType) {
			Finger leapFinger = LeapUtil.GetValidFinger(pLeapHand, pLeapFingerType);

			if ( leapFinger == null ) {
				UpdateForNull();
				return;
			}

			Bone bone = leapFinger.Bone(Bone.BoneType.TYPE_DISTAL); //GC_ALLOC

			IsAvailable = true;
			Position = leapFinger.TipPosition.ToUnityScaled(); //GC_ALLOC
			Rotation = LeapUtil.CalcQuaternion(bone.Basis); //GC_ALLOC

			Size = leapFinger.Width*SizeScaleFactor;
		}
Esempio n. 20
0
    //Checks the grip angle of a finger to see if it is part of a grab pose
    public bool checkFingerGrip(Leap.Finger finger)
    {
        Vector3 distal       = getDistalPosition(finger);
        Vector3 proximal     = getProximalPosition(finger);
        Vector3 intermediate = getIntermediatePosition(finger);
        Vector3 metacarpal   = getMetacarpalPosition(finger);
        //Fetch the angle that is created between bones.
        float mpAngle = 180 - Vector3.Angle(proximal - metacarpal, intermediate - proximal);
        float pdAngle = 180 - Vector3.Angle(intermediate - proximal, distal - intermediate);

        //If a proper angle return tru.
        if (mpAngle < 120f && pdAngle < 120f)
        {
            return(true);
        }
        return(false);
    }
Esempio n. 21
0
        private void DrawFingerBones(Leap.Finger oFinger, InteractionBox interactionBox,
                                     DrawingContext drawingContext)
        {
            Bone bone;

            foreach (Bone.BoneType boneType in (Bone.BoneType[])Enum.GetValues(typeof(Bone.BoneType)))
            {
                bone = oFinger.Bone(boneType);
                Leap.Vector startPosition = interactionBox.NormalizePoint(bone.PrevJoint);
                Leap.Vector endPosition   = interactionBox.NormalizePoint(bone.NextJoint);

                Point  posStart = this.ToScreen(startPosition);
                Point  posEnd   = this.ToScreen(endPosition);
                double dX1      = posStart.X;
                double dY1      = posStart.Y;
                double dX2      = posEnd.X;
                double dY2      = posEnd.Y;
                drawingContext.DrawLine(new Pen()
                {
                    Brush = new SolidColorBrush(Colors.Blue), Thickness = 1
                },
                                        new Point(dX1, dY1), new Point(dX2, dY2));

                Pen oPen = new Pen();
                if (boneType == Bone.BoneType.TYPE_PROXIMAL)
                {
                    drawingContext.DrawEllipse(new SolidColorBrush(Colors.Gold), oPen, new Point(dX1, dY1), 6, 6);
                }
                else if (boneType == Bone.BoneType.TYPE_METACARPAL)
                {
                    drawingContext.DrawEllipse(new SolidColorBrush(Colors.Black), oPen, new Point(dX1, dY1), 6, 6);
                }
                else if (boneType == Bone.BoneType.TYPE_INTERMEDIATE)
                {
                    drawingContext.DrawEllipse(new SolidColorBrush(Colors.DarkGreen), oPen, new Point(dX1, dY1), 6, 6);
                }
                else if (boneType == Bone.BoneType.TYPE_DISTAL)
                {
                    drawingContext.DrawEllipse(new SolidColorBrush(Colors.Red), oPen, new Point(dX1, dY1), 6, 6);
                    drawingContext.DrawEllipse(new SolidColorBrush(Colors.Red), oPen, new Point(dX2, dY2), 12, 12);
                }
            }
        }
        ////////////////////////////////////////////////////////////////////////////////////////////////
        /*--------------------------------------------------------------------------------------------*/
        private CursorType GetFingerCursorType(bool pIsLeft, Finger.FingerType pLeapFingerType)
        {
            switch ( pLeapFingerType ) {
                case Finger.FingerType.TYPE_THUMB:
                    return (pIsLeft ? CursorType.LeftThumb : CursorType.RightThumb);

                case Finger.FingerType.TYPE_INDEX:
                    return (pIsLeft ? CursorType.LeftIndex : CursorType.RightIndex);

                case Finger.FingerType.TYPE_MIDDLE:
                    return (pIsLeft ? CursorType.LeftMiddle : CursorType.RightMiddle);

                case Finger.FingerType.TYPE_RING:
                    return (pIsLeft ? CursorType.LeftRing : CursorType.RightRing);

                case Finger.FingerType.TYPE_PINKY:
                    return (pIsLeft ? CursorType.LeftPinky : CursorType.RightPinky);
            }

            throw new Exception("Unhandled cursor combination: "+pIsLeft+" / "+pLeapFingerType);
        }
Esempio n. 23
0
    protected PinchState GetNewPinchState()
    {
        HandModel hand_model = GetComponent <HandModel>();

        Leap.Hand leap_hand = hand_model.GetLeapHand();

        Leap.Vector leap_thumb_tip   = leap_hand.Fingers[0].TipPosition;
        float       closest_distance = Mathf.Infinity;

        // Check thumb tip distance to joints on all other fingers.
        // If it's close enough, you're pinching.
        for (int i = 1; i < HandModel.NUM_FINGERS; ++i)
        {
            Leap.Finger finger = leap_hand.Fingers[i];

            for (int j = 0; j < FingerModel.NUM_BONES; ++j)
            {
                Leap.Vector leap_joint_position = finger.Bone((Leap.Bone.BoneType)j).NextJoint;

                float thumb_tip_distance = leap_joint_position.DistanceTo(leap_thumb_tip);
                closest_distance = Mathf.Min(closest_distance, thumb_tip_distance);
            }
        }

        // Scale trigger distance by thumb proximal bone length.
        float proximal_length  = leap_hand.Fingers[0].Bone(Leap.Bone.BoneType.TYPE_PROXIMAL).Length;
        float trigger_distance = proximal_length * grabTriggerDistance;
        float release_distance = proximal_length * releaseTriggerDistance;

        if (closest_distance <= trigger_distance)
        {
            return(PinchState.kPinched);
        }
        if (closest_distance <= release_distance && pinch_state_ != PinchState.kReleased &&
            !ObjectReleaseBreak(current_pinch_position_))
        {
            return(PinchState.kReleasing);
        }
        return(PinchState.kReleased);
    }
Esempio n. 24
0
        private void FixedUpdate()
        {
            if (_leap == null) return;

            var frame = _leap.Frame();

            if (frame.Hands.Count > 1 && frame.Fingers.Count < 6)
            {
                //is last finger in fingerlist ?
                if (_activeFinger != null && frame.Fingers.Count(x => x.Id == _activeFinger.Id) == 0)
                    _activeFinger = null;

                //Get last finger again or frontmost as default
                _activeFinger = (_activeFinger != null) ? frame.Finger(_activeFinger.Id) : frame.Fingers.Frontmost;

                //Switch finger to the finger, which is closer to the mondrian cube
                foreach (var finger in frame.Fingers.Where(finger => finger.Id != _activeFinger.Id &&
                                                                     (finger.TipPosition.ToUnityScaled().x > -2 &&
                                                                      finger.TipPosition.ToUnityScaled().x < 2) &&
                                                                     !(_activeFinger.TipPosition.ToUnityScaled().x > -2 &&
                                                                       _activeFinger.TipPosition.ToUnityScaled().x < 2)
                    ))
                {
                    _activeFinger = finger;
                }

                //Force quit fingers if action disabled
                if (!ActionEnabled())
                {
                    _activeFinger = null;
                }
            }
            else
            {
                _activeFinger = null;
            }

            HandleFinger(_activeFinger, _pointer);
            HandleGestures(frame.Gestures());
        }
Esempio n. 25
0
        //Update the finger
        public void UpdateFinger(Leap.Finger finger)
        {
            if (!finger.IsValid)
            {
                return;
            }

            //Refresh leap finger data
            this.finger = finger;

            //Set fingerObject position
            //Reverse z coordinate
            fingerObject.transform.position = new Vector3(finger.TipPosition.x, finger.TipPosition.y, -finger.TipPosition.z);

            //Set last position
            lastPosition = position;

            //Set last speed
            lastSpeed = speed;

            //Set position
            position = fingerObject.transform.position;

            //Set speed
            speed = new Vector3(finger.TipVelocity.x, finger.TipVelocity.y, -finger.TipVelocity.z);

            //Set finger color
            if (finger.IsExtended)
            {
                fingerObject.transform.renderer.material.color = Color.cyan;
            }
            else
            {
                fingerObject.transform.renderer.material.color = Color.yellow;
            }

            //Update bones
            UpdateBones();
        }
Esempio n. 26
0
        public Vector getFingerVector(Controller controller, Finger finger)
        {
            Vector finger_vector = new Vector();

            // Get the closest screen intercepting a ray projecting from the finger
            Leap.Screen screen = controller.CalibratedScreens.ClosestScreenHit(finger);

            if (screen != null && screen.IsValid)
            {
                Vector screenStabilized = screen.Intersect(finger, true);
                var xScreenIntersect = screenStabilized.x;
                var yScreenIntersect = screenStabilized.y;

                if (xScreenIntersect.ToString() != "NaN")
                {
                    finger_vector.x = (int)(xScreenIntersect * screen.WidthPixels);
                    finger_vector.y = (int)(screen.HeightPixels - (yScreenIntersect * screen.HeightPixels * yAxisMultiplier));
                }
                //SafeWriteLine("yScreenIntersect / HeightPixels" + "/" + yScreenIntersect + "/" + screen.HeightPixels);
            }

            return finger_vector;
        }
Esempio n. 27
0
        static Finger MakeFinger(Finger.FingerType name, Vector position, Vector forward, Vector up, float[] jointLengths, 
            int frameId, int handId, int fingerId)
        {
            Bone[] bones = new Bone[5];
            float proximalDistance = -jointLengths[0];
            Bone metacarpal = MakeBone (Bone.BoneType.TYPE_METACARPAL, position + forward * proximalDistance, jointLengths[0], 8f, forward, up);
            proximalDistance += jointLengths[0];
            bones[0] = metacarpal;

            Bone proximal = MakeBone (Bone.BoneType.TYPE_PROXIMAL,  position + forward * proximalDistance, jointLengths[1], 8f, forward, up);
            proximalDistance += jointLengths[1];
            bones[1] = proximal;

            Bone intermediate = MakeBone (Bone.BoneType.TYPE_INTERMEDIATE,  position + forward * proximalDistance, jointLengths[2], 8f, forward, up);
            proximalDistance += jointLengths[2];
            bones[2] = intermediate;

            Bone distal = MakeBone (Bone.BoneType.TYPE_DISTAL,  position + forward * proximalDistance, jointLengths[3], 8f, forward, up);
            bones[3] = distal;

            return new Finger(frameId,
            handId,
            fingerId,
            0.0f,
            position,
            new Vector(0,0,0),
            forward,
            position,
            8f,
            jointLengths[1] + jointLengths[2] +jointLengths[3],
            true,
            name,
            bones[0],
            bones[1],
            bones[2],
            bones[3]);
        }
 public Finger makeFinger(Frame owner, ref LEAP_HAND hand, ref LEAP_DIGIT digit, Finger.FingerType type)
 {
   Bone metacarpal = makeBone(ref digit.metacarpal, Bone.BoneType.TYPE_METACARPAL);
   Bone proximal = makeBone(ref digit.proximal, Bone.BoneType.TYPE_PROXIMAL);
   Bone intermediate = makeBone(ref digit.intermediate, Bone.BoneType.TYPE_INTERMEDIATE);
   Bone distal = makeBone(ref digit.distal, Bone.BoneType.TYPE_DISTAL);
   return new Finger((int)owner.Id,
       (int)hand.id,
       (int)digit.finger_id,
       hand.visible_time,
       distal.NextJoint,
       new Vector(digit.tip_velocity.x, digit.tip_velocity.y, digit.tip_velocity.z),
       intermediate.Direction,
       new Vector(digit.stabilized_tip_position.x, digit.stabilized_tip_position.y, digit.stabilized_tip_position.z),
       intermediate.Width,
       proximal.Length + intermediate.Length + (distal.Length * 0.77f), //0.77 is used in platform code for this calculation
       digit.is_extended != 0,
       type,
       metacarpal,
       proximal,
       intermediate,
       distal
   );
 }
        /*--------------------------------------------------------------------------------------------*/
        private void UpdateCursorsWithFinger(Hand pLeapHand, Finger pLeapFinger)
        {
            CursorType cursorType = GetFingerCursorType(pLeapHand.IsLeft, pLeapFinger.Type);

            if ( !CursorDataProvider.HasCursorData(cursorType) ) {
                return;
            }

            Vector tipPos = (UseStabilizedPositions ?
                pLeapFinger.StabilizedTipPosition: pLeapFinger.TipPosition);
            Bone distalBone = pLeapFinger.Bone(Bone.BoneType.TYPE_DISTAL);
            Vector3 tipWorldPos = tipPos.ToVector3();
            Vector3 boneWorldPos = distalBone.Center.ToVector3();
            Vector3 extendedWorldPos = tipWorldPos;

            if ( ExtendFingertipDistance != 0 ) {
                extendedWorldPos += (tipWorldPos-boneWorldPos).normalized*ExtendFingertipDistance;
            }

            IHoverCursorDataForInput data = CursorDataProvider.GetCursorDataForInput(cursorType);
            data.SetWorldPosition(extendedWorldPos);
            data.SetWorldRotation(distalBone.Basis.CalculateRotation()*RotationFix);
            data.SetSize(pLeapFinger.Width);
            data.SetUsedByInput(true);
        }
 protected bool IsOtherFingerClosed(Hand hand, Finger.FingerType type)
 {
     foreach (var finger in hand.Fingers)
     {
         if (finger.Type() != type && finger.IsExtended)
         return false;
     }
     return true;
 }
Esempio n. 31
0
 private bool IsNear(Finger one, Finger another)
 {
     return one.TipPosition.DistanceTo (another.TipPosition) < THRESHOLD;
 }
Esempio n. 32
0
 public Vector3 getIntermediatePosition(Leap.Finger finger)
 {
     return(finger.Bone(Leap.Bone.BoneType.TYPE_INTERMEDIATE).Center.ToVector3());
 }
Esempio n. 33
0
 //Functions to recieve bone position of a finger
 public Vector3 getMetacarpalPosition(Leap.Finger finger)
 {
     return(finger.Bone(Leap.Bone.BoneType.TYPE_METACARPAL).Center.ToVector3());
 }
Esempio n. 34
0
 private bool matchFingerState(Finger finger, int ordinal)
 {
     PointingState requiredState;
       switch (ordinal) {
     case 0:
       requiredState = Thumb;
       break;
     case 1:
       requiredState = Index;
       break;
     case 2:
       requiredState = Middle;
       break;
     case 3:
       requiredState = Ring;
       break;
     case 4:
       requiredState = Pinky;
       break;
     default:
       return false;
       }
       return (requiredState == PointingState.Either) ||
      (requiredState == PointingState.Extended && finger.IsExtended) ||
      (requiredState == PointingState.NotExtended && !finger.IsExtended);
 }
Esempio n. 35
0
        private int? GetAngle(Finger f)
        {
            var point = f.Hand.PalmPosition;
            var direction = f.Hand.Direction;
            var fingerPosition = f.TipPosition;
            if(point.Equals(Leap.Vector.Zero))
                return null;
            if(direction.Equals(Leap.Vector.Zero))
                return null;
            if(fingerPosition.Equals(Leap.Vector.Zero))
                return null;
            //Console.WriteLine("Palm " + point.NiceToString());
            //Console.WriteLine("Direction " + direction);
            //Console.WriteLine("Finger " + fingerPosition.NiceToString());

            var h = f.Hand.PalmNormal * (point.Dot(f.Hand.PalmNormal) / f.Hand.PalmNormal.MagnitudeSquared);

            var ph = h - point;
            //Console.WriteLine(pToProj.NiceToString());
            //Console.WriteLine("Projection " + pToProj);

            var angle = Math.Acos((direction.Dot(ph)) / (direction.Magnitude * ph.Magnitude));
            //Console.WriteLine("Angle : " + Helper.RadianToDegree(angle));
            return (int)Helper.RadianToDegree(angle);
        }
Esempio n. 36
0
    public float[] getFingerAbsoluteData()
    {
        float[] ret         = null;
        bool    hasLeftHand = false;

        foreach (Hand hand in handController.Frame().Hands)
        {
            if (hand.IsLeft)
            {
                hasLeftHand = true;
                Bone bone0 = hand.Fingers[0].Bone(Bone.BoneType.TYPE_DISTAL);                      //大拇指
                Bone bone1 = hand.Fingers[hand.Fingers.Count - 1].Bone(Bone.BoneType.TYPE_DISTAL); //小拇指

                //Debug.LogError(bone0.PrevJoint.x.ToString() + "," +  bone1.PrevJoint.x.ToString() + ". a-b = " +(bone0.PrevJoint.x - bone1.PrevJoint.x).ToString());

                if (bone0.PrevJoint.x - bone1.PrevJoint.x > 0)                 //手心向下
                {
                    setenceWatch.Stop();
                    setenceWatch.Reset();
                    if (wordWatch.IsRunning)
                    {
                        if (wordWatch.ElapsedMilliseconds >= eraseWordTime)
                        {
                            //Debug.LogError("erase a word" + wordWatch.ElapsedMilliseconds.ToString());
                            int count = predicts.Count;
                            if (count > 0)
                            {
                                predicts.RemoveAt(count - 1);
                            }
                            wordWatch.Stop();
                            wordWatch.Reset();
                        }
                    }
                    else
                    {
                        wordWatch.Start();
                    }
                }
                else                   //手心向上
                {
                    wordWatch.Stop();
                    wordWatch.Reset();
                    if (setenceWatch.IsRunning)
                    {
                        if (setenceWatch.ElapsedMilliseconds >= eraseSetenceTime)
                        {
                            //Debug.LogError("erase a setence" + setenceWatch.ElapsedMilliseconds.ToString());
                            predicts.Clear();
                            setenceWatch.Stop();
                            setenceWatch.Reset();
                        }
                    }
                    else
                    {
                        setenceWatch.Start();
                    }
                }
                break;
            }
            else if (hand.IsRight)
            {
                if (ret == null)
                {
                    ret = new float[DIMENSION];
                }
                ret[0] = hand.PalmPosition.x;
                ret[1] = hand.PalmPosition.y;
                ret[2] = hand.PalmPosition.z;
                for (int i = 0; i < hand.Fingers.Count; i++)
                {
                    Leap.Finger finger = hand.Fingers[i];
                    Bone        bone1  = finger.Bone(Bone.BoneType.TYPE_DISTAL);            //末梢
                    Bone        bone2  = finger.Bone(Bone.BoneType.TYPE_INTERMEDIATE);      //中间的
                    Bone        bone3  = finger.Bone(Bone.BoneType.TYPE_PROXIMAL);
                    Bone        bone4  = finger.Bone(Bone.BoneType.TYPE_METACARPAL);
                    ret[i * 12 + 3]  = bone1.PrevJoint.x;
                    ret[i * 12 + 4]  = bone1.PrevJoint.y;
                    ret[i * 12 + 5]  = bone1.PrevJoint.z;
                    ret[i * 12 + 6]  = bone2.PrevJoint.x;
                    ret[i * 12 + 7]  = bone2.PrevJoint.y;
                    ret[i * 12 + 8]  = bone2.PrevJoint.z;
                    ret[i * 12 + 9]  = bone3.PrevJoint.x;
                    ret[i * 12 + 10] = bone3.PrevJoint.y;
                    ret[i * 12 + 11] = bone3.PrevJoint.z;
                    ret[i * 12 + 12] = bone4.PrevJoint.x;
                    ret[i * 12 + 13] = bone4.PrevJoint.y;
                    ret[i * 12 + 14] = bone4.PrevJoint.z;
                }
            }
        }
        if (!hasLeftHand)
        {
            wordWatch.Stop();
            wordWatch.Reset();

            setenceWatch.Stop();
            setenceWatch.Reset();
        }
        return(ret);
    }
		/*--------------------------------------------------------------------------------------------*/
		public static Finger GetValidFinger(Hand pHand, Finger.FingerType pFingerType) {
			//Skip "Fingers.FingerType()" API method to avoid GC allocations
			FingerList fingers = pHand.Fingers; //GC_ALLOC

			for ( int i = 0 ; i < fingers.Count ; i++ ) {
				Finger finger = fingers[i]; //GC_ALLOC

				if ( finger.Type == pFingerType && finger.IsValid ) {
					return finger;
				}
			}

			return null;
		}
Esempio n. 38
0
 /**
  * Deprecated as of version 2.0
  * Use 'bone' method instead.
  */
 public Vector JointPosition(Finger.FingerJoint jointIx)
 {
     switch (jointIx){
     case FingerJoint.JOINT_MCP:
         return _bones[0].NextJoint;
     case FingerJoint.JOINT_PIP:
         return _bones[1].NextJoint;
     case FingerJoint.JOINT_DIP:
         return _bones[2].NextJoint;
     case FingerJoint.JOINT_TIP:
         return _bones[3].NextJoint;
     }
     return Vector.Zero;
 }
Esempio n. 39
0
        //WORK IN PROGRESS//
        public Boolean scrollUpDown(Finger right_finger)
        {
            Boolean return_status = false;

            if (right_finger.TipVelocity.y != 0)
            {
                MouseInput.ScrollUpDown(right_finger.TipVelocity.y);
                return_status = true;
            }

            return return_status;
        }
Esempio n. 40
0
        public ArrayList leftHandFingers(FingerList fingers, Finger cursor_finger)
        {
            ArrayList fingers_on_left_hand = new ArrayList();

            foreach(Finger finger in fingers)
            {
                if (!finger.Equals(cursor_finger))
                {
                    float x_diff = cursor_finger.TipPosition.x - finger.TipPosition.x;
                    if (x_diff > 5)
                    {
                        fingers_on_left_hand.Add(finger);
                    }
                }
            }

            return fingers_on_left_hand;
        }
        /*--------------------------------------------------------------------------------------------*/
        private void UpdateCursorsWithFinger(Hand pLeapHand, Finger pLeapFinger)
        {
            CursorType cursorType = GetFingerCursorType(pLeapHand.IsLeft, pLeapFinger.Type);

            if ( !CursorDataProvider.HasCursorData(cursorType) ) {
                return;
            }

            Transform leapTx = LeapControl.transform;
            Vector tipPos = (UseStabilizedPositions ?
                pLeapFinger.StabilizedTipPosition: pLeapFinger.TipPosition);
            Bone distalBone = pLeapFinger.Bone(Bone.BoneType.TYPE_DISTAL);
            Vector3 tipWorldPos = leapTx.TransformPoint(tipPos.ToUnityScaled());
            Vector3 boneWorldPos = leapTx.TransformPoint(distalBone.Center.ToUnityScaled());
            Vector3 extendedWorldPos = tipWorldPos;

            if ( ExtendFingertipDistance != 0 ) {
                extendedWorldPos += (tipWorldPos-boneWorldPos).normalized*ExtendFingertipDistance;
            }

            IHoverCursorDataForInput data = CursorDataProvider.GetCursorDataForInput(cursorType);
            data.SetWorldPosition(extendedWorldPos);
            data.SetWorldRotation(leapTx.rotation*distalBone.Basis.Rotation()*RotationFix);
            data.SetSize(pLeapFinger.Width*UnityVectorExtension.INPUT_SCALE);
            data.SetUsedByInput(true);
        }
Esempio n. 42
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;*/
    }
    //Member Function: refresh/////////////////////////////////////////////////
    //
    //This function refreshes the tracking data from the Leap Motion device.
    //
    public bool refresh()
    {
        //Try.
        try
        {
            //If there's no controller, make a new one.
            if (controller == null)
            {
                controller = new Leap.Controller();
            }

            //Check if the controller is connected.
            connected = controller.IsConnected && controller.Devices.Count > 0 && controller.Devices[0].IsValid;

            //If we're connected, update.
            if (connected)
            {
                //Get the most recent frame.
                frame = controller.Frame();

                //Assign some basic information from the frame to our variables.
                fingers   = frame.Fingers.Count;
                hands     = frame.Hands.Count;
                timestamp = frame.Timestamp;

                //If we see some hands, get their positions and their fingers.
                if (!frame.Hands.IsEmpty)
                {
                    //Get the hand's position, size and first finger.
                    handPosition    = frame.Hands[0].PalmPosition;
                    handDirection   = frame.Hands[0].Direction;
                    fingerPosition  = frame.Hands[0].Fingers[0].TipPosition;
                    fingerDirection = frame.Hands[0].Fingers[0].Direction;

                    //Get the hand's normal vector and direction
                    Vector normal    = frame.Hands[0].PalmNormal;
                    Vector direction = frame.Hands[0].Direction;

                    //Get the hand's angles.
                    handPitch = (float)direction.Pitch * 180.0f / (float)System.Math.PI;
                    handRoll  = (float)normal.Roll * 180.0f / (float)System.Math.PI;
                    handYaw   = (float)direction.Yaw * 180.0f / (float)System.Math.PI;

                    thumb = null;

                    //Find the thumb for the primary hand.
                    foreach (Leap.Finger finger in frame.Hands[0].Fingers)
                    {
                        if (thumb != null && finger.TipPosition.x < thumb.TipPosition.x && finger.TipPosition.x < handPosition.x)
                        {
                            thumb = finger;
                        }

                        else if (thumb == null && finger.TipPosition.x < handPosition.x - thumbDistance)
                        {
                            thumb = finger;
                        }
                    }
                }
            }

            //Otherwise, reset all outgoing data to 0.
            else
            {
                //Fingers contained in the current frame.
                fingers = 0;

                //Hands contained in the current frame.
                hands = 0;

                //Various easy-access hand values.
                handPitch = 0.0F;
                handRoll  = 0.0F;
                handYaw   = 0.0F;

                //Hand and finger positions.
                handPosition    = Vector.Zero;
                fingerPosition  = Vector.Zero;
                handDirection   = Vector.Zero;
                fingerDirection = Vector.Zero;

                //Quick-find for the right thumb.
                thumb = null;
            }

            return(true);
        }

        //In the event that anything goes wrong while reading and converting tracking data, log the exception.
        catch (System.Exception e) { UnityEngine.Debug.LogException(e);  return(false); }
    }
Esempio n. 44
0
        public LeapFinger(Leap.Finger finger)
        {
            //Create finger object
            fingerObject = GameObject.CreatePrimitive(PrimitiveType.Sphere);

            //Set finger object name
            switch (finger.Type())
            {
            case Finger.FingerType.TYPE_THUMB:
                if (finger.Hand.IsLeft)
                {
                    fingerObject.name = "LeftThumb";
                }
                if (finger.Hand.IsRight)
                {
                    fingerObject.name = "RightThumb";
                }
                break;

            case Finger.FingerType.TYPE_INDEX:
                if (finger.Hand.IsLeft)
                {
                    fingerObject.name = "LeftIndex";
                }
                if (finger.Hand.IsRight)
                {
                    fingerObject.name = "RightIndex";
                }
                break;

            case Finger.FingerType.TYPE_MIDDLE:
                if (finger.Hand.IsLeft)
                {
                    fingerObject.name = "LeftMiddle";
                }
                if (finger.Hand.IsRight)
                {
                    fingerObject.name = "RightMiddle";
                }
                break;

            case Finger.FingerType.TYPE_RING:
                if (finger.Hand.IsLeft)
                {
                    fingerObject.name = "LeftRing";
                }
                if (finger.Hand.IsRight)
                {
                    fingerObject.name = "RightRing";
                }
                break;

            case Finger.FingerType.TYPE_PINKY:
                if (finger.Hand.IsLeft)
                {
                    fingerObject.name = "LeftPinky";
                }
                if (finger.Hand.IsRight)
                {
                    fingerObject.name = "RightPinky";
                }
                break;
            }

            //Save leap finger data
            this.finger = finger;

            //Set fingerObject position
            //Reverse z coordinate
            fingerObject.transform.position = new Vector3(finger.TipPosition.x, finger.TipPosition.y, -finger.TipPosition.z);

            //Set position
            position = fingerObject.transform.position;

            //Set speed
            speed = new Vector3(finger.TipVelocity.x, finger.TipVelocity.y, -finger.TipVelocity.z);

            //Set finger color
            if (finger.IsExtended)
            {
                fingerObject.transform.renderer.material.color = Color.cyan;
            }
            else
            {
                fingerObject.transform.renderer.material.color = Color.yellow;
            }

            //Set finger size
            fingerObject.transform.localScale = new Vector3(scale, scale, scale);

            //Initialize bones
            InitializeBones();
        }
    // 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;
        }
    }
Esempio n. 46
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');
    }
Esempio n. 47
0
 public Vector3 getProximalPosition(Leap.Finger finger)
 {
     return(finger.Bone(Leap.Bone.BoneType.TYPE_PROXIMAL).Center.ToVector3());
 }
 /**
  * Returns a new finger that is a copy of a finger, with an additional rigid
  * transformation applied to it.
  *
  * @param transform The transformation to be applied to the copied finger.
  */
 public static Finger TransformedCopy(this Finger finger, LeapTransform transform)
 {
     return(new Finger().CopyFrom(finger).Transform(transform));
 }
Esempio n. 49
0
 public Vector3 getDistalPosition(Leap.Finger finger)
 {
     return(finger.Bone(Leap.Bone.BoneType.TYPE_DISTAL).Center.ToVector3());
 }
Esempio n. 50
0
        private void HandleFinger(Finger finger, GameObject pPointer)
        {
            if (finger == null)
            {
                if (pPointer.activeSelf)
                {
                    pPointer.SetActive(false);
                }
            }
            else
            {
                if (!pPointer.activeSelf)
                {
                    pPointer.SetActive(true);
                }

                //Reset Timer
                _resetTimer.ResetCounter();

                //Calc position for pointer object - finger representation
                var calcedPos = finger.TipPosition.ToUnityScaled();

                calcedPos.z = calcedPos.z + _pointerZOffset;

                var avgZ = (calcedPos.z < PointerMaxZ)
                    ? PointerMaxZ
                    : (calcedPos.z > PointerMinZ) ? PointerMinZ : calcedPos.z;

                var newPos = new Vector3(calcedPos.x, calcedPos.y + PointerYOffset, avgZ);

                pPointer.transform.position = Vector3.Lerp(pPointer.transform.position, newPos, 0.5F);

                RaycastHit hit;
                var directionRay = new Ray(pPointer.transform.position, Vector3.forward);
                //Debug.DrawRay(pPointer.transform.position, Vector3.forward * 10);

                //Check if we point to something
                if (Physics.Raycast(directionRay, out hit, 10))
                {
                    HandleRaycastHit(hit);
                }
                else
                {
                    //No hit - reset highlight color etc
                    ResetGameObjectColor();
                }
            }
        }
Esempio n. 51
0
    //next two untested
    bool checkDirectionUp(Leap.Finger finger)
    {
        Vector3 direction = finger.Direction.ToVector3();

        return(direction.x > .95f && direction.y > .95f && direction.z > .95f);
    }
 /** Sets the Leap Hand and Leap Finger for this finger.
 * Note that Leap Hand and Finger objects are recreated every frame. The
 * parent HandModel object calls this function to set or update the underlying
 * finger. The tracking data in the Leap objects are used to update the FingerModel.
 */ 
 public void SetLeapHand(Hand hand) {
   hand_ = hand;
   if (hand_ != null)
     finger_ = hand.Fingers[(int)fingerType];
 }
 private static IEnumerable<BodyPart> CreateFinger(Finger finger, JointType jt)
 {
     var bones = new List<Bone.BoneType> {Bone.BoneType.TYPE_DISTAL, Bone.BoneType.TYPE_INTERMEDIATE, Bone.BoneType.TYPE_METACARPAL, Bone.BoneType.TYPE_PROXIMAL}
         .Select<Bone.BoneType, Bone>(finger.Bone)
         .Where(bone => bone != null);
     return bones.Select(bone => new BodyPart
     {
         Id = BoneType2JointType(jt, bone.Type).ToInt(),
         Position = new Vector3(bone.PrevJoint.x, bone.PrevJoint.y, bone.PrevJoint.z),
         Rotation = new Vector4(bone.Rotation.x, bone.Rotation.y, bone.Rotation.z, bone.Rotation.w),
         Length = ExtractLength(bone)
     }).Where(part => part.Id != JointType.THUMB_LEFT_METACARPAL.ToInt() && part.Id != JointType.THUMB_RIGHT_METACARPAL.ToInt());
 }
        /*--------------------------------------------------------------------------------------------*/
        private void UpdateForFinger(Hand pLeapHand, Finger.FingerType pLeapFingerType)
        {
            Finger leapFinger = pLeapHand.Fingers
                .FingerType(pLeapFingerType)
                .FirstOrDefault(f => f.IsValid);

            if ( leapFinger == null ) {
                UpdateForNull();
                return;
            }

            Bone bone = leapFinger.Bone(Bone.BoneType.TYPE_DISTAL);

            IsAvailable = true;
            Position = leapFinger.TipPosition.ToUnityScaled();
            Rotation = LeapUtil.CalcQuaternion(bone.Basis);
            Size = leapFinger.Width*SizeScaleFactor;
        }