Tanoda
TransformExtensions.cs
Go to the documentation of this file.
1/******************************************************************************
2 * Copyright (C) Ultraleap, Inc. 2011-2020. *
3 * *
4 * Use subject to the terms of the Apache License 2.0 available at *
5 * http://www.apache.org/licenses/LICENSE-2.0, or another agreement *
6 * between Ultraleap and you, your company or other organization. *
7 ******************************************************************************/
8
9namespace Leap {
10 using System;
11
12 public static class TransformExtensions {
13
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);
23 }
24
25 return frame;
26 }
27
34 public static Frame TransformedCopy(this Frame frame, LeapTransform transform) {
35 return new Frame().CopyFrom(frame).Transform(transform);
36 }
37
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);
53
54 hand.Arm.Transform(transform);
55
56 for (int i = 5; i-- != 0;) {
57 hand.Fingers[i].Transform(transform);
58 }
59
60 return hand;
61 }
62
69 public static Hand TransformedCopy(this Hand hand, LeapTransform transform) {
70 return new Hand().CopyFrom(hand).Transform(transform);
71 }
72
79 public static Finger Transform(this Finger finger, LeapTransform transform) {
80 Bone nextBone = finger.bones[3];
81 nextBone.NextJoint = transform.TransformPoint(nextBone.NextJoint);
82
83 finger.TipPosition = nextBone.NextJoint;
84
85 for (int i = 3; i-- != 0;) {
86 Bone bone = finger.bones[i];
87
88 bone.NextJoint = nextBone.PrevJoint = transform.TransformPoint(bone.NextJoint);
89
90 nextBone.TransformGivenJoints(transform);
91 nextBone = bone;
92 }
93
94 nextBone.PrevJoint = transform.TransformPoint(nextBone.PrevJoint);
95 nextBone.TransformGivenJoints(transform);
96
97 finger.Direction = finger.bones[2].Direction;
98 finger.Width *= Math.Abs(transform.scale.x);
99 finger.Length *= Math.Abs(transform.scale.z);
100
101 return finger;
102 }
103
110 public static Finger TransformedCopy(this Finger finger, LeapTransform transform) {
111 return new Finger().CopyFrom(finger).Transform(transform);
112 }
113
120 public static Bone Transform(this Bone bone, LeapTransform transform) {
121 bone.PrevJoint = transform.TransformPoint(bone.PrevJoint);
122 bone.NextJoint = transform.TransformPoint(bone.NextJoint);
123
124 bone.TransformGivenJoints(transform);
125
126 return bone;
127 }
128
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;
138
139 if (bone.Length < float.Epsilon) {
140 bone.Direction = Vector.Zero;
141 } else {
142 bone.Direction = (bone.NextJoint - bone.PrevJoint) / bone.Length;
143 }
144
145 bone.Width *= Math.Abs(transform.scale.x);
146 bone.Rotation = transform.TransformQuaternion(bone.Rotation);
147 }
148
155 public static Bone TransformedCopy(this Bone bone, LeapTransform transform) {
156 return new Bone().CopyFrom(bone).Transform(transform);
157 }
158 }
159}
Es.InkPainter.Math Math
Definition: PaintTest.cs:7