// 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 ){ mustPause=true; } mustPause=false; if (!hand1.IsValid ||(hand1.IsValid && hand1.Fingers.Count<=2) ){ if (mustPause==false && frame.Hands[0].Id != hand1ID){ // (*)<-- // first navigation type // if (hand0.Fingers.Count<=2){ // float moveInputX = firstfinger.TipVelocity.x /400; // transform.position += new Vector3(moveInputX, 0, 0); // float moveInputY = firstfinger.TipVelocity.y /400; // transform.position += new Vector3(0, moveInputY, 0); // float moveInputZ = firstfinger.TipVelocity.z /400; // if (moveInputZ >=0) transform.position -= new Vector3(0, 0 , moveInputZ*2); // else transform.position -= new Vector3(0, 0 , moveInputZ*2); // }else{ // // second navigation type // float moveStraightX = hand0.PalmPosition.x; // if (moveStraightX>25) transform.position += new Vector3(moveStraightX/45, 0 , 0); // else if (moveStraightX<-25) transform.position -= new Vector3(5, 0 , 0); // // float moveStraightZ = hand0.PalmPosition.z; // if (moveStraightZ>25) transform.position -= new Vector3(0, 0 , 1); // else if (moveStraightZ<-2) transform.position += new Vector3(0, 0 , 1); // /////////////////////////////////////////////////////////////// float moveStraightY = hand0.PalmPosition.y; if (moveStraightY >=160) { moveStraightY/=460; if (moveStraightY>1) {moveStraightY=1; } audio.pitch = moveStraightY; }else{ //if (audio.pitch > 0.0f ) {audio.pitch -=0.115f;} //disco fermo ---- //se velocità troppo bassa azzera pitch <<------------------------------------------------------- /////////////////////////////////////////////////////////////// fingerTemp = hand0.Fingers[0].TipVelocity.z; float zPosition = hand0.Fingers[0].TipPosition.z/20; if (zPosition <10 ){ //se non sono in zona morta fingerTemp /= 250; if (fingerTemp>0 ){ audio.pitch = -fingerTemp; }else if (fingerTemp<0 ){ audio.pitch = -fingerTemp; } else{ audio.pitch=0.0f; } } }//------- // } } } // 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); } //Ok no figners,but there's at least a hand,so a palm // Get the hand's normal vector and direction Leap.Vector normal = hand0.PalmNormal; Leap.Vector direction = hand0.Direction; // float HandRoll = hand1.PalmNormal.Roll * 180.0f / (float)3.14 ; // if (HandRoll > 100) HandRoll = 100; // if (HandRoll < -100) HandRoll = -100; // Calculate the hand's pitch, roll, and yaw angles print ("Hand pitch: " + direction.Pitch * 180.0f / (float)3.14 + " degrees, " /*+ "roll: " + HandRoll + " degrees, "*/ + "yaw: " + direction.Yaw * 180.0f / (float)3.14 + " degrees" + "Hand sphere radius: " + hand0.SphereRadius.ToString("n2") + " mm, palm position: " + hand0.PalmPosition); // // if (hand1.IsValid) if (HandRoll > 25 || HandRoll < -25) transform.Rotate(new Vector3(0, 1 , 0),HandRoll/100); } else { if (audio.pitch<0.95f) audio.pitch +=0.145f; if (audio.pitch>1.12f) audio.pitch -=0.145f; if (audio.pitch>0.95 && audio.pitch<1.12) audio.pitch = 1.0f; scratch= false; } counter= counter+1; if (counter>=19) { temp = hand0.Fingers[0].TipPosition.z/20; counter=0; } 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; // when first hand disappears,the second one becomes the first one on the list (with ID = 1).So before losing its ID,I want to remember its value } else hand0ID = -1; // if here no Hands on the scene. Hand1ID can be a dirty value. if (Input.GetKey (KeyCode.G)){ float moveInputz = Time.deltaTime * 3; transform.position = new Vector3(0, 50, -50); } }
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; } }
public ScreenTapEvent(Leap.ScreenTapGesture screenTap) { _screenTap = screenTap; }
// 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; } }