public Hand makeHand(ref LEAP_HAND hand, Frame owningFrame)
    {
      Arm newArm = makeArm(ref hand.arm);

      Hand newHand = new Hand(
        (int)owningFrame.Id,
        (int)hand.id,
        hand.confidence,
        hand.grab_strength,
        hand.grab_angle,
        hand.pinch_strength,
        hand.pinch_distance,
        hand.palm.width,
        hand.type == eLeapHandType.eLeapHandType_Left,
        hand.visible_time,
        newArm,
        new List<Finger>(5),
        new Vector(hand.palm.position.x, hand.palm.position.y, hand.palm.position.z),
        new Vector(hand.palm.stabilized_position.x, hand.palm.stabilized_position.y, hand.palm.stabilized_position.z),
        new Vector(hand.palm.velocity.x, hand.palm.velocity.y, hand.palm.velocity.z),
        new Vector(hand.palm.normal.x, hand.palm.normal.y, hand.palm.normal.z),
        new Vector(hand.palm.direction.x, hand.palm.direction.y, hand.palm.direction.z),
        newArm.NextJoint //wrist position
      );
      newHand.Fingers.Insert(0, makeFinger(owningFrame, ref hand, ref hand.thumb, Finger.FingerType.TYPE_THUMB));
      newHand.Fingers.Insert(1, makeFinger(owningFrame, ref hand, ref hand.index, Finger.FingerType.TYPE_INDEX));
      newHand.Fingers.Insert(2, makeFinger(owningFrame, ref hand, ref hand.middle, Finger.FingerType.TYPE_MIDDLE));
      newHand.Fingers.Insert(3, makeFinger(owningFrame, ref hand, ref hand.ring, Finger.FingerType.TYPE_RING));
      newHand.Fingers.Insert(4, makeFinger(owningFrame, ref hand, ref hand.pinky, Finger.FingerType.TYPE_PINKY));

      return newHand;
    }
示例#2
0
    public static LEAP_HAND CreateHand(Hand hand) {
      LEAP_HAND leapHand = new LEAP_HAND();
      leapHand.id = (uint)hand.Id;
      leapHand.type = hand.IsLeft ? eLeapHandType.eLeapHandType_Right : eLeapHandType.eLeapHandType_Left; //HACK: flip due to coordinate space handedness
      leapHand.confidence = hand.Confidence;
      leapHand.visible_time = (uint)(hand.TimeVisible * 1000);
      leapHand.grab_angle = hand.GrabAngle;
      leapHand.grab_strength = hand.GrabStrength;
      leapHand.pinch_distance = hand.PinchDistance;
      leapHand.pinch_strength = hand.PinchStrength;

      LEAP_PALM palm = new LEAP_PALM();
      palm.position = new LEAP_VECTOR(hand.PalmPosition);
      palm.stabilized_position = Vector3.zero.ToCVector(); //HACK: stabilized position is sometimes NaN, ignore it
      palm.velocity = new LEAP_VECTOR(hand.PalmVelocity);
      palm.normal = new LEAP_VECTOR(hand.PalmNormal);
      palm.width = hand.PalmWidth;
      palm.direction = new LEAP_VECTOR(hand.Direction);

      leapHand.palm = palm;
      leapHand.arm = CreateBone(hand.Arm);

      for (int i = 0; i < hand.Fingers.Count; i++) {
        Finger finger = hand.Fingers[i];
        switch (finger.Type) {
          case Finger.FingerType.TYPE_THUMB:
            leapHand.thumb = CreateDigit(finger);
            break;
          case Finger.FingerType.TYPE_INDEX:
            leapHand.index = CreateDigit(finger);
            break;
          case Finger.FingerType.TYPE_MIDDLE:
            leapHand.middle = CreateDigit(finger);
            break;
          case Finger.FingerType.TYPE_RING:
            leapHand.ring = CreateDigit(finger);
            break;
          case Finger.FingerType.TYPE_PINKY:
            leapHand.pinky = CreateDigit(finger);
            break;
          default:
            throw new Exception("Unexpected Finger Type " + finger.Type);
        }
      }

      return leapHand;
    }
    public Hand makeHand(ref LEAP_HAND hand, Frame owningFrame)
    {
      LEAP_BONE arm = LeapC.PtrToStruct<LEAP_BONE>(hand.arm);
      Arm newArm = makeArm(ref arm);
      LEAP_PALM palm = LeapC.PtrToStruct<LEAP_PALM>(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 = LeapC.PtrToStruct<LEAP_DIGIT>(hand.thumb);
      newHand.Fingers.Insert(0, makeFinger(owningFrame, ref hand, ref thumbDigit, Finger.FingerType.TYPE_THUMB));

      LEAP_DIGIT indexDigit = LeapC.PtrToStruct<LEAP_DIGIT>(hand.index);
      newHand.Fingers.Insert(1, makeFinger(owningFrame, ref hand, ref indexDigit, Finger.FingerType.TYPE_INDEX));

      LEAP_DIGIT middleDigit = LeapC.PtrToStruct<LEAP_DIGIT>(hand.middle);
      newHand.Fingers.Insert(2, makeFinger(owningFrame, ref hand, ref middleDigit, Finger.FingerType.TYPE_MIDDLE));

      LEAP_DIGIT ringDigit = LeapC.PtrToStruct<LEAP_DIGIT>(hand.ring);
      newHand.Fingers.Insert(3, makeFinger(owningFrame, ref hand, ref ringDigit, Finger.FingerType.TYPE_RING));

      LEAP_DIGIT pinkyDigit = LeapC.PtrToStruct<LEAP_DIGIT>(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
   );
 }