private void SetType(Leap.Gesture gesture) { switch (gesture.Type) { case Leap.Gesture.GestureType.TYPE_INVALID: Type = GestureType.INVALID; break; case Leap.Gesture.GestureType.TYPE_SWIPE: Type = GestureType.SWIPE; break; case Leap.Gesture.GestureType.TYPE_CIRCLE: Type = GestureType.CIRCLE; break; case Leap.Gesture.GestureType.TYPE_SCREEN_TAP: Type = GestureType.SCREEN_TAP; break; case Leap.Gesture.GestureType.TYPE_KEY_TAP: Type = GestureType.KEY_TAP; break; default: throw new Exception("Unknow gesture type"); } }
public Gesture(Leap.Gesture gesture, Frame frame, List <Hand> hands, List <Pointable> pointables) { Frame = frame; Duration = gesture.Duration; DurationSeconds = gesture.DurationSeconds; SetType(gesture); SetState(gesture); SetHandsFromLeap(gesture, hands); SetPointablesFromLeap(gesture, pointables); }
private void BuiltInImprovedGestureRecognised(Leap.Gesture gesture, EasyLeapGestureType type) { if (!gestureList.ContainsKey(-(int)type)) { RecordNewGesture(-(int)type, EasyLeapGestureState.STATESTOP, EasyLeapGestureState.STATEUPDATE, type, -1, gesture.Hands[0].StabilizedPalmPosition); } }
private void SetPointablesFromLeap(Leap.Gesture gesture, List <Pointable> pointables) { Pointables = new List <Pointable>(); foreach (Leap.Pointable gp in gesture.Pointables) { foreach (Pointable p in pointables) { if (gp.Id == p.Id) { Pointables.Add(p); } } } }
private void SetHandsFromLeap(Leap.Gesture gesture, List <Hand> hands) { Hands = new List <Hand>(); foreach (Leap.Hand lp in gesture.Hands) { foreach (Hand h in hands) { if (lp.Id == h.Id) { Hands.Add(h); } } } }
private void SetState(Leap.Gesture gesture) { switch (gesture.State) { case Leap.Gesture.GestureState.STATE_INVALID: State = GestureState.INVALID; break; case Leap.Gesture.GestureState.STATE_START: State = GestureState.START; break; case Leap.Gesture.GestureState.STATE_UPDATE: State = GestureState.UPDATE; break; case Leap.Gesture.GestureState.STATE_STOP: State = GestureState.STOP; break; default: throw new Exception("Unknow gesture state"); } }
public static GestureState GetGestureState(Leap.Gesture gesture) { return((GestureState)gesture.State); }
public static GestureType GetGestureType(Leap.Gesture gesture) { return((GestureType)gesture.Type); }
private void BuiltInGestureRecognised(Leap.Gesture gesture, EasyLeapGestureType type) { RecordNewGesture(gesture.Id, ConvertGestureState(gesture.State), ConvertGestureState(gesture.State), type, gesture.Duration, gesture.Hands[0].StabilizedPalmPosition); }
// 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; } }
public void Update(LeapLibrary.LeapComponet leap) { if (leap.FirstHand != null) { Position.X = (leap.FirstHand.PalmPosition.x / 120.0f) * 900; Position.Y = (leap.FirstHand.PalmPosition.z / 130.0f) * 900; for (int i = 0; i < leap.Gestures.Count; i++) { Leap.Gesture gesture = leap.Gestures[i]; switch (gesture.Type) { case Leap.Gesture.GestureType.TYPECIRCLE: StaticInfo.cptTimerProjectile += StaticInfo.SpeedTimerProjectile; if (StaticInfo.cptTimerProjectile > 1.0f) { StaticInfo.cptTimerProjectile = 0; ListBananes.Add(new ProjectileBanane(Position, StaticInfo.MonkeySpeedBanane)); } break; } } } Position.X += Convert.ToInt32(Keyboard.GetState().IsKeyDown(Keys.D)) * 15; Position.X -= Convert.ToInt32(Keyboard.GetState().IsKeyDown(Keys.A)) * 15; Position.Y += Convert.ToInt32(Keyboard.GetState().IsKeyDown(Keys.S)) * 15; Position.Y -= Convert.ToInt32(Keyboard.GetState().IsKeyDown(Keys.W)) * 15; if (Position.X < StaticInfo.LimiteInf.X) { Position.X = StaticInfo.LimiteInf.X; } if (Position.Y < StaticInfo.LimiteInf.Y) { Position.Y = StaticInfo.LimiteInf.Y; } if (Position.X > StaticInfo.LimiteSup.X) { Position.X = StaticInfo.LimiteSup.X; } if (Position.Y > StaticInfo.LimiteSup.Y) { Position.Y = StaticInfo.LimiteSup.Y; } //if(leap.FirstHand.pal->RPalmStrength > 0.75f) //if (leap.FirstHand.Finger(1).IsValid ) for (int i = 0; i < ListBananes.Count; i++) { ListBananes[i].Update(); if (ListBananes[i].Delete) { ListBananes.RemoveAt(i); i--; } } RecCollision.X = ((int)Position.X - RecCollision.Width / 2); RecCollision.Y = ((int)Position.Y - RecCollision.Height); FWheelAP.PlayAnimation(FWheelA); BWheelAP.PlayAnimation(BWheelA); PlayerAP.PlayAnimation(PersoA); YeuxAP.PlayAnimation(YeuxA); base.Udpate(RecCollision); }