12 public static class TransformExtensions {
20 public static Frame Transform(
this Frame frame, LeapTransform transform) {
21 for (
int i = frame.Hands.Count; i-- != 0;) {
22 frame.Hands[i].Transform(transform);
34 public static Frame TransformedCopy(
this Frame frame, LeapTransform transform) {
35 return new Frame().CopyFrom(frame).Transform(transform);
44 public static Hand Transform(
this Hand hand, LeapTransform transform) {
45 hand.PalmPosition = transform.TransformPoint(hand.PalmPosition);
46 hand.StabilizedPalmPosition = transform.TransformPoint(hand.StabilizedPalmPosition);
47 hand.PalmVelocity = transform.TransformVelocity(hand.PalmVelocity);
48 hand.PalmNormal = transform.TransformDirection(hand.PalmNormal);
49 hand.Direction = transform.TransformDirection(hand.Direction);
50 hand.WristPosition = transform.TransformPoint(hand.WristPosition);
51 hand.PalmWidth *=
Math.Abs(transform.scale.x);
52 hand.Rotation = transform.TransformQuaternion(hand.Rotation);
54 hand.Arm.Transform(transform);
56 for (
int i = 5; i-- != 0;) {
57 hand.Fingers[i].Transform(transform);
69 public static Hand TransformedCopy(
this Hand hand, LeapTransform transform) {
70 return new Hand().CopyFrom(hand).Transform(transform);
79 public static Finger Transform(
this Finger finger, LeapTransform transform) {
80 Bone nextBone = finger.bones[3];
81 nextBone.NextJoint = transform.TransformPoint(nextBone.NextJoint);
83 finger.TipPosition = nextBone.NextJoint;
85 for (
int i = 3; i-- != 0;) {
86 Bone bone = finger.bones[i];
88 bone.NextJoint = nextBone.PrevJoint = transform.TransformPoint(bone.NextJoint);
90 nextBone.TransformGivenJoints(transform);
94 nextBone.PrevJoint = transform.TransformPoint(nextBone.PrevJoint);
95 nextBone.TransformGivenJoints(transform);
97 finger.Direction = finger.bones[2].Direction;
98 finger.Width *=
Math.Abs(transform.scale.x);
99 finger.Length *=
Math.Abs(transform.scale.z);
110 public static Finger TransformedCopy(
this Finger finger, LeapTransform transform) {
111 return new Finger().CopyFrom(finger).Transform(transform);
120 public static Bone Transform(
this Bone bone, LeapTransform transform) {
121 bone.PrevJoint = transform.TransformPoint(bone.PrevJoint);
122 bone.NextJoint = transform.TransformPoint(bone.NextJoint);
124 bone.TransformGivenJoints(transform);
135 internal static void TransformGivenJoints(
this Bone bone, LeapTransform transform) {
136 bone.Length *=
Math.Abs(transform.scale.z);
137 bone.Center = (bone.PrevJoint + bone.NextJoint) / 2.0f;
139 if (bone.Length <
float.Epsilon) {
140 bone.Direction = Vector.Zero;
142 bone.Direction = (bone.NextJoint - bone.PrevJoint) / bone.Length;
145 bone.Width *=
Math.Abs(transform.scale.x);
146 bone.Rotation = transform.TransformQuaternion(bone.Rotation);
155 public static Bone TransformedCopy(
this Bone bone, LeapTransform transform) {
156 return new Bone().CopyFrom(bone).Transform(transform);