private void SetType(Leap.Finger finger) { switch (finger.Type()) { case Leap.Finger.FingerType.TYPE_THUMB: Type = FingerType.THUMB; break; case Leap.Finger.FingerType.TYPE_INDEX: Type = FingerType.INDEX; break; case Leap.Finger.FingerType.TYPE_MIDDLE: Type = FingerType.MIDDLE; break; case Leap.Finger.FingerType.TYPE_RING: Type = FingerType.RING; break; case Leap.Finger.FingerType.TYPE_PINKY: Type = FingerType.PINKY; break; default: throw new Exception("Unknow finger"); } }
public static void GetBones(Leap.Finger finger, out Leap.Bone metacarpal, out Leap.Bone proximal, out Leap.Bone intermediate, out Leap.Bone distal) { metacarpal = finger.Bone((Leap.Bone.BoneType)BoneType.Metacarpal); proximal = finger.Bone((Leap.Bone.BoneType)BoneType.Proximal); intermediate = finger.Bone((Leap.Bone.BoneType)BoneType.Intermediate); distal = finger.Bone((Leap.Bone.BoneType)BoneType.Distal); }
//public void UpdateFingerState(Leap.Vector vecterFingerTip, Leap.Vector vecterPalm, Leap.Finger oFinger) //{ // double dInterval = this.GetVecterDistance(vecterFingerTip, vecterPalm); // if (Max == 0) // { // Max = dInterval; // return; // } // if (dInterval > Max) // { // Max = dInterval; // } // if (dInterval < Sensitive) // { // Sensitive = dInterval; // } // if (dInterval < Sensitive) // dInterval = Sensitive; // double dPercent = (dInterval - Sensitive) / (this.Max - Sensitive); // double dScale = 1 - 0.5 * dPercent; // this.ScaleX = dScale; // this.ScaleY = dScale; //} public void UpdateFingerState(Leap.Vector vecterFingerTip, Leap.Vector vecterPalm, Leap.Finger oFinger) { if (oFinger.Type != Leap.Finger.FingerType.TYPE_THUMB) { double angle = (180 - (oFinger.Hand.Direction.AngleTo(oFinger.Direction) / Math.PI) * 180); if (this.Max == 0) { this.Max = angle; return; } if (angle > this.Max) { this.Max = angle; } if (angle < this.Min) { this.Min = angle; } double dAngleDeviation = 30d * (1 - angle / 180d); double dPercent = (angle - dAngleDeviation - this.Min) / (this.Max - this.Min); double dScale = 1 - 0.5 * dPercent; this.ScaleX = dScale; this.ScaleY = dScale; } else if (oFinger.Type == Leap.Finger.FingerType.TYPE_THUMB) { Leap.Bone bone1 = oFinger.Bone(Leap.Bone.BoneType.TYPE_DISTAL); Leap.Bone bone2 = oFinger.Bone(Leap.Bone.BoneType.TYPE_PROXIMAL); double angle = (180 - (bone1.Direction.AngleTo(bone2.Direction) / Math.PI) * 180); if (this.Max == 0) { this.Max = angle; return; } if (angle > this.Max) { this.Max = angle; } if (angle < this.Min) { this.Min = angle; } double dAngleDeviation = (this.Max - this.Min) * (1 - angle / 180d); double dPercent = (angle - dAngleDeviation - this.Min) / (this.Max - this.Min); double dScale = 1 - 0.5 * dPercent; this.ScaleX = dScale; this.ScaleY = dScale; } }
public Finger(Leap.Finger finger, Frame frame, Hand hand) : base(finger, frame, hand) { SetType(finger); SetJoints(finger); B_Metacarpal = new Bone(finger.Bone(Leap.Bone.BoneType.TYPE_METACARPAL)); B_Proximal = new Bone(finger.Bone(Leap.Bone.BoneType.TYPE_PROXIMAL)); B_Intermediate = new Bone(finger.Bone(Leap.Bone.BoneType.TYPE_INTERMEDIATE)); B_Distal = new Bone(finger.Bone(Leap.Bone.BoneType.TYPE_DISTAL)); }
private void SetJoints(Leap.Finger finger) { //J_Distal = new Vector(finger.JointPosition(Leap.Finger.FingerJoint.JOINT_DIP)); //J_Intermediate = new Vector(finger.JointPosition(Leap.Finger.FingerJoint.JOINT_TIP)); //J_Proximal = new Vector(finger.JointPosition(Leap.Finger.FingerJoint.JOINT_PIP)); //J_Metacarpal = new Vector(finger.JointPosition(Leap.Finger.FingerJoint.JOINT_MCP)); //J_Wrist = new Vector(finger.Bone(Leap.Bone.BoneType.TYPE_METACARPAL).PrevJoint); J_Distal = new Vector(finger.Bone(Leap.Bone.BoneType.TYPE_DISTAL).NextJoint); J_Intermediate = new Vector(finger.Bone(Leap.Bone.BoneType.TYPE_INTERMEDIATE).NextJoint); J_Proximal = new Vector(finger.Bone(Leap.Bone.BoneType.TYPE_PROXIMAL).NextJoint); J_Metacarpal = new Vector(finger.Bone(Leap.Bone.BoneType.TYPE_METACARPAL).NextJoint); J_Wrist = new Vector(finger.Bone(Leap.Bone.BoneType.TYPE_METACARPAL).PrevJoint); }
private void UpdateLeapFinger(FingersTarget.TargetedFinger finger, int fingerIx) { Leap.Finger leapFinger = leapHand.Fingers[fingerIx]; Quaternion proximalRotation = leapFinger.Bone(Leap.Bone.BoneType.TYPE_PROXIMAL).Rotation.ToQuaternion(); finger.proximal.target.transform.rotation = proximalRotation * Quaternion.AngleAxis(handTarget.isLeft ? 90 : -90, Vector3.up); Quaternion intermediateRotation = leapFinger.Bone(Leap.Bone.BoneType.TYPE_INTERMEDIATE).Rotation.ToQuaternion(); finger.intermediate.target.transform.rotation = intermediateRotation * Quaternion.AngleAxis(handTarget.isLeft ? 90 : -90, Vector3.up); Quaternion distalRotation = leapFinger.Bone(Leap.Bone.BoneType.TYPE_DISTAL).Rotation.ToQuaternion(); finger.distal.target.transform.rotation = distalRotation * Quaternion.AngleAxis(handTarget.isLeft ? 90 : -90, Vector3.up); }
void Listener_LeapFingerReady(object sender, Leap.Finger first, Leap.Finger second) { if (detialWindow != null) { Point3D left, right; Action action1, action2; left = new Point3D(first.TipPosition.x * 3.5, -3.5 * (first.TipPosition.y - 100) + SystemParameters.PrimaryScreenHeight / 2, first.TipPosition.z); right = new Point3D(second.TipPosition.x * 3.5, -3.5 * (second.TipPosition.y - 100) + SystemParameters.PrimaryScreenHeight / 2, second.TipPosition.z); if (first.TipPosition.x <= second.TipPosition.x) { action1 = () => detialWindow.SetHandLeftPoint3D(left); action2 = () => detialWindow.SetHandRightPoint3D(right); } else { action1 = () => detialWindow.SetHandLeftPoint3D(right); action2 = () => detialWindow.SetHandRightPoint3D(left); } Dispatcher.BeginInvoke(DispatcherPriority.Send, action1); Dispatcher.BeginInvoke(DispatcherPriority.Send, action2); } }
public static Leap.Bone GetBone(Leap.Finger finger, BoneType type) { return(finger.Bone((Leap.Bone.BoneType)type)); }
public static FingerType GetFingerType(Leap.Finger finger) { return((FingerType)finger.Type); }
//------------------------------------------------- void Update() { // check finger state foreach (RiggedHand h in hands) { Leap.Hand leapHand = h.GetLeapHand(); if (leapHand == null) { continue; } Leap.Finger index = leapHand.GetIndex(); Leap.Finger thumb = leapHand.GetThumb(); if (index.TipPosition.DistanceTo(thumb.TipPosition) < 0.03) { if (fingerState == FingerState.PRESSED) { fingerState = FingerState.DOWN; } else if (fingerState != FingerState.DOWN) { fingerState = FingerState.PRESSED; } } else { if (fingerState == FingerState.RELEASED) { fingerState = FingerState.NONE; } else if (fingerState != FingerState.NONE) { fingerState = FingerState.RELEASED; } } } // Hand oldPointerHand = pointerHand; Hand newPointerHand = null; foreach (Hand hand in player.hands) { if (visible) { if (WasTeleportButtonReleased(hand)) { if (pointerHand == hand) //This is the pointer hand { TryTeleportPlayer(); } } } if (WasTeleportButtonPressed(hand)) { newPointerHand = hand; } } //If something is attached to the hand that is preventing teleport if (allowTeleportWhileAttached && !allowTeleportWhileAttached.teleportAllowed) { HidePointer(); } else { if (!visible && newPointerHand != null) { //Begin showing the pointer ShowPointer(newPointerHand, oldPointerHand); } else if (visible) { if (newPointerHand == null && !IsTeleportButtonDown(pointerHand)) { //Hide the pointer HidePointer(); } else if (newPointerHand != null) { //Move the pointer to a new hand ShowPointer(newPointerHand, oldPointerHand); } } } if (visible) { UpdatePointer(); if (meshFading) { UpdateTeleportColors(); } if (onActivateObjectTransform.gameObject.activeSelf && Time.time - pointerShowStartTime > activateObjectTime) { onActivateObjectTransform.gameObject.SetActive(false); } } else { if (onDeactivateObjectTransform.gameObject.activeSelf && Time.time - pointerHideStartTime > deactivateObjectTime) { onDeactivateObjectTransform.gameObject.SetActive(false); } } }
public Finger(Leap.Finger finger, Frame frame, Hand hand) : base(finger, frame, hand) { }