//1,DISTAL(tip) 2,INTERMEDIATE 3,PROXIMAL // Update is called once per frame void Update() { Leap.Frame frame = controller.GetFrame(); if (gestureOption == 0) { hands = frame.Hands; Leap.Hand hand = hands.Leftmost; //Debug.Log ("here"); if (hand.IsValid && hand.IsLeft) { Leap.FingerList fingers = hand.Fingers; Leap.Vector tipV = fingers[0].TipVelocity; float tipVmag = tipV.Magnitude; //Leap.Vector tipV2 = fingers[1].TipVelocity; Leap.Bone bone = fingers[0].Bone(Leap.Bone.BoneType.TYPE_DISTAL); //Leap.Bone bone2 = fingers[1].Bone (Leap.Bone.BoneType.TYPE_DISTAL); float distFromBoneToPalm = bone.Center.DistanceTo(hand.PalmPosition); float palmDirectionSign = hand.PalmNormal.Dot(vecUpInLeapForm); //Debug.Log (distFromBoneToPalm + " " + palmDirectionSign + " " + tipVmag + " " + hand.Confidence); //Debug.Log (bone.Direction.Pitch); if (distFromBoneToPalm < 70 && palmDirectionSign > 0.5 && tipVmag > 30 && hand.Confidence > 0.7) { getCollidersInARangeAndSendMessage(); } } } else if (gestureOption == 1) { Leap.GestureList gestures = frame.Gestures(); for (int i = 0; i < gestures.Count; i++) { if (gestures[i].Type == Leap.Gesture.GestureType.TYPESWIPE) { if (gestures[i].IsValid && gestures[i].State == Leap.Gesture.GestureState.STATESTOP) { Debug.Log("Yes"); getCollidersInARangeAndSendMessage(); } } } } }
public override void OnFrame(Leap.Controller controller) { Leap.Frame frame = controller.Frame(); Leap.InteractionBox interactionBox = frame.InteractionBox; _pointerPosition = interactionBox.NormalizePoint(frame.Pointables.Frontmost.TipPosition); _standardGestures = frame.Gestures(); foreach (Leap.Gesture gesture in _standardGestures) { if (gesture.State.Equals(Leap.Gesture.GestureState.STATESTOP)) { if (gesture.Type.Equals(Leap.Gesture.GestureType.TYPESWIPE)) { Print("Finger Swipe Detected"); Leap.SwipeGesture swipe = new Leap.SwipeGesture(gesture); Events.FingerSwipeEvent swipeEvent = new Events.FingerSwipeEvent(swipe); OnFingerSwipeDetected(swipeEvent); } if (gesture.Type.Equals(Leap.Gesture.GestureType.TYPE_CIRCLE)) { Print("Circle Gesture Detected"); Leap.CircleGesture circle = new Leap.CircleGesture(gesture); Events.CircleEvent circleEvent = new Events.CircleEvent(circle); OnCircleDetected(circleEvent); } if (gesture.Type.Equals(Leap.Gesture.GestureType.TYPE_SCREEN_TAP)) { Print("Screen Tap Detected"); Leap.ScreenTapGesture screenTap = new Leap.ScreenTapGesture(gesture); Events.ScreenTapEvent screenTapEvent = new Events.ScreenTapEvent(screenTap); OnScreenTapDetected(screenTapEvent); } } } Gestures.HandSwipe handSwipe = Gestures.HandSwipe.IsHandSwipe(frame); if (handSwipe != null) { if (handSwipe.State.Equals(Gestures.GestureState.END)) { Print("Hand Swipe Detected"); Events.HandSwipeEvent swipeEvent = new Events.HandSwipeEvent(handSwipe); OnHandSwipeDetected(swipeEvent); } } Gestures.ZoomIn zoomIn = Gestures.ZoomIn.IsZoomIn(frame); if (zoomIn != null) { if (zoomIn.State.Equals(Gestures.GestureState.END)) { Print("ZoomIn Detected"); Events.ZoomInEvent zoomInEvent = new Events.ZoomInEvent(zoomIn); OnZoomInDetected(zoomInEvent); } } Gestures.ZoomOut zoomOut = Gestures.ZoomOut.IsZoomOut(frame); if (zoomOut != null) { if (zoomOut.State.Equals(Gestures.GestureState.END)) { Print("ZoomOut Detected"); Events.ZoomOutEvent zoomOutEvent = new Events.ZoomOutEvent(zoomOut); OnZoomOutDetected(zoomOutEvent); } } }
// Update is called once per frame void Update() { Leap.Frame frame = controller.Frame(); guiFrame = frame; if (!frame.Hands.Empty) { // Get the first hand hand0 = frame.Hands[0]; hand1 = frame.Hands[1]; // Check if the hand has any fingers Leap.FingerList fingers = hand0.Fingers; if (!fingers.Empty) { Leap.Finger firstfinger = fingers[0]; // If at leasts 3 fingers are valid on the second hand (remember that when you take away your hand from leap,the second hand becomes the first on the HandsList) (*)<-- if ((hand1.Fingers.Count) >= 3) { hasPaused = true; } if (firstfinger.IsValid) { hasPaused = false; if (!hand1.IsValid || (hand1.IsValid && hand1.Fingers.Count <= 2)) { if (hasPaused == false && frame.Hands[0].Id != hand1ID) // (*)<-- { float moveInputX = firstfinger.TipVelocity.x / 600; transform.position += new Vector3(moveInputX, 0, 0); float moveInputY = firstfinger.TipVelocity.y / 600; transform.position += new Vector3(0, moveInputY, 0); float moveInputZ = firstfinger.TipVelocity.z / 600; transform.position -= new Vector3(0, 0, moveInputZ); } } } // Calculate the hand's average finger tip position Leap.Vector avgPos = Leap.Vector.Zero; foreach (Leap.Finger finger in fingers) { avgPos += finger.TipPosition; } avgPos /= fingers.Count; print("Hand has " + fingers.Count + " fingers, average finger tip position: " + avgPos); } // // Get the hand's sphere radius and palm position // print("Hand sphere radius: " + hand0.SphereRadius.ToString("n2") // + " mm, palm position: " + hand0.PalmPosition); // // // Get the hand's normal vector and direction // Leap.Vector normal = hand0.PalmNormal; // Leap.Vector direction = hand0.Direction; // // // Calculate the hand's pitch, roll, and yaw angles // print("Hand pitch: " + direction.Pitch * 180.0f / (float)3.14 + " degrees, " // + "roll: " + normal.Roll * 180.0f / (float)3.14 + " degrees, " // + "yaw: " + direction.Yaw * 180.0f / (float)3.14 + " degrees"); } Leap.GestureList gestures = frame.Gestures(); for (int i = 0; i < gestures.Count; i++) { Leap.Gesture gesture = gestures[i]; switch (gesture.Type) { case Leap.Gesture.GestureType.TYPECIRCLE: Leap.CircleGesture circle = new Leap.CircleGesture(gesture); // Calculate clock direction using the angle between circle normal and pointable string clockwiseness; if (circle.Pointable.Direction.AngleTo(circle.Normal) <= 3.1487 / 4) { //Clockwise if angle is less than 90 degrees clockwiseness = "clockwise"; } else { clockwiseness = "counterclockwise"; } float sweptAngle = 0; // Calculate angle swept since last frame if (circle.State != Leap.Gesture.GestureState.STATESTART) { Leap.CircleGesture previousUpdate = new Leap.CircleGesture(controller.Frame(1).Gesture(circle.Id)); sweptAngle = (circle.Progress - previousUpdate.Progress) * 360; } globalInfo = ("Circle id: " + circle.Id + ", " + circle.State + ", progress: " + circle.Progress + ", radius: " + circle.Radius + ", angle: " + sweptAngle + ", " + clockwiseness); break; case Leap.Gesture.GestureType.TYPESWIPE: Leap.SwipeGesture swipe = new Leap.SwipeGesture(gesture); globalInfo = ("Swipe id: " + swipe.Id + ", " + swipe.State + ", position: " + swipe.Position + ", direction: " + swipe.Direction + ", speed: " + swipe.Speed); break; case Leap.Gesture.GestureType.TYPEKEYTAP: Leap.KeyTapGesture keytap = new Leap.KeyTapGesture(gesture); globalInfo = ("Tap id: " + keytap.Id + ", " + keytap.State + ", position: " + keytap.Position + ", direction: " + keytap.Direction); break; case Leap.Gesture.GestureType.TYPESCREENTAP: Leap.ScreenTapGesture screentap = new Leap.ScreenTapGesture(gesture); globalInfo = ("Tap id: " + screentap.Id + ", " + screentap.State + ", position: " + screentap.Position + ", direction: " + screentap.Direction); break; default: print("Unknown gesture type."); break; } } if (!frame.Hands.Empty) { hand0ID = hand0.Id; if (hand1.Id != -1) { hand1ID = hand1.Id; // since when u take away your first hand,the second one becomes the first one on the list (with ID = 1),I want to remember its value } } else { hand0ID = -1; } }