FrameInformation fetchFrameInformation() { FrameInformation frameInfo = new FrameInformation(); frameInfo.grabHeld = grabHeld; frameInfo.pinchHeld = pinchHeld; foreach (Leap.Finger f in hand.Fingers) { FingerInformation fingerInfo = new FingerInformation(); fingerInfo.isExtended = f.IsExtended; fingerInfo.direction = f.Direction.ToVector3(); fingerInfo.padDirection = Vector3.Cross(fingerInfo.direction, Vector3.Cross(fingerInfo.direction, f.bones[1].Direction.ToVector3())); fingerInfo.tipPosition = f.TipPosition.ToVector3(); fingerInfo.tipVelocity = f.TipVelocity.ToVector3(); switch (f.Type) { case Leap.Finger.FingerType.TYPE_INDEX: frameInfo.index = fingerInfo; break; case Leap.Finger.FingerType.TYPE_MIDDLE: frameInfo.middle = fingerInfo; break; case Leap.Finger.FingerType.TYPE_RING: frameInfo.ring = fingerInfo; break; case Leap.Finger.FingerType.TYPE_PINKY: frameInfo.pinky = fingerInfo; break; case Leap.Finger.FingerType.TYPE_THUMB: frameInfo.thumb = fingerInfo; break; } } if (handedness == "Right") { hand = Hands.Right; } else { hand = Hands.Left; } HandInformation handInfo = new HandInformation(); handInfo.direction = hand.Direction.ToVector3(); handInfo.pitch = hand.Direction.Pitch; handInfo.roll = hand.Direction.Roll; handInfo.yaw = hand.Direction.Yaw; handInfo.palmPosition = hand.PalmPosition.ToVector3(); handInfo.palmVelocity = hand.PalmVelocity.ToVector3(); handInfo.palmNormal = hand.PalmNormal.ToVector3(); handInfo.rotation = hand.Rotation.ToQuaternion(); frameInfo.hand = handInfo; return(frameInfo); }
//Checks for a tap gesture, uses previous frame information. public bool checkTap(Queue <FrameInformation> frameQueue, Leap.Hand hand) { //Do not want ring or pinky extended when tapping. if (Hands.GetRing(hand).IsExtended || Hands.GetPinky(hand).IsExtended) { return(false); } int count = frameQueue.Count; if (count < 11) { return(false); } FrameInformation[] fArr = frameQueue.ToArray(); float[] sharpness = new float[count]; float[] padvel = new float[count]; float[] accelMag = new float[count]; for (int i = 1; i < count - 1; ++i) { FingerInformation p = fArr[i - 1].index; FingerInformation n = fArr[i + 1].index; FingerInformation v = fArr[i].index; //Vector3 jerk = (n.tipVelocity - v.tipVelocity) - (v.tipVelocity - p.tipVelocity); //jerk = Vector3.Project(jerk, fArr[i].index.padDirection); //Fetch magnitude of acceleration of recent frames as well as pad velocity and sharpness Vector3 accel = (n.tipVelocity - p.tipVelocity); Vector3.Project(accel, fArr[i].index.padDirection); accelMag[i] = Vector3.Project(accel, fArr[i].index.padDirection).magnitude; accelMag[i] *= Mathf.Sign(Vector3.Dot(accel, fArr[i].index.padDirection)); padvel[i] = Vector3.Project(v.tipVelocity, fArr[i].index.padDirection).magnitude; padvel[i] *= Mathf.Sign(Vector3.Dot(v.tipVelocity, fArr[i].index.padDirection)); sharpness[i] = Vector3.Angle(v.tipPosition - p.tipPosition, n.tipPosition - v.tipPosition) * accel.sqrMagnitude; } /*if (sharpness[count - 2] > 20f && sharpness[count - 1] < sharpness[count - 2] && sharpness[count - 3] < sharpness[count - 2] * && fArr[count-2].index.isExtended * && accelMag[count-2] > 0)*/ //Checks to see if a tap existed in this frame. if (accelMag[count - 2] < -.5f && accelMag[count - 3] > accelMag[count - 2] && accelMag[count - 1] > accelMag[count - 2]) { return(true); } else { return(false); } }