void newFrameHandler(Leap.Frame frame) { int rot_on = 0; currentTime = frame.Timestamp; timeChange = currentTime - previousTime; this.displayTimestamp.Content = timeChange; HandList hands = frame.Hands; Hand firstHand = hands[0]; Hand secondHand = hands[1]; if (timeChange > 100000) { if (hands[0].IsValid) { if (hands[0].IsRight) { this.displayID.Content = "오른손 작동"; } else { this.displayID.Content = "왼손 작동"; } if (hands[0].GrabStrength > 0.5) { if (hands[0].IsRight) { // this.displayFPS.Content = "오른손 주먹"; } else { // this.displayFPS.Content = "왼손 주먹"; } } else { // this.displayFPS.Content = "손 펴져있음"; } //양손일때 if (hands[1].IsValid) { this.displayID.Content = "양손 작동"; //Console.WriteLine(hands[1].PinchStrength); if (hands[1].GrabStrength > 0.5) { if (hands[0].GrabStrength == 0) { if (hands[1].IsRight) { // this.displayFPS.Content = "오른손 주먹"; } else { // this.displayFPS.Content = "왼손 주먹"; rot_on = 1; } } else { // this.displayFPS.Content = "양손 주먹"; } } } } else { this.displayID.Content = "손 없음"; } var handVelocity = (int)firstHand.PalmVelocity.Magnitude; if (handVelocity < 200)//1500 { // Console.WriteLine(handVelocity); //this.displayImageCount.Content = "손빠르기"; this.displayGestureCount.Content = " "; } else { for (int g = 0; g < frame.Gestures().Count; g++) { //switch(frame.Gesture(0).Type) Gesture gesture = frame.Gestures()[g]; if (swipe_d == 1) { } else if (swipe_d == -1) { } else if (swipe_d == 0) { switch (gesture.Type) { case Gesture.GestureType.TYPE_CIRCLE: CircleGesture cir = new CircleGesture(frame.Gesture(g)); // CircleGesture cir = new CircleGesture(frame.Gesture(0)); String clockwiseness; if (cir.Pointable.Direction.AngleTo(cir.Normal) <= Math.PI / 2) { clockwiseness = "clockwise"; } else { clockwiseness = "counterclockwise"; } //this.displayImageCount.Content = frame.Gesture(g).ToString() + "의 지름은 " + cir.Radius + "그리고 상태는 " + frame.Gesture(g).State + "=" + frame.Gestures()[g].State; this.displayGestureCount.Content = "원방향" + clockwiseness; Console.WriteLine("원방향" + clockwiseness); break; /* case Gesture.GestureType.TYPE_KEY_TAP: //Handle key tap gestures KeyTapGesture keytapGesture = new KeyTapGesture(frame.Gesture(g)); // this.displayImageCount.Content = "키탭"; Console.WriteLine(frame.Gesture(g).ToString() + "의 방향은 " + keytapGesture.Direction + "그리고 상태는 " + frame.Gesture(g).State + "=" + frame.Gestures()[g].State); Console.WriteLine(frame.Gesture(g).ToString() + "의 포인터은 " + keytapGesture.Pointable + "그리고" + keytapGesture.Position); break; case Gesture.GestureType.TYPE_SCREEN_TAP: //Handle screen tap gestures // this.displayImageCount.Content = "스크린탭"; ScreenTapGesture screentapGesture = new ScreenTapGesture(frame.Gesture(g)); Console.WriteLine(screentapGesture.Direction); break; */ case Gesture.GestureType.TYPE_SWIPE: // this.displayImageCount.Content = "쓸기"; SwipeGesture swipeGesture = new SwipeGesture(gesture); //1. start position위치 확인 Leap.Vector start = iBox.NormalizePoint(swipeGesture.StartPosition); // if (start.x > 0.9 || start.x < 0.1 ) return; //2. swipe speed 확인 float speed = swipeGesture.Speed; // if (speed < 1500.0) return; //3. 방향 확인 this.displayFPS.Content = swipeGesture.Direction;//y < 0 ? "Swipe to left" : "Swipe to right"; Console.WriteLine(swipeGesture.Direction.y < 0 ? "Swipe to left" : "Swipe to right"); break; default: this.displayGestureCount.Content = " ";//this.displayImageCount.Content = 0; break; } } // } Finger finger = frame.Fingers[0]; // Get the closest screen intercepting a ray projecting from the finger Screen screen = controller.LocatedScreens.ClosestScreenHit(finger); if (screen != null && screen.IsValid) { // Get the velocity of the finger tip var tipVelocity = (int)finger.TipVelocity.Magnitude; // Use tipVelocity to reduce jitters when attempting to hold // the cursor steady if (tipVelocity > 25) { var xScreenIntersect = screen.Intersect(finger, true).x; var yScreenIntersect = screen.Intersect(finger, true).y; if (xScreenIntersect.ToString() != "NaN") { var x = (int)(xScreenIntersect * screen.WidthPixels); var y = (int)(screen.HeightPixels - (yScreenIntersect * screen.HeightPixels)); /* Console.WriteLine("Screen intersect X: " + xScreenIntersect.ToString()); Console.WriteLine("Screen intersect Y: " + yScreenIntersect.ToString()); Console.WriteLine("Width pixels: " + screen.WidthPixels.ToString()); Console.WriteLine("Height pixels: " + screen.HeightPixels.ToString()); Console.WriteLine("\n"); Console.WriteLine("x: " + x.ToString()); Console.WriteLine("y: " + y.ToString()); Console.WriteLine("\n"); Console.WriteLine("Tip velocity: " + tipVelocity.ToString()); // Move the cursor //MouseCursor.MoveCursor(x, y); Console.WriteLine("\n" + new String('=', 40) + "\n");*/ if (rot_on == 1) { this.displayGestureCount.Content = "x,y 좌표는 : " + x.ToString() + "," + y.ToString(); } } } } //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(); } } previousTime = currentTime; } }
void newFrameHandler(Leap.Frame frame) { currentTime = frame.Timestamp; timeChange = currentTime - previousTime; HandList hands = frame.Hands; Hand firstHand = hands[0]; Hand secondHand = hands[1]; if (timeChange > 100000) { if (hands[0].IsValid) { if (hands[1].IsValid) { //Console.WriteLine(hands[1].PinchStrength); }else{ // Console.WriteLine("only 0"); } } var handVelocity = (int)firstHand.PalmVelocity.Magnitude; if (handVelocity > 10000)//1500 { Console.WriteLine(handVelocity); this.displayImageCount.Content = "손빠르기"; } else { for (int g = 0; g < frame.Gestures().Count; g++) { switch (frame.Gestures()[g].Type) { case Gesture.GestureType.TYPE_CIRCLE: CircleGesture cir = new CircleGesture(frame.Gesture(g)); //this.displayImageCount.Content = frame.Gesture(g).ToString() + "의 지름은 " + cir.Radius + "그리고 상태는 " + frame.Gesture(g).State + "=" + frame.Gestures()[g].State; this.displayImageCount.Content = "원" +frame.Gesture(g).ToString() + "의 지름은 " + cir.Radius + "그리고 상태는 " + frame.Gesture(g).State; break; case Gesture.GestureType.TYPE_KEY_TAP: //Handle key tap gestures KeyTapGesture keytapGesture = new KeyTapGesture(frame.Gesture(g)); this.displayImageCount.Content = "키탭"; Console.WriteLine(frame.Gesture(g).ToString() + "의 방향은 " + keytapGesture.Direction + "그리고 상태는 " + frame.Gesture(g).State + "=" + frame.Gestures()[g].State); Console.WriteLine(frame.Gesture(g).ToString() + "의 포인터은 " + keytapGesture.Pointable + "그리고" + keytapGesture.Position); break; case Gesture.GestureType.TYPE_SCREEN_TAP: //Handle screen tap gestures this.displayImageCount.Content = "스크린탭"; ScreenTapGesture screentapGesture = new ScreenTapGesture(frame.Gesture(g)); Console.WriteLine(screentapGesture.Direction); break; case Gesture.GestureType.TYPE_SWIPE: this.displayImageCount.Content = "쓸기"; break; default: //this.displayImageCount.Content = 0; break; } } 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(); } previousTime = currentTime; } }