//method to detect hand and creates the frame object public void detectGesture(Leap.Frame frame) { // creates an object GestureList gestures = frame.Gestures(); //returns list of gestures for (int i = 0; i < gestures.Count(); i++) { Gesture gesture = gestures[i]; //switch using gesture.type as a flag, when it gets the type of gesture it will go to its respective case switch (gesture.Type) { //these are the cases and prints out the detected gesture case Gesture.GestureType.TYPE_CIRCLE: Debug.WriteLine("Circle"); break; case Gesture.GestureType.TYPE_KEY_TAP: Debug.WriteLine("Key Tap"); break; case Gesture.GestureType.TYPE_SWIPE: Debug.WriteLine("Swipe"); break; case Gesture.GestureType.TYPE_SCREEN_TAP: Debug.WriteLine("Screen Tap"); break; } } }
private void detectGesture(Leap.Frame frame) { GestureList gestures = frame.Gestures(); for (int i = 0; i < gestures.Count(); i++) { Gesture gesture = gestures[i]; switch (gesture.Type) { case Gesture.GestureType.TYPE_CIRCLE: //richTextBox1.AppendText("Movement detected!" + Environment.NewLine); break; case Gesture.GestureType.TYPE_KEY_TAP: //richTextBox1.AppendText("Movement detected!" + Environment.NewLine); break; case Gesture.GestureType.TYPE_SWIPE: // richTextBox1.AppendText("Translation detected!" + Environment.NewLine); break; case Gesture.GestureType.TYPE_INVALID: //richTextBox1.AppendText("NO MOVEMENT "); break; } } }
protected void DetectLeapGesture(Controller leap, Leap.Frame frame) { GestureList gestures = frame.Gestures(); foreach (Gesture gesture in gestures) { if (gesture.State != Gesture.GestureState.STATESTOP) { continue; } switch (gesture.Type) { case Gesture.GestureType.TYPESWIPE: SwipeGesture swipe = new SwipeGesture(gesture); if (swipe.StartPosition.x < 0 && swipe.Direction.x > 0) { TurnSlide(-1); } else if (swipe.StartPosition.x > 0 && swipe.Direction.x < 0) { TurnSlide(+1); } break; default: break; } } }
public void detectGesture(Leap.Frame frame) //Función publica de detección de gesto con los frames recibidos del Leap Motion { GestureList gestures = frame.Gestures(); //Intanciación del objeto gestos con la llamada de frames for (int i = 0; i < gestures.Count(); i++) //Bucle for para recorrer la cantidad de gestos recibidos { Gesture gesture = gestures[i]; //Aignación de las posiciones del array segun se recorre el array de gestos switch (gesture.Type) //Switch de caos del tipo de gesto { case Gesture.GestureType.TYPE_CIRCLE: //Si se recibe el gesto de circulo richTextBox1.AppendText("Circle detected!" + Environment.NewLine); //Se muestra el texto por pantalla y se pasa a la siguiente linea del cuadro de muestras de texto por pantalla break; //Salida case Gesture.GestureType.TYPE_SCREEN_TAP: //Si se recibe el gesto de screen tap richTextBox1.AppendText("Screen tap!" + Environment.NewLine); //Se muestra el texto por pantalla y se pasa a la siguiente linea del cuadro de muestras de texto por pantalla break; //Salida case Gesture.GestureType.TYPE_KEY_TAP: //Si se recibe el gesto de key tap richTextBox1.AppendText("Key tap!" + Environment.NewLine); //Se muestra el texto por pantalla y se pasa a la siguiente linea del cuadro de muestras de texto por pantalla break; //Salida case Gesture.GestureType.TYPE_SWIPE: //Si se recibe el gesto de swipe richTextBox1.AppendText("Swipe detected!" + Environment.NewLine); //Se muestra el texto por pantalla y se pasa a la siguiente linea del cuadro de muestras de texto por pantalla break; //Salida } } }
public void detectGesture(Leap.Frame frame) { GestureList gestures = frame.Gestures(); //Return a list of gestures for (int i = 0; i < gestures.Count(); i++) // enumerate all the gestures detected in a frame { Gesture gesture = gestures[i]; switch (gesture.Type) { case Gesture.GestureType.TYPE_CIRCLE: richTextBox1.AppendText("Circle detected!" + Environment.NewLine); break; case Gesture.GestureType.TYPE_KEY_TAP: richTextBox1.AppendText("Key Tap detected!" + Environment.NewLine); break; case Gesture.GestureType.TYPE_SWIPE: richTextBox1.AppendText("Swipe detected!" + Environment.NewLine); break; case Gesture.GestureType.TYPE_SCREEN_TAP: richTextBox1.AppendText("Screen Tap detected!" + Environment.NewLine); break; } } }
public void detectGesture(Leap.Frame frame) { GestureList gestures = frame.Gestures(); //Return a list of gestures for (int i = 0; i < gestures.Count(); i++) // enumerate all the gestures detected in a frame { Gesture gesture = gestures[i]; switch (gesture.Type) { case Gesture.GestureType.TYPE_CIRCLE: richTextBox1.AppendText("Circle detected!" + Environment.NewLine); this.Unlocked = true; this.UnlockGestureTimer.Stop(); this.UnlockGestureTimer.Start(); break; case Gesture.GestureType.TYPE_KEY_TAP: FanController.WindLevel(); richTextBox1.AppendText("Key Tap detected!" + Environment.NewLine); break; case Gesture.GestureType.TYPE_SWIPE: FanController.PowerOff(); richTextBox1.AppendText("Swipe detected!" + Environment.NewLine); break; case Gesture.GestureType.TYPE_SCREEN_TAP: FanController.LightOn(); richTextBox1.AppendText("Screen Tap detected!" + Environment.NewLine); break; } } }
void newFrameHandler(Leap.Frame frame) { displayID.Text = frame.Id.ToString(); //this.displayTimestamp.Content = frame.Timestamp.ToString(); //this.displayFPS.Content = frame.CurrentFramesPerSecond.ToString(); //this.displayIsValid.Content = frame.IsValid.ToString(); displayGestureCount.Text = frame.Gestures().Count.ToString(); //this.displayImageCount.Content = frame.Images.Count.ToString(); }
// 实时采集信息显示 private void ShowGeneralInfo(Leap.Frame frame) { this.TbkFrameId.Text = "Frame ID: " + frame.Id; this.TbkTimestamp.Text = "Timestamp: " + frame.Timestamp; this.TbkGesturesCount.Text = "Gestures Count: " + frame.Gestures().Count; this.TbkHandsCount.Text = "Hands Count: " + frame.Hands.Count; this.TbkFingersCount.Text = "Fingers Count: " + frame.Fingers.Count; this.TbkToolsCount.Text = "Tools Count: " + frame.Tools.Count; }
void OnGUI() { //We display the game GUI from the playerscript //It would be nicer to have a seperate script dedicated to the GUI though... GUILayout.Label("Frame id: " + guiFrame.Id + ", timestamp: " + guiFrame.Timestamp + ", hands: " + guiFrame.Hands.Count + ", fingers: " + guiFrame.Fingers.Count + ", tools: " + guiFrame.Tools.Count + ", gestures: " + guiFrame.Gestures().Count + ", FirstHandID: " + hand0ID + ", SecondHandID: " + hand1ID); }
public void checkGestures(Leap.Frame frame) { // Get gestures GestureList gestures = frame.Gestures(); for (int i = 0; i < gestures.Count; i++) { Gesture gesture = gestures [i]; switch (gesture.Type) { case Gesture.GestureType.TYPE_CIRCLE: CircleGesture circle = new CircleGesture(gesture); // Calculate clock direction using the angle between circle normal and pointable break; case Gesture.GestureType.TYPE_SWIPE: SwipeGesture swipe = new SwipeGesture(gesture); //display the swipe position in label SwipePosition.Content = swipe.Position; break; case Gesture.GestureType.TYPE_KEY_TAP: KeyTapGesture keytap = new KeyTapGesture(gesture); break; case Gesture.GestureType.TYPE_SCREEN_TAP: ScreenTapGesture screentap = new ScreenTapGesture(gesture); break; default: break; } } }
//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(); } } } } }
void newFrameHandler(Leap.Frame frame) { try { this.displayID.Content = frame.Id.ToString(); this.displayTimestamp.Content = frame.Timestamp.ToString(); this.displayFPS.Content = frame.CurrentFramesPerSecond.ToString(); this.displayIsValid.Content = frame.IsValid.ToString(); this.displayGestureCount.Content = frame.Gestures().Count.ToString(); this.displayImageCount.Content = frame.Images.Count.ToString(); // Bitmap To BitmapSource方式获取图像 //Leap.Image image = frame.Images[0]; //this.DrawRawImages_Bitmap(image.Data, image.Width, image.Height); //WriteableBitmap方式 Leap.Image image = frame.Images[0]; this.DrawRawImages_WriteableBitmap(image.Data, image.Width, image.Height); } catch (Exception ex) { this.debugText.Text += "Init " + "\r\n"; } }
private void newFrameHandler(Leap.Frame currentFrame) { if (slideShowActive) { deltaTime = currentFrame.Timestamp - timestamp; timestamp = currentFrame.Timestamp; slideSwitchCooldownTimer -= deltaTime; modeSwitchTimer -= deltaTime; if (slideSwitchCooldownTimer < 0) { slideSwitchCooldownTimer = 0; } if (modeSwitchTimer < 0) { modeSwitchTimer = 0; } if (!currentFrame.Hands.IsEmpty) { FingerList indexList = currentFrame.Fingers.FingerType(Finger.FingerType.TYPE_INDEX); FingerList thumbList = currentFrame.Fingers.FingerType(Finger.FingerType.TYPE_THUMB); FingerList middleList = currentFrame.Fingers.FingerType(Finger.FingerType.TYPE_MIDDLE); FingerList ringList = currentFrame.Fingers.FingerType(Finger.FingerType.TYPE_RING); FingerList pinkyList = currentFrame.Fingers.FingerType(Finger.FingerType.TYPE_PINKY); // Get the first finger in the list of fingers Finger index = indexList[0]; Finger thumb = thumbList[0]; Finger middle = middleList[0]; Finger ring = ringList[0]; Finger pinky = pinkyList[0]; updateCursor(index, ring, pinky); if (thumbUpGestureActivated == false && thumb.IsExtended && !index.IsExtended && !middle.IsExtended && !ring.IsExtended && !pinky.IsExtended) { modeSwitchTimer = modeSwitchTime; thumbUpGestureActivated = true; } if (thumbUpGestureActivated == true && modeSwitchTimer > 0 && !thumb.IsExtended && !index.IsExtended && !middle.IsExtended && !ring.IsExtended && !pinky.IsExtended) { thumbUpGestureActivated = false; //set the next mode if (mode == Mode.Cursor) { mode = Mode.Pen; } else if (mode == Mode.Pen) { mode = Mode.Highlighter; } else if (mode == Mode.Highlighter) { mode = Mode.Eraser; } else if (mode == Mode.Eraser) { mode = Mode.Cursor; } updateIcons(); } //ignore the gesture if left halfway while triggering time runs out if (modeSwitchTimer == 0) { thumbUpGestureActivated = false; } //ignore the gesture if invalidated halfway if (thumbUpGestureActivated == true && !(thumb.IsExtended && !index.IsExtended && !middle.IsExtended && !ring.IsExtended && !pinky.IsExtended)) { thumbUpGestureActivated = false; } if (index.IsExtended && thumb.IsExtended) { if (mode == Mode.Pen) { setPenMode(); } if (mode == Mode.Highlighter) { setHighlighterMode(); } if (mode == Mode.Eraser) { setEraserMode(); } } else { setCursorMode(); } GestureList gestures = currentFrame.Gestures(); for (int i = 0; i < gestures.Count(); i++) { Gesture gesture = gestures[i]; if (slideSwitchCooldownTimer == 0) { //gesture - action -mapping if (horizontalSwipeToRight(gesture)) { slideSwitchCooldownTimer = slideSwitchCooldownTime; nextSlide(); } else if (horizontalSwipeToLeft(gesture)) { slideSwitchCooldownTimer = slideSwitchCooldownTime; previousSlide(); } } } } else { setCursorMode(); } } }
void newFrameHandler(Leap.Frame frame) { //this.displayID.Content = frame.Id.ToString(); //this.displayTimestamp.Content = frame.Timestamp.ToString(); //this.displayFPS.Content = frame.CurrentFramesPerSecond.ToString(); //this.displayIsValid.Content = frame.IsValid.ToString(); //this.displayGestureCount.Content = frame.Gestures().Count.ToString(); //this.displayImageCount.Content = frame.Images.Count.ToString(); //Parse the gestures here for (int i = 0; i < frame.Gestures().Count; i++) { Gesture gesture = frame.Gestures()[i]; switch (gesture.Type) { case Gesture.GestureType.TYPE_CIRCLE: CircleGesture circle = new CircleGesture(gesture); // Calculate clock direction using the angle between circle normal and pointable String clockwiseness; if (circle.Pointable.Direction.AngleTo(circle.Normal) <= Math.PI / 2) { //Clockwise if angle is less than 90 degrees clockwiseness = "clockwise"; this.Info = "gesture circle-" + clockwiseness; //MessageBox.Show(Info); //View1 and View2 zoom out zoomInCounter = zoomInCounter + 1.0; view1.IsZoomEnabled = true; view2.IsZoomEnabled = true; if (zoomInCounter > 0) { view1.ZoomExtents(new Rect3D(0, 0, 0, zoomInCounter * zoomOffset + 1, zoomInCounter * zoomOffset + 1, zoomInCounter * zoomOffset + 1)); view2.ZoomExtents(new Rect3D(0, 0, 0, zoomInCounter * zoomOffset + 1, zoomInCounter * zoomOffset + 1, zoomInCounter * zoomOffset + 1)); } else { zoomInCounter = 0; } } else { clockwiseness = "counterclockwise"; this.Info = "gesture circle-" + clockwiseness; zoomInCounter = zoomInCounter - 1.0; if (zoomInCounter > 0) { view1.ZoomExtents(new Rect3D(0, 0, 0, zoomInCounter * zoomOffset + 1, zoomInCounter * zoomOffset + 1, zoomInCounter * zoomOffset + 1)); view2.ZoomExtents(new Rect3D(0, 0, 0, zoomInCounter * zoomOffset + 1, zoomInCounter * zoomOffset + 1, zoomInCounter * zoomOffset + 1)); } } float sweptAngle = 0; // Calculate angle swept since last frame if (circle.State != Gesture.GestureState.STATE_START) { CircleGesture previousUpdate = new CircleGesture(controller.Frame(1).Gesture(circle.Id)); sweptAngle = (circle.Progress - previousUpdate.Progress) * 360; } break; case Gesture.GestureType.TYPE_SWIPE: SwipeGesture swipe = new SwipeGesture(gesture); this.Info = "gesture swipe" + swipe.Pointable.ToString() + swipe.Direction.ToString(); //Enable the Rotation of view1 and view2 view1.IsRotationEnabled = true; view1.RotationSensitivity = 5.0; view2.IsRotationEnabled = true; view2.RotationSensitivity = 5.0; //Set the camera rotation mode here //view1.CameraRotationMode = HelixToolkit.Wpf.CameraRotationMode.Trackball; //Get teh original camera position vector 3D Leap.Vector startPosition = swipe.StartPosition; Leap.Vector currentPosition = swipe.Position; //Swipe Down direction if ((currentPosition.y - startPosition.y) > 0.0) { //Rotate view1 ModelVisual3D device3D_0 = root1; Vector3D axis_0 = new Vector3D(0, 1, 0); var angle_0 = 10; var matrix_0 = device3D_0.Transform.Value; matrix_0.Rotate(new Quaternion(axis_0, angle_0)); device3D_0.Transform = new MatrixTransform3D(matrix_0); //Rotate view2 device3D_0 = root2; matrix_0 = device3D_0.Transform.Value; matrix_0.Rotate(new Quaternion(axis_0, angle_0)); device3D_0.Transform = new MatrixTransform3D(matrix_0); } //Swipe Up direction if ((currentPosition.y - startPosition.y) < 0.0) { ModelVisual3D device3D_1 = root1; var axis_1 = new Vector3D(0, -1, 0); var angle_1 = -10; var matrix_1 = device3D_1.Transform.Value; matrix_1.Rotate(new Quaternion(axis_1, angle_1)); device3D_1.Transform = new MatrixTransform3D(matrix_1); //Rotate view2 device3D_1 = root2; matrix_1 = device3D_1.Transform.Value; matrix_1.Rotate(new Quaternion(axis_1, angle_1)); device3D_1.Transform = new MatrixTransform3D(matrix_1); } //swipe Right direction if ((currentPosition.x - startPosition.x) > 0.0) { ModelVisual3D device3D_2 = root1; var axis_2 = new Vector3D(1, 0, 0); var angle_2 = 10; var matrix_2 = device3D_2.Transform.Value; matrix_2.Rotate(new Quaternion(axis_2, angle_2)); device3D_2.Transform = new MatrixTransform3D(matrix_2); //Rotate view2 device3D_2 = root2; matrix_2 = device3D_2.Transform.Value; matrix_2.Rotate(new Quaternion(axis_2, angle_2)); device3D_2.Transform = new MatrixTransform3D(matrix_2); } //Swipe left direction if ((currentPosition.x - startPosition.x) < 0.0) { ModelVisual3D device3D_3 = root1; var axis_3 = new Vector3D(-1, 0, 0); var angle_3 = -10; var matrix_3 = device3D_3.Transform.Value; matrix_3.Rotate(new Quaternion(axis_3, angle_3)); device3D_3.Transform = new MatrixTransform3D(matrix_3); //Rotate view2 device3D_3 = root2; matrix_3 = device3D_3.Transform.Value; matrix_3.Rotate(new Quaternion(axis_3, angle_3)); device3D_3.Transform = new MatrixTransform3D(matrix_3); } break; case Gesture.GestureType.TYPE_KEY_TAP: KeyTapGesture keytap = new KeyTapGesture(gesture); this.Info = "gesture key tape" + keytap.Position.ToString() + keytap.Direction.ToString(); break; case Gesture.GestureType.TYPE_SCREEN_TAP: ScreenTapGesture screentap = new ScreenTapGesture(gesture); this.Info = "gesture screen tap" + screentap.Position.ToString() + screentap.Direction.ToString(); //Translate the objects to where finger screen taps ModelVisual3D device3D = root1; //var axis = new Vector3D(-1, 0, 0); //var angle = -10; var matrix = device3D.Transform.Value; //matrix.Rotate(new Quaternion(axis, angle)); matrix.Transform(new Point3D(screentap.Position.x, screentap.Position.y, screentap.Position.z)); device3D.Transform = new MatrixTransform3D(matrix); //Rotate view2 device3D = root2; matrix = device3D.Transform.Value; //matrix.Rotate(new Quaternion(axis, angle)); matrix.Transform(new Point3D(screentap.Position.x, screentap.Position.y, screentap.Position.z)); device3D.Transform = new MatrixTransform3D(matrix); break; default: this.Info = "Unknown gesture!"; break; } } }
public void checkGestures(Leap.Frame frame) { // Get gestures GestureList gestures = frame.Gestures(); foreach (Gesture gesture in gestures) { if (gesture.Type == Gesture.GestureType.TYPE_SWIPE) { //declare a new swipe gesture SwipeGesture swipe = new SwipeGesture(gesture); //pass the swipe gesture's data into labels SwipeDirection.Content = "Swipe Direction" + swipe.Direction; SwipePosition.Content = "Swipe start Position: " + swipe.StartPosition + "Swipe position is: " + swipe.Position; SwipeSpeed.Content = "Swipe Speed is " + swipe.Speed; //Specify the images img = new BitmapImage(); img2 = new BitmapImage(); //only when you begin to act a swipe gesture and your direction is from left to right will the gesture be counted if (swipe.State == Gesture.GestureState.STATE_START && swipe.Direction.x > 0 && Math.Abs(swipe.Direction.y) < 5) { countSwipe++; } //use the data to debug Debug.WriteLine(countSwipe); /**change image according to the number of swipe gesture * Intially, the data is 0, 1.jpg will be shown in the right * Then 1.jpg will be shown in left and 2.jpg will be shown in right * In similar fashion, the left page will show the image that have already be shown in right, to model a turnning page effect, * as if you have turnned a page from right to left*/ switch (countSwipe % 12) { case 0: img.BeginInit(); img.UriSource = new Uri("Images/1.jpg", UriKind.Relative); img.EndInit(); Rightimg.Source = img; break; case 1: img.BeginInit(); img.UriSource = new Uri("Images/2.jpg", UriKind.Relative); img.EndInit(); img2.BeginInit(); img2.UriSource = new Uri("Images/1.jpg", UriKind.Relative); img2.EndInit(); Leftimg.Source = img2; Rightimg.Source = img; break; case 2: img.BeginInit(); img.UriSource = new Uri("Images/3.jpg", UriKind.Relative); img.EndInit(); img2.BeginInit(); img2.UriSource = new Uri("Images/2.jpg", UriKind.Relative); img2.EndInit(); Leftimg.Source = img2; Rightimg.Source = img; break; case 3: img.BeginInit(); img.UriSource = new Uri("Images/4.jpg", UriKind.Relative); img.EndInit(); img2.BeginInit(); img2.UriSource = new Uri("Images/3.jpg", UriKind.Relative); img2.EndInit(); Leftimg.Source = img2; Rightimg.Source = img; break; case 4: img.BeginInit(); img.UriSource = new Uri("Images/5.jpg", UriKind.Relative); img.EndInit(); img2.BeginInit(); img2.UriSource = new Uri("Images/4.jpg", UriKind.Relative); img2.EndInit(); Leftimg.Source = img2; Rightimg.Source = img; break; case 5: img.BeginInit(); img.UriSource = new Uri("Images/6.jpg", UriKind.Relative); img.EndInit(); img2.BeginInit(); img2.UriSource = new Uri("Images/5.jpg", UriKind.Relative); img2.EndInit(); Leftimg.Source = img2; Rightimg.Source = img; break; case 6: img.BeginInit(); img.UriSource = new Uri("Images/7.jpg", UriKind.Relative); img.EndInit(); img2.BeginInit(); img2.UriSource = new Uri("Images/6.jpg", UriKind.Relative); img2.EndInit(); Leftimg.Source = img2; Rightimg.Source = img; break; case 7: img.BeginInit(); img.UriSource = new Uri("Images/8.jpg", UriKind.Relative); img.EndInit(); img2.BeginInit(); img2.UriSource = new Uri("Images/7.jpg", UriKind.Relative); img2.EndInit(); Leftimg.Source = img2; Rightimg.Source = img; break; case 8: img.BeginInit(); img.UriSource = new Uri("Images/9.jpg", UriKind.Relative); img.EndInit(); img2.BeginInit(); img2.UriSource = new Uri("Images/8.jpg", UriKind.Relative); img2.EndInit(); Leftimg.Source = img2; Rightimg.Source = img; break; case 9: img.BeginInit(); img.UriSource = new Uri("Images/10.jpg", UriKind.Relative); img.EndInit(); img2.BeginInit(); img2.UriSource = new Uri("Images/9.jpg", UriKind.Relative); img2.EndInit(); Leftimg.Source = img2; Rightimg.Source = img; break; case 10: img.BeginInit(); img.UriSource = new Uri("Images/11.jpg", UriKind.Relative); img.EndInit(); img2.BeginInit(); img2.UriSource = new Uri("Images/10.jpg", UriKind.Relative); img2.EndInit(); Leftimg.Source = img2; Rightimg.Source = img; break; case 11: img.BeginInit(); img.UriSource = new Uri("Images/12.jpg", UriKind.Relative); img.EndInit(); img2.BeginInit(); img2.UriSource = new Uri("Images/11.jpg", UriKind.Relative); img2.EndInit(); Leftimg.Source = img2; Rightimg.Source = img; break; } //end switch }//end if }//end for each } //end checkGestures method
// Update is called once per frame void Update() { if (RBDone) { if (Retrying) { Application.LoadLevel("InGame"); } else { Application.LoadLevel("SelectMusic"); } return; } if (Retrying || Backing) { if (CoverColor.a < 0) { Debug.Log(1); //BigCover = Instantiate (CoverPrefab); EndCover.rectTransform.sizeDelta = new Vector2(Screen.width * 2, Screen.height * 2); CoverColor = new Color(EndCover.color.r, EndCover.color.g, EndCover.color.b, 0); } else { Debug.Log(2); CoverColor.a += Time.deltaTime * 2f; EndCover.color = CoverColor; if (CoverColor.a >= 1) { RBDone = true; } } return; } if (!ShowUI) { CoverColor.a -= Time.deltaTime * 2; BigCover.color = CoverColor; if (CoverColor.a <= 0) { ShowUI = true; CoverColor.a = 1f; CoverColor.r = CoverColor.g = CoverColor.b = 50 / 255f; Destroy(BigCover); } } if (!DisplayDone) { ScoreText.text = ScoreNow.ToString(); ComboText.text = ComboNow.ToString(); PerfectText.text = PerfectNow.ToString(); GoodText.text = GoodNow.ToString(); BadText.text = BadNow.ToString(); MissText.text = MissNow.ToString(); } if (DisplayDone) { if (Timer > 1) { Timer = 0.5f; } else if (Timer >= 0) { Timer -= Time.deltaTime; } Leap.Frame frame = leap.Frame(); foreach (Leap.Gesture gesture in frame.Gestures()) { if (gesture.Type == Leap.Gesture.GestureType.TYPE_SWIPE) { Leap.SwipeGesture swipeGesture = new Leap.SwipeGesture(gesture); Leap.Vector gestureDirection = swipeGesture.Direction; //float x = gestureDirection.x; float y = gestureDirection.y; Debug.Log(y); if (y > 0.7) { Retry(); } if (y < -0.7) { Back(); } } } if (Input.GetKey(KeyCode.DownArrow) || Input.GetKey(KeyCode.Escape) || Input.GetKey(KeyCode.S) || Input.GetKey(KeyCode.B)) { Back(); } if (Input.GetKey(KeyCode.UpArrow) || Input.GetKey(KeyCode.W) || Input.GetKey(KeyCode.R)) { Retry(); } } if (DisplayDone && Timer < 0 && CoverColor.a > 0) { CoverColor.a -= Time.deltaTime * 2; SmallCover.color = CoverColor; if (CoverColor.a <= 0) { Destroy(SmallCover); } } }
public void checkGestures(Leap.Frame frame) { //create a gesture list GestureList gestures = frame.Gestures(); //access every getures that is detected foreach (Gesture gesture in gestures) { // Gesture gesture = gestures[i]; switch (gesture.Type) { case Gesture.GestureType.TYPE_CIRCLE: CircleGesture circle = new CircleGesture(gesture); // Calculate clock direction using the angle between circle normal and pointable String clockwiseness; if (circle.Pointable.Direction.AngleTo(circle.Normal) <= Math.PI / 2) { //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 != Gesture.GestureState.STATE_START) { CircleGesture previousUpdate = new CircleGesture(controller.Frame(1).Gesture(circle.Id)); sweptAngle = (circle.Progress - previousUpdate.Progress) * 360; } //fill things into labels: id, state, progress, radius, angle circleLB.Content = " Circle id: " + circle.Id + ", " + circle.State + ", progress: " + circle.Progress + ", radius: " + circle.Radius + ", angle: " + sweptAngle + ", " + clockwiseness; Debug.WriteLine(" Circle id: " + circle.Id + ", " + circle.State + ", progress: " + circle.Progress + ", radius: " + circle.Radius + ", angle: " + sweptAngle + ", " + clockwiseness); break; case Gesture.GestureType.TYPE_SWIPE: SwipeGesture swipe = new SwipeGesture(gesture); swipeLB.Content = " Swipe id: " + swipe.Id + ", " + swipe.State + ", position: " + swipe.Position + ", direction: " + swipe.Direction + ", speed: " + swipe.Speed; Debug.WriteLine(" Swipe id: " + swipe.Id + ", " + swipe.State + ", position: " + swipe.Position + ", direction: " + swipe.Direction + ", speed: " + swipe.Speed); break; case Gesture.GestureType.TYPE_KEY_TAP: KeyTapGesture keytap = new KeyTapGesture(gesture); keyTapLB.Content = " Tap id: " + keytap.Id + ", " + keytap.State + ", position: " + keytap.Position + ", direction: " + keytap.Direction; Debug.WriteLine(" Tap id: " + keytap.Id + ", " + keytap.State + ", position: " + keytap.Position + ", direction: " + keytap.Direction); break; case Gesture.GestureType.TYPE_SCREEN_TAP: ScreenTapGesture screentap = new ScreenTapGesture(gesture); screenTapLB.Content = " Tap id: " + screentap.Id + ", " + screentap.State + ", position: " + screentap.Position + ", direction: " + screentap.Direction; Debug.WriteLine(" Tap id: " + screentap.Id + ", " + screentap.State + ", position: " + screentap.Position + ", direction: " + screentap.Direction); break; default: Debug.WriteLine(" Unknown gesture type."); break; } } }
void newFrameHandler(Leap.Frame frame) { string whichHand = null; HandList handsinFrame = frame.Hands; GestureList gestureinFrame = frame.Gestures(); if (handsinFrame.IsEmpty == true) { displayHandsID1.Text = "0"; displayHandsID2.Text = "0"; whichHand = "no hand"; displayWhichHand1.Text = whichHand; displayWhichHand2.Text = whichHand; whichHand = null; } else if (handsinFrame.Count >= 1) { displayHandsID1.Text = handsinFrame[0].Id.ToString(); // displayGestureType1.Text = gestureinFrame[0].Type.ToString(); if (handsinFrame[0].IsLeft == true) { whichHand = "left"; } else { whichHand = "right"; } displayWhichHand1.Text = whichHand; whichHand = null; if (handsinFrame.Count > 1) { displayHandsID2.Text = handsinFrame[1].Id.ToString(); // displayGestureType2.Text = gestureinFrame[1].Type.ToString(); if (handsinFrame[1].IsLeft == true) { whichHand = "left"; } else { whichHand = "right"; } displayWhichHand2.Text = whichHand; whichHand = null; } else { displayHandsID2.Text = "0"; whichHand = "no hand"; displayWhichHand2.Text = whichHand; whichHand = null; } } if (gestureinFrame[0].Hands[0].Id == handsinFrame[0].Id) { displayGestureType1.Text = gestureinFrame[0].Type.ToString(); displayGestureType2.Text = gestureinFrame[1].Type.ToString(); } else if (gestureinFrame[0].Hands[0].Id == handsinFrame[1].Id) { displayGestureType2.Text = gestureinFrame[0].Type.ToString(); displayGestureType1.Text = gestureinFrame[1].Type.ToString(); } displayID.Text = frame.Id.ToString(); displayFingerCount.Text = frame.Fingers.Count.ToString(); displayHandCount.Text = frame.Hands.Count.ToString(); displayGestureCount.Text = frame.Gestures().Count.ToString(); /*for (int g = 0; g < frame.Gestures().Count; g++) * { * //displayGestureType.Text = frame.Gestures()[g].GetType().ToString(); * switch (frame.Gestures()[g].Type) * { * case Gesture.GestureType.TYPE_CIRCLE: * //Handle circle gestures * Debug.WriteLine("circle"+frame.Id); * displayGestureType.Text = "circle"; * break; * case Gesture.GestureType.TYPE_KEY_TAP: * //Handle key tap gestures * Debug.WriteLine("key_tap" + frame.Id); * displayGestureType.Text = "key_tap"; * break; * case Gesture.GestureType.TYPE_SCREEN_TAP: * //Handle screen tap gestures * Debug.WriteLine("screen_tap" + frame.Id); * displayGestureType.Text = "screen_tap"; * break; * case Gesture.GestureType.TYPE_SWIPE: * //Handle swipe gestures * Debug.WriteLine("swipe" + frame.Id); * displayGestureType.Text = "swipe"; * break; * default: * //Handle unrecognized gestures * break; * } * } * * * * for (int g = 0; g < frame.Gestures().Count; g++) * { * Console.WriteLine(frame.Gestures()[g].Type); * displayGestureType1.Text = frame.Gestures()[g].Type; * } */ }
public void _leapListener_OnFrameChanged(object sender, LeapListenerEventArgs e) { if (!Dispatcher.CheckAccess()) { Dispatcher.BeginInvoke(DispatcherPriority.Normal, (Action)((() => _leapListener_OnFrameChanged(sender, e)))); } else { var controller = e.LmController; // Get the most recent frame and report some basic information Leap.Frame frame = _leapController.Frame(); /*SafeWriteLine("Frame id: " + frame.Id + ", timestamp: " + frame.Timestamp + ", hands: " + frame.Hands.Count + ", fingers: " + frame.Fingers.Count + ", tools: " + frame.Tools.Count + ", gestures: " + frame.Gestures().Count);*/ if (!frame.Hands.IsEmpty) { // Get the first hand Hand hand = frame.Hands[0]; // Check if the hand has any fingers FingerList fingers = hand.Fingers; if (!fingers.IsEmpty) { // Get gestures GestureList gestures = frame.Gestures(); for (int i = 0; i < gestures.Count; i++) { //Console.WriteLine("Gesture!!!"); Gesture gesture = gestures[i]; switch (gesture.Type) { case Gesture.GestureType.TYPESWIPE: SwipeGesture swipe = new SwipeGesture(gesture); if (swipe.State == Gesture.GestureState.STATESTOP) { if (swipe.StartPosition.y > (swipe.Position.y + 15)) { //SafeWriteLine("Select motion accepted"); } if (swipe.StartPosition.x > (swipe.Position.x + 20)) { //SafeWriteLine("DIS IS A SWIPE TO DA LEFT"); //temp_box.Text = "No button click"; no_button_Click(sender, new RoutedEventArgs()); //left_button_Click(sender, new RoutedEventArgs()); } else if (swipe.StartPosition.x < (swipe.Position.x - 20)) { //SafeWriteLine("DIS IS A SWIPE TO DA RIGHT"); //temp_box.Text = "Yes button click"; yes_button_Click(sender, new RoutedEventArgs()); } } break; case Gesture.GestureType.TYPEKEYTAP: KeyTapGesture keytap = new KeyTapGesture(gesture); //Gotta put the button click up here! if (keytap.State == Gesture.GestureState.STATESTOP) { left_button_Click(sender, new RoutedEventArgs()); } break; case Gesture.GestureType.TYPESCREENTAP: ScreenTapGesture screentap = new ScreenTapGesture(gesture); //Unused break; default: SafeWriteLine("Unknown gesture type."); break; } } } // Get the hand's sphere radius and palm position //SafeWriteLine("Hand sphere radius: " + hand.SphereRadius.ToString("n2") // + " mm, palm position: " + hand.PalmPosition); // Get the hand's normal vector and direction Leap.Vector normal = hand.PalmNormal; Leap.Vector direction = hand.Direction; // Calculate the hand's pitch, roll, and yaw angles //SafeWriteLine("Hand pitch: " + direction.Pitch * 180.0f / (float)Math.PI + " degrees, " // + "roll: " + normal.Roll * 180.0f / (float)Math.PI + " degrees, " // + "yaw: " + direction.Yaw * 180.0f / (float)Math.PI + " degrees"); } if (!frame.Hands.IsEmpty || !frame.Gestures().IsEmpty) { SafeWriteLine(""); } } }
public override void OnFrame(Controller controller) { // Get the most recent frame and report some basic information Leap.Frame frame = controller.Frame(); if (!frame.Hands.Empty) { if (frame.Fingers.Count >= 2 && LeapFingerReady != null) { LeapFingerReady(this, frame.Fingers[0], frame.Fingers[1]); } } // Get gestures GestureList gestures = frame.Gestures(); for (int i = 0; i < gestures.Count; i++) { Gesture gesture = gestures[i]; switch (gesture.Type) { case Gesture.GestureType.TYPECIRCLE: CircleGesture circle = new CircleGesture(gesture); // Calculate clock direction using the angle between circle normal and pointable if (circle.State == Gesture.GestureState.STATESTART) { Thread.Sleep(500); LeapCircleReady(this); } break; case Gesture.GestureType.TYPESWIPE: SwipeGesture swipe = new SwipeGesture(gesture); if (swipe.State == Gesture.GestureState.STATESTART && LeapSwipeReady != null) { if (swipe.Direction.x < -0.5) { LeapSwipeReady(this, SwipeType.SwipeLeft); } else if (swipe.Direction.x > 0.5) { LeapSwipeReady(this, SwipeType.SwipeRight); } //else if (swipe.Direction.z < -0.2) //{ // LeapSwipeReady(this, SwipeType.SwpieIn); //} //else if (swipe.Direction.z > 0.2) //{ // Thread.Sleep(300); // LeapSwipeReady(this, SwipeType.SwipeOut); //} } break; case Gesture.GestureType.TYPEKEYTAP: KeyTapGesture keytap = new KeyTapGesture(gesture); SafeWriteLine("Tap id: " + keytap.Id + ", " + keytap.State + ", position: " + keytap.Position + ", direction: " + keytap.Direction); break; case Gesture.GestureType.TYPESCREENTAP: ScreenTapGesture screentap = new ScreenTapGesture(gesture); if (screentap.State == Gesture.GestureState.STATESTOP && LeapTapScreenReady != null) { if (frame.Fingers.Count > 1) { Thread.Sleep(800); } LeapTapScreenReady(this); } break; } } }
// 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; } }
// Update is called once per frame void Update() { mFrame = leapController.Frame(); int fingerCount = 0; if (numbersGestureRegistered || closeFistRegistered || openFistRegistered || keytapGestureRegistered || twoFingerKeytapRegistered || threeFingerKeytapRegistered || screentapGestureRegistered || twoFingerScreentapRegistered || threeFingerScreentapRegistered || steeringWheelRegistered) { fingerCount = GetFingerCount(); } foreach (Leap.Gesture gesture in mFrame.Gestures()) { switch (gesture.Type) { case Leap.Gesture.GestureType.TYPECIRCLE: if (circleGestureRegistered) { BuiltInGestureRecognised(gesture, EasyLeapGestureType.TYPECIRCLE); onCircleGestureRecognized(); } break; case Leap.Gesture.GestureType.TYPESWIPE: if (swipeGestureRegistered) { BuiltInGestureRecognised(gesture, EasyLeapGestureType.TYPESWIPE); } break; case Leap.Gesture.GestureType.TYPEKEYTAP: if (keytapGestureRegistered && fingerCount == 1) { BuiltInGestureRecognised(gesture, EasyLeapGestureType.TYPEKEYTAP); } if (twoFingerKeytapRegistered && fingerCount == 2) { BuiltInImprovedGestureRecognised(gesture, EasyLeapGestureType.TWO_FINGERS_KEYTAP); } if (threeFingerKeytapRegistered && fingerCount == 3) { BuiltInImprovedGestureRecognised(gesture, EasyLeapGestureType.THREE_FINGERS_KEYTAP); } break; case Leap.Gesture.GestureType.TYPESCREENTAP: if (screentapGestureRegistered && fingerCount == 1) { BuiltInGestureRecognised(gesture, EasyLeapGestureType.TYPESCREENTAP); } if (twoFingerScreentapRegistered && fingerCount == 2) { BuiltInImprovedGestureRecognised(gesture, EasyLeapGestureType.TWO_FINGERS_SCREENTAP); } if (threeFingerScreentapRegistered && fingerCount == 3) { BuiltInImprovedGestureRecognised(gesture, EasyLeapGestureType.THREE_FINGERS_SCREENTAP); } break; } } if (mFrame.Gestures().Count == 0) { ClearDraggingGestures(); } if (numbersGestureRegistered || closeFistRegistered || openFistRegistered) { switch (fingerCount) { case 0: // NO FINGERS if (numbersGestureRegistered) { NumbersGestureRecognised(EasyLeapGestureType.DEFAULT); } if (closeFistRegistered) { if (mFrame.Hands.Count == 1) { if (PalmIsHorizontal(mFrame.Hands[0])) { CloseFistGestureRecognised(EasyLeapGestureState.STATESTOP); } } else { CloseFistGestureRecognised(EasyLeapGestureState.STATEINVALID); } } if (openFistRegistered) { if (mFrame.Hands.Count == 1) { if (PalmIsHorizontal(mFrame.Hands[0])) { OpenFistGestureRecognised(EasyLeapGestureState.STATESTART); } } else { OpenFistGestureRecognised(EasyLeapGestureState.STATEINVALID); } } break; case 1: if (numbersGestureRegistered) { NumbersGestureRecognised(EasyLeapGestureType.ONE); } break; case 2: if (numbersGestureRegistered) { NumbersGestureRecognised(EasyLeapGestureType.TWO); } break; case 3: if (numbersGestureRegistered) { NumbersGestureRecognised(EasyLeapGestureType.THREE); } break; case 4: if (numbersGestureRegistered) { NumbersGestureRecognised(EasyLeapGestureType.FOUR); } break; case 5: if (numbersGestureRegistered) { NumbersGestureRecognised(EasyLeapGestureType.FIVE); } if (closeFistRegistered && mFrame.Hands.Count == 1) { CloseFistGestureRecognised(EasyLeapGestureState.STATESTART); } if (openFistRegistered) { OpenFistGestureRecognised(EasyLeapGestureState.STATESTOP); } break; case 6: if (numbersGestureRegistered) { NumbersGestureRecognised(EasyLeapGestureType.SIX); } break; case 7: if (numbersGestureRegistered) { NumbersGestureRecognised(EasyLeapGestureType.SEVEN); } break; case 8: if (numbersGestureRegistered) { NumbersGestureRecognised(EasyLeapGestureType.EIGHT); } break; case 9: if (numbersGestureRegistered) { NumbersGestureRecognised(EasyLeapGestureType.NINE); } break; case 10: if (numbersGestureRegistered) { NumbersGestureRecognised(EasyLeapGestureType.TEN); } break; } } if (pushGestureRegistered || pullGestureRegistered) { if (mFrame.Hands.Count == 1) { if (pushGestureRegistered) { if (mFrame.Hands[0].PalmVelocity.y < -EasyLeapGesture.MinPushPullVelocity) { PushGestureRecognised(EasyLeapGestureState.STATESTART); } else { PushGestureRecognised(EasyLeapGestureState.STATEINVALID); } } if (pullGestureRegistered) { if (mFrame.Hands[0].PalmVelocity.y > EasyLeapGesture.MinPushPullVelocity) { PullGestureRecognised(EasyLeapGestureState.STATESTART); } else { PullGestureRecognised(EasyLeapGestureState.STATEINVALID); } } } else { PushGestureRecognised(EasyLeapGestureState.STATEINVALID); PullGestureRecognised(EasyLeapGestureState.STATEINVALID); } } if (doubleInwardsSwipeGestureRegistered || doubleOutwardsSwipeGestureRegistered) { if (mFrame.Hands.Count == 2) { bool leftHandSwipeIn = (PalmIsHorizontal(mFrame.Hands.Leftmost)) && mFrame.Hands.Leftmost.PalmVelocity.x > EasyLeapGesture.MinSwipeVelocity; bool rightHandSwipeIn = (PalmIsHorizontal(mFrame.Hands.Rightmost)) && mFrame.Hands.Rightmost.PalmVelocity.x < -EasyLeapGesture.MinSwipeVelocity; if (doubleInwardsSwipeGestureRegistered && (leftHandSwipeIn && rightHandSwipeIn)) { if (mFrame.Hands[0].StabilizedPalmPosition.DistanceTo(mFrame.Hands[1].StabilizedPalmPosition) < EasyLeapGesture.MaxPalmDistance) { DoubleInwardsSwipeRecognised(EasyLeapGestureState.STATESTART); } } else { DoubleInwardsSwipeRecognised(EasyLeapGestureState.STATEINVALID); } bool leftHandSwipeOut = (PalmIsHorizontal(mFrame.Hands.Leftmost)) && mFrame.Hands.Leftmost.PalmVelocity.x < -EasyLeapGesture.MinSwipeVelocity; bool rightHandSwipeOut = (PalmIsHorizontal(mFrame.Hands.Rightmost)) && mFrame.Hands.Rightmost.PalmVelocity.x > EasyLeapGesture.MinSwipeVelocity; if (doubleOutwardsSwipeGestureRegistered && leftHandSwipeOut && rightHandSwipeOut) { if (mFrame.Hands[0].StabilizedPalmPosition.DistanceTo(mFrame.Hands[1].StabilizedPalmPosition) > EasyLeapGesture.MaxPalmDistance) { DoubleOutwardsSwipeRecognised(EasyLeapGestureState.STATESTART); } } else { DoubleOutwardsSwipeRecognised(EasyLeapGestureState.STATEINVALID); } } } if (clapGestureRegistered) { if (mFrame.Hands.Count == 2) { bool leftHandSwipeIn = (!PalmIsHorizontal(mFrame.Hands.Leftmost)) && mFrame.Hands.Leftmost.PalmVelocity.x > EasyLeapGesture.MinClapVelocity; bool rightHandSwipeIn = (!PalmIsHorizontal(mFrame.Hands.Rightmost)) && mFrame.Hands.Rightmost.PalmVelocity.x < -EasyLeapGesture.MinClapVelocity; if (leftHandSwipeIn && rightHandSwipeIn) { if (mFrame.Hands[0].StabilizedPalmPosition.DistanceTo(mFrame.Hands[1].StabilizedPalmPosition) < EasyLeapGesture.MaxPalmClapDistance) { ClapRecognised(EasyLeapGestureState.STATESTART); } } else { ClapRecognised(EasyLeapGestureState.STATEINVALID); } } } if (steeringWheelRegistered) { float palmsAngle = (mFrame.Hands.Leftmost.PalmNormal.AngleTo(mFrame.Hands.Rightmost.PalmNormal) * Mathf.Rad2Deg); if (mFrame.Hands.Count >= 1 && fingerCount < 2 && (palmsAngle > 110 || palmsAngle < 70)) { Leap.Vector leftMost = mFrame.Hands.Leftmost.StabilizedPalmPosition; Leap.Vector rightMost = mFrame.Hands.Rightmost.StabilizedPalmPosition; Leap.Vector steerVector = (leftMost - rightMost).Normalized; //steerVector.z = 0; float angle = steerVector.AngleTo(Leap.Vector.Left) * Mathf.Rad2Deg * (leftMost.y > rightMost.y ? 1 : -1); SteeringWheelRecognised(angle, Mathf.Abs(leftMost.z) - Mathf.Abs(rightMost.z)); } } // Send gestures detected to all registered gesture listeners SendGesturesToListeners(); }
// Update is called once per frame void Update() { Leap.Frame frame = LeapInputEx.Frame; if (frame == null) { return; } //Debug.Log(frame.Gestures().Count); foreach (Gesture gesture in frame.Gestures()) { /* * if(gesture.Type == Leap.Gesture.GestureType.TYPESWIPE) * { * //frozen = true; * * //SwipeGesture swipeGesture = SwipeGesture(gesture); * //if this is a new swipe * if(gestureID != gesture.Id) * { * if(frozen) * { * Destroy(selectionBox); * selectionBox = null; * } * //frozen = !frozen; * /* * //destroy old box, so if this isn't first box you don't just move old one, creates problems * if(frozen == false) * { * Destroy(selectionBox); * selectionBox = null; * } * Debug.Log("Swiper no swiping!"); * } * }*/ if (gesture.Type == Leap.Gesture.GestureType.TYPECIRCLE) { if (gestureID != gesture.Id) { CircleGesture circleGesture = new CircleGesture(gesture); if (circleGesture.Progress >= 2) { frozen = !frozen; //destroy old box, so if this isn't first box you don't just move old one, creates problems if (frozen == false) { Destroy(selectionBox); selectionBox = null; } Debug.Log("Circling!"); } } } if (gesture.Type == Leap.Gesture.GestureType.TYPESCREENTAP) { if (gestureID != gesture.Id) { ScreenTapGesture screenTapGesture = new ScreenTapGesture(gesture); // Debug.Log (screenTapGesture.Direction); //Debug.Log(screenTapGesture.DurationSeconds); if (screenTapGesture.Direction.z < 0) { frozen = !frozen; // if frozen, get rid of old box. //destroy old box, so if this isn't first box you don't just move old one, creates problems if (frozen == false) { Destroy(selectionBox); selectionBox = null; } Debug.Log("Tapped!"); //Debug.Log (gesture); } } } } HandList hands = frame.Hands; FingerList fingers = frame.Fingers; Hand lh = hands.Leftmost; Hand rh = hands.Rightmost; Vector3 rpos = rh.PalmPosition.ToUnityScaled(); Vector3 rdir = rh.Direction.ToUnity(); Vector3 rnorm = rh.PalmNormal.ToUnity(); Vector3 lpos = lh.PalmPosition.ToUnityScaled(); float farthestZ = -10000f; int thumbID = -1; int otherFingerID = -1; int count = 0; GameObject hand = GameObject.Find("right"); #region defining thumb/other fingers //for(int x = 0; x < m.fin //foreach(Finger finger in fingers) foreach (Finger finger in rh.Fingers) { count += 1; if (count == 1) { otherFingerID = finger.Id; } if (finger.TipPosition.z > farthestZ) { thumbID = finger.Id; farthestZ = finger.TipPosition.z; } else { otherFingerID = finger.Id; } } Vector3 rightHandPosition = (frame.Finger(thumbID).TipPosition.ToUnityScaled() + frame.Finger(otherFingerID).TipPosition.ToUnityScaled()) / 2; count = 0; foreach (Finger finger in lh.Fingers) { count += 1; if (count == 1) { otherFingerID = finger.Id; } if (finger.TipPosition.z > farthestZ) { thumbID = finger.Id; farthestZ = finger.TipPosition.z; } else { otherFingerID = finger.Id; } } Vector3 leftHandPosition = (frame.Finger(thumbID).TipPosition.ToUnityScaled() + frame.Finger(otherFingerID).TipPosition.ToUnityScaled()) / 2; #endregion //get positions of left and right hand models if (GameObject.Find("RightRiggedHand(Clone)")) { rpos = GameObject.Find("RightRiggedHand(Clone)").transform.position; handsObject = GameObject.Find("RightRiggedHand(Clone)"); } if (GameObject.Find("LeftRiggedHand(Clone)")) { lpos = GameObject.Find("LeftRiggedHand(Clone)").transform.position; } //box position is in the middle of two hand models Vector3 boxPosition = Vector3.Lerp(lpos, rpos, 0.5f); if (!frozen) { //Debug.Log ("boxPosition: " + boxPosition); if (selectionBox == null && GameObject.Find("RightRiggedHand(Clone)")) { Transform box = Instantiate(selectionBoxObject, new Vector3(0, 0, 0), Quaternion.identity) as Transform; selectionBox = box.gameObject; //(GameObject)(selectionBox); selectionBox.renderer.material.color = Color.blue; //GameObject handsObject = GameObject.Find("RightRiggedHand(Clone)"); //handsObject.transform.position = new Vector3(0,0,0); //set position of box selectionBox.transform.localPosition = boxPosition; // + new Vector3(boxPosition.x,0,0); //selectionBox.transform.parent = handsObject.transform; //don't rotate box based on hands rotation selectionBox.transform.rotation = Quaternion.identity; //selectionBox.transform.rotation = selectionBox.transform.parent.rotation; //selectionBox.transform.Rotate(new Vector3(0,0,90f)); //selectionBox.AddComponent("BoxCollider"); //Debug.Log("not frozen, doesn't exist"); } if (selectionBox != null && GameObject.Find("RightRiggedHand(Clone)")) { /* * Destroy(selectionBox); * selectionBox = null; * * Transform box = Instantiate(selectionBoxObject,new Vector3(0,0,0),Quaternion.identity) as Transform; * selectionBox = box.gameObject;//(GameObject)(selectionBox); * selectionBox.renderer.material.color = Color.blue; * GameObject handsObject = GameObject.Find("Primary Hand"); * //handsObject.transform.position = new Vector3(0,0,0); * selectionBox.transform.localPosition = new Vector3(0f,-2f,2.5f) + boxPosition; * selectionBox.transform.parent = handsObject.transform;*/ //GameObject handsObject = GameObject.Find("RightRiggedHand(Clone)"); selectionBox.transform.localPosition = boxPosition; // + new Vector3(boxPosition.x,0,0); //selectionBox.transform.parent = handsObject.transform; selectionBox.transform.rotation = Quaternion.identity; //selectionBox.transform.rotation = selectionBox.transform.parent.rotation; Vector3 handDiff = lpos - rpos; float xDiff = (float)(Math.Sqrt(Math.Pow(handDiff.x, 2f))) / 2f; float yDiff = (float)(Math.Sqrt(Math.Pow(handDiff.y, 2f))) * .75f; float zDiff = (float)(Math.Sqrt(Math.Pow(handDiff.z, 2f))) * 1f; //limit how small box can be float minScale = 0.1f; if (xDiff < minScale) { xDiff = minScale; } if (yDiff < minScale) { yDiff = minScale; } if (zDiff < minScale) { zDiff = minScale; } //limit how large box can be float maxScale = 1f; if (xDiff > maxScale) { xDiff = maxScale; } if (yDiff > maxScale) { yDiff = maxScale; } if (zDiff > maxScale) { zDiff = maxScale; } Vector3 newScale = new Vector3(xDiff, yDiff, zDiff); //Debug.Log (newScale); selectionBox.transform.localScale = newScale; /* * if(xDiff > 1 && yDiff > 1 && zDiff > 1) // minimum scale * { * selectionBox.transform.localScale = newScale; * } * else * { * selectionBox.transform.localScale = Vector3.one; * } */ //Debug.Log("not frozen, but exists"); } } else { if (selectionBox != null) { selectionBox.renderer.material.color = Color.red; Vector3 temp = selectionBox.transform.position; selectionBox.transform.parent = null; selectionBox.transform.position = temp; //Debug.Log("frozen and exists"); //Destroy(selectionBox); //selectionBox = null; } } }