Update to Ultraleap Gemini v5.12

Update to Ultraleap Unity Plugin v6.9.0
Unclamped spreads and curls
This commit is contained in:
SDraw 2023-07-04 11:54:10 +03:00
parent 965c0bf93d
commit 5c33abc9d2
No known key found for this signature in database
GPG key ID: BB95B4DAB2BB8BB5
46 changed files with 1143 additions and 2564 deletions

View file

@ -9,7 +9,8 @@ namespace ml_lme
{
static readonly List<string> ms_assets = new List<string>()
{
"leapmotion_controller.asset"
"leapmotion_controller.asset",
"leapmotion_hands.asset"
};
static Dictionary<string, AssetBundle> ms_loadedAssets = new Dictionary<string, AssetBundle>();

View file

@ -22,11 +22,15 @@ namespace ml_lme
public readonly float[] m_spreads = null;
public readonly float[] m_bends = null;
public float m_grabStrength = 0f;
public Vector3[] m_fingerPosition;
public Quaternion[] m_fingerRotation;
public HandData()
{
m_spreads = new float[5];
m_bends = new float[5];
m_fingerPosition = new Vector3[20];
m_fingerRotation = new Quaternion[20];
}
public void Reset()
@ -37,6 +41,11 @@ namespace ml_lme
m_bends[i] = 0f;
m_spreads[i] = 0f;
}
for(int i = 0; i < 20; i++)
{
m_fingerPosition[i].Set(0f, 0f, 0f);
m_fingerRotation[i].Set(0f, 0f, 0f, 1f);
}
m_grabStrength = 0f;
}
}
@ -77,9 +86,9 @@ namespace ml_lme
{
// Unity's IK and FinalIK move hand bones to target, therefore - wrist
p_data.m_present = true;
p_data.m_position.Set(p_hand.WristPosition.x, p_hand.WristPosition.y, p_hand.WristPosition.z);
p_data.m_rotation.Set(p_hand.Rotation.x, p_hand.Rotation.y, p_hand.Rotation.z, p_hand.Rotation.w);
p_data.m_elbowPosition.Set(p_hand.Arm.ElbowPosition.x, p_hand.Arm.ElbowPosition.y, p_hand.Arm.ElbowPosition.z);
p_data.m_position = p_hand.WristPosition;
p_data.m_rotation = p_hand.Rotation;
p_data.m_elbowPosition = p_hand.Arm.ElbowPosition;
// Bends
foreach(Leap.Finger l_finger in p_hand.Fingers)
@ -89,41 +98,36 @@ namespace ml_lme
float l_angle = 0f;
foreach(Leap.Bone l_bone in l_finger.bones)
{
p_data.m_fingerPosition[(int)l_finger.Type * 4 + (int)l_bone.Type] = l_bone.PrevJoint;
p_data.m_fingerRotation[(int)l_finger.Type * 4 + (int)l_bone.Type] = l_bone.Rotation;
if(l_bone.Type == Leap.Bone.BoneType.TYPE_METACARPAL)
{
l_prevSegment = new Quaternion(l_bone.Rotation.x, l_bone.Rotation.y, l_bone.Rotation.z, l_bone.Rotation.w);
l_prevSegment = l_bone.Rotation;
continue;
}
Quaternion l_curSegment = new Quaternion(l_bone.Rotation.x, l_bone.Rotation.y, l_bone.Rotation.z, l_bone.Rotation.w);
Quaternion l_diff = Quaternion.Inverse(l_prevSegment) * l_curSegment;
l_prevSegment = l_curSegment;
Quaternion l_diff = Quaternion.Inverse(l_prevSegment) * l_bone.Rotation;
l_prevSegment = l_bone.Rotation;
// Bend - local X rotation
float l_curAngle = 360f - l_diff.eulerAngles.x;
if(l_curAngle > 180f)
l_curAngle -= 360f;
l_angle += l_curAngle;
float l_angleDiff = l_diff.eulerAngles.x;
if(l_angleDiff > 180f)
l_angleDiff -= 360f;
l_angle += l_angleDiff;
}
p_data.m_bends[(int)l_finger.Type] = Mathf.InverseLerp(0f, (l_finger.Type == Leap.Finger.FingerType.TYPE_THUMB) ? 90f : 180f, l_angle);
p_data.m_bends[(int)l_finger.Type] = Utils.InverseLerpUnclamped(0f, (l_finger.Type == Leap.Finger.FingerType.TYPE_THUMB) ? 90f : 180f, l_angle);
}
// Spreads
foreach(Leap.Finger l_finger in p_hand.Fingers)
{
float l_angle = 0f;
Leap.Bone l_parent = l_finger.Bone(Leap.Bone.BoneType.TYPE_METACARPAL);
Leap.Bone l_child = l_finger.Bone(Leap.Bone.BoneType.TYPE_PROXIMAL);
Quaternion l_parentRot = new Quaternion(l_parent.Rotation.x, l_parent.Rotation.y, l_parent.Rotation.z, l_parent.Rotation.w);
Quaternion l_childRot = new Quaternion(l_child.Rotation.x, l_child.Rotation.y, l_child.Rotation.z, l_child.Rotation.w);
Quaternion l_diff = Quaternion.Inverse(l_parentRot) * l_childRot;
Quaternion l_diff = Quaternion.Inverse(l_parent.Rotation) * l_child.Rotation;
// Spread - local Y rotation, but thumb is obnoxious
l_angle = l_diff.eulerAngles.y;
float l_angle = 360f - l_diff.eulerAngles.y;
if(l_angle > 180f)
l_angle -= 360f;
@ -134,15 +138,15 @@ namespace ml_lme
if(l_finger.Type != Leap.Finger.FingerType.TYPE_THUMB)
{
if(l_angle < 0f)
p_data.m_spreads[(int)l_finger.Type] = 0.5f * Mathf.InverseLerp(ms_fingerLimits[(int)l_finger.Type].x, 0f, l_angle);
p_data.m_spreads[(int)l_finger.Type] = 0.5f * Utils.InverseLerpUnclamped(ms_fingerLimits[(int)l_finger.Type].x, 0f, l_angle);
else
p_data.m_spreads[(int)l_finger.Type] = 0.5f + 0.5f * Mathf.InverseLerp(0f, ms_fingerLimits[(int)l_finger.Type].y, l_angle);
p_data.m_spreads[(int)l_finger.Type] = 0.5f + 0.5f * Utils.InverseLerpUnclamped(0f, ms_fingerLimits[(int)l_finger.Type].y, l_angle);
}
else
p_data.m_spreads[(int)l_finger.Type] = Mathf.InverseLerp(ms_fingerLimits[(int)l_finger.Type].x, ms_fingerLimits[(int)l_finger.Type].y, l_angle);
p_data.m_spreads[(int)l_finger.Type] = Utils.InverseLerpUnclamped(ms_fingerLimits[(int)l_finger.Type].x, ms_fingerLimits[(int)l_finger.Type].y, l_angle);
}
p_data.m_grabStrength = (p_data.m_bends[1] + p_data.m_bends[2] + p_data.m_bends[3] + p_data.m_bends[4]) * 0.25f;
p_data.m_grabStrength = Mathf.Clamp01((p_data.m_bends[1] + p_data.m_bends[2] + p_data.m_bends[3] + p_data.m_bends[4]) * 0.25f);
}
}
}

View file

@ -145,58 +145,58 @@ namespace ml_lme
{
if(p_data.m_leftHand.m_present)
{
UpdatePoseMuscle(ref m_pose, (int)MuscleIndex.LeftThumb1Stretched, Mathf.Lerp(0.85f, -0.85f, p_data.m_leftHand.m_bends[0]));
UpdatePoseMuscle(ref m_pose, (int)MuscleIndex.LeftThumb2Stretched, Mathf.Lerp(0.85f, -0.85f, p_data.m_leftHand.m_bends[0]));
UpdatePoseMuscle(ref m_pose, (int)MuscleIndex.LeftThumb3Stretched, Mathf.Lerp(0.85f, -0.85f, p_data.m_leftHand.m_bends[0]));
UpdatePoseMuscle(ref m_pose, (int)MuscleIndex.LeftThumbSpread, Mathf.Lerp(-1.5f, 1.0f, p_data.m_leftHand.m_spreads[0])); // Ok
UpdatePoseMuscle(ref m_pose, (int)MuscleIndex.LeftThumb1Stretched, Mathf.LerpUnclamped(0.85f, -0.85f, p_data.m_leftHand.m_bends[0]));
UpdatePoseMuscle(ref m_pose, (int)MuscleIndex.LeftThumb2Stretched, Mathf.LerpUnclamped(0.85f, -0.85f, p_data.m_leftHand.m_bends[0]));
UpdatePoseMuscle(ref m_pose, (int)MuscleIndex.LeftThumb3Stretched, Mathf.LerpUnclamped(0.85f, -0.85f, p_data.m_leftHand.m_bends[0]));
UpdatePoseMuscle(ref m_pose, (int)MuscleIndex.LeftThumbSpread, Mathf.LerpUnclamped(-1.5f, 1.0f, p_data.m_leftHand.m_spreads[0])); // Ok
UpdatePoseMuscle(ref m_pose, (int)MuscleIndex.LeftIndex1Stretched, Mathf.Lerp(0.7f, -1f, p_data.m_leftHand.m_bends[1]));
UpdatePoseMuscle(ref m_pose, (int)MuscleIndex.LeftIndex2Stretched, Mathf.Lerp(0.7f, -1f, p_data.m_leftHand.m_bends[1]));
UpdatePoseMuscle(ref m_pose, (int)MuscleIndex.LeftIndex3Stretched, Mathf.Lerp(0.7f, -1f, p_data.m_leftHand.m_bends[1]));
UpdatePoseMuscle(ref m_pose, (int)MuscleIndex.LeftIndexSpread, Mathf.Lerp(1f, -1f, p_data.m_leftHand.m_spreads[1])); // Ok
UpdatePoseMuscle(ref m_pose, (int)MuscleIndex.LeftIndex1Stretched, Mathf.LerpUnclamped(0.7f, -1f, p_data.m_leftHand.m_bends[1]));
UpdatePoseMuscle(ref m_pose, (int)MuscleIndex.LeftIndex2Stretched, Mathf.LerpUnclamped(0.7f, -1f, p_data.m_leftHand.m_bends[1]));
UpdatePoseMuscle(ref m_pose, (int)MuscleIndex.LeftIndex3Stretched, Mathf.LerpUnclamped(0.7f, -1f, p_data.m_leftHand.m_bends[1]));
UpdatePoseMuscle(ref m_pose, (int)MuscleIndex.LeftIndexSpread, Mathf.LerpUnclamped(1f, -1f, p_data.m_leftHand.m_spreads[1])); // Ok
UpdatePoseMuscle(ref m_pose, (int)MuscleIndex.LeftMiddle1Stretched, Mathf.Lerp(0.7f, -1f, p_data.m_leftHand.m_bends[2]));
UpdatePoseMuscle(ref m_pose, (int)MuscleIndex.LeftMiddle2Stretched, Mathf.Lerp(0.7f, -1f, p_data.m_leftHand.m_bends[2]));
UpdatePoseMuscle(ref m_pose, (int)MuscleIndex.LeftMiddle3Stretched, Mathf.Lerp(0.7f, -1f, p_data.m_leftHand.m_bends[2]));
UpdatePoseMuscle(ref m_pose, (int)MuscleIndex.LeftMiddleSpread, Mathf.Lerp(2f, -2f, p_data.m_leftHand.m_spreads[2]));
UpdatePoseMuscle(ref m_pose, (int)MuscleIndex.LeftMiddle1Stretched, Mathf.LerpUnclamped(0.7f, -1f, p_data.m_leftHand.m_bends[2]));
UpdatePoseMuscle(ref m_pose, (int)MuscleIndex.LeftMiddle2Stretched, Mathf.LerpUnclamped(0.7f, -1f, p_data.m_leftHand.m_bends[2]));
UpdatePoseMuscle(ref m_pose, (int)MuscleIndex.LeftMiddle3Stretched, Mathf.LerpUnclamped(0.7f, -1f, p_data.m_leftHand.m_bends[2]));
UpdatePoseMuscle(ref m_pose, (int)MuscleIndex.LeftMiddleSpread, Mathf.LerpUnclamped(2f, -2f, p_data.m_leftHand.m_spreads[2]));
UpdatePoseMuscle(ref m_pose, (int)MuscleIndex.LeftRing1Stretched, Mathf.Lerp(0.7f, -1f, p_data.m_leftHand.m_bends[3]));
UpdatePoseMuscle(ref m_pose, (int)MuscleIndex.LeftRing2Stretched, Mathf.Lerp(0.7f, -1f, p_data.m_leftHand.m_bends[3]));
UpdatePoseMuscle(ref m_pose, (int)MuscleIndex.LeftRing3Stretched, Mathf.Lerp(0.7f, -1f, p_data.m_leftHand.m_bends[3]));
UpdatePoseMuscle(ref m_pose, (int)MuscleIndex.LeftRingSpread, Mathf.Lerp(-2f, 2f, p_data.m_leftHand.m_spreads[3]));
UpdatePoseMuscle(ref m_pose, (int)MuscleIndex.LeftRing1Stretched, Mathf.LerpUnclamped(0.7f, -1f, p_data.m_leftHand.m_bends[3]));
UpdatePoseMuscle(ref m_pose, (int)MuscleIndex.LeftRing2Stretched, Mathf.LerpUnclamped(0.7f, -1f, p_data.m_leftHand.m_bends[3]));
UpdatePoseMuscle(ref m_pose, (int)MuscleIndex.LeftRing3Stretched, Mathf.LerpUnclamped(0.7f, -1f, p_data.m_leftHand.m_bends[3]));
UpdatePoseMuscle(ref m_pose, (int)MuscleIndex.LeftRingSpread, Mathf.LerpUnclamped(-2f, 2f, p_data.m_leftHand.m_spreads[3]));
UpdatePoseMuscle(ref m_pose, (int)MuscleIndex.LeftLittle1Stretched, Mathf.Lerp(0.7f, -1f, p_data.m_leftHand.m_bends[4]));
UpdatePoseMuscle(ref m_pose, (int)MuscleIndex.LeftLittle2Stretched, Mathf.Lerp(0.7f, -1f, p_data.m_leftHand.m_bends[4]));
UpdatePoseMuscle(ref m_pose, (int)MuscleIndex.LeftLittle3Stretched, Mathf.Lerp(0.7f, -1f, p_data.m_leftHand.m_bends[4]));
UpdatePoseMuscle(ref m_pose, (int)MuscleIndex.LeftLittleSpread, Mathf.Lerp(-0.5f, 1f, p_data.m_leftHand.m_spreads[4]));
UpdatePoseMuscle(ref m_pose, (int)MuscleIndex.LeftLittle1Stretched, Mathf.LerpUnclamped(0.7f, -1f, p_data.m_leftHand.m_bends[4]));
UpdatePoseMuscle(ref m_pose, (int)MuscleIndex.LeftLittle2Stretched, Mathf.LerpUnclamped(0.7f, -1f, p_data.m_leftHand.m_bends[4]));
UpdatePoseMuscle(ref m_pose, (int)MuscleIndex.LeftLittle3Stretched, Mathf.LerpUnclamped(0.7f, -1f, p_data.m_leftHand.m_bends[4]));
UpdatePoseMuscle(ref m_pose, (int)MuscleIndex.LeftLittleSpread, Mathf.LerpUnclamped(-0.5f, 1f, p_data.m_leftHand.m_spreads[4]));
}
if(p_data.m_rightHand.m_present)
{
UpdatePoseMuscle(ref m_pose, (int)MuscleIndex.RightThumb1Stretched, Mathf.Lerp(0.85f, -0.85f, p_data.m_rightHand.m_bends[0]));
UpdatePoseMuscle(ref m_pose, (int)MuscleIndex.RightThumb2Stretched, Mathf.Lerp(0.85f, -0.85f, p_data.m_rightHand.m_bends[0]));
UpdatePoseMuscle(ref m_pose, (int)MuscleIndex.RightThumb3Stretched, Mathf.Lerp(0.85f, -0.85f, p_data.m_rightHand.m_bends[0]));
UpdatePoseMuscle(ref m_pose, (int)MuscleIndex.RightThumbSpread, Mathf.Lerp(-1.5f, 1.0f, p_data.m_rightHand.m_spreads[0])); // Ok
UpdatePoseMuscle(ref m_pose, (int)MuscleIndex.RightThumb1Stretched, Mathf.LerpUnclamped(0.85f, -0.85f, p_data.m_rightHand.m_bends[0]));
UpdatePoseMuscle(ref m_pose, (int)MuscleIndex.RightThumb2Stretched, Mathf.LerpUnclamped(0.85f, -0.85f, p_data.m_rightHand.m_bends[0]));
UpdatePoseMuscle(ref m_pose, (int)MuscleIndex.RightThumb3Stretched, Mathf.LerpUnclamped(0.85f, -0.85f, p_data.m_rightHand.m_bends[0]));
UpdatePoseMuscle(ref m_pose, (int)MuscleIndex.RightThumbSpread, Mathf.LerpUnclamped(-1.5f, 1.0f, p_data.m_rightHand.m_spreads[0])); // Ok
UpdatePoseMuscle(ref m_pose, (int)MuscleIndex.RightIndex1Stretched, Mathf.Lerp(0.7f, -1f, p_data.m_rightHand.m_bends[1]));
UpdatePoseMuscle(ref m_pose, (int)MuscleIndex.RightIndex2Stretched, Mathf.Lerp(0.7f, -1f, p_data.m_rightHand.m_bends[1]));
UpdatePoseMuscle(ref m_pose, (int)MuscleIndex.RightIndex3Stretched, Mathf.Lerp(0.7f, -1f, p_data.m_rightHand.m_bends[1]));
UpdatePoseMuscle(ref m_pose, (int)MuscleIndex.RightIndexSpread, Mathf.Lerp(1f, -1f, p_data.m_rightHand.m_spreads[1])); // Ok
UpdatePoseMuscle(ref m_pose, (int)MuscleIndex.RightIndex1Stretched, Mathf.LerpUnclamped(0.7f, -1f, p_data.m_rightHand.m_bends[1]));
UpdatePoseMuscle(ref m_pose, (int)MuscleIndex.RightIndex2Stretched, Mathf.LerpUnclamped(0.7f, -1f, p_data.m_rightHand.m_bends[1]));
UpdatePoseMuscle(ref m_pose, (int)MuscleIndex.RightIndex3Stretched, Mathf.LerpUnclamped(0.7f, -1f, p_data.m_rightHand.m_bends[1]));
UpdatePoseMuscle(ref m_pose, (int)MuscleIndex.RightIndexSpread, Mathf.LerpUnclamped(1f, -1f, p_data.m_rightHand.m_spreads[1])); // Ok
UpdatePoseMuscle(ref m_pose, (int)MuscleIndex.RightMiddle1Stretched, Mathf.Lerp(0.7f, -1f, p_data.m_rightHand.m_bends[2]));
UpdatePoseMuscle(ref m_pose, (int)MuscleIndex.RightMiddle2Stretched, Mathf.Lerp(0.7f, -1f, p_data.m_rightHand.m_bends[2]));
UpdatePoseMuscle(ref m_pose, (int)MuscleIndex.RightMiddle3Stretched, Mathf.Lerp(0.7f, -1f, p_data.m_rightHand.m_bends[2]));
UpdatePoseMuscle(ref m_pose, (int)MuscleIndex.RightMiddleSpread, Mathf.Lerp(2f, -2f, p_data.m_rightHand.m_spreads[2]));
UpdatePoseMuscle(ref m_pose, (int)MuscleIndex.RightMiddle1Stretched, Mathf.LerpUnclamped(0.7f, -1f, p_data.m_rightHand.m_bends[2]));
UpdatePoseMuscle(ref m_pose, (int)MuscleIndex.RightMiddle2Stretched, Mathf.LerpUnclamped(0.7f, -1f, p_data.m_rightHand.m_bends[2]));
UpdatePoseMuscle(ref m_pose, (int)MuscleIndex.RightMiddle3Stretched, Mathf.LerpUnclamped(0.7f, -1f, p_data.m_rightHand.m_bends[2]));
UpdatePoseMuscle(ref m_pose, (int)MuscleIndex.RightMiddleSpread, Mathf.LerpUnclamped(2f, -2f, p_data.m_rightHand.m_spreads[2]));
UpdatePoseMuscle(ref m_pose, (int)MuscleIndex.RightRing1Stretched, Mathf.Lerp(0.7f, -1f, p_data.m_rightHand.m_bends[3]));
UpdatePoseMuscle(ref m_pose, (int)MuscleIndex.RightRing2Stretched, Mathf.Lerp(0.7f, -1f, p_data.m_rightHand.m_bends[3]));
UpdatePoseMuscle(ref m_pose, (int)MuscleIndex.RightRing3Stretched, Mathf.Lerp(0.7f, -1f, p_data.m_rightHand.m_bends[3]));
UpdatePoseMuscle(ref m_pose, (int)MuscleIndex.RightRingSpread, Mathf.Lerp(-2f, 2f, p_data.m_rightHand.m_spreads[3]));
UpdatePoseMuscle(ref m_pose, (int)MuscleIndex.RightRing1Stretched, Mathf.LerpUnclamped(0.7f, -1f, p_data.m_rightHand.m_bends[3]));
UpdatePoseMuscle(ref m_pose, (int)MuscleIndex.RightRing2Stretched, Mathf.LerpUnclamped(0.7f, -1f, p_data.m_rightHand.m_bends[3]));
UpdatePoseMuscle(ref m_pose, (int)MuscleIndex.RightRing3Stretched, Mathf.LerpUnclamped(0.7f, -1f, p_data.m_rightHand.m_bends[3]));
UpdatePoseMuscle(ref m_pose, (int)MuscleIndex.RightRingSpread, Mathf.LerpUnclamped(-2f, 2f, p_data.m_rightHand.m_spreads[3]));
UpdatePoseMuscle(ref m_pose, (int)MuscleIndex.RightLittle1Stretched, Mathf.Lerp(0.7f, -1f, p_data.m_rightHand.m_bends[4]));
UpdatePoseMuscle(ref m_pose, (int)MuscleIndex.RightLittle2Stretched, Mathf.Lerp(0.7f, -1f, p_data.m_rightHand.m_bends[4]));
UpdatePoseMuscle(ref m_pose, (int)MuscleIndex.RightLittle3Stretched, Mathf.Lerp(0.7f, -1f, p_data.m_rightHand.m_bends[4]));
UpdatePoseMuscle(ref m_pose, (int)MuscleIndex.RightLittleSpread, Mathf.Lerp(-0.5f, 1f, p_data.m_rightHand.m_spreads[4]));
UpdatePoseMuscle(ref m_pose, (int)MuscleIndex.RightLittle1Stretched, Mathf.LerpUnclamped(0.7f, -1f, p_data.m_rightHand.m_bends[4]));
UpdatePoseMuscle(ref m_pose, (int)MuscleIndex.RightLittle2Stretched, Mathf.LerpUnclamped(0.7f, -1f, p_data.m_rightHand.m_bends[4]));
UpdatePoseMuscle(ref m_pose, (int)MuscleIndex.RightLittle3Stretched, Mathf.LerpUnclamped(0.7f, -1f, p_data.m_rightHand.m_bends[4]));
UpdatePoseMuscle(ref m_pose, (int)MuscleIndex.RightLittleSpread, Mathf.LerpUnclamped(-0.5f, 1f, p_data.m_rightHand.m_spreads[4]));
}
}

View file

@ -8,7 +8,9 @@ namespace ml_lme
class LeapTracking : MonoBehaviour
{
public static LeapTracking Instance { get; private set; } = null;
static Quaternion ms_identityRotation = Quaternion.identity;
static Quaternion ms_dummyRotation = Quaternion.identity;
static readonly Quaternion ms_hmdRotation = new Quaternion(0f, 0.7071068f, 0.7071068f, 0f);
static readonly Quaternion ms_screentopRotation = new Quaternion(0f, 0f, -1f, 0f);
bool m_inVR = false;
@ -17,6 +19,9 @@ namespace ml_lme
GameObject m_leapElbowLeft = null;
GameObject m_leapElbowRight = null;
GameObject m_leapControllerModel = null;
GameObject m_visualHands = null;
VisualHand m_visualHandLeft = null;
VisualHand m_visualHandRight = null;
float m_scaleRelation = 1f;
@ -56,8 +61,21 @@ namespace ml_lme
m_leapControllerModel.transform.localRotation = Quaternion.identity;
}
m_visualHands = AssetsHandler.GetAsset("assets/models/hands/leaphands.prefab");
if(m_visualHands != null)
{
m_visualHands.name = "VisualHands";
m_visualHands.transform.parent = this.transform;
m_visualHands.transform.localPosition = Vector3.zero;
m_visualHands.transform.localRotation = Quaternion.identity;
m_visualHandLeft = new VisualHand(m_visualHands.transform.Find("HandL"), true);
m_visualHandRight = new VisualHand(m_visualHands.transform.Find("HandR"), false);
}
Settings.DesktopOffsetChange += this.OnDesktopOffsetChange;
Settings.ModelVisibilityChange += this.OnModelVisibilityChange;
Settings.VisualHandsChange += this.OnVisualHandsChange;
Settings.TrackingModeChange += this.OnTrackingModeChange;
Settings.RootAngleChange += this.OnRootAngleChange;
Settings.HeadAttachChange += this.OnHeadAttachChange;
@ -66,6 +84,7 @@ namespace ml_lme
MelonLoader.MelonCoroutines.Start(WaitForLocalPlayer());
OnModelVisibilityChange(Settings.ModelVisibility);
OnVisualHandsChange(Settings.VisualHands);
OnTrackingModeChange(Settings.TrackingMode);
OnRootAngleChange(Settings.RootAngle);
}
@ -99,22 +118,34 @@ namespace ml_lme
if(l_data.m_leftHand.m_present)
{
Utils.LeapToUnity(ref l_data.m_leftHand.m_position, ref l_data.m_leftHand.m_rotation, Settings.TrackingMode);
OrientationAdjustment(ref l_data.m_leftHand.m_position, ref l_data.m_leftHand.m_rotation, Settings.TrackingMode);
for(int i = 0; i < 20; i++)
OrientationAdjustment(ref l_data.m_leftHand.m_fingerPosition[i], ref l_data.m_leftHand.m_fingerRotation[i], Settings.TrackingMode);
m_leapHandLeft.transform.localPosition = l_data.m_leftHand.m_position;
m_leapHandLeft.transform.localRotation = l_data.m_leftHand.m_rotation;
Utils.LeapToUnity(ref l_data.m_leftHand.m_elbowPosition, ref ms_identityRotation, Settings.TrackingMode);
OrientationAdjustment(ref l_data.m_leftHand.m_elbowPosition, ref ms_dummyRotation, Settings.TrackingMode);
m_leapElbowLeft.transform.localPosition = l_data.m_leftHand.m_elbowPosition;
if(Settings.VisualHands)
m_visualHandLeft?.Update(l_data.m_leftHand);
}
if(l_data.m_rightHand.m_present)
{
Utils.LeapToUnity(ref l_data.m_rightHand.m_position, ref l_data.m_rightHand.m_rotation, Settings.TrackingMode);
OrientationAdjustment(ref l_data.m_rightHand.m_position, ref l_data.m_rightHand.m_rotation, Settings.TrackingMode);
for(int i = 0; i < 20; i++)
OrientationAdjustment(ref l_data.m_rightHand.m_fingerPosition[i], ref l_data.m_rightHand.m_fingerRotation[i], Settings.TrackingMode);
m_leapHandRight.transform.localPosition = l_data.m_rightHand.m_position;
m_leapHandRight.transform.localRotation = l_data.m_rightHand.m_rotation;
Utils.LeapToUnity(ref l_data.m_rightHand.m_elbowPosition, ref ms_identityRotation, Settings.TrackingMode);
OrientationAdjustment(ref l_data.m_rightHand.m_elbowPosition, ref ms_dummyRotation, Settings.TrackingMode);
m_leapElbowRight.transform.localPosition = l_data.m_rightHand.m_elbowPosition;
if(Settings.VisualHands)
m_visualHandRight?.Update(l_data.m_rightHand);
}
}
}
@ -136,6 +167,11 @@ namespace ml_lme
m_leapControllerModel.SetActive(p_state);
}
void OnVisualHandsChange(bool p_state)
{
m_visualHands.SetActive(p_state);
}
void OnTrackingModeChange(Settings.LeapTrackingMode p_mode)
{
switch(p_mode)
@ -198,5 +234,27 @@ namespace ml_lme
m_scaleRelation = p_relation;
OnHeadAttachChange(Settings.HeadAttach);
}
static void OrientationAdjustment(ref Vector3 p_pos, ref Quaternion p_rot, Settings.LeapTrackingMode p_mode)
{
switch(p_mode)
{
case Settings.LeapTrackingMode.Screentop:
{
p_pos.x *= -1f;
p_pos.y *= -1f;
p_rot = (ms_screentopRotation * p_rot);
}
break;
case Settings.LeapTrackingMode.HMD:
{
p_pos.x *= -1f;
Utils.Swap(ref p_pos.y, ref p_pos.z);
p_rot = (ms_hmdRotation * p_rot);
}
break;
}
}
}
}

View file

@ -34,7 +34,8 @@ namespace ml_lme
TrackElbows,
Input,
InteractThreadhold,
GripThreadhold
GripThreadhold,
VisualHands
};
public static bool Enabled { get; private set; } = false;
@ -49,6 +50,7 @@ namespace ml_lme
public static bool Input { get; private set; } = true;
public static float InteractThreadhold { get; private set; } = 0.8f;
public static float GripThreadhold { get; private set; } = 0.4f;
public static bool VisualHands { get; private set; } = false;
static MelonLoader.MelonPreferences_Category ms_category = null;
static List<MelonLoader.MelonPreferences_Entry> ms_entries = null;
@ -65,6 +67,7 @@ namespace ml_lme
static public event Action<bool> InputChange;
static public event Action<float> InteractThreadholdChange;
static public event Action<float> GripThreadholdChange;
static public event Action<bool> VisualHandsChange;
internal static void Init()
{
@ -90,6 +93,7 @@ namespace ml_lme
ms_category.CreateEntry(ModSetting.Input.ToString(), Input),
ms_category.CreateEntry(ModSetting.InteractThreadhold.ToString(), (int)(InteractThreadhold * 100f)),
ms_category.CreateEntry(ModSetting.GripThreadhold.ToString(), (int)(GripThreadhold * 100f)),
ms_category.CreateEntry(ModSetting.VisualHands.ToString(), VisualHands)
};
Load();
@ -146,6 +150,7 @@ namespace ml_lme
Input = (bool)ms_entries[(int)ModSetting.Input].BoxedValue;
InteractThreadhold = (int)ms_entries[(int)ModSetting.InteractThreadhold].BoxedValue * 0.01f;
GripThreadhold = (int)ms_entries[(int)ModSetting.GripThreadhold].BoxedValue * 0.01f;
VisualHands = (bool)ms_entries[(int)ModSetting.VisualHands].BoxedValue;
}
static void OnToggleUpdate(string p_name, string p_value)
@ -195,6 +200,13 @@ namespace ml_lme
InputChange?.Invoke(Input);
}
break;
case ModSetting.VisualHands:
{
VisualHands = bool.Parse(p_value);
VisualHandsChange?.Invoke(VisualHands);
}
break;
}
ms_entries[(int)l_setting].BoxedValue = bool.Parse(p_value);

View file

@ -10,9 +10,6 @@ namespace ml_lme
{
static class Utils
{
static readonly Quaternion ms_hmdRotationFix = new Quaternion(0f, 0.7071068f, 0.7071068f, 0f);
static readonly Quaternion ms_screentopRotationFix = new Quaternion(0f, 0f, -1f, 0f);
static FieldInfo ms_cohtmlView = typeof(CohtmlControlledViewDisposable).GetField("_view", BindingFlags.NonPublic | BindingFlags.Instance);
public static bool IsInVR() => ((CheckVR.Instance != null) && CheckVR.Instance.hasVrDeviceLoaded);
@ -38,38 +35,18 @@ namespace ml_lme
public static void ExecuteScript(this CohtmlControlledViewDisposable p_instance, string p_script) => ((cohtml.Net.View)ms_cohtmlView.GetValue(p_instance))?.ExecuteScript(p_script);
public static void LeapToUnity(ref Vector3 p_pos, ref Quaternion p_rot, Settings.LeapTrackingMode p_mode)
{
p_pos *= 0.001f;
p_pos.z *= -1f;
p_rot.x *= -1f;
p_rot.y *= -1f;
switch(p_mode)
{
case Settings.LeapTrackingMode.Screentop:
{
p_pos.x *= -1f;
p_pos.y *= -1f;
p_rot = (ms_screentopRotationFix * p_rot);
}
break;
case Settings.LeapTrackingMode.HMD:
{
p_pos.x *= -1f;
Swap(ref p_pos.y, ref p_pos.z);
p_rot = (ms_hmdRotationFix * p_rot);
}
break;
}
}
public static void Swap<T>(ref T lhs, ref T rhs)
{
T temp = lhs;
lhs = rhs;
rhs = temp;
}
public static float InverseLerpUnclamped(float a, float b, float value)
{
if(a != b)
return (value - a) / (b - a);
return 0f;
}
}
}

71
ml_lme/VisualHand.cs Normal file
View file

@ -0,0 +1,71 @@
using UnityEngine;
namespace ml_lme
{
class VisualHand
{
Transform m_root = null;
Transform m_wrist = null;
Transform[] m_fingers = null;
public VisualHand(Transform p_root, bool p_left)
{
m_root = p_root;
if(m_root != null)
{
m_wrist = m_root.Find(p_left ? "LeftHand/Wrist" : "RightHand/Wrist");
if(m_wrist != null)
{
m_fingers = new Transform[20];
m_fingers[0] = null; // Actual thumb-meta, look at Leap Motion docs, dummy
m_fingers[1] = m_wrist.Find("thumb_meta");
m_fingers[2] = m_wrist.Find("thumb_meta/thumb_a");
m_fingers[3] = m_wrist.Find("thumb_meta/thumb_a/thumb_b");
m_fingers[4] = m_wrist.Find("index_meta");
m_fingers[5] = m_wrist.Find("index_meta/index_a");
m_fingers[6] = m_wrist.Find("index_meta/index_a/index_b");
m_fingers[7] = m_wrist.Find("index_meta/index_a/index_b/index_c");
m_fingers[8] = m_wrist.Find("middle_meta");
m_fingers[9] = m_wrist.Find("middle_meta/middle_a");
m_fingers[10] = m_wrist.Find("middle_meta/middle_a/middle_b");
m_fingers[11] = m_wrist.Find("middle_meta/middle_a/middle_b/middle_c");
m_fingers[12] = m_wrist.Find("ring_meta");
m_fingers[13] = m_wrist.Find("ring_meta/ring_a");
m_fingers[14] = m_wrist.Find("ring_meta/ring_a/ring_b");
m_fingers[15] = m_wrist.Find("ring_meta/ring_a/ring_b/ring_c");
m_fingers[16] = m_wrist.Find("pinky_meta");
m_fingers[17] = m_wrist.Find("pinky_meta/pinky_a");
m_fingers[18] = m_wrist.Find("pinky_meta/pinky_a/pinky_b");
m_fingers[19] = m_wrist.Find("pinky_meta/pinky_a/pinky_b/pinky_c");
}
}
}
public void Update(GestureMatcher.HandData p_data)
{
if(m_wrist != null)
{
m_wrist.position = p_data.m_position;
m_wrist.rotation = p_data.m_rotation;
for(int i = 0; i < 20; i++)
{
if(m_fingers[i] != null)
{
//m_fingers[i].position = p_data.m_fingerPosition[i];
m_fingers[i].rotation = p_data.m_fingerRotation[i];
}
}
m_wrist.localPosition = p_data.m_position;
m_wrist.localRotation = p_data.m_rotation;
}
}
}
}

View file

@ -4,7 +4,7 @@
<TargetFramework>netstandard2.1</TargetFramework>
<Platforms>x64</Platforms>
<PackageId>LeapMotionExtension</PackageId>
<Version>1.3.7</Version>
<Version>1.3.8</Version>
<Authors>SDraw</Authors>
<Company>None</Company>
<Product>LeapMotionExtension</Product>
@ -24,11 +24,13 @@
<ItemGroup>
<None Remove="LeapMotionExtension.json" />
<None Remove="resources\leapmotion_controller.asset" />
<None Remove="resources\leapmotion_hands.asset" />
<None Remove="resources\menu.js" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="resources\leapmotion_controller.asset" />
<EmbeddedResource Include="resources\leapmotion_hands.asset" />
<EmbeddedResource Include="resources\menu.js" />
<EmbeddedResource Include="vendor\LeapSDK\lib\x64\LeapC.dll">
<Link>LeapC.dll</Link>
@ -86,6 +88,10 @@
</Reference>
</ItemGroup>
<ItemGroup>
<Folder Include="vendor\LeapCSharp\" />
</ItemGroup>
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
<Exec Command="copy /y &quot;$(TargetPath)&quot; &quot;D:\Games\Steam\steamapps\common\ChilloutVR\Mods\&quot;" />
</Target>

Binary file not shown.

View file

@ -385,6 +385,13 @@ function inp_dropdown_mod_lme(_obj, _callbackName) {
</div>
</div>
<div class ="row-wrapper">
<div class ="option-caption">Visualize hands: </div>
<div class ="option-input">
<div id="VisualHands" class ="inp_toggle no-scroll" data-current="false"></div>
</div>
</div>
<div class ="row-wrapper">
<div class ="option-caption">Interaction input: </div>
<div class ="option-input">

View file

@ -1,5 +1,5 @@
/******************************************************************************
* Copyright (C) Ultraleap, Inc. 2011-2021. *
* Copyright (C) Ultraleap, Inc. 2011-2023. *
* *
* Use subject to the terms of the Apache License 2.0 available at *
* http://www.apache.org/licenses/LICENSE-2.0, or another agreement *
@ -26,27 +26,6 @@ namespace Leap
/// </summary>
public Arm() : base() { }
/// <summary>
/// Constructs a new Arm object.
/// @since 3.0
/// </summary>
[System.Obsolete("This signature will be removed in the next major version of the plugin. Use the one with Vector3 and Quaternion instead.")]
public Arm(Vector elbow,
Vector wrist,
Vector center,
Vector direction,
float length,
float width,
LeapQuaternion rotation)
: base(elbow,
wrist,
center,
direction,
length,
width,
BoneType.TYPE_METACARPAL, //ignored for arms
rotation)
{ }
/// <summary>
/// Constructs a new Arm object.
/// </summary>
@ -94,8 +73,7 @@ namespace Leap
///
/// @since 2.0.3
/// </summary>
[System.Obsolete("Its type will be changed from Vector to Vector3")]
public Vector ElbowPosition
public Vector3 ElbowPosition
{
get
{
@ -112,8 +90,7 @@ namespace Leap
///
/// @since 2.0.3
/// </summary>
[System.Obsolete("Its type will be changed from Vector to Vector3")]
public Vector WristPosition
public Vector3 WristPosition
{
get
{

View file

@ -1,5 +1,5 @@
/******************************************************************************
* Copyright (C) Ultraleap, Inc. 2011-2021. *
* Copyright (C) Ultraleap, Inc. 2011-2023. *
* *
* Use subject to the terms of the Apache License 2.0 available at *
* http://www.apache.org/licenses/LICENSE-2.0, or another agreement *
@ -27,7 +27,6 @@ namespace Leap
[Serializable]
public class Bone : IEquatable<Bone>
{
#pragma warning disable 0618
/// <summary>
/// Constructs a default invalid Bone object.
///
@ -38,30 +37,6 @@ namespace Leap
Type = BoneType.TYPE_INVALID;
}
/// <summary>
/// Constructs a new Bone object.
/// @since 3.0
/// </summary>
[System.Obsolete("This signature will be removed in the next major version of the plugin. Use Bone with Vector3s instead. If you believe that it needs to be kept, please open a discussion on the GitHub forum (https://github.com/ultraleap/UnityPlugin/discussions)")]
public Bone(Vector prevJoint,
Vector nextJoint,
Vector center,
Vector direction,
float length,
float width,
Bone.BoneType type,
LeapQuaternion rotation)
{
PrevJoint = prevJoint;
NextJoint = nextJoint;
Center = center;
Direction = direction;
Rotation = rotation;
Length = length;
Width = width;
Type = type;
}
/// <summary>
/// Constructs a new Bone object.
/// @since 3.0
@ -75,11 +50,11 @@ namespace Leap
Bone.BoneType type,
Quaternion rotation)
{
PrevJoint = new Vector(prevJoint.x, prevJoint.y, prevJoint.z);
NextJoint = new Vector(nextJoint.x, nextJoint.y, nextJoint.z);
Center = new Vector(center.x, center.y, center.z);
Direction = new Vector(direction.x, direction.y, direction.z);
Rotation = new LeapQuaternion(rotation.x, rotation.y, rotation.z, rotation.w);
PrevJoint = prevJoint;
NextJoint = nextJoint;
Center = center;
Direction = direction;
Rotation = rotation;
Length = length;
Width = width;
Type = type;
@ -111,31 +86,27 @@ namespace Leap
/// In anatomical terms, this is the proximal end of the bone.
/// @since 2.0
/// </summary>
[System.Obsolete("Its type will be changed from Vector to Vector3")]
public Vector PrevJoint;
public Vector3 PrevJoint;
/// <summary>
/// The end of the bone, closest to the finger tip.
/// In anatomical terms, this is the distal end of the bone.
/// @since 2.0
/// </summary>
[System.Obsolete("Its type will be changed from Vector to Vector3")]
public Vector NextJoint;
public Vector3 NextJoint;
/// <summary>
/// The midpoint of the bone.
/// @since 2.0
/// </summary>
[System.Obsolete("Its type will be changed from Vector to Vector3")]
public Vector Center;
public Vector3 Center;
/// <summary>
/// The normalized direction of the bone from base to tip.
/// @since 2.0
/// </summary>
[System.Obsolete("Its type will be changed from Vector to Vector3")]
public Vector Direction;
public Vector3 Direction;
/// <summary>
/// The estimated length of the bone.
@ -159,8 +130,9 @@ namespace Leap
/// The orientation of this Bone as a Quaternion.
/// @since 2.0
/// </summary>
[System.Obsolete("Its type will be changed from LeapQuaternion to UnityEngine.Quaternion")]
public LeapQuaternion Rotation;
public Quaternion Rotation;
LeapTransform _basis = new LeapTransform(Vector3.one, Quaternion.identity);
/// <summary>
/// The orthonormal basis vectors for this Bone as a Matrix.
@ -193,7 +165,16 @@ namespace Leap
///
/// @since 2.0
/// </summary>
public LeapTransform Basis { get { return new LeapTransform(PrevJoint, Rotation); } }
public LeapTransform Basis
{
get
{
_basis.translation = PrevJoint;
_basis.rotation = Rotation;
return _basis;
}
}
/// <summary>
/// Enumerates the type of bones.
@ -210,7 +191,5 @@ namespace Leap
TYPE_INTERMEDIATE = 2,
TYPE_DISTAL = 3
}
#pragma warning restore 0618
}
}

View file

@ -1,5 +1,5 @@
/******************************************************************************
* Copyright (C) Ultraleap, Inc. 2011-2021. *
* Copyright (C) Ultraleap, Inc. 2011-2023. *
* *
* Use subject to the terms of the Apache License 2.0 available at *
* http://www.apache.org/licenses/LICENSE-2.0, or another agreement *

View file

@ -1,5 +1,5 @@
/******************************************************************************
* Copyright (C) Ultraleap, Inc. 2011-2021. *
* Copyright (C) Ultraleap, Inc. 2011-2023. *
* *
* Use subject to the terms of the Apache License 2.0 available at *
* http://www.apache.org/licenses/LICENSE-2.0, or another agreement *

View file

@ -1,5 +1,5 @@
/******************************************************************************
* Copyright (C) Ultraleap, Inc. 2011-2021. *
* Copyright (C) Ultraleap, Inc. 2011-2023. *
* *
* Use subject to the terms of the Apache License 2.0 available at *
* http://www.apache.org/licenses/LICENSE-2.0, or another agreement *
@ -119,66 +119,6 @@ namespace Leap
return false;
}
[Obsolete("Use the generic Set<T> method instead.")]
public ValueType Type(string key)
{
return ValueType.TYPE_UNKNOWN;
}
[Obsolete("Use the generic Get<T> method instead.")]
public bool GetBool(string key)
{
return false;
}
[Obsolete("Use the generic Set<T> method instead.")]
public bool SetBool(string key, bool value)
{
return false;
}
[Obsolete("Use the generic Get<T> method instead.")]
public bool GetInt32(string key)
{
return false;
}
[Obsolete("Use the generic Set<T> method instead.")]
public bool SetInt32(string key, int value)
{
return false;
}
[Obsolete("Use the generic Get<T> method instead.")]
public bool GetFloat(string key)
{
return false;
}
[Obsolete("Use the generic Set<T> method instead.")]
public bool SetFloat(string key, float value)
{
return false;
}
[Obsolete("Use the generic Get<T> method instead.")]
public bool GetString(string key)
{
return false;
}
[Obsolete("Use the generic Set<T> method instead.")]
public bool SetString(string key, string value)
{
return false;
}
[Obsolete]
public bool Save()
{
return false;
}
/// <summary>
/// Enumerates the possible data types for configuration values.
/// @since 1.0

View file

@ -1,5 +1,5 @@
/******************************************************************************
* Copyright (C) Ultraleap, Inc. 2011-2021. *
* Copyright (C) Ultraleap, Inc. 2011-2023. *
* *
* Use subject to the terms of the Apache License 2.0 available at *
* http://www.apache.org/licenses/LICENSE-2.0, or another agreement *
@ -21,7 +21,7 @@ namespace LeapInternal
public readonly int connectionId;
public readonly string serverNamespace;
public Key(int connectionId, string serverNamespace = null)
public Key(int connectionId, string serverNamespace = "Leap Service")
{
this.connectionId = connectionId;
this.serverNamespace = serverNamespace;
@ -417,6 +417,11 @@ namespace LeapInternal
{
LeapFrame.DispatchOnContext(this, EventContext, new FrameEventArgs(new Frame(deviceID).CopyFrom(ref trackingMsg)));
}
if (LeapInternalFrame != null)
{
LeapInternalFrame.DispatchOnContext(this, EventContext, new InternalFrameEventArgs(ref trackingMsg));
}
}
@ -853,6 +858,7 @@ namespace LeapInternal
//since the distortion struct cannot be represented safely in c#
distortionData.Data = new float[(int)(distortionData.Width * distortionData.Height * 2)]; //2 float values per map point
Marshal.Copy(image.distortionMatrix, distortionData.Data, 0, distortionData.Data.Length);
distortionData.OnDataChanged();
if (LeapDistortionChange != null)
{
@ -1019,6 +1025,56 @@ namespace LeapInternal
}
}
/// <summary>
/// Temporarily makes a connection to determine if a Service is available.
/// Returns the result and closes the temporary connection upon completion.
/// </summary>
public static bool IsConnectionAvailable(string serverNamespace = "Leap Service")
{
LEAP_CONNECTION_CONFIG config = new LEAP_CONNECTION_CONFIG();
config.server_namespace = Marshal.StringToHGlobalAnsi(serverNamespace);
config.flags = 0;
config.size = (uint)Marshal.SizeOf(config);
IntPtr tempConnection;
eLeapRS result;
result = LeapC.CreateConnection(ref config, out tempConnection);
if (result != eLeapRS.eLeapRS_Success || tempConnection == IntPtr.Zero)
{
LeapC.CloseConnection(tempConnection);
return false;
}
result = LeapC.OpenConnection(tempConnection);
if (result != eLeapRS.eLeapRS_Success)
{
LeapC.CloseConnection(tempConnection);
return false;
}
LEAP_CONNECTION_MESSAGE _msg = new LEAP_CONNECTION_MESSAGE();
uint timeout = 150;
result = LeapC.PollConnection(tempConnection, timeout, ref _msg);
LEAP_CONNECTION_INFO pInfo = new LEAP_CONNECTION_INFO();
pInfo.size = (uint)Marshal.SizeOf(pInfo);
result = LeapC.GetConnectionInfo(tempConnection, ref pInfo);
if (pInfo.status == eLeapConnectionStatus.eLeapConnectionStatus_Connected)
{
LeapC.CloseConnection(tempConnection);
return true;
}
LeapC.CloseConnection(tempConnection);
return false;
}
/// <summary>
/// Gets the active setting for a specific policy.
///
@ -1056,6 +1112,17 @@ namespace LeapInternal
return false;
}
public bool IsDeviceAvailable(Device device = null)
{
uint deviceID = 0;
if (device != null)
{
deviceID = device.DeviceID;
}
return _activePolicies.ContainsKey(deviceID);
}
public uint GetConfigValue(string config_key)
{
uint requestId = 0;
@ -1186,21 +1253,6 @@ namespace LeapInternal
reportAbnormalResults("LeapC UnsubscribeEvents call was ", result);
}
/// <summary>
/// Converts from image-space pixel coordinates to camera-space rectilinear coordinates
/// </summary>
[System.Obsolete("This signature will be removed in the next major version of the plugin. Use the one with Vector3 instead.")]
public Vector PixelToRectilinear(Image.CameraType camera, Vector pixel)
{
LEAP_VECTOR pixelStruct = new LEAP_VECTOR(pixel);
LEAP_VECTOR ray = LeapC.LeapPixelToRectilinear(_leapConnection,
(camera == Image.CameraType.LEFT ?
eLeapPerspectiveType.eLeapPerspectiveType_stereo_left :
eLeapPerspectiveType.eLeapPerspectiveType_stereo_right),
pixelStruct);
return new Vector(ray.x, ray.y, ray.z);
}
/// <summary>
/// Converts from image-space pixel coordinates to camera-space rectilinear coordinates
/// </summary>
@ -1215,29 +1267,6 @@ namespace LeapInternal
return new UnityEngine.Vector3(ray.x, ray.y, ray.z);
}
/// <summary>
/// Converts from image-space pixel coordinates to camera-space rectilinear coordinates
///
/// Also allows specifying a specific device handle and calibration type.
///
/// @since 4.1
/// </summary>
[System.Obsolete("This signature will be removed in the next major version of the plugin. Use the one with Vector3 instead.")]
public Vector PixelToRectilinearEx(IntPtr deviceHandle,
Image.CameraType camera, Image.CalibrationType calibType, Vector pixel)
{
LEAP_VECTOR pixelStruct = new LEAP_VECTOR(pixel);
LEAP_VECTOR ray = LeapC.LeapPixelToRectilinearEx(_leapConnection,
deviceHandle,
(camera == Image.CameraType.LEFT ?
eLeapPerspectiveType.eLeapPerspectiveType_stereo_left :
eLeapPerspectiveType.eLeapPerspectiveType_stereo_right),
(calibType == Image.CalibrationType.INFRARED ?
eLeapCameraCalibrationType.eLeapCameraCalibrationType_infrared :
eLeapCameraCalibrationType.eLeapCameraCalibrationType_visual),
pixelStruct);
return new Vector(ray.x, ray.y, ray.z);
}
/// <summary>
/// Converts from image-space pixel coordinates to camera-space rectilinear coordinates
///
@ -1262,8 +1291,7 @@ namespace LeapInternal
/// <summary>
/// Converts from camera-space rectilinear coordinates to image-space pixel coordinates
/// </summary>
[System.Obsolete("This signature will be removed in the next major version of the plugin. Use the one with Vector3 instead.")]
public Vector RectilinearToPixel(Image.CameraType camera, Vector ray)
public UnityEngine.Vector3 RectilinearToPixel(Image.CameraType camera, UnityEngine.Vector3 ray)
{
LEAP_VECTOR rayStruct = new LEAP_VECTOR(ray);
LEAP_VECTOR pixel = LeapC.LeapRectilinearToPixel(_leapConnection,
@ -1271,15 +1299,20 @@ namespace LeapInternal
eLeapPerspectiveType.eLeapPerspectiveType_stereo_left :
eLeapPerspectiveType.eLeapPerspectiveType_stereo_right),
rayStruct);
return new Vector(pixel.x, pixel.y, pixel.z);
return new UnityEngine.Vector3(pixel.x, pixel.y, pixel.z);
}
/// <summary>
/// Converts from camera-space rectilinear coordinates to image-space pixel coordinates
///
/// Also allows specifying a specific device handle and calibration type.
/// </summary>
public UnityEngine.Vector3 RectilinearToPixel(Image.CameraType camera, UnityEngine.Vector3 ray)
public UnityEngine.Vector3 RectilinearToPixelEx(IntPtr deviceHandle,
Image.CameraType camera, UnityEngine.Vector3 ray)
{
LEAP_VECTOR rayStruct = new LEAP_VECTOR(ray);
LEAP_VECTOR pixel = LeapC.LeapRectilinearToPixel(_leapConnection,
LEAP_VECTOR pixel = LeapC.LeapRectilinearToPixelEx(_leapConnection,
deviceHandle,
(camera == Image.CameraType.LEFT ?
eLeapPerspectiveType.eLeapPerspectiveType_stereo_left :
eLeapPerspectiveType.eLeapPerspectiveType_stereo_right),
@ -1322,9 +1355,7 @@ namespace LeapInternal
pm.frameId = pmi.frame_id;
pm.timestamp = pmi.timestamp;
#pragma warning disable 0618
pm.points = new Vector[nPoints];
#pragma warning restore 0618
pm.points = new UnityEngine.Vector3[nPoints];
pm.ids = new UInt32[nPoints];
float[] points = new float[3 * nPoints];

View file

@ -1,5 +1,5 @@
/******************************************************************************
* Copyright (C) Ultraleap, Inc. 2011-2021. *
* Copyright (C) Ultraleap, Inc. 2011-2023. *
* *
* Use subject to the terms of the Apache License 2.0 available at *
* http://www.apache.org/licenses/LICENSE-2.0, or another agreement *
@ -542,25 +542,6 @@ namespace Leap
return Controller.CheckRequiredServiceVersion(minServiceVersion, _connection);
}
/// <summary>
/// Requests setting and clearing policy flags on a specific device
///
/// A request to change a policy is subject to user approval and a policy
/// can be changed by the user at any time (using the Leap Motion settings dialog).
/// The desired policy flags must be set every time an application runs.
///
/// Policy changes are completed asynchronously and, because they are subject
/// to user approval or system compatibility checks, may not complete successfully. Call
/// Controller.IsPolicySet() after a suitable interval to test whether
/// the change was accepted.
/// @since 2.1.6 (5.4.4 for specific device)
/// </summary>
[Obsolete("This method signature will be removed in a future update. Please use the equivalent method that does not take the serial number")]
public void SetAndClearPolicy(PolicyFlag set, PolicyFlag clear, string deviceSerial = "", Device device = null)
{
_connection.SetAndClearPolicy(set, clear, device);
}
/// <summary>
/// Requests setting and clearing policy flags on a specific device
///
@ -597,25 +578,6 @@ namespace Leap
_connection.SetPolicy(policy, device);
}
/// <summary>
/// Requests setting a policy.
///
/// A request to change a policy is subject to user approval and a policy
/// can be changed by the user at any time (using the Leap Motion settings dialog).
/// The desired policy flags must be set every time an application runs.
///
/// Policy changes are completed asynchronously and, because they are subject
/// to user approval or system compatibility checks, may not complete successfully. Call
/// Controller.IsPolicySet() after a suitable interval to test whether
/// the change was accepted.
/// @since 2.1.6
/// </summary>
[Obsolete("Use the version of SetPolicy that also takes the device")]
public void SetPolicy(PolicyFlag policy)
{
SetPolicy(policy, null);
}
/// <summary>
/// Requests clearing a policy on a specific device
///
@ -630,21 +592,6 @@ namespace Leap
_connection.ClearPolicy(policy, device);
}
/// <summary>
/// Requests clearing a policy
///
/// Policy changes are completed asynchronously and, because they are subject
/// to user approval or system compatibility checks, may not complete successfully. Call
/// Controller.IsPolicySet() after a suitable interval to test whether
/// the change was accepted.
/// @since 2.1.6
/// </summary>
[Obsolete("Use the version of ClearPolicy that also takes the device")]
public void ClearPolicy(PolicyFlag policy)
{
ClearPolicy(policy, null);
}
/// <summary>
/// Gets the active setting for a specific device.
///
@ -665,22 +612,14 @@ namespace Leap
}
/// <summary>
/// Gets the active setting
/// Checks if the specified device is available.
///
/// Keep in mind that setting a policy flag is asynchronous, so changes are
/// not effective immediately after calling setPolicyFlag(). In addition, a
/// policy request can be declined by the user. You should always set the
/// policy flags required by your application at startup and check that the
/// policy change request was successful after an appropriate interval.
///
/// If the controller object is not connected to the Leap Motion software, then the default
/// state for the selected policy is returned.
///
/// @since 2.1.6
[Obsolete("Use the version of IsPolicySet that also takes the device")]
public bool IsPolicySet(PolicyFlag policy)
/// Device availability is determined by checking it has active policy flags set against it
/// via its connection.
/// </summary>
public bool IsDeviceAvailable(Device device = null)
{
return IsPolicySet(policy, null);
return _connection.IsDeviceAvailable(device);
}
/// <summary>

View file

@ -1,5 +1,5 @@
/******************************************************************************
* Copyright (C) Ultraleap, Inc. 2011-2021. *
* Copyright (C) Ultraleap, Inc. 2011-2023. *
* *
* Use subject to the terms of the Apache License 2.0 available at *
* http://www.apache.org/licenses/LICENSE-2.0, or another agreement *
@ -9,9 +9,19 @@
namespace LeapInternal
{
using Leap;
#pragma warning disable 0618
using UnityEngine;
public static class CopyFromLeapCExtensions
{
public static readonly float MM_TO_M = 1e-3f;
public static void TransformToUnityUnits(this Hand hand)
{
LeapTransform leapTransform = new LeapTransform(Vector3.zero, Quaternion.identity, new Vector3(MM_TO_M, MM_TO_M, MM_TO_M));
leapTransform.MirrorZ();
hand.Transform(leapTransform);
}
/**
* Copies the data from an internal tracking message into a frame.
@ -42,7 +52,7 @@ namespace LeapInternal
* @param leapHand The internal hand definition to be copied into this hand.
* @param frameId The frame id of the frame this hand belongs to.
*/
public static Hand CopyFrom(this Hand hand, ref LEAP_HAND leapHand, long frameId)
private static Hand CopyFrom(this Hand hand, ref LEAP_HAND leapHand, long frameId)
{
hand.FrameId = frameId;
hand.Id = (int)leapHand.id;
@ -51,18 +61,17 @@ namespace LeapInternal
hand.Confidence = leapHand.confidence;
hand.GrabStrength = leapHand.grab_strength;
hand.GrabAngle = leapHand.grab_angle;
hand.PinchStrength = leapHand.pinch_strength;
hand.PinchDistance = leapHand.pinch_distance;
hand.PalmWidth = leapHand.palm.width;
hand.IsLeft = leapHand.type == eLeapHandType.eLeapHandType_Left;
hand.TimeVisible = (float)(leapHand.visible_time * 1e-6);
hand.PalmPosition = leapHand.palm.position.ToLeapVector();
hand.StabilizedPalmPosition = leapHand.palm.stabilized_position.ToLeapVector();
hand.PalmVelocity = leapHand.palm.velocity.ToLeapVector();
hand.PalmNormal = leapHand.palm.normal.ToLeapVector();
hand.Rotation = leapHand.palm.orientation.ToLeapQuaternion();
hand.Direction = leapHand.palm.direction.ToLeapVector();
hand.PalmPosition = leapHand.palm.position.ToVector3();
hand.StabilizedPalmPosition = leapHand.palm.stabilized_position.ToVector3();
hand.PalmVelocity = leapHand.palm.velocity.ToVector3();
hand.PalmNormal = leapHand.palm.normal.ToVector3();
hand.Rotation = leapHand.palm.orientation.ToQuaternion();
hand.Direction = leapHand.palm.direction.ToVector3();
hand.WristPosition = hand.Arm.NextJoint;
hand.Fingers[0].CopyFrom(leapHand.thumb, Leap.Finger.FingerType.TYPE_THUMB, hand.Id, hand.TimeVisible);
@ -71,6 +80,8 @@ namespace LeapInternal
hand.Fingers[3].CopyFrom(leapHand.ring, Leap.Finger.FingerType.TYPE_RING, hand.Id, hand.TimeVisible);
hand.Fingers[4].CopyFrom(leapHand.pinky, Leap.Finger.FingerType.TYPE_PINKY, hand.Id, hand.TimeVisible);
hand.TransformToUnityUnits();
return hand;
}
@ -83,7 +94,7 @@ namespace LeapInternal
* @param handId The hand id of the hand this finger belongs to.
* @param timeVisible The time in seconds that this finger has been visible.
*/
public static Finger CopyFrom(this Finger finger, LEAP_DIGIT leapBone, Finger.FingerType type, int handId, float timeVisible)
private static Finger CopyFrom(this Finger finger, LEAP_DIGIT leapBone, Finger.FingerType type, int handId, float timeVisible)
{
finger.Id = (handId * 10) + leapBone.finger_id;
finger.HandId = handId;
@ -115,17 +126,17 @@ namespace LeapInternal
* @param leapBone The internal bone definition to be copied into this bone.
* @param type The bone type of this bone.
*/
public static Bone CopyFrom(this Bone bone, LEAP_BONE leapBone, Bone.BoneType type)
private static Bone CopyFrom(this Bone bone, LEAP_BONE leapBone, Bone.BoneType type)
{
bone.Type = type;
bone.PrevJoint = leapBone.prev_joint.ToLeapVector();
bone.NextJoint = leapBone.next_joint.ToLeapVector();
bone.PrevJoint = leapBone.prev_joint.ToVector3();
bone.NextJoint = leapBone.next_joint.ToVector3();
bone.Direction = (bone.NextJoint - bone.PrevJoint);
bone.Length = bone.Direction.Magnitude;
bone.Length = bone.Direction.magnitude;
if (bone.Length < float.Epsilon)
{
bone.Direction = Vector.Zero;
bone.Direction = Vector3.zero;
}
else
{
@ -133,11 +144,10 @@ namespace LeapInternal
}
bone.Center = (bone.PrevJoint + bone.NextJoint) / 2.0f;
bone.Rotation = leapBone.rotation.ToLeapQuaternion();
bone.Rotation = leapBone.rotation.ToQuaternion();
bone.Width = leapBone.width;
return bone;
}
}
#pragma warning restore 0618
}

View file

@ -1,5 +1,5 @@
/******************************************************************************
* Copyright (C) Ultraleap, Inc. 2011-2021. *
* Copyright (C) Ultraleap, Inc. 2011-2023. *
* *
* Use subject to the terms of the Apache License 2.0 available at *
* http://www.apache.org/licenses/LICENSE-2.0, or another agreement *
@ -8,7 +8,6 @@
namespace Leap
{
#pragma warning disable 0618
public static class CopyFromOtherExtensions
{
@ -46,7 +45,6 @@ namespace Leap
hand.Id = source.Id;
hand.Confidence = source.Confidence;
hand.GrabStrength = source.GrabStrength;
hand.GrabAngle = source.GrabAngle;
hand.Rotation = source.Rotation;
hand.PinchStrength = source.PinchStrength;
hand.PinchDistance = source.PinchDistance;
@ -117,5 +115,4 @@ namespace Leap
return bone;
}
}
#pragma warning restore 0618
}

View file

@ -1,11 +1,13 @@
/******************************************************************************
* Copyright (C) Ultraleap, Inc. 2011-2021. *
* Copyright (C) Ultraleap, Inc. 2011-2023. *
* *
* Use subject to the terms of the Apache License 2.0 available at *
* http://www.apache.org/licenses/LICENSE-2.0, or another agreement *
* between Ultraleap and you, your company or other organization. *
******************************************************************************/
using UnityEngine;
namespace Leap
{
using LeapInternal;
@ -53,7 +55,6 @@ namespace Leap
uint deviceID)
{
Handle = deviceHandle;
InternalHandle = internalHandle;
HorizontalViewAngle = horizontalViewAngle;
VerticalViewAngle = verticalViewAngle;
Range = range;
@ -139,12 +140,10 @@ namespace Leap
/// </summary>
public IntPtr Handle { get; private set; }
private IntPtr InternalHandle;
[Obsolete("Use LeapC.SetLeapPause instead")]
public bool SetPaused(bool pause)
{
eLeapRS result = LeapC.LeapSetPause(Handle, pause);
return result == eLeapRS.eLeapRS_Success;
return false;
}
/// <summary>
@ -246,10 +245,57 @@ namespace Leap
/// <summary>
/// Reports the ID assoicated with the device
///
/// </summary>
public uint DeviceID { get; private set; }
private bool poseSet = false;
private Pose devicePose = Pose.identity;
/// <summary>
/// The transform to world coordinates from 3D Leap coordinates.
/// </summary>
public Pose DevicePose
{
get
{
if (poseSet) // Assumes the devicePose never changes and so, uses the cached pose.
{
return devicePose;
}
//float[] data = new float[16];
//eLeapRS result = LeapC.GetDeviceTransform(Handle, data);
//if (result != eLeapRS.eLeapRS_Success || data == null)
//{
// devicePose = Pose.identity;
// return devicePose;
//}
//// Get transform matrix and convert to unity space by inverting Z.
//Matrix4x4 transformMatrix = new Matrix4x4(
// new Vector4(data[0], data[1], data[2], data[3]),
// new Vector4(data[4], data[5], data[6], data[7]),
// new Vector4(data[8], data[9], data[10], data[11]),
// new Vector4(data[12], data[13], data[14], data[15]));
//Matrix4x4 toUnity = Matrix4x4.Scale(new Vector3(1, 1, -1));
//transformMatrix = toUnity * transformMatrix;
//// Identity matrix here means we have no device transform, also check validity.
//if (transformMatrix.isIdentity || !transformMatrix.ValidTRS())
//{
// devicePose = Pose.identity;
// return devicePose;
//}
//// Return the valid pose
//devicePose = new Pose(transformMatrix.GetColumn(3), transformMatrix.rotation);
poseSet = true;
return devicePose;
}
}
/// <summary>
/// Returns the internal status field of the current device
/// </summary>
@ -260,7 +306,7 @@ namespace Leap
LEAP_DEVICE_INFO deviceInfo = new LEAP_DEVICE_INFO();
deviceInfo.serial = IntPtr.Zero;
deviceInfo.size = (uint)System.Runtime.InteropServices.Marshal.SizeOf(deviceInfo);
result = LeapC.GetDeviceInfo(InternalHandle, ref deviceInfo);
result = LeapC.GetDeviceInfo(Handle, ref deviceInfo);
if (result != eLeapRS.eLeapRS_Success)
return 0;
@ -329,10 +375,10 @@ namespace Leap
/// </summary>
TYPE_3DI = (int)eLeapDeviceType.eLeapDevicePID_3Di,
[Obsolete]
TYPE_LAPTOP,
[Obsolete]
TYPE_KEYBOARD
/// <summary>
/// The Ultraleap Leap Motion Controller 2 hand tracking camera.
/// </summary>
TYPE_LMC2 = (int)eLeapDeviceType.eLeapDevicePID_LMC2
}
}
}

View file

@ -1,5 +1,5 @@
/******************************************************************************
* Copyright (C) Ultraleap, Inc. 2011-2021. *
* Copyright (C) Ultraleap, Inc. 2011-2023. *
* *
* Use subject to the terms of the Apache License 2.0 available at *
* http://www.apache.org/licenses/LICENSE-2.0, or another agreement *
@ -54,33 +54,6 @@ namespace Leap
return null;
}
[Obsolete("Multiple devices can now be streaming, use ActiveDevices instead.", false)]
/// <summary>
/// The device that is currently streaming tracking data.
/// If no streaming devices are found, returns null
/// </summary>
public Device ActiveDevice
{
get
{
if (Count == 1)
{
return this[0];
}
for (int d = 0; d < Count; d++)
{
this[d].UpdateStatus(LeapInternal.eLeapDeviceStatus.eLeapDeviceStatus_Streaming);
if (this[d].IsStreaming)
{
return this[d];
}
}
return null;
}
}
/// <summary>
/// The devices that are currently streaming tracking data.
/// If no streaming devices are found, returns null

View file

@ -1,5 +1,5 @@
/******************************************************************************
* Copyright (C) Ultraleap, Inc. 2011-2021. *
* Copyright (C) Ultraleap, Inc. 2011-2023. *
* *
* Use subject to the terms of the Apache License 2.0 available at *
* http://www.apache.org/licenses/LICENSE-2.0, or another agreement *
@ -22,6 +22,9 @@ namespace Leap
/// </summary>
public class DistortionData
{
private float[] _flippedData;
private float[] _originalData;
/// <summary>
/// Constructs an uninitialized distortion object.
/// @since 3.0
@ -67,11 +70,41 @@ namespace Leap
/// </summary>
public float Height { get; set; }
/// <summary>
/// The distortion data.
/// The original distortion data, as provided by the service
///
/// @since 3.0
/// </summary>
public float[] Data { get; set; }
public float[] Data
{
get
{
return _originalData;
}
set
{
_originalData = value;
// Note, the contents of the array are normally copied into the buffer by a marshall operation,
// so the flipped data needs to be updated explicitly, not when the _orginalData member is set
}
}
/// <summary>
/// Returns the distortion data, adjusted so that a location in the distortion map texture now refers to the
/// same region of the texture containing the IR image - e.g. the bottom left of the distortion texture
/// maps to bottom left of the IR image
///
/// @since 3.0
/// </summary>
public float[] FlippedData
{
get
{
return _flippedData;
}
}
/// <summary>
/// Reports whether the distortion data is internally consistent.
/// @since 3.0
@ -89,5 +122,33 @@ namespace Leap
return false;
}
}
internal void OnDataChanged()
{
UpdateFlippedData();
}
private void UpdateFlippedData()
{
if (_originalData == null)
{
return;
}
// This is called normally once a session, so allocation is fine
float[] flipped = new float[LeapInternal.LeapC.DistortionSize * LeapInternal.LeapC.DistortionSize * 2];
for (int x = 0; x < LeapInternal.LeapC.DistortionSize; x++)
{
for (int y = 0; y < LeapInternal.LeapC.DistortionSize; y++)
{
// We change the data so that the *mapped* Y value is inverted
flipped[((x + y * LeapInternal.LeapC.DistortionSize) * 2)] = _originalData[((x + y * LeapInternal.LeapC.DistortionSize) * 2)];
flipped[((x + y * LeapInternal.LeapC.DistortionSize) * 2) + 1] = (float)1.0 - _originalData[((x + y * LeapInternal.LeapC.DistortionSize) * 2) + 1];
}
}
_flippedData = flipped;
}
}
}

View file

@ -1,5 +1,5 @@
/******************************************************************************
* Copyright (C) Ultraleap, Inc. 2011-2021. *
* Copyright (C) Ultraleap, Inc. 2011-2023. *
* *
* Use subject to the terms of the Apache License 2.0 available at *
* http://www.apache.org/licenses/LICENSE-2.0, or another agreement *
@ -113,13 +113,6 @@ namespace Leap
this.device = device;
}
[Obsolete("Use the constructor that takes the device and oldPolicyIsValid flag")]
public PolicyEventArgs(UInt64 currentPolicies, UInt64 oldPolicies) : base(LeapEvent.EVENT_POLICY_CHANGE)
{
this.currentPolicies = currentPolicies;
this.oldPolicies = oldPolicies;
}
/// <summary>
/// Current policy flags
/// </summary>

View file

@ -1,5 +1,5 @@
/******************************************************************************
* Copyright (C) Ultraleap, Inc. 2011-2021. *
* Copyright (C) Ultraleap, Inc. 2011-2023. *
* *
* Use subject to the terms of the Apache License 2.0 available at *
* http://www.apache.org/licenses/LICENSE-2.0, or another agreement *

View file

@ -1,5 +1,5 @@
/******************************************************************************
* Copyright (C) Ultraleap, Inc. 2011-2021. *
* Copyright (C) Ultraleap, Inc. 2011-2023. *
* *
* Use subject to the terms of the Apache License 2.0 available at *
* http://www.apache.org/licenses/LICENSE-2.0, or another agreement *

View file

@ -1,5 +1,5 @@
/******************************************************************************
* Copyright (C) Ultraleap, Inc. 2011-2021. *
* Copyright (C) Ultraleap, Inc. 2011-2023. *
* *
* Use subject to the terms of the Apache License 2.0 available at *
* http://www.apache.org/licenses/LICENSE-2.0, or another agreement *
@ -11,7 +11,6 @@ using UnityEngine;
namespace Leap
{
using System;
#pragma warning disable 0618
/// <summary>
/// The Finger class represents a tracked finger.
///
@ -22,6 +21,12 @@ namespace Leap
[Serializable]
public class Finger
{
/// <summary>
/// An array of Bone objects that represents each bone of the finger
///
/// There are 4 bones per finger by default
/// @since 3.0
/// </summary>
public Bone[] bones = new Bone[4];
/// <summary>
@ -40,44 +45,6 @@ namespace Leap
bones[3] = new Bone();
}
/// <summary>
/// Constructs a finger.
///
/// Generally, you should not create your own finger objects. Such objects will not
/// have valid tracking data. Get valid finger objects from a hand in a frame
/// received from the service.
/// @since 3.0
/// </summary>
[System.Obsolete("This signature will be removed in the next major version of the plugin. Use the one with Vector3 instead.")]
public Finger(long frameId,
int handId,
int fingerId,
float timeVisible,
Vector tipPosition,
Vector direction,
float width,
float length,
bool isExtended,
FingerType type,
Bone metacarpal,
Bone proximal,
Bone intermediate,
Bone distal)
{
Type = type;
bones[0] = metacarpal;
bones[1] = proximal;
bones[2] = intermediate;
bones[3] = distal;
Id = (handId * 10) + fingerId;
HandId = handId;
TipPosition = tipPosition;
Direction = direction;
Width = width;
Length = length;
IsExtended = isExtended;
TimeVisible = timeVisible;
}
/// <summary>
/// Constructs a finger.
///
@ -107,8 +74,8 @@ namespace Leap
bones[3] = distal;
Id = (handId * 10) + fingerId;
HandId = handId;
TipPosition = ToVector(tipPosition);
Direction = ToVector(direction);
TipPosition = tipPosition;
Direction = direction;
Width = width;
Length = length;
IsExtended = isExtended;
@ -164,16 +131,14 @@ namespace Leap
/// The tip position of this Finger.
/// @since 1.0
/// </summary>
[System.Obsolete("Its type will be changed from Vector to Vector3")]
public Vector TipPosition;
public Vector3 TipPosition;
/// <summary>
/// The direction in which this finger or tool is pointing. The direction is expressed
/// as a unit vector pointing in the same direction as the tip.
/// as a unit vector pointing in the same direction as the intermediate bone.
/// @since 1.0
/// </summary>
[System.Obsolete("Its type will be changed from Vector to Vector3")]
public Vector Direction;
public Vector3 Direction;
/// <summary>
/// The estimated width of the finger.
@ -220,13 +185,5 @@ namespace Leap
TYPE_PINKY = 4,
TYPE_UNKNOWN = -1
}
[Obsolete("This will be removed in the next major version update")]
private Vector ToVector(Vector3 v)
{
return new Vector(v.x, v.y, v.z);
}
}
#pragma warning restore 0618
}

View file

@ -1,5 +1,5 @@
/******************************************************************************
* Copyright (C) Ultraleap, Inc. 2011-2021. *
* Copyright (C) Ultraleap, Inc. 2011-2023. *
* *
* Use subject to the terms of the Apache License 2.0 available at *
* http://www.apache.org/licenses/LICENSE-2.0, or another agreement *
@ -70,30 +70,6 @@ namespace Leap
/// </summary>
public UInt32 DeviceID;
[Obsolete]
public int SerializeLength
{
get
{
throw new NotImplementedException();
}
}
[Obsolete]
public byte[] Serialize
{
get
{
throw new NotImplementedException();
}
}
[Obsolete]
public void Deserialize(byte[] arg)
{
throw new NotImplementedException();
}
/// <summary>
/// The Hand object with the specified ID in this frame, or null if none
/// exists.

View file

@ -1,5 +1,5 @@
/******************************************************************************
* Copyright (C) Ultraleap, Inc. 2011-2021. *
* Copyright (C) Ultraleap, Inc. 2011-2023. *
* *
* Use subject to the terms of the Apache License 2.0 available at *
* http://www.apache.org/licenses/LICENSE-2.0, or another agreement *
@ -11,7 +11,6 @@ namespace Leap
{
using System;
using System.Collections.Generic;
#pragma warning disable 0618
/// <summary>
/// The Hand class reports the physical characteristics of a detected hand.
///
@ -47,56 +46,6 @@ namespace Leap
Fingers.Add(new Finger());
}
/// <summary>
/// Constructs a hand.
///
/// Generally, you should not create your own Hand objects. Such objects will not
/// have valid tracking data. Get valid Hand objects from a frame
/// received from the service.
/// @since 3.0
/// </summary>
[System.Obsolete("This signature will be removed in the next major version of the plugin. Use the one with Vector3 and Quaternion instead.")]
public Hand(long frameID,
int id,
float confidence,
float grabStrength,
float grabAngle,
float pinchStrength,
float pinchDistance,
float palmWidth,
bool isLeft,
float timeVisible,
Arm arm,
List<Finger> fingers,
Vector palmPosition,
Vector stabilizedPalmPosition,
Vector palmVelocity,
Vector palmNormal,
LeapQuaternion palmOrientation,
Vector direction,
Vector wristPosition)
{
FrameId = frameID;
Id = id;
Confidence = confidence;
GrabStrength = grabStrength;
GrabAngle = grabAngle;
PinchStrength = pinchStrength;
PinchDistance = pinchDistance;
PalmWidth = palmWidth;
IsLeft = isLeft;
TimeVisible = timeVisible;
Arm = arm;
Fingers = fingers;
PalmPosition = palmPosition;
StabilizedPalmPosition = stabilizedPalmPosition;
PalmVelocity = palmVelocity;
PalmNormal = palmNormal;
Rotation = palmOrientation;
Direction = direction;
WristPosition = wristPosition;
}
/// <summary>
/// Constructs a hand.
///
@ -108,7 +57,6 @@ namespace Leap
int id,
float confidence,
float grabStrength,
float grabAngle,
float pinchStrength,
float pinchDistance,
float palmWidth,
@ -128,7 +76,6 @@ namespace Leap
Id = id;
Confidence = confidence;
GrabStrength = grabStrength;
GrabAngle = grabAngle;
PinchStrength = pinchStrength;
PinchDistance = pinchDistance;
PalmWidth = palmWidth;
@ -136,13 +83,13 @@ namespace Leap
TimeVisible = timeVisible;
Arm = arm;
Fingers = fingers;
PalmPosition = ToVector(palmPosition);
StabilizedPalmPosition = ToVector(stabilizedPalmPosition);
PalmVelocity = ToVector(palmVelocity);
PalmNormal = ToVector(palmNormal);
Rotation = ToLeapQuaternion(palmOrientation);
Direction = ToVector(direction);
WristPosition = ToVector(wristPosition);
PalmPosition = palmPosition;
StabilizedPalmPosition = stabilizedPalmPosition;
PalmVelocity = palmVelocity;
PalmNormal = palmNormal;
Rotation = palmOrientation;
Direction = direction;
WristPosition = wristPosition;
}
/// <summary>
@ -221,15 +168,13 @@ namespace Leap
/// The center position of the palm.
/// @since 1.0
/// </summary>
[System.Obsolete("Its type will be changed from Vector to Vector3")]
public Vector PalmPosition;
public Vector3 PalmPosition;
/// <summary>
/// The rate of change of the palm position.
/// @since 1.0
/// </summary>
[System.Obsolete("Its type will be changed from Vector to Vector3")]
public Vector PalmVelocity;
public Vector3 PalmVelocity;
/// <summary>
/// The normal vector to the palm. If your hand is flat, this vector will
@ -242,8 +187,7 @@ namespace Leap
/// respect to the horizontal plane.
/// @since 1.0
/// </summary>
[System.Obsolete("Its type will be changed from Vector to Vector3")]
public Vector PalmNormal;
public Vector3 PalmNormal;
/// <summary>
/// The direction from the palm position toward the fingers.
@ -255,8 +199,9 @@ namespace Leap
/// respect to the horizontal plane.
/// @since 1.0
/// </summary>
[System.Obsolete("Its type will be changed from Vector to Vector3")]
public Vector Direction;
public Vector3 Direction;
LeapTransform _basis = new LeapTransform(Vector3.one, Quaternion.identity);
/// <summary>
/// The transform of the hand.
@ -264,15 +209,23 @@ namespace Leap
/// Note, in version prior to 3.1, the Basis was a Matrix object.
/// @since 3.1
/// </summary>
public LeapTransform Basis { get { return new LeapTransform(PalmPosition, Rotation); } }
public LeapTransform Basis
{
get
{
_basis.translation = PalmPosition;
_basis.rotation = Rotation;
return _basis;
}
}
/// <summary>
/// The rotation of the hand as a quaternion.
///
/// @since 3.1
/// </summary>
[System.Obsolete("Its type will be changed from LeapQuaternion to UnityEngine.Quaternion")]
public LeapQuaternion Rotation;
public Quaternion Rotation;
/// <summary>
/// The strength of a grab hand pose.
@ -283,20 +236,6 @@ namespace Leap
/// </summary>
public float GrabStrength;
/// <summary>
/// The angle between the fingers and the hand of a grab hand pose.
///
/// The angle is computed by looking at the angle between the direction of the
/// 4 fingers and the direction of the hand. Thumb is not considered when
/// computing the angle.
/// The angle is 0 radian for an open hand, and reaches pi radians when the pose
/// is a tight fist.
///
/// @since 3.0
/// </summary>
[System.Obsolete("This code will be removed in the next major version of the plugin. If you believe that it needs to be kept, please open a discussion on the GitHub forum (https://github.com/ultraleap/UnityPlugin/discussions)")]
public float GrabAngle;
/// <summary>
/// The holding strength of a pinch hand pose.
///
@ -332,15 +271,13 @@ namespace Leap
/// primarily on the speed of movement.
/// @since 1.0
/// </summary>
[System.Obsolete("Its type will be changed from Vector to Vector3")]
public Vector StabilizedPalmPosition;
public Vector3 StabilizedPalmPosition;
/// <summary>
/// The position of the wrist of this hand.
/// @since 2.0.3
/// </summary>
[System.Obsolete("Its type will be changed from Vector to Vector3")]
public Vector WristPosition;
public Vector3 WristPosition;
/// <summary>
/// The duration of time this Hand has been visible to the Leap Motion Controller, in seconds
@ -376,20 +313,5 @@ namespace Leap
/// @since 2.0.3
/// </summary>
public Arm Arm;
[Obsolete("This will be removed in the next major version update")]
private Vector ToVector(Vector3 v)
{
return new Vector(v.x, v.y, v.z);
}
[Obsolete("This will be removed in the next major version update")]
private LeapQuaternion ToLeapQuaternion(Quaternion q)
{
return new LeapQuaternion(q.x, q.y, q.z, q.w);
}
}
#pragma warning restore 0618
}

View file

@ -1,5 +1,5 @@
/******************************************************************************
* Copyright (C) Ultraleap, Inc. 2011-2021. *
* Copyright (C) Ultraleap, Inc. 2011-2023. *
* *
* Use subject to the terms of the Apache License 2.0 available at *
* http://www.apache.org/licenses/LICENSE-2.0, or another agreement *
@ -17,13 +17,6 @@ namespace Leap
Frame GetTransformedFrame(LeapTransform trs, int history = 0);
Frame GetInterpolatedFrame(Int64 time);
[Obsolete]
void SetPolicy(Controller.PolicyFlag policy);
[Obsolete]
void ClearPolicy(Controller.PolicyFlag policy);
[Obsolete]
bool IsPolicySet(Controller.PolicyFlag policy);
void SetPolicy(Controller.PolicyFlag policy, Device device = null);
void ClearPolicy(Controller.PolicyFlag policy, Device device = null);
bool IsPolicySet(Controller.PolicyFlag policy, Device device = null);

View file

@ -1,5 +1,5 @@
/******************************************************************************
* Copyright (C) Ultraleap, Inc. 2011-2021. *
* Copyright (C) Ultraleap, Inc. 2011-2023. *
* *
* Use subject to the terms of the Apache License 2.0 available at *
* http://www.apache.org/licenses/LICENSE-2.0, or another agreement *
@ -151,14 +151,10 @@ namespace Leap
if (camera != CameraType.LEFT && camera != CameraType.RIGHT)
return null;
return imageData(camera).DistortionData.Data;
// We return the FlippedData, not the Data member as this corrects for a Y flip in the distortion matrix coming from the service.
return imageData(camera).DistortionData.FlippedData;
}
[System.Obsolete("This signature will be removed in the next major version of the plugin. Use the one with Vector3 instead.")]
public Vector PixelToRectilinear(CameraType camera, Vector pixel)
{
return Connection.GetConnection().PixelToRectilinear(camera, pixel);
}
/// <summary>
/// Provides the corrected camera ray intercepting the specified point on the image.
///
@ -183,11 +179,6 @@ namespace Leap
return Connection.GetConnection().PixelToRectilinear(camera, pixel);
}
[System.Obsolete("This signature will be removed in the next major version of the plugin. Use the one with Vector3 instead.")]
public Vector RectilinearToPixel(CameraType camera, Vector ray)
{
return Connection.GetConnection().RectilinearToPixel(camera, ray);
}
/// <summary>
/// Provides the point in the image corresponding to a ray projecting
/// from the camera.
@ -214,7 +205,11 @@ namespace Leap
/// </summary>
public UnityEngine.Vector3 RectilinearToPixel(CameraType camera, UnityEngine.Vector3 ray)
{
return Connection.GetConnection().RectilinearToPixel(camera, ray);
return Connection.GetConnection().RectilinearToPixelEx(
Connection.GetConnection().Devices.FindDeviceByID(deviceId).Handle,
camera,
ray
);
}
/// <summary>

View file

@ -1,5 +1,5 @@
/******************************************************************************
* Copyright (C) Ultraleap, Inc. 2011-2021. *
* Copyright (C) Ultraleap, Inc. 2011-2023. *
* *
* Use subject to the terms of the Apache License 2.0 available at *
* http://www.apache.org/licenses/LICENSE-2.0, or another agreement *

View file

@ -1,5 +1,5 @@
/******************************************************************************
* Copyright (C) Ultraleap, Inc. 2011-2021. *
* Copyright (C) Ultraleap, Inc. 2011-2023. *
* *
* Use subject to the terms of the Apache License 2.0 available at *
* http://www.apache.org/licenses/LICENSE-2.0, or another agreement *
@ -20,7 +20,6 @@ namespace LeapInternal
eLeapConnectionFlag_MultipleDevicesAware = 0x00000001,
};
//
public enum eLeapConnectionStatus : uint
{
/// <summary>
@ -74,7 +73,11 @@ namespace LeapInternal
/// <summary>
/// The Ultraleap 3Di hand tracking camera.
/// </summary>
eLeapDevicePID_3Di = 0x1204
eLeapDevicePID_3Di = 0x1204,
/// <summary>
/// The Ultraleap Leap Motion Controller 2 hand tracking camera.
/// </summary>
eLeapDevicePID_LMC2 = 0x1206
};
public enum eLeapServiceDisposition : uint
@ -799,23 +802,11 @@ namespace LeapInternal
public float y;
public float z;
[System.Obsolete("This code will be removed in the next major version of the plugin. Use 'ToVector3()' instead.")]
public Leap.Vector ToLeapVector()
{
return new Leap.Vector(x, y, z);
}
public UnityEngine.Vector3 ToVector3()
{
return new UnityEngine.Vector3(x, y, z);
}
[System.Obsolete("This signature will be removed in the next major version of the plugin. Use the one taking a Vector3 instead.")]
public LEAP_VECTOR(Leap.Vector leap)
{
x = leap.x;
y = leap.y;
z = leap.z;
}
public LEAP_VECTOR(UnityEngine.Vector3 vector)
{
x = vector.x;
@ -832,24 +823,11 @@ namespace LeapInternal
public float z;
public float w;
[System.Obsolete("This code will be removed in the next major version of the plugin. Use 'ToQuaternion()' instead.")]
public Leap.LeapQuaternion ToLeapQuaternion()
{
return new Leap.LeapQuaternion(x, y, z, w);
}
public UnityEngine.Quaternion ToQuaternion()
{
return new UnityEngine.Quaternion(x, y, z, w);
}
[System.Obsolete("This signature will be removed in the next major version of the plugin. Use the one taking a UnityEngine.Quaternion instead.")]
public LEAP_QUATERNION(Leap.LeapQuaternion q)
{
x = q.x;
y = q.y;
z = q.z;
w = q.w;
}
public LEAP_QUATERNION(UnityEngine.Quaternion q)
{
x = q.x;
@ -1075,7 +1053,7 @@ namespace LeapInternal
public static extern eLeapRS GetDeviceInfo(IntPtr hDevice, ref LEAP_DEVICE_INFO info);
[DllImport("LeapC", EntryPoint = "LeapGetDeviceTransform")]
public static extern eLeapRS GetDeviceTransform(IntPtr hDevice, out float[] transform);
public static extern eLeapRS GetDeviceTransform(IntPtr hDevice, [MarshalAs(UnmanagedType.LPArray, SizeConst = 16)] float[] transform);
[DllImport("LeapC", EntryPoint = "LeapSetPolicyFlags")]
public static extern eLeapRS SetPolicyFlags(IntPtr hConnection, UInt64 set, UInt64 clear);
@ -1130,7 +1108,7 @@ namespace LeapInternal
[DllImport("LeapC", EntryPoint = "LeapRectilinearToPixelEx")]
public static extern LEAP_VECTOR LeapRectilinearToPixelEx(IntPtr hConnection,
IntPtr hDevice, eLeapPerspectiveType camera, eLeapCameraCalibrationType calibrationType, LEAP_VECTOR rectilinear);
IntPtr hDevice, eLeapPerspectiveType camera, LEAP_VECTOR rectilinear);
[DllImport("LeapC", EntryPoint = "LeapCloseDevice")]
public static extern void CloseDevice(IntPtr pDevice);

View file

@ -1,172 +0,0 @@
/******************************************************************************
* Copyright (C) Ultraleap, Inc. 2011-2021. *
* *
* Use subject to the terms of the Apache License 2.0 available at *
* http://www.apache.org/licenses/LICENSE-2.0, or another agreement *
* between Ultraleap and you, your company or other organization. *
******************************************************************************/
namespace Leap
{
using System;
/// <summary>
/// The LeapQuaternion struct represents a rotation in three-dimensional space.
/// @since 3.1.2
/// </summary>
[System.Obsolete("This code will be moved to a legacy package in the next major version of the plugin. Use Unity's Quaternion instead. If you believe that it needs to be kept in tracking, please open a discussion on the GitHub forum (https://github.com/ultraleap/UnityPlugin/discussions)")]
[Serializable]
public struct LeapQuaternion :
IEquatable<LeapQuaternion>
{
/// <summary>
/// Creates a new LeapQuaternion with the specified component values.
/// @since 3.1.2
/// </summary>
public LeapQuaternion(float x, float y, float z, float w) :
this()
{
this.x = x;
this.y = y;
this.z = z;
this.w = w;
}
/// <summary>
/// Copies the specified LeapQuaternion.
/// @since 3.1.2
/// </summary>
public LeapQuaternion(LeapQuaternion quaternion) :
this()
{
x = quaternion.x;
y = quaternion.y;
z = quaternion.z;
w = quaternion.w;
}
/// <summary>
/// Copies the specified LEAP_QUATERNION.
/// @since 3.1.2
/// </summary>
public LeapQuaternion(LeapInternal.LEAP_QUATERNION quaternion) :
this()
{
x = quaternion.x;
y = quaternion.y;
z = quaternion.z;
w = quaternion.w;
}
/// <summary>
/// Returns a string containing this quaternion in a human readable format: (x, y, z).
/// @since 3.1.2
/// </summary>
public override string ToString()
{
return "(" + x + ", " + y + ", " + z + ", " + w + ")";
}
/// <summary>
/// Compare LeapQuaternion equality component-wise.
/// @since 3.1.2
/// </summary>
public bool Equals(LeapQuaternion v)
{
return x.NearlyEquals(v.x) && y.NearlyEquals(v.y) && z.NearlyEquals(v.z) && w.NearlyEquals(v.w);
}
public override bool Equals(Object obj)
{
return obj is LeapQuaternion && Equals((LeapQuaternion)obj);
}
/// <summary>
/// Returns true if all of the quaternion's components are finite. If any
/// component is NaN or infinite, then this returns false.
/// @since 3.1.2
/// </summary>
public bool IsValid()
{
return !(float.IsNaN(x) || float.IsInfinity(x) ||
float.IsNaN(y) || float.IsInfinity(y) ||
float.IsNaN(z) || float.IsInfinity(z) ||
float.IsNaN(w) || float.IsInfinity(w));
}
public float x;
public float y;
public float z;
public float w;
/// <summary>
/// The magnitude, or length, of this quaternion.
/// @since 3.1.2
/// </summary>
public float Magnitude
{
get { return (float)Math.Sqrt(x * x + y * y + z * z + w * w); }
}
/// <summary>
/// The square of the magnitude, or length, of this quaternion.
/// @since 3.1.2
/// </summary>
public float MagnitudeSquared
{
get { return x * x + y * y + z * z + w * w; }
}
/// <summary>
/// A normalized copy of this quaternion.
/// @since 3.1.2
/// </summary>
public LeapQuaternion Normalized
{
get
{
float denom = MagnitudeSquared;
if (denom <= CSharpExtensions.Constants.EPSILON)
{
return Identity;
}
denom = 1.0f / (float)Math.Sqrt(denom);
return new LeapQuaternion(x * denom, y * denom, z * denom, w * denom);
}
}
/// <summary>
/// Concatenates the rotation described by this quaternion with the one provided
/// and returns the result.
/// @since 3.1.2
/// </summary>
public LeapQuaternion Multiply(LeapQuaternion rhs)
{
return new LeapQuaternion(
w * rhs.x + x * rhs.w + y * rhs.z - z * rhs.y,
w * rhs.y + y * rhs.w + z * rhs.x - x * rhs.z,
w * rhs.z + z * rhs.w + x * rhs.y - y * rhs.x,
w * rhs.w - x * rhs.x - y * rhs.y - z * rhs.z);
}
/// <summary>
/// The identity quaternion.
/// @since 3.1.2
/// </summary>
public static readonly LeapQuaternion Identity = new LeapQuaternion(0, 0, 0, 1);
public override int GetHashCode()
{
unchecked // Overflow is fine, just wrap
{
int hash = 17;
hash = hash * 23 + x.GetHashCode();
hash = hash * 23 + y.GetHashCode();
hash = hash * 23 + z.GetHashCode();
hash = hash * 23 + w.GetHashCode();
return hash;
}
}
}
}

View file

@ -1,5 +1,5 @@
/******************************************************************************
* Copyright (C) Ultraleap, Inc. 2011-2021. *
* Copyright (C) Ultraleap, Inc. 2011-2023. *
* *
* Use subject to the terms of the Apache License 2.0 available at *
* http://www.apache.org/licenses/LICENSE-2.0, or another agreement *
@ -10,7 +10,6 @@ using UnityEngine;
namespace Leap
{
using System;
#pragma warning disable 0618
/// <summary>
/// The LeapTransform class represents a transform in three dimensional space.
///
@ -19,15 +18,6 @@ namespace Leap
/// </summary>
public struct LeapTransform
{
/// <summary>
/// Constructs a new transform from the specified translation and rotation.
/// @since 3.1.2
/// </summary>
[System.Obsolete("This signature will be removed in the next major version of the plugin. Use the one with Vector3 and Quaternion instead.")]
public LeapTransform(Vector translation, LeapQuaternion rotation) :
this(translation, rotation, Vector.Ones)
{
}
/// <summary>
/// Constructs a new transform from the specified translation and rotation.
/// </summary>
@ -36,29 +26,16 @@ namespace Leap
{
}
/// <summary>
/// Constructs a new transform from the specified translation, rotation and scale.
/// @since 3.1.2
/// </summary>
[System.Obsolete("This signature will be removed in the next major version of the plugin. Use the one with Vector3 and Quaternion instead.")]
public LeapTransform(Vector translation, LeapQuaternion rotation, Vector scale) :
this()
{
_scale = scale;
// these are non-trival setters.
this.translation = translation;
this.rotation = rotation; // Calls validateBasis
}
/// <summary>
/// Constructs a new transform from the specified translation, rotation and scale.
/// </summary>
public LeapTransform(Vector3 translation, Quaternion rotation, Vector3 scale) :
this()
{
_scale = ToVector(scale);
this.scale = scale;
// these are non-trival setters.
this.translation = ToVector(translation);
this.rotation = ToLeapQuaternion(rotation); // Calls validateBasis
this.translation = translation;
this.rotation = rotation; // Calls validateBasis
}
/// <summary>
@ -67,92 +44,35 @@ namespace Leap
/// <param name="t">Unity Transform</param>
public LeapTransform(Transform t) : this()
{
float MM_TO_M = 1e-3f;
_scale = new Vector(t.lossyScale.x * MM_TO_M, t.lossyScale.y * MM_TO_M, t.lossyScale.z * MM_TO_M);
this.translation = ToVector(t.position);
this.rotation = ToLeapQuaternion(t.rotation);
this.MirrorZ(); // Unity is left handed.
this.scale = t.lossyScale;
this.translation = t.position;
this.rotation = t.rotation;
}
/// <summary>
/// Transforms the specified position vector, applying translation, rotation and scale.
/// @since 3.1.2
/// </summary>
[System.Obsolete("This signature will be removed in the next major version of the plugin. Use the one with Vector3 instead.")]
public Vector TransformPoint(Vector point)
{
return _xBasisScaled * point.x + _yBasisScaled * point.y + _zBasisScaled * point.z + translation;
}
/// <summary>
/// Transforms the specified position vector, applying translation, rotation and scale.
/// </summary>
public Vector3 TransformPoint(Vector3 point)
{
return ToVector3(_xBasisScaled * point.x + _yBasisScaled * point.y + _zBasisScaled * point.z + translation);
return _xBasisScaled * point.x + _yBasisScaled * point.y + _zBasisScaled * point.z + translation;
}
/// <summary>
/// Transforms the specified direction vector, applying rotation only.
/// @since 3.1.2
/// </summary>
[System.Obsolete("This signature will be removed in the next major version of the plugin. Use the one with Vector3 instead.")]
public Vector TransformDirection(Vector direction)
{
return _xBasis * direction.x + _yBasis * direction.y + _zBasis * direction.z;
}
/// <summary>
/// Transforms the specified direction vector, applying rotation only.
/// </summary>
public Vector3 TransformDirection(Vector3 direction)
{
return ToVector3(_xBasis * direction.x + _yBasis * direction.y + _zBasis * direction.z);
return _xBasis * direction.x + _yBasis * direction.y + _zBasis * direction.z;
}
/// <summary>
/// Transforms the specified velocity vector, applying rotation and scale.
/// @since 3.1.2
/// </summary>
[System.Obsolete("This signature will be removed in the next major version of the plugin. Use the one with Vector3 instead.")]
public Vector TransformVelocity(Vector velocity)
{
return _xBasisScaled * velocity.x + _yBasisScaled * velocity.y + _zBasisScaled * velocity.z;
}
/// <summary>
/// Transforms the specified velocity vector, applying rotation and scale.
/// </summary>
public Vector3 TransformVelocity(Vector3 velocity)
{
return ToVector3(_xBasisScaled * velocity.x + _yBasisScaled * velocity.y + _zBasisScaled * velocity.z);
return _xBasisScaled * velocity.x + _yBasisScaled * velocity.y + _zBasisScaled * velocity.z;
}
/// <summary>
/// Transforms the specified quaternion.
/// Multiplies the quaternion representing the rotational part of this transform by the specified
/// quaternion.
///
/// **Important:** Modifying the basis vectors of this transform directly leaves the underlying quaternion in
/// an indeterminate state. Neither this function nor the LeapTransform.rotation quaternion can be used after
/// the basis vectors are set.
///
/// @since 3.1.2
/// </summary>
[System.Obsolete("This signature will be removed in the next major version of the plugin. Use the one with UnityEngine.Quaternion instead.")]
public LeapQuaternion TransformQuaternion(LeapQuaternion rhs)
{
if (_quaternionDirty)
throw new InvalidOperationException("Calling TransformQuaternion after Basis vectors have been modified.");
if (_flip)
{
// Mirror the axis of rotation across the flip axis.
rhs.x *= _flipAxes.x;
rhs.y *= _flipAxes.y;
rhs.z *= _flipAxes.z;
}
LeapQuaternion t = _quaternion.Multiply(rhs);
return t;
}
/// <summary>
/// Transforms the specified quaternion.
/// Multiplies the quaternion representing the rotational part of this transform by the specified
@ -175,7 +95,7 @@ namespace Leap
rhs.z *= _flipAxes.z;
}
Quaternion t = ToQuaternion(_quaternion) * rhs;
Quaternion t = _quaternion * rhs;
return t;
}
@ -216,8 +136,7 @@ namespace Leap
///
/// @since 3.1.2
/// </summary>
[System.Obsolete("Its type will be changed from Vector to Vector3")]
public Vector xBasis
public Vector3 xBasis
{
get { return _xBasis; }
set
@ -237,8 +156,7 @@ namespace Leap
///
/// @since 3.1.2
/// </summary>
[System.Obsolete("Its type will be changed from Vector to Vector3")]
public Vector yBasis
public Vector3 yBasis
{
get { return _yBasis; }
set
@ -258,8 +176,7 @@ namespace Leap
///
/// @since 3.1.2
/// </summary>
[System.Obsolete("Its type will be changed from Vector to Vector3")]
public Vector zBasis
public Vector3 zBasis
{
get { return _zBasis; }
set
@ -274,8 +191,7 @@ namespace Leap
/// The translation component of the transform.
/// @since 3.1.2
/// </summary>
[System.Obsolete("Its type will be changed from Vector to Vector3")]
public Vector translation
public Vector3 translation
{
get { return _translation; }
set
@ -289,8 +205,7 @@ namespace Leap
/// Scale is kept separate from translation.
/// @since 3.1.2
/// </summary>
[System.Obsolete("Its type will be changed from Vector to Vector3")]
public Vector scale
public Vector3 scale
{
get { return _scale; }
set
@ -311,8 +226,7 @@ namespace Leap
///
/// @since 3.1.2
/// </summary>
[System.Obsolete("Its type will be changed from LeapQuaternion to UnityEngine.Quaternion")]
public LeapQuaternion rotation
public Quaternion rotation
{
get
{
@ -331,9 +245,9 @@ namespace Leap
float xx = value.x * xs, xy = value.x * ys, xz = value.x * zs;
float yy = value.y * ys, yz = value.y * zs, zz = value.z * zs;
_xBasis = new Vector(1.0f - (yy + zz), xy + wz, xz - wy);
_yBasis = new Vector(xy - wz, 1.0f - (xx + zz), yz + wx);
_zBasis = new Vector(xz + wy, yz - wx, 1.0f - (xx + yy));
_xBasis = new Vector3(1.0f - (yy + zz), xy + wz, xz - wy);
_yBasis = new Vector3(xy - wz, 1.0f - (xx + zz), yz + wx);
_zBasis = new Vector3(xz + wy, yz - wx, 1.0f - (xx + yy));
_xBasisScaled = _xBasis * scale.x;
_yBasisScaled = _yBasis * scale.y;
@ -341,7 +255,7 @@ namespace Leap
_quaternionDirty = false;
_flip = false;
_flipAxes = new Vector(1.0f, 1.0f, 1.0f);
_flipAxes = new Vector3(1.0f, 1.0f, 1.0f);
}
}
@ -351,52 +265,17 @@ namespace Leap
/// </summary>
public static readonly LeapTransform Identity = new LeapTransform(Vector3.zero, Quaternion.identity, Vector3.one);
[System.Obsolete("Its type will be changed from Vector to Vector3")]
private Vector _translation;
[System.Obsolete("Its type will be changed from Vector to Vector3")]
private Vector _scale;
[System.Obsolete("Its type will be changed from LeapQuaternion to UnityEngine.Quaternion")]
private LeapQuaternion _quaternion;
private Vector3 _translation;
private Vector3 _scale;
private Quaternion _quaternion;
private bool _quaternionDirty;
private bool _flip;
[System.Obsolete("Its type will be changed from Vector to Vector3")]
private Vector _flipAxes;
[System.Obsolete("Its type will be changed from Vector to Vector3")]
private Vector _xBasis;
[System.Obsolete("Its type will be changed from Vector to Vector3")]
private Vector _yBasis;
[System.Obsolete("Its type will be changed from Vector to Vector3")]
private Vector _zBasis;
[System.Obsolete("Its type will be changed from Vector to Vector3")]
private Vector _xBasisScaled;
[System.Obsolete("Its type will be changed from Vector to Vector3")]
private Vector _yBasisScaled;
[System.Obsolete("Its type will be changed from Vector to Vector3")]
private Vector _zBasisScaled;
[Obsolete("This will be removed in the next major version update")]
private Vector ToVector(Vector3 v)
{
return new Vector(v.x, v.y, v.z);
}
[Obsolete("This will be removed in the next major version update")]
private Vector3 ToVector3(Vector v)
{
return new Vector3(v.x, v.y, v.z);
}
[Obsolete("This will be removed in the next major version update")]
private LeapQuaternion ToLeapQuaternion(Quaternion q)
{
return new LeapQuaternion(q.x, q.y, q.z, q.w);
}
[Obsolete("This will be removed in the next major version update")]
private Quaternion ToQuaternion(LeapQuaternion q)
{
return new Quaternion(q.x, q.y, q.z, q.w);
private Vector3 _flipAxes;
private Vector3 _xBasis;
private Vector3 _yBasis;
private Vector3 _zBasis;
private Vector3 _xBasisScaled;
private Vector3 _yBasisScaled;
private Vector3 _zBasisScaled;
}
}
#pragma warning restore 0618
}

View file

@ -1,5 +1,5 @@
/******************************************************************************
* Copyright (C) Ultraleap, Inc. 2011-2021. *
* Copyright (C) Ultraleap, Inc. 2011-2023. *
* *
* Use subject to the terms of the Apache License 2.0 available at *
* http://www.apache.org/licenses/LICENSE-2.0, or another agreement *

View file

@ -1,363 +0,0 @@
/******************************************************************************
* Copyright (C) Ultraleap, Inc. 2011-2021. *
* *
* Use subject to the terms of the Apache License 2.0 available at *
* http://www.apache.org/licenses/LICENSE-2.0, or another agreement *
* between Ultraleap and you, your company or other organization. *
******************************************************************************/
namespace Leap
{
using System;
/// <summary>
/// The Matrix struct represents a transformation matrix.
///
/// To use this struct to transform a Vector, construct a matrix containing the
/// desired transformation and then use the Matrix::transformPoint() or
/// Matrix.TransformDirection() functions to apply the transform.
///
/// Transforms can be combined by multiplying two or more transform matrices using
/// the * operator.
/// @since 1.0
/// </summary>
[System.Obsolete("This code will be moved to a legacy package in the next major version of the plugin. If you believe that it needs to be kept in tracking, please open a discussion on the GitHub forum (https://github.com/ultraleap/UnityPlugin/discussions)")]
public struct Matrix
{
/// <summary>
/// Multiply two matrices.
/// </summary>
public static Matrix operator *(Matrix m1, Matrix m2)
{
return m1._operator_mul(m2);
}
/// <summary>
/// Copy this matrix to the specified array of 9 float values in row-major order.
/// </summary>
public float[] ToArray3x3(float[] output)
{
output[0] = xBasis.x;
output[1] = xBasis.y;
output[2] = xBasis.z;
output[3] = yBasis.x;
output[4] = yBasis.y;
output[5] = yBasis.z;
output[6] = zBasis.x;
output[7] = zBasis.y;
output[8] = zBasis.z;
return output;
}
/// <summary>
/// Copy this matrix to the specified array containing 9 double values in row-major order.
/// </summary>
public double[] ToArray3x3(double[] output)
{
output[0] = xBasis.x;
output[1] = xBasis.y;
output[2] = xBasis.z;
output[3] = yBasis.x;
output[4] = yBasis.y;
output[5] = yBasis.z;
output[6] = zBasis.x;
output[7] = zBasis.y;
output[8] = zBasis.z;
return output;
}
/// <summary>
/// Convert this matrix to an array containing 9 float values in row-major order.
/// </summary>
public float[] ToArray3x3()
{
return ToArray3x3(new float[9]);
}
/// <summary>
/// Copy this matrix to the specified array of 16 float values in row-major order.
/// </summary>
public float[] ToArray4x4(float[] output)
{
output[0] = xBasis.x;
output[1] = xBasis.y;
output[2] = xBasis.z;
output[3] = 0.0f;
output[4] = yBasis.x;
output[5] = yBasis.y;
output[6] = yBasis.z;
output[7] = 0.0f;
output[8] = zBasis.x;
output[9] = zBasis.y;
output[10] = zBasis.z;
output[11] = 0.0f;
output[12] = origin.x;
output[13] = origin.y;
output[14] = origin.z;
output[15] = 1.0f;
return output;
}
/// <summary>
/// Copy this matrix to the specified array of 16 double values in row-major order.
/// </summary>
public double[] ToArray4x4(double[] output)
{
output[0] = xBasis.x;
output[1] = xBasis.y;
output[2] = xBasis.z;
output[3] = 0.0f;
output[4] = yBasis.x;
output[5] = yBasis.y;
output[6] = yBasis.z;
output[7] = 0.0f;
output[8] = zBasis.x;
output[9] = zBasis.y;
output[10] = zBasis.z;
output[11] = 0.0f;
output[12] = origin.x;
output[13] = origin.y;
output[14] = origin.z;
output[15] = 1.0f;
return output;
}
/// <summary>
/// Convert this matrix to an array containing 16 float values in row-major order.
/// </summary>
public float[] ToArray4x4()
{
return ToArray4x4(new float[16]);
}
/// <summary>
/// Constructs a copy of the specified Matrix object.
/// @since 1.0
/// </summary>
public Matrix(Matrix other) :
this()
{
xBasis = other.xBasis;
yBasis = other.yBasis;
zBasis = other.zBasis;
origin = other.origin;
}
/// <summary>
/// Constructs a transformation matrix from the specified basis vectors.
/// @since 1.0
/// </summary>
public Matrix(Vector xBasis, Vector yBasis, Vector zBasis) :
this()
{
this.xBasis = xBasis;
this.yBasis = yBasis;
this.zBasis = zBasis;
this.origin = Vector.Zero;
}
/// <summary>
/// Constructs a transformation matrix from the specified basis and translation vectors.
/// @since 1.0
/// </summary>
public Matrix(Vector xBasis, Vector yBasis, Vector zBasis, Vector origin) :
this()
{
this.xBasis = xBasis;
this.yBasis = yBasis;
this.zBasis = zBasis;
this.origin = origin;
}
/// <summary>
/// Constructs a transformation matrix specifying a rotation around the specified vector.
/// @since 1.0
/// </summary>
public Matrix(Vector axis, float angleRadians) :
this()
{
xBasis = Vector.XAxis;
yBasis = Vector.YAxis;
zBasis = Vector.ZAxis;
origin = Vector.Zero;
SetRotation(axis, angleRadians);
}
/// <summary>
/// Constructs a transformation matrix specifying a rotation around the specified vector
/// and a translation by the specified vector.
/// @since 1.0
/// </summary>
public Matrix(Vector axis, float angleRadians, Vector translation) :
this()
{
xBasis = Vector.XAxis;
yBasis = Vector.YAxis;
zBasis = Vector.ZAxis;
origin = translation;
this.SetRotation(axis, angleRadians);
}
public Matrix(float m00,
float m01,
float m02,
float m10,
float m11,
float m12,
float m20,
float m21,
float m22) :
this()
{
xBasis = new Vector(m00, m01, m02);
yBasis = new Vector(m10, m11, m12);
zBasis = new Vector(m20, m21, m22);
origin = Vector.Zero;
}
public Matrix(float m00,
float m01,
float m02,
float m10,
float m11,
float m12,
float m20,
float m21,
float m22,
float m30,
float m31,
float m32) :
this()
{
xBasis = new Vector(m00, m01, m02);
yBasis = new Vector(m10, m11, m12);
zBasis = new Vector(m20, m21, m22);
origin = new Vector(m30, m31, m32);
}
/// <summary>
/// Sets this transformation matrix to represent a rotation around the specified vector.
///
/// This function erases any previous rotation and scale transforms applied
/// to this matrix, but does not affect translation.
///
/// @since 1.0
/// </summary>
public void SetRotation(Vector axis, float angleRadians)
{
Vector n = axis.Normalized;
float s = (float)Math.Sin(angleRadians);
float c = (float)Math.Cos(angleRadians);
float C = (1 - c);
xBasis = new Vector(n[0] * n[0] * C + c, n[0] * n[1] * C - n[2] * s, n[0] * n[2] * C + n[1] * s);
yBasis = new Vector(n[1] * n[0] * C + n[2] * s, n[1] * n[1] * C + c, n[1] * n[2] * C - n[0] * s);
zBasis = new Vector(n[2] * n[0] * C - n[1] * s, n[2] * n[1] * C + n[0] * s, n[2] * n[2] * C + c);
}
/// <summary>
/// Transforms a vector with this matrix by transforming its rotation,
/// scale, and translation.
///
/// Translation is applied after rotation and scale.
///
/// @since 1.0
/// </summary>
public Vector TransformPoint(Vector point)
{
return xBasis * point.x + yBasis * point.y + zBasis * point.z + origin;
}
/// <summary>
/// Transforms a vector with this matrix by transforming its rotation and
/// scale only.
/// @since 1.0
/// </summary>
public Vector TransformDirection(Vector direction)
{
return xBasis * direction.x + yBasis * direction.y + zBasis * direction.z;
}
/// <summary>
/// Performs a matrix inverse if the matrix consists entirely of rigid
/// transformations (translations and rotations). If the matrix is not rigid,
/// this operation will not represent an inverse.
///
/// Note that all matrices that are directly returned by the API are rigid.
///
/// @since 1.0
/// </summary>
public Matrix RigidInverse()
{
Matrix rotInverse = new Matrix(new Vector(xBasis[0], yBasis[0], zBasis[0]),
new Vector(xBasis[1], yBasis[1], zBasis[1]),
new Vector(xBasis[2], yBasis[2], zBasis[2]));
rotInverse.origin = rotInverse.TransformDirection(-origin);
return rotInverse;
}
/// <summary>
/// Multiply transform matrices.
/// Combines two transformations into a single equivalent transformation.
/// @since 1.0
/// </summary>
private Matrix _operator_mul(Matrix other)
{
return new Matrix(TransformDirection(other.xBasis),
TransformDirection(other.yBasis),
TransformDirection(other.zBasis),
TransformPoint(other.origin));
}
/// <summary>
/// Compare Matrix equality component-wise.
/// @since 1.0
/// </summary>
public bool Equals(Matrix other)
{
return xBasis == other.xBasis &&
yBasis == other.yBasis &&
zBasis == other.zBasis &&
origin == other.origin;
}
/// <summary>
/// Write the matrix to a string in a human readable format.
/// </summary>
public override string ToString()
{
return string.Format("xBasis: {0} yBasis: {1} zBasis: {2} origin: {3}", xBasis, yBasis, zBasis, origin);
}
/// <summary>
/// The basis vector for the x-axis.
/// @since 1.0
/// </summary>
public Vector xBasis { get; set; }
/// <summary>
/// The basis vector for the y-axis.
/// @since 1.0
/// </summary>
public Vector yBasis { get; set; }
/// <summary>
/// The basis vector for the z-axis.
/// @since 1.0
/// </summary>
public Vector zBasis { get; set; }
/// <summary>
/// The translation factors for all three axes.
/// @since 1.0
/// </summary>
public Vector origin { get; set; }
/// <summary>
/// Returns the identity matrix specifying no translation, rotation, and scale.
/// @since 1.0
/// </summary>
public static readonly Matrix Identity = new Matrix(Vector.XAxis, Vector.YAxis, Vector.ZAxis, Vector.Zero);
}
}

View file

@ -1,5 +1,5 @@
/******************************************************************************
* Copyright (C) Ultraleap, Inc. 2011-2021. *
* Copyright (C) Ultraleap, Inc. 2011-2023. *
* *
* Use subject to the terms of the Apache License 2.0 available at *
* http://www.apache.org/licenses/LICENSE-2.0, or another agreement *

View file

@ -1,5 +1,5 @@
/******************************************************************************
* Copyright (C) Ultraleap, Inc. 2011-2021. *
* Copyright (C) Ultraleap, Inc. 2011-2023. *
* *
* Use subject to the terms of the Apache License 2.0 available at *
* http://www.apache.org/licenses/LICENSE-2.0, or another agreement *

View file

@ -1,5 +1,5 @@
/******************************************************************************
* Copyright (C) Ultraleap, Inc. 2011-2021. *
* Copyright (C) Ultraleap, Inc. 2011-2023. *
* *
* Use subject to the terms of the Apache License 2.0 available at *
* http://www.apache.org/licenses/LICENSE-2.0, or another agreement *
@ -8,13 +8,11 @@
namespace Leap
{
#pragma warning disable 0618
public struct PointMapping
{
public long frameId;
public long timestamp;
public Vector[] points;
public UnityEngine.Vector3[] points;
public uint[] ids;
}
#pragma warning restore 0618
}

View file

@ -1,5 +1,5 @@
/******************************************************************************
* Copyright (C) Ultraleap, Inc. 2011-2021. *
* Copyright (C) Ultraleap, Inc. 2011-2023. *
* *
* Use subject to the terms of the Apache License 2.0 available at *
* http://www.apache.org/licenses/LICENSE-2.0, or another agreement *

View file

@ -1,5 +1,5 @@
/******************************************************************************
* Copyright (C) Ultraleap, Inc. 2011-2021. *
* Copyright (C) Ultraleap, Inc. 2011-2023. *
* *
* Use subject to the terms of the Apache License 2.0 available at *
* http://www.apache.org/licenses/LICENSE-2.0, or another agreement *
@ -11,7 +11,6 @@ using UnityEngine;
namespace Leap
{
using System;
#pragma warning disable 0618
public static class TransformExtensions
{
@ -153,7 +152,7 @@ namespace Leap
if (bone.Length < float.Epsilon)
{
bone.Direction = Vector.Zero;
bone.Direction = Vector3.zero;
}
else
{
@ -175,5 +174,4 @@ namespace Leap
return new Bone().CopyFrom(bone).Transform(transform);
}
}
#pragma warning restore 0618
}

View file

@ -1,427 +0,0 @@
/******************************************************************************
* Copyright (C) Ultraleap, Inc. 2011-2021. *
* *
* Use subject to the terms of the Apache License 2.0 available at *
* http://www.apache.org/licenses/LICENSE-2.0, or another agreement *
* between Ultraleap and you, your company or other organization. *
******************************************************************************/
namespace Leap
{
using System;
/// <summary>
/// Constants used in Leap Motion math functions.
/// </summary>
[System.Obsolete("This code will be moved to Leap.CSharpExtensions.Constants in the next major version of the plugin.")]
public static class Constants
{
public const float PI = 3.1415926536f;
public const float DEG_TO_RAD = 0.0174532925f;
public const float RAD_TO_DEG = 57.295779513f;
public const float EPSILON = 1.192092896e-07f;
}
/// <summary>
/// The Vector struct represents a three-component mathematical vector or point
/// such as a direction or position in three-dimensional space.
///
/// The Leap Motion software employs a right-handed Cartesian coordinate system.
/// Values given are in units of real-world millimeters. The origin is centered
/// at the center of the Leap Motion Controller. The x- and z-axes lie in the horizontal
/// plane, with the x-axis running parallel to the long edge of the device.
/// The y-axis is vertical, with positive values increasing upwards (in contrast
/// to the downward orientation of most computer graphics coordinate systems).
/// The z-axis has positive values increasing away from the computer screen.
/// @since 1.0
/// </summary>
[System.Obsolete("This code will be moved to a legacy package in the next major version of the plugin. Use Unity's Vector3 instead. If you believe that it needs to be kept in tracking, please open a discussion on the GitHub forum (https://github.com/ultraleap/UnityPlugin/discussions)")]
[Serializable]
public struct Vector : IEquatable<Vector>
{
public static Vector operator +(Vector v1, Vector v2)
{
return new Vector(v1.x + v2.x, v1.y + v2.y, v1.z + v2.z);
}
public static Vector operator -(Vector v1, Vector v2)
{
return new Vector(v1.x - v2.x, v1.y - v2.y, v1.z - v2.z);
}
public static Vector operator *(Vector v1, float scalar)
{
return new Vector(v1.x * scalar, v1.y * scalar, v1.z * scalar);
}
public static Vector operator *(float scalar, Vector v1)
{
return new Vector(v1.x * scalar, v1.y * scalar, v1.z * scalar);
}
public static Vector operator /(Vector v1, float scalar)
{
return new Vector(v1.x / scalar, v1.y / scalar, v1.z / scalar);
}
public static Vector operator -(Vector v1)
{
return new Vector(-v1.x, -v1.y, -v1.z);
}
public static bool operator ==(Vector v1, Vector v2)
{
return v1.Equals(v2);
}
public static bool operator !=(Vector v1, Vector v2)
{
return !v1.Equals(v2);
}
public float[] ToFloatArray()
{
return new float[] { x, y, z };
}
/// <summary>
/// Creates a new Vector with the specified component values.
/// @since 1.0
/// </summary>
public Vector(float x, float y, float z) :
this()
{
this.x = x;
this.y = y;
this.z = z;
}
/// <summary>
/// Copies the specified Vector.
/// @since 1.0
/// </summary>
public Vector(Vector vector) :
this()
{
x = vector.x;
y = vector.y;
z = vector.z;
}
/// <summary>
/// The distance between the point represented by this Vector
/// object and a point represented by the specified Vector object.
///
/// @since 1.0
/// </summary>
public float DistanceTo(Vector other)
{
return (float)Math.Sqrt((x - other.x) * (x - other.x) +
(y - other.y) * (y - other.y) +
(z - other.z) * (z - other.z));
}
/// <summary>
/// The angle between this vector and the specified vector in radians.
///
/// The angle is measured in the plane formed by the two vectors. The
/// angle returned is always the smaller of the two conjugate angles.
/// Thus A.angleTo(B) == B.angleTo(A) and is always a positive
/// value less than or equal to pi radians (180 degrees).
///
/// If either vector has zero length, then this function returns zero.
/// @since 1.0
/// </summary>
public float AngleTo(Vector other)
{
float denom = MagnitudeSquared * other.MagnitudeSquared;
if (denom <= CSharpExtensions.Constants.EPSILON)
{
return 0.0f;
}
float val = Dot(other) / (float)Math.Sqrt(denom);
if (val >= 1.0f)
{
return 0.0f;
}
else if (val <= -1.0f)
{
return CSharpExtensions.Constants.PI;
}
return (float)Math.Acos(val);
}
/// <summary>
/// The dot product of this vector with another vector.
///
/// The dot product is the magnitude of the projection of this vector
/// onto the specified vector.
/// @since 1.0
/// </summary>
public float Dot(Vector other)
{
return (x * other.x) + (y * other.y) + (z * other.z);
}
/// <summary>
/// The cross product of this vector and the specified vector.
///
/// The cross product is a vector orthogonal to both original vectors.
/// It has a magnitude equal to the area of a parallelogram having the
/// two vectors as sides. The direction of the returned vector is
/// determined by the right-hand rule. Thus A.cross(B) == -B.cross(A).
///
/// @since 1.0
/// </summary>
public Vector Cross(Vector other)
{
return new Vector((y * other.z) - (z * other.y),
(z * other.x) - (x * other.z),
(x * other.y) - (y * other.x));
}
/// <summary>
/// Returns a string containing this vector in a human readable format: (x, y, z).
/// @since 1.0
/// </summary>
public override string ToString()
{
return "(" + x + ", " + y + ", " + z + ")";
}
/// <summary>
/// Compare Vector equality component-wise.
/// @since 1.0
/// </summary>
public bool Equals(Vector v)
{
return x.NearlyEquals(v.x) && y.NearlyEquals(v.y) && z.NearlyEquals(v.z);
}
public override bool Equals(Object obj)
{
return obj is Vector && Equals((Vector)obj);
}
/// <summary>
/// Returns true if all of the vector's components are finite. If any
/// component is NaN or infinite, then this returns false.
/// @since 1.0
/// </summary>
public bool IsValid()
{
return !(float.IsNaN(x) || float.IsInfinity(x) ||
float.IsNaN(y) || float.IsInfinity(y) ||
float.IsNaN(z) || float.IsInfinity(z));
}
/// <summary>
/// Index vector components numerically.
/// Index 0 is x, index 1 is y, and index 2 is z.
/// @since 1.0
/// </summary>
public float this[uint index]
{
get
{
if (index == 0)
return x;
if (index == 1)
return y;
if (index == 2)
return z;
throw new IndexOutOfRangeException();
}
set
{
if (index == 0)
x = value;
if (index == 1)
y = value;
if (index == 2)
z = value;
throw new IndexOutOfRangeException();
}
}
public float x;
public float y;
public float z;
/// <summary>
/// The magnitude, or length, of this vector.
///
/// The magnitude is the L2 norm, or Euclidean distance between the origin and
/// the point represented by the (x, y, z) components of this Vector object.
/// @since 1.0
/// </summary>
public float Magnitude
{
get { return (float)Math.Sqrt(x * x + y * y + z * z); }
}
/// <summary>
/// The square of the magnitude, or length, of this vector.
/// @since 1.0
/// </summary>
public float MagnitudeSquared
{
get { return x * x + y * y + z * z; }
}
/// <summary>
/// The pitch angle in radians.
///
/// Pitch is the angle between the negative z-axis and the projection of
/// the vector onto the y-z plane. In other words, pitch represents rotation
/// around the x-axis.
/// If the vector points upward, the returned angle is between 0 and pi radians
/// (180 degrees); if it points downward, the angle is between 0 and -pi radians.
///
/// @since 1.0
/// </summary>
public float Pitch
{
get { return (float)Math.Atan2(y, -z); }
}
/// <summary>
/// The roll angle in radians.
///
/// Roll is the angle between the y-axis and the projection of
/// the vector onto the x-y plane. In other words, roll represents rotation
/// around the z-axis. If the vector points to the left of the y-axis,
/// then the returned angle is between 0 and pi radians (180 degrees);
/// if it points to the right, the angle is between 0 and -pi radians.
///
/// Use this function to get roll angle of the plane to which this vector is a
/// normal. For example, if this vector represents the normal to the palm,
/// then this function returns the tilt or roll of the palm plane compared
/// to the horizontal (x-z) plane.
///
/// @since 1.0
/// </summary>
public float Roll
{
get { return (float)Math.Atan2(x, -y); }
}
/// <summary>
/// The yaw angle in radians.
///
/// Yaw is the angle between the negative z-axis and the projection of
/// the vector onto the x-z plane. In other words, yaw represents rotation
/// around the y-axis. If the vector points to the right of the negative z-axis,
/// then the returned angle is between 0 and pi radians (180 degrees);
/// if it points to the left, the angle is between 0 and -pi radians.
///
/// @since 1.0
/// </summary>
public float Yaw
{
get { return (float)Math.Atan2(x, -z); }
}
/// <summary>
/// A normalized copy of this vector.
///
/// A normalized vector has the same direction as the original vector,
/// but with a length of one.
///
/// @since 1.0
/// </summary>
public Vector Normalized
{
get
{
float denom = MagnitudeSquared;
if (denom <= CSharpExtensions.Constants.EPSILON)
{
return Zero;
}
denom = 1.0f / (float)Math.Sqrt(denom);
return new Vector(x * denom, y * denom, z * denom);
}
}
/// <summary>
/// The zero vector: (0, 0, 0)
/// </summary>
public static readonly Vector Zero = new Vector(0, 0, 0);
/// <summary>
/// The ones vector: (1, 1, 1)
/// </summary>
public static readonly Vector Ones = new Vector(1, 1, 1);
/// <summary>
/// The x-axis unit vector: (1, 0, 0)
/// </summary>
public static readonly Vector XAxis = new Vector(1, 0, 0);
/// <summary>
/// The y-axis unit vector: (0, 1, 0)
/// </summary>
public static readonly Vector YAxis = new Vector(0, 1, 0);
/// <summary>
/// The z-axis unit vector: (0, 0, 1)
/// </summary>
public static readonly Vector ZAxis = new Vector(0, 0, 1);
/// <summary>
/// The unit vector pointing forward along the negative z-axis: (0, 0, -1)
/// </summary>
public static readonly Vector Forward = new Vector(0, 0, -1);
/// <summary>
/// The unit vector pointing backward along the positive z-axis: (0, 0, 1)
/// </summary>
public static readonly Vector Backward = new Vector(0, 0, 1);
/// <summary>
/// The unit vector pointing left along the negative x-axis: (-1, 0, 0)
/// </summary>
public static readonly Vector Left = new Vector(-1, 0, 0);
/// <summary>
/// The unit vector pointing right along the positive x-axis: (1, 0, 0)
/// </summary>
public static readonly Vector Right = new Vector(1, 0, 0);
/// <summary>
/// The unit vector pointing up along the positive y-axis: (0, 1, 0)
/// </summary>
public static readonly Vector Up = new Vector(0, 1, 0);
/// <summary>
/// The unit vector pointing down along the negative y-axis: (0, -1, 0)
/// </summary>
public static readonly Vector Down = new Vector(0, -1, 0);
public static Vector Lerp(Vector a, Vector b, float t)
{
return new Vector(
a.x + t * (b.x - a.x),
a.y + t * (b.y - a.y),
a.z + t * (b.z - a.z)
);
}
public override int GetHashCode()
{
unchecked // Overflow is fine, just wrap
{
int hash = 17;
hash = hash * 23 + x.GetHashCode();
hash = hash * 23 + y.GetHashCode();
hash = hash * 23 + z.GetHashCode();
return hash;
}
}
}
}

View file

@ -5,8 +5,6 @@
## Package contents:
LeapSDK
- docs
* API reference documentation & guidelines.
- include
* API headers.
- lib
@ -15,8 +13,10 @@ LeapSDK
* Various samples demonstrating several different usages.
- LICENSE.md
* Ultraleap Tracking SDK license.
- Uninstall.exe
* Program to uninstall the LeapSDK application (Windows only).
- README.md
* Ultraleap Tracking SDK readme.
- ThirdPartyNotices.md
* Ultraleap Tracking SDK third party licenses.
## Requirements:
@ -75,7 +75,7 @@ cmake --build $env:REPOS_BUILD_ROOT/$env:BUILD_TYPE/LeapSDK/leapc_example -j --c
### x64 Linux
1. Open CMake using /usr/share/doc/ultraleap-tracking/samples as the source directory
1. Open CMake using /usr/share/doc/ultraleap-hand-tracking-service/samples as the source directory
2. Select a build directory (eg. ~/ultraleap-tracking-samples/build) to use
@ -84,7 +84,7 @@ cmake --build $env:REPOS_BUILD_ROOT/$env:BUILD_TYPE/LeapSDK/leapc_example -j --c
4. Open and build the CMake generated project files. For more help, see the CMake documentation.
* An example script would be :
```bash
SRC_DIR=/usr/share/doc/ultraleap-tracking/samples
SRC_DIR=/usr/share/doc/ultraleap-hand-tracking-service/samples
BUILD_TYPE='Release'
REPOS_BUILD_ROOT=~/ultraleap-tracking-samples/build
REPOS_INSTALL_ROOT=/usr/bin/ultraleap-tracking-samples
@ -96,6 +96,29 @@ cmake -S ${SRC_DIR} -B ${REPOS_BUILD_ROOT}/${BUILD_TYPE}/LeapSDK/leapc_example `
cmake --build ${REPOS_BUILD_ROOT}/${BUILD_TYPE}/LeapSDK/leapc_example -j --config ${BUILD_TYPE}
```
### MacOS
1. Open CMake using /Library/Application Support/Ultraleap/LeapSDK/samples as the source directory
2. Select a build directory (eg. ~/ultraleap-tracking-samples/build) to use
3. Configure & Generate CMake with the generator of your choice
4. Open and build the CMake generated project files. For more help, see the CMake documentation.
* An example script would be :
```bash
SRC_DIR='/Library/Application Support/Ultraleap/LeapSDK/samples'
BUILD_TYPE='Release'
REPOS_BUILD_ROOT=~/ultraleap-tracking-samples/build
REPOS_INSTALL_ROOT=~/ultraleap-tracking-samples/bin
cmake -S ${SRC_DIR} -B ${REPOS_BUILD_ROOT}/${BUILD_TYPE}/LeapSDK/leapc_example `
-DCMAKE_INSTALL_PREFIX="${REPOS_INSTALL_ROOT}/leapc_example" `
-DCMAKE_BUILD_TYPE="${BUILD_TYPE}"
cmake --build ${REPOS_BUILD_ROOT}/${BUILD_TYPE}/LeapSDK/leapc_example -j --config ${BUILD_TYPE}
```
## Resources:
1. Ultraleap For Developers Site (https://developer.leapmotion.com)

File diff suppressed because it is too large Load diff

Binary file not shown.

Binary file not shown.