void Update() { HandModel hand_model = GetComponent <HandModel>(); Hand leap_hand = hand_model.GetLeapHand(); if (leap_hand == null) { return; } bool draw_trigger = false; Vector3 thumb_tip = leap_hand.Fingers[0].TipPosition.ToUnityScaled(); for (int i = 1; i < 5 && !draw_trigger; ++i) { for (int j = 0; j < 4 && !draw_trigger; ++j) { Finger.FingerJoint joint = (Finger.FingerJoint)(j); Vector3 difference = leap_hand.Fingers[i].JointPosition(joint).ToUnityScaled() - thumb_tip; if (difference.magnitude < THUMB_TRIGGER_DISTANCE && leap_hand.Confidence > MIN_CONFIDENCE) { draw_trigger = true; } } } if (draw_trigger) { canvas.AddNextPoint(hand_model.fingers[1].GetJointPosition(FingerModel.NUM_JOINTS - 1)); } }
private const float MIN_CONFIDENCE = 0.2f; //Minimum value of handmodel confidence #endregion // Update is called once per frame void Update() { //define LeapHands & Fingers handModel = GetComponent <HandModel> (); leapHand = handModel.GetLeapHand(); //get indexfinger indexFingerModel = handModel.fingers [1]; //get indexfingerTip position indexTip = indexFingerModel.GetTipPosition(); //get thumbTip position thumbTip = leapHand.Fingers [0].TipPosition.ToUnityScaled(); //calculating velocity of finger currPosition = thumbTip; velocity = (currPosition - prePosition).magnitude / Time.deltaTime; prePosition = thumbTip; //Trigger test (true: thumbTip got close to rest of fingers) bool patternTrigger = false; for (int i = 1; i < 5 && !patternTrigger; ++i) { for (int j = 0; j < 4 && !patternTrigger; ++j) { Finger.FingerJoint joint = (Finger.FingerJoint)(j); Vector3 difference = leapHand.Fingers[i].JointPosition(joint).ToUnityScaled() - thumbTip; if (difference.magnitude < THUMB_TRIGGER_DISTANCE && leapHand.Confidence > MIN_CONFIDENCE) { //Trigger is ON patternTrigger = true; } } } //Particle system On/Off switch (patternTrigger) { case (true): //Start recording finger position AddPositionCache(indexTip); transform.FindChild("particle").gameObject.SetActive(true); break; case (false): transform.FindChild("particle").gameObject.SetActive(false); break; } if (DetectFingerGesture()) { //Detected! } }
public void updateInfo(Hand hand) { _lastTimeUpdated = Time.time; _leapHand = hand; foreach (Finger finger in hand.Fingers) { Dictionary <Finger.FingerJoint, InteractionPoint> fingerPoints; if (!_fingerPointMap.TryGetValue(finger.Type, out fingerPoints)) { fingerPoints = new Dictionary <Finger.FingerJoint, InteractionPoint>(); _fingerPointMap[finger.Type] = fingerPoints; } for (int i = 0; i < 4; i++) { Finger.FingerJoint jointType = (Finger.FingerJoint)i; Vector3 jointPosition = HandInfo.unityPos(finger.JointPosition(jointType)); InteractionPoint point; if (!fingerPoints.TryGetValue(jointType, out point)) { point = new InteractionPoint(); fingerPoints[jointType] = point; } point.update(jointPosition); } } Vector3 palmPoint = HandInfo.unityPos(hand.PalmPosition); Matrix basis = hand.Basis; Vector3 xBasis = HandInfo.unityDir(basis.xBasis) * PALM_BASIS_WEIGHT; Vector3 yBasis = HandInfo.unityDir(basis.yBasis) * PALM_BASIS_WEIGHT; Vector3 zBasis = HandInfo.unityDir(basis.zBasis) * PALM_BASIS_WEIGHT; _basisPoints[0].update(palmPoint + xBasis); _basisPoints[1].update(palmPoint + yBasis); _basisPoints[2].update(palmPoint + zBasis); _basisPoints[3].update(palmPoint - xBasis); _basisPoints[4].update(palmPoint - yBasis); _basisPoints[5].update(palmPoint - zBasis); _closeObjects.Clear(); Collider[] colliders = Physics.OverlapSphere(palmPoint, HandInfo.unityLength(0.25f), InteractionController.instance.grabbableLayer); foreach (Collider c in colliders) { _closeObjects.Add(c.gameObject); } }
/** * Deprecated as of version 2.0 * Use 'bone' method instead. */ public Vector JointPosition(Finger.FingerJoint jointIx) { switch (jointIx) { case FingerJoint.JOINT_MCP: return(_bones[0].NextJoint); case FingerJoint.JOINT_PIP: return(_bones[1].NextJoint); case FingerJoint.JOINT_DIP: return(_bones[2].NextJoint); case FingerJoint.JOINT_TIP: return(_bones[3].NextJoint); } return(Vector.Zero); }