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 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; }