/**
         * Copies the data from an internal finger definition into a finger.
         *
         * @param leapBone The internal finger definition to be copied into this finger.
         * @param type The finger type of this finger.
         * @param frameId The frame id of the frame this finger belongs to.
         * @param handId The hand id of the hand this finger belongs to.
         * @param timeVisible The time in seconds that this finger has been visible.
         */
        public static Finger CopyFrom(this Finger finger, LEAP_DIGIT leapBone, Finger.FingerType type, int handId, float timeVisible)
        {
            finger.Id          = (handId * 10) + leapBone.finger_id;
            finger.HandId      = handId;
            finger.TimeVisible = timeVisible;

            Bone metacarpal   = finger.bones[0];
            Bone proximal     = finger.bones[1];
            Bone intermediate = finger.bones[2];
            Bone distal       = finger.bones[3];

            metacarpal.CopyFrom(leapBone.metacarpal, Leap.Bone.BoneType.TYPE_METACARPAL);
            proximal.CopyFrom(leapBone.proximal, Leap.Bone.BoneType.TYPE_PROXIMAL);
            intermediate.CopyFrom(leapBone.intermediate, Leap.Bone.BoneType.TYPE_INTERMEDIATE);
            distal.CopyFrom(leapBone.distal, Leap.Bone.BoneType.TYPE_DISTAL);

            finger.TipPosition = distal.NextJoint;
            finger.Direction   = intermediate.Direction;
            finger.Width       = intermediate.Width;
            finger.Length      = (leapBone.finger_id == 0 ? 0.0f : 0.5f * proximal.Length) + intermediate.Length + 0.77f * distal.Length; //The values 0.5 for proximal and 0.77 for distal are used in platform code for this calculation
            finger.IsExtended  = leapBone.is_extended != 0;
            finger.Type        = type;

            return(finger);
        }
        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
                              ));
        }
Beispiel #3
0
        /**
         * Copies the data from an internal finger definition into a finger.
         *
         * @param leapBone The internal finger definition to be copied into this finger.
         * @param type The finger type of this finger.
         * @param frameId The frame id of the frame this finger belongs to.
         * @param handId The hand id of the hand this finger belongs to.
         * @param timeVisible The time in seconds that this finger has been visible.
         */
        public static Finger CopyFrom(this Finger finger, LEAP_DIGIT leapBone, Finger.FingerType type, int handId, float timeVisible)
        {
            finger.Id          = (handId * 10) + leapBone.finger_id;
            finger.HandId      = handId;
            finger.TimeVisible = timeVisible;

            Bone metacarpal   = finger.bones[0];
            Bone proximal     = finger.bones[1];
            Bone intermediate = finger.bones[2];
            Bone distal       = finger.bones[3];

            metacarpal.CopyFrom(leapBone.metacarpal, Leap.Bone.BoneType.TYPE_METACARPAL);
            proximal.CopyFrom(leapBone.proximal, Leap.Bone.BoneType.TYPE_PROXIMAL);
            intermediate.CopyFrom(leapBone.intermediate, Leap.Bone.BoneType.TYPE_INTERMEDIATE);
            distal.CopyFrom(leapBone.distal, Leap.Bone.BoneType.TYPE_DISTAL);

            finger.TipPosition           = distal.NextJoint;
            finger.TipVelocity           = leapBone.tip_velocity.ToLeapVector();
            finger.Direction             = intermediate.Direction;
            finger.StabilizedTipPosition = leapBone.stabilized_tip_position.ToLeapVector();
            finger.Width      = intermediate.Width;
            finger.Length     = proximal.Length + intermediate.Length + (distal.Length * 0.77f); //0.77 is used in platform code for this calculation
            finger.IsExtended = leapBone.is_extended != 0;
            finger.Type       = type;

            return(finger);
        }
 public static LEAP_DIGIT CreateDigit(Finger finger) {
   LEAP_DIGIT digit = new LEAP_DIGIT();
   digit.finger_id = finger.Id;
   digit.metacarpal = CreateBone(finger.Bone(Bone.BoneType.TYPE_METACARPAL));
   digit.proximal = CreateBone(finger.Bone(Bone.BoneType.TYPE_PROXIMAL));
   digit.intermediate = CreateBone(finger.Bone(Bone.BoneType.TYPE_INTERMEDIATE));
   digit.distal = CreateBone(finger.Bone(Bone.BoneType.TYPE_DISTAL));
   digit.tip_velocity = new LEAP_VECTOR(finger.TipVelocity);
   digit.stabilized_tip_position = Vector3.zero.ToCVector(); //HACK: stabilized position is sometimes NaN, ignore it
   digit.is_extended = finger.IsExtended ? 1 : 0;
   return digit;
 }
Beispiel #5
0
        public Hand makeHand(ref LEAP_HAND hand, Frame owningFrame)
        {
            LEAP_BONE arm = StructMarshal <LEAP_BONE> .PtrToStruct(hand.arm);

            Arm       newArm = makeArm(ref arm);
            LEAP_PALM palm   = StructMarshal <LEAP_PALM> .PtrToStruct(hand.palm);

            Hand newHand = new Hand(
                (int)owningFrame.Id,
                (int)hand.id,
                hand.confidence,
                hand.grab_strength,
                hand.grab_angle,
                hand.pinch_strength,
                hand.pinch_distance,
                palm.width,
                hand.type == eLeapHandType.eLeapHandType_Left,
                hand.visible_time,
                newArm,
                new List <Finger>(5),
                new Vector(palm.position.x, palm.position.y, palm.position.z),
                new Vector(palm.stabilized_position.x, palm.stabilized_position.y, palm.stabilized_position.z),
                new Vector(palm.velocity.x, palm.velocity.y, palm.velocity.z),
                new Vector(palm.normal.x, palm.normal.y, palm.normal.z),
                new Vector(palm.direction.x, palm.direction.y, palm.direction.z),
                newArm.NextJoint //wrist position
                );
            LEAP_DIGIT thumbDigit = StructMarshal <LEAP_DIGIT> .PtrToStruct(hand.thumb);

            newHand.Fingers.Insert(0, makeFinger(owningFrame, ref hand, ref thumbDigit, Finger.FingerType.TYPE_THUMB));

            LEAP_DIGIT indexDigit = StructMarshal <LEAP_DIGIT> .PtrToStruct(hand.index);

            newHand.Fingers.Insert(1, makeFinger(owningFrame, ref hand, ref indexDigit, Finger.FingerType.TYPE_INDEX));

            LEAP_DIGIT middleDigit = StructMarshal <LEAP_DIGIT> .PtrToStruct(hand.middle);

            newHand.Fingers.Insert(2, makeFinger(owningFrame, ref hand, ref middleDigit, Finger.FingerType.TYPE_MIDDLE));

            LEAP_DIGIT ringDigit = StructMarshal <LEAP_DIGIT> .PtrToStruct(hand.ring);

            newHand.Fingers.Insert(3, makeFinger(owningFrame, ref hand, ref ringDigit, Finger.FingerType.TYPE_RING));

            LEAP_DIGIT pinkyDigit = StructMarshal <LEAP_DIGIT> .PtrToStruct(hand.pinky);

            newHand.Fingers.Insert(4, makeFinger(owningFrame, ref hand, ref pinkyDigit, Finger.FingerType.TYPE_PINKY));

            return(newHand);
        }
 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
   );
 }