12 public static class CopyFromLeapCExtensions {
19 public static Frame CopyFrom(
this Frame frame, ref LEAP_TRACKING_EVENT trackingMsg) {
20 frame.Id = (long)trackingMsg.info.frame_id;
21 frame.Timestamp = (
long)trackingMsg.info.timestamp;
22 frame.CurrentFramesPerSecond = trackingMsg.framerate;
24 frame.ResizeHandList((
int)trackingMsg.nHands);
26 for (
int i = frame.Hands.Count; i-- != 0;) {
28 StructMarshal<LEAP_HAND>.ArrayElementToStruct(trackingMsg.pHands, i, out hand);
29 frame.Hands[i].CopyFrom(ref hand, frame.Id);
41 public static Hand CopyFrom(
this Hand hand, ref LEAP_HAND leapHand,
long frameId) {
42 hand.FrameId = frameId;
43 hand.Id = (int)leapHand.id;
45 hand.Arm.CopyFrom(leapHand.arm, Bone.BoneType.TYPE_INVALID);
47 hand.Confidence = leapHand.confidence;
48 hand.GrabStrength = leapHand.grab_strength;
49 hand.GrabAngle = leapHand.grab_angle;
50 hand.PinchStrength = leapHand.pinch_strength;
51 hand.PinchDistance = leapHand.pinch_distance;
52 hand.PalmWidth = leapHand.palm.width;
53 hand.IsLeft = leapHand.type ==
eLeapHandType.eLeapHandType_Left;
54 hand.TimeVisible = (float)(leapHand.visible_time * 1e-6);
55 hand.PalmPosition = leapHand.palm.position.ToLeapVector();
56 hand.StabilizedPalmPosition = leapHand.palm.stabilized_position.ToLeapVector();
57 hand.PalmVelocity = leapHand.palm.velocity.ToLeapVector();
58 hand.PalmNormal = leapHand.palm.normal.ToLeapVector();
59 hand.Rotation = leapHand.palm.orientation.ToLeapQuaternion();
60 hand.Direction = leapHand.palm.direction.ToLeapVector();
61 hand.WristPosition = hand.Arm.NextJoint;
63 hand.Fingers[0].CopyFrom(leapHand.thumb,
Leap.
Finger.
FingerType.TYPE_THUMB, hand.Id, hand.TimeVisible);
64 hand.Fingers[1].CopyFrom(leapHand.index,
Leap.
Finger.
FingerType.TYPE_INDEX, hand.Id, hand.TimeVisible);
65 hand.Fingers[2].CopyFrom(leapHand.middle,
Leap.
Finger.
FingerType.TYPE_MIDDLE, hand.Id, hand.TimeVisible);
66 hand.Fingers[3].CopyFrom(leapHand.ring,
Leap.
Finger.
FingerType.TYPE_RING, hand.Id, hand.TimeVisible);
67 hand.Fingers[4].CopyFrom(leapHand.pinky,
Leap.
Finger.
FingerType.TYPE_PINKY, hand.Id, hand.TimeVisible);
81 public static Finger CopyFrom(
this Finger finger, LEAP_DIGIT leapBone, Finger.FingerType type,
int handId,
float timeVisible) {
82 finger.Id = (handId * 10) + leapBone.finger_id;
83 finger.HandId = handId;
84 finger.TimeVisible = timeVisible;
86 Bone metacarpal = finger.bones[0];
87 Bone proximal = finger.bones[1];
88 Bone intermediate = finger.bones[2];
89 Bone distal = finger.bones[3];
91 metacarpal.CopyFrom(leapBone.metacarpal,
Leap.
Bone.
BoneType.TYPE_METACARPAL);
93 intermediate.CopyFrom(leapBone.intermediate,
Leap.
Bone.
BoneType.TYPE_INTERMEDIATE);
96 finger.TipPosition = distal.NextJoint;
97 finger.Direction = intermediate.Direction;
98 finger.Width = intermediate.Width;
99 finger.Length = (leapBone.finger_id == 0 ? 0.0f : 0.5f * proximal.Length) + intermediate.Length + 0.77f * distal.Length;
100 finger.IsExtended = leapBone.is_extended != 0;
112 public static Bone CopyFrom(
this Bone bone, LEAP_BONE leapBone, Bone.BoneType type) {
114 bone.PrevJoint = leapBone.prev_joint.ToLeapVector();
115 bone.NextJoint = leapBone.next_joint.ToLeapVector();
116 bone.Direction = (bone.NextJoint - bone.PrevJoint);
117 bone.Length = bone.Direction.Magnitude;
119 if (bone.Length <
float.Epsilon) {
120 bone.Direction = Vector.Zero;
122 bone.Direction /= bone.Length;
125 bone.Center = (bone.PrevJoint + bone.NextJoint) / 2.0f;
126 bone.Rotation = leapBone.rotation.ToLeapQuaternion();
127 bone.Width = leapBone.width;
The Bone class represents a tracked bone.
BoneType
Enumerates the type of bones.
The Finger class represents a tracked finger.
FingerType
Enumerates the names of the fingers.