private float GetAngle(Leap.Hand hand) { Vector3 proximalAxis = hand.DistalAxis() * -1f; Vector3 radialAxis = hand.RadialAxis(); if (hand.IsLeft) { radialAxis *= -1f; } List <float> fingerAngles = new List <float> { Vector3.SignedAngle(proximalAxis, hand.GetIndex().Direction.ToVector3(), radialAxis), Vector3.SignedAngle(proximalAxis, hand.GetMiddle().Direction.ToVector3(), radialAxis), Vector3.SignedAngle(proximalAxis, hand.GetRing().Direction.ToVector3(), radialAxis), Vector3.SignedAngle(proximalAxis, hand.GetPinky().Direction.ToVector3(), radialAxis) }; List <float> fingerAnglesShifted = new List <float>(); foreach (float angle in fingerAngles) { float shiftedAngle = angle; if (angle < -90f) { shiftedAngle += 360f; } fingerAnglesShifted.Add(shiftedAngle); } angle = 0.25f * (fingerAnglesShifted[0] + fingerAnglesShifted[1] + fingerAnglesShifted[2] + fingerAnglesShifted[3]); return(angle); }
//returns a true if a finger is pinching with the thumb, false if not public bool checkPinchOfFinger(Leap.Hand hand, string finger) { switch (finger) { case "index": if (getPinchDistance(hand.GetIndex(), hand.GetThumb()) < dist) { return(true); } break; case "middle": if (getPinchDistance(hand.GetMiddle(), hand.GetThumb()) < dist) { return(true); } break; case "ring": if (getPinchDistance(hand.GetRing(), hand.GetThumb()) < dist) { return(true); } break; case "pinky": if (getPinchDistance(hand.GetPinky(), hand.GetThumb()) < dist) { return(true); } break; default: break; } return(false); }