Exemplo n.º 1
0
    // Update is called once per frame
    void Update()
    {
        Frame frame = controller.Frame();

        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);
                    Debug.Log ("CIRCLE");
                    Application.LoadLevel(1);
                    break;
                case Gesture.GestureType.TYPESCREENTAP:
                    Debug.Log ("yo");
                    ScreenTapGesture screentap = new ScreenTapGesture (gesture);
                    Application.LoadLevel(0);
                    break;
                default:
                    break;
            }
        }
    }
Exemplo n.º 2
0
    void objectOperationWithLeapMotion()
    {
        Frame frame = controller.Frame();

        FingerCount = frame.Fingers.Count;
        GestureList    gestures       = frame.Gestures();
        InteractionBox interactionBox = frame.InteractionBox;

        if (frame.Fingers[0].IsValid)
        {
            for (int n = 0; n < gestures.Count; n++)
            {
                Gesture gesture = gestures[n];
                Debug.Log(gesture.Type);
                switch (gesture.Type)
                {
                case Gesture.GestureType.TYPEKEYTAP:
                    KeyTapGesture keytapGesture = new KeyTapGesture(gesture);
                    Debug.Log("KeyTap");
                    break;

                case Gesture.GestureType.TYPESCREENTAP:
                    ScreenTapGesture screenTapGesture = new ScreenTapGesture(gesture);
                    Debug.Log("ScreenTap");
                    break;

                default:
                    break;
                }
            }
        }
    }
Exemplo n.º 3
0
 // Screen Tap Event
 public void OnScreenTapGesture(ScreenTapGesture g)
 {
     GameObject go = (GameObject) GameObject.Instantiate(screenTapGesturePrefab);
     ScreenTapGestureDisplay screenTap = go.GetComponent<ScreenTapGestureDisplay>();
     screenTap.gesture = g;
     //Debug.Log("OnScreenTapGesture " + g.Id);
 }
Exemplo n.º 4
0
    private void TapGestures()
    {
        GestureList gestures = controller.GetCustomGestures();

        for (int i = 0; i < gestures.Count; i++)
        {
            Gesture gesture = gestures[i];
            Vector3 vect    = new Vector3();
            if (gesture.Type == ScreenTapGesture.ClassType())
            {
                //Debug.Log ("tap");
                ScreenTapGesture screenTapGesture = new ScreenTapGesture(gesture);
                vect = screenTapGesture.Position.ToUnityScaled();
            }
            if (gesture.Type == KeyTapGesture.ClassType())
            {
                //Debug.Log ("key");
                KeyTapGesture screenTapGesture = new KeyTapGesture(gesture);
                vect = screenTapGesture.Position.ToUnityScaled();
            }
            vect = controller.transform.TransformPoint(vect);

            foreach (Button button in buttons)
            {
                Vector3[]     corners   = new Vector3 [4];
                RectTransform rectTrans = button.gameObject.GetComponent <RectTransform>();
                rectTrans.GetWorldCorners(corners);
                if (ContainInWorld(corners, vect))
                {
                    button.onClick.Invoke();
                }
            }
        }
    }
Exemplo n.º 5
0
    void objectOperationWithLeapMotion()
    {
        Frame frame = controller.Frame();
        FingerCount = frame.Fingers.Count;
        GestureList gestures = frame.Gestures();
        InteractionBox interactionBox = frame.InteractionBox;
        if(frame.Fingers[0].IsValid){
            for(int n=0; n<gestures.Count; n++){

                Gesture gesture =gestures[n];
                Debug.Log(gesture.Type);
                switch(gesture.Type){
                    case Gesture.GestureType.TYPEKEYTAP:
                        KeyTapGesture keytapGesture = new KeyTapGesture(gesture);
                            Debug.Log("KeyTap");
                    break;
                    case Gesture.GestureType.TYPESCREENTAP:
                        ScreenTapGesture screenTapGesture = new ScreenTapGesture(gesture);
                        Debug.Log("ScreenTap");
                    break;
                    default:
                    break;
                }
          		}
        }
    }
Exemplo n.º 6
0
    // Screen Tap Event
    public void OnScreenTapGesture(ScreenTapGesture g)
    {
        GameObject go = (GameObject)GameObject.Instantiate(screenTapGesturePrefab);
        ScreenTapGestureDisplay screenTap = go.GetComponent <ScreenTapGestureDisplay>();

        screenTap.gesture = g;
        //Debug.Log("OnScreenTapGesture " + g.Id);
    }
    void DetectSwipe()
    {
        Frame frame = leapController.Frame ();
        GestureList gestures = frame.Gestures ();
        Gesture gesture;
        KeyTapGesture keyTapGesture;
        ScreenTapGesture screenTapGesture;
        SwipeGesture swipeGesture;

        for (int i = 0; i < gestures.Count; i++) {
            gesture = gestures[i];
            //Debug.Log("Gesture number: " + i + " " + gesture.Type);

            switch (gesture.Type) {
            case Gesture.GestureType.TYPECIRCLE:
                break;
            case Gesture.GestureType.TYPEINVALID:
                break;
            case Gesture.GestureType.TYPEKEYTAP:
                keyTapGesture = new KeyTapGesture();
                Debug.Log("Key Tap: " + keyTapGesture.State);
                break;
            case Gesture.GestureType.TYPESCREENTAP:
                screenTapGesture = new ScreenTapGesture();
                Debug.Log("Screen Tap: " + screenTapGesture.State);
                break;
            case Gesture.GestureType.TYPESWIPE:
                swipeGesture = new SwipeGesture(gesture);
                if (swipeGesture.State == Gesture.GestureState.STATE_START) {
                    Debug.Log("Swipe StartPosition: " + swipeGesture.StartPosition);
                    Debug.Log("Swipe Position: " + swipeGesture.Position);

                    if (swipeGesture.Position.x - swipeGesture.StartPosition.x < -50) {
                        Debug.Log("Swipe: LEFT");
                    } else if(swipeGesture.Position.x - swipeGesture.StartPosition.x > 50) {
                        Debug.Log("Swipe: RIGHT");
                    }
                    if (swipeGesture.Position.y - swipeGesture.StartPosition.y < -50) {
                        Debug.Log("Swipe: UP");
                    } else if(swipeGesture.Position.y - swipeGesture.StartPosition.y > 50) {
                        Debug.Log("Swipe: DOWN");
                    }
                    if (swipeGesture.Position.z - swipeGesture.StartPosition.z < -50) {
                        Debug.Log("Swipe: FORWARD");
                    }
                } else if (swipeGesture.State == Gesture.GestureState.STATE_STOP) {
                    Debug.Log("Swipe State: " + swipeGesture.State);
                } else if (swipeGesture.State == Gesture.GestureState.STATE_UPDATE) {
                    //Debug.Log("Swipe State: " + swipeGesture.State);
                }
                break;
            }

            break;
        }
    }
 public override void Start()
 {
     if (gesture == null || gesture.Type != Gesture.GestureType.TYPESCREENTAP)
         Destroy (this);
     else
     {
         screenTapGesture = new ScreenTapGesture(gesture);
         transform.position = screenTapGesture.Position.ToUnityTranslated();
     }
 }
Exemplo n.º 9
0
 public override void Start()
 {
     if (gesture == null || gesture.Type != Gesture.GestureType.TYPESCREENTAP)
     {
         Destroy(this);
     }
     else
     {
         screenTapGesture   = new ScreenTapGesture(gesture);
         transform.position = screenTapGesture.Position.ToUnityTranslated();
     }
 }
Exemplo n.º 10
0
 void processScreenTaps(ScreenTapGesture gesture)
 {
     Debug.Log(System.String.Format("Screen tap dirn {0}", gesture));
     Vector pos = gesture.Position.Normalized;
     Debug.Log(System.String.Format("Pos: {0}", pos.ToString()));
     float dist = Vector3.Distance(buttonPos, new Vector3(pos.x, pos.y, pos.z));
     Debug.Log(System.String.Format("Distance: {0}", dist));
     if (dist <= epsilon)
     {
         addObject();
     }
 }
Exemplo n.º 11
0
    void processScreenTaps(ScreenTapGesture gesture)
    {
        Debug.Log(System.String.Format("Screen tap dirn {0}", gesture));
        Vector pos = gesture.Position.Normalized;

        Debug.Log(System.String.Format("Pos: {0}", pos.ToString()));
        float dist = Vector3.Distance(buttonPos, new Vector3(pos.x, pos.y, pos.z));

        Debug.Log(System.String.Format("Distance: {0}", dist));
        if (dist <= epsilon)
        {
            addObject();
        }
    }
Exemplo n.º 12
0
        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;
                }
            }
        }
    // ジェスチャーを判定する
    void judgeGesture()
    {
        Frame frame = controller.Frame();
        //int fingerCount = frame.Fingers.Count;    // サンプルに書いてあるくせに使ってない
        GestureList gestures = frame.Gestures();    // GestureListとはなんなのか
        //InteractionBox interactionBox = frame.InteractionBox; // サンプルに書いてあるくせに使ってない

        if (frame.Fingers[0].IsValid)
        {
            for (int i = 0; i < gestures.Count; i++)
            {
                Gesture gesture = gestures[i];
                switch (gesture.Type)
                {
                    case Gesture.GestureType.TYPECIRCLE:
                        var circleGesture = new CircleGesture(gesture);
                        Debug.Log(circleGesture);
                        Debug.Log("Circle");
                        break;

                    case Gesture.GestureType.TYPEKEYTAP:
                        var keytapGesture = new KeyTapGesture(gesture);
                        Debug.Log(keytapGesture);
                        Debug.Log("KeyTap");
                        break;

                    case Gesture.GestureType.TYPESCREENTAP:
                        var screentapGesture = new ScreenTapGesture(gesture);
                        Debug.Log(screentapGesture);
                        Debug.Log("ScreenTap");
                        break;

                    case Gesture.GestureType.TYPE_SWIPE:
                        var swipeGesture = new SwipeGesture(gesture);
                        Debug.Log(swipeGesture);
                        Debug.Log("Swipe");
                        break;

                    default:
                        break;
                }

            }
        }
    }
Exemplo n.º 14
0
    // Update is called once per frame
    void Update()
    {
        var frame          = controller.Frame();
        var fingerCount    = frame.Fingers.Count;
        var gestures       = frame.Gestures();
        var interactionBox = frame.InteractionBox;

        if (frame.Fingers[0].IsValid)
        {
            for (int i = 0; i < gestures.Count; i++)
            {
                // ジェスチャー結果取得 & 表示
                Gesture gesture = gestures[i];
                switch (gesture.Type)
                {
                //case Gesture.GestureType.TYPECIRCLE:
                //    var circleGesture = new CircleGesture(gesture);
                //    printGesture("Circle");
                //    break;
                //case Gesture.GestureType.TYPEKEYTAP:
                //    var keytapGesture = new KeyTapGesture(gesture);
                //    printGesture("KeyTap");
                //    break;
                case Gesture.GestureType.TYPESCREENTAP:
                    var screentapGesture = new ScreenTapGesture(gesture);
                    controller.Config.SetFloat("Gesture.ScreenTap.MinForwardVelocity", 30.0f);
                    controller.Config.SetFloat("Gesture.ScreenTap.HistorySeconds", 0.5f);
                    controller.Config.SetFloat("Gesture.ScreenTap.MinDistance", 1.0f);
                    controller.Config.Save();
                    printGesture("ScreenTap");
                    break;

                //case Gesture.GestureType.TYPE_SWIPE:
                //    var swipeGesture = new SwipeGesture(gesture);
                //    controller.Config.SetFloat("Gesture.Swipe.MinLength", 200.0f);
                //    controller.Config.SetFloat("Gesture.Swipe.MinVelocity", 750f);
                //    controller.Config.Save();
                //    printGesture("Swipe");
                //    break;
                default:
                    break;
                }
            }
        }
    }
Exemplo n.º 15
0
 // Update is called once per frame
 void Update()
 {
     Frame frame = controller.Frame();
     GestureList gestures = frame.Gestures();
     foreach (Gesture gesture in gestures)
     {
         if (gesture.Type == Gesture.GestureType.TYPE_SCREEN_TAP)
         {
             ScreenTapGesture screentapGesture = new ScreenTapGesture(gesture);
             processScreenTaps(screentapGesture);
         }
         else if (gesture.Type == Gesture.GestureType.TYPE_KEY_TAP)
         {
             KeyTapGesture keyTapGesture = new KeyTapGesture(gesture);
             processKeyTaps(keyTapGesture);
         }
     }
 }
Exemplo n.º 16
0
	void Update ()
    {
        Frame frame = controller.Frame();
        GestureList gestures = frame.Gestures();

        for (int i = 0; i < gestures.Count; i++)
        {
            Gesture gesture = gestures[i];

            if (gesture.Type == Gesture.GestureType.TYPECIRCLE)
            {
                CircleGesture circle = new CircleGesture(gesture);
                //Vector CircleDirection = Circle.Direction;

                Debug.Log("Did a circle gesture");
            }

            if (gesture.Type == Gesture.GestureType.TYPE_SCREEN_TAP)
            {
                ScreenTapGesture screenTapGesture = new ScreenTapGesture(gesture);
            //Debug.Log("Pointed");


                if (curPointingGo != null)
                {
                    Debug.Log(curPointingGo);
                }
                /*
                                    if (rcRCheck.pointedGo != null)
                                    {
                                        pointingGo = rcRCheck.pointedGo;
                                    }
                              //  }

                                    if (rcLCheck == null)
                                        rcLCheck = GameObject.Find("Bip01 R Finger12").GetComponent<RayCastCheck>();

                                    if (rcLCheck.pointedGo != null)
                                    {
                                        pointingGo = rcLCheck.pointedGo;
                                    }*/
            }
        }
	}
Exemplo n.º 17
0
    // Update is called once per frame
    void Update()
    {
        Frame       frame    = controller.Frame();
        GestureList gestures = frame.Gestures();

        foreach (Gesture gesture in gestures)
        {
            if (gesture.Type == Gesture.GestureType.TYPE_SCREEN_TAP)
            {
                ScreenTapGesture screentapGesture = new ScreenTapGesture(gesture);
                processScreenTaps(screentapGesture);
            }
            else if (gesture.Type == Gesture.GestureType.TYPE_KEY_TAP)
            {
                KeyTapGesture keyTapGesture = new KeyTapGesture(gesture);
                processKeyTaps(keyTapGesture);
            }
        }
    }
Exemplo n.º 18
0
 // Update is called once per frame
 void Update()
 {
     if (
         controller.IsConnected) { //controller is a Controller object
         Frame aFrame = controller.Frame (); //The latest frame
         Frame previous = controller.Frame (1); //The previous frame
         foreach (Gesture g in aFrame.Gestures()) {
             Debug.Log("GESTURING");
             if (g.Type.Equals(Gesture.GestureType.TYPE_SCREEN_TAP)) {
                 //CircleGesture circleGesture = new CircleGesture(g);
                 ScreenTapGesture circleGesture = new ScreenTapGesture(g);
                 GameObject spawnFinger = GameObject.Find("SpawnSpot");
                 Vector3 posV3 = spawnFinger.transform.position;
                 ready = false;
                 GameObject.Instantiate(spawnThis, posV3 ,Quaternion.identity);
                 Debug.Log(posV3);
             }
         }
     }
 }
    public virtual void CheckGesture()
    {
        _lastFrame = _leap_controller.Frame(0);
        Hands = _lastFrame.Hands;
        _gestures = _lastFrame.Gestures();

        foreach(Hand hand in Hands)
        {
            tempHand = hand;
            _fingers = hand.Fingers;
            if (WhichSide.IsEnableGestureHand(this))
            {

                foreach (Gesture gesture in _gestures)
                {
                    if ((gesture.Type == Gesture.GestureType.TYPE_SCREEN_TAP) && WhichSide.capturedSide(hand, _useArea, this._mountType))
                    {
                        _screentap_gesture = new ScreenTapGesture(gesture);

                        this.GetDirection();
                        this.GetPointable();
                        this.GetGestureInvokePosition();

                        this._isChecked = true;
                        break;
                    }
                }

                if (this._isChecked)
                    break;

            }
        }
       

        if (this._isChecked)
        {
            DoAction();
        }
    }
Exemplo n.º 20
0
    public virtual void CheckGesture()
    {
        _lastFrame = _leap_controller.Frame(0);
        Hands      = _lastFrame.Hands;
        _gestures  = _lastFrame.Gestures();

        foreach (Hand hand in Hands)
        {
            tempHand = hand;
            _fingers = hand.Fingers;
            if (WhichSide.IsEnableGestureHand(this))
            {
                foreach (Gesture gesture in _gestures)
                {
                    if ((gesture.Type == Gesture.GestureType.TYPE_SCREEN_TAP) && WhichSide.capturedSide(hand, _useArea, this._mountType))
                    {
                        _screentap_gesture = new ScreenTapGesture(gesture);

                        this.GetDirection();
                        this.GetPointable();
                        this.GetGestureInvokePosition();

                        this._isChecked = true;
                        break;
                    }
                }

                if (this._isChecked)
                {
                    break;
                }
            }
        }


        if (this._isChecked)
        {
            DoAction();
        }
    }
Exemplo n.º 21
0
        private void ProcessScreenTap(ScreenTapGesture tap)
        {
            if (_visibleHands > 1)
            {
                return;
            }

            if (_visibleFingers != TapFingersRequired)
            {
                #if DEBUG
                SendDebugMessage("Screen Tap -- invalid finger count: " + _visibleFingers);
                #endif

                return;
            }
            else if (_visibleTools != TapToolsRequired)
            {
                #if DEBUG
                SendDebugMessage("Screen Tap -- invalid tool count: " + _visibleTools);
                #endif

                return;
            }

            if (OnScreenTap != null)
            {
                OnScreenTap();
            }

            #if DEBUG
            SendDebugMessage(string.Format("Screen Tap (x:{0} y:{1} dur:{2})",
                                           tap.Direction.x,
                                           tap.Direction.y,
                                           tap.DurationSeconds
                                           ));
            #endif

            _lastGestureEvent = DateTime.Now;
        }
Exemplo n.º 22
0
	public override void OnFrame (Controller controller)
	{
		// Get the most recent frame and report some basic information
		Frame frame = controller.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) {
				// Calculate the hand's average finger tip position
				Vector avgPos = Vector.Zero;
				foreach (Finger finger in fingers) {
					avgPos += finger.TipPosition;
				}
				avgPos /= fingers.Count;
				SafeWriteLine ("Hand has " + fingers.Count
                            + " fingers, average finger tip position: " + avgPos);
			}

			// 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
			Vector normal = hand.PalmNormal;
			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");
		}

		// 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
				String clockwiseness;
				if (circle.Pointable.Direction.AngleTo (circle.Normal) <= Math.PI / 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 != Gesture.GestureState.STATE_START) {
					CircleGesture previousUpdate = new CircleGesture (controller.Frame (1).Gesture (circle.Id));
					sweptAngle = (circle.Progress - previousUpdate.Progress) * 360;
				}

				SafeWriteLine ("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);
				SafeWriteLine ("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);
				SafeWriteLine ("Tap id: " + keytap.Id
                               + ", " + keytap.State
                               + ", position: " + keytap.Position
                               + ", direction: " + keytap.Direction);
				break;
			case Gesture.GestureType.TYPE_SCREEN_TAP:
				ScreenTapGesture screentap = new ScreenTapGesture (gesture);
				SafeWriteLine ("Tap id: " + screentap.Id
                               + ", " + screentap.State
                               + ", position: " + screentap.Position
                               + ", direction: " + screentap.Direction);
				break;
			default:
				SafeWriteLine ("Unknown gesture type.");
				break;
			}
		}

		if (!frame.Hands.IsEmpty || !frame.Gestures ().IsEmpty) {
			SafeWriteLine ("");
		}
	}
Exemplo n.º 23
0
    void Update()
    {
        if(leapInitialized && leapController != null)
        {
            Leap.Frame frame = leapController.Frame();

            if(frame.IsValid && (frame.Id != lastFrameID))
            {
                leapFrame = frame;
                lastFrameID = leapFrame.Id;
                leapFrameCounter++;

                // fix unfinished leap gesture progress
                if(fCircleProgress > 0f && fCircleProgress < 1f)
                    fCircleProgress = 0f;
                if(fSwipeProgress > 0f && fSwipeProgress < 1f)
                    fSwipeProgress = 0f;
                if(fKeyTapProgress > 0f && fKeyTapProgress < 1f)
                    fKeyTapProgress = 0f;
                if(fScreenTapProgress > 0f && fScreenTapProgress < 1f)
                    fScreenTapProgress = 0f;

                // get a suitable pointable
                leapPointable = leapFrame.Pointable(leapPointableID);

                if(!leapPointable.IsValid)
                    leapPointable = leapFrame.Pointables.Frontmost;

                Leap.Vector stabilizedPosition = Leap.Vector.Zero;
                Leap.Hand handPrim = leapFrame.Hands.Count > 0 ? leapFrame.Hands[leapFrame.Hands.Count - 1] : null;

                if(leapPointable != null && leapPointable.IsValid &&
                    leapPointable.Hand != null && leapPointable.Hand.IsValid &&
                    handPrim != null && leapPointable.Hand.Id == handPrim.Id)
                {
                    leapPointableID = leapPointable.Id;
                    leapPointableHandID = leapPointable.Hand != null && leapPointable.Hand.IsValid ? leapPointable.Hand.Id : 0;

                    leapPointablePos = LeapToUnity(leapPointable.StabilizedTipPosition, true);
                    leapPointableDir = LeapToUnity(leapPointable.Direction, false);
                    //leapPointableQuat = Quaternion.LookRotation(leapPointableDir);

                    leapPointableZone = leapPointable.TouchZone;
                    //stabilizedPosition = leapPointable.StabilizedTipPosition;

                    leapHand = leapPointable.Hand;
                    leapHandID = leapHand.Id;
                }
                else
                {
                    leapPointableID = 0;
                    leapPointable = null;

                    // get leap hand
                    leapHand = leapFrame.Hand(leapHandID);
                    if(leapHand == null || !leapHand.IsValid)
                    {
                        leapHandID = 0;

                        if(leapFrame.Hands.Count > 0)
                        {
                            for(int i = leapFrame.Hands.Count - 1; i >= 0; i--)
                            {
                                leapHand = leapFrame.Hands[i];

                                if(leapHand.IsValid /**&& leapHand.Fingers.Count > 0*/)
                                {
                                    leapHandID = leapHand.Id;
                                    break;
                                }
                            }
                        }
                    }

                }

                if(leapHandID != 0)
                {
                    leapHandPos = LeapToUnity(leapHand.StabilizedPalmPosition, true);
                    stabilizedPosition = leapHand.StabilizedPalmPosition;
                    leapHandFingersCount = leapHand.Fingers.Count;
                }

                // estimate the cursor coordinates
                if(stabilizedPosition != Leap.Vector.Zero)
                {
                    Leap.InteractionBox iBox = frame.InteractionBox;
                    Leap.Vector normalizedPosition = iBox.NormalizePoint(stabilizedPosition);

                    cursorNormalPos.x = normalizedPosition.x;
                    cursorNormalPos.y = normalizedPosition.y;
                    cursorScreenPos.x = cursorNormalPos.x * UnityEngine.Screen.width;
                    cursorScreenPos.y = cursorNormalPos.y * UnityEngine.Screen.height;
                }

                // do fingers count filter
                if(leapHandID != fingersCountHandID)
                {
                    fingersCountHandID = leapHandID;
                    fingersCountPrev = -1;
                    fingersCountPrevPrev = -1;

                    handGripDetected = false;
                    fingersCountFilter.Reset();
                }

                if(leapHandID != 0)
                {
                    fingersCountFiltered = leapHandFingersCount;
                    fingersCountFilter.UpdateFilter(ref fingersCountFiltered);

                    if((leapFrameCounter - handGripFrameCounter) >= FramesToSkip)
                    {
                        handGripFrameCounter = leapFrameCounter;
                        int fingersCountNow = (int)(fingersCountFiltered + 0.5f);
                        //int fingersCountNow = leapHandFingersCount;

                        if(fingersCountPrev == fingersCountPrevPrev)
                        {
                            if(!handGripDetected)
                            {
                                if(fingersCountNow < fingersCountPrev)
                                {
                                    Finger leftFinger = leapHand.Finger(leapHandLFingerId);
                                    Finger rightFinger = leapHand.Finger(leapHandRFingerId);
                                    bool bThumbOff = !LeftHandedUser ? leapHandLFingerId != 0 && (leftFinger == null || !leftFinger.IsValid) :
                                        leapHandRFingerId != 0 && (rightFinger == null || !rightFinger.IsValid);

                                    if(bThumbOff)
                                    {
                                        handGripDetected = true;
                                        handGripFingersCount = fingersCountPrev;
                                    }
                                }
                                else
                                {
                                    leapHandLFingerId = leapHand != null && leapHand.Fingers.Count > 0 ? leapHand.Fingers.Leftmost.Id : 0;
                                    leapHandRFingerId = leapHand != null && leapHand.Fingers.Count > 0 ? leapHand.Fingers.Rightmost.Id : 0;
                                }
                            }
                            else
                            {
                                if(fingersCountNow >= fingersCountPrev/**handGripFingersCount*/)
                                {
                                    Finger leftFinger = leapHand.Finger(leapHandLFingerId);
                                    Finger rightFinger = leapHand.Finger(leapHandRFingerId);

                                    bool bThumbOn = !LeftHandedUser ? (leftFinger != null && leftFinger.IsValid) :
                                        (rightFinger != null && rightFinger.IsValid);

                                    if(bThumbOn || fingersCountNow >= handGripFingersCount)
                                    {
                                        handGripDetected = false;
                                    }
                                }
                                else if(leapHand == null || !leapHand.IsValid)
                                {
                                    // stop pinching if the hand is lost
                                    handGripDetected = false;
                                }
                            }
                        }

                        fingersCountPrevPrev = fingersCountPrev;
                        fingersCountPrev = fingersCountNow;
                    }
                }

                if(Time.realtimeSinceStartup >= gestureTrackingAtTime)
                {
                    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);

                                if((leapFrameCounter - iCircleFrameCounter) >= FramesToSkip &&
                                    iCircleGestureID != circle.Id &&
                                    circle.State == Gesture.GestureState.STATESTOP)
                                {
                                    iCircleFrameCounter = leapFrameCounter;
                                    iCircleGestureID = circle.Id;
                                    fCircleProgress = 1f;

                                    gestureTrackingAtTime = Time.realtimeSinceStartup + MinTimeBetweenGestures;
                                }
                                else if(circle.Progress < 1f)
                                {
                                    fCircleProgress = circle.Progress;
                                }
                                break;

                            case Gesture.GestureType.TYPESWIPE:
                                SwipeGesture swipe = new SwipeGesture(gesture);

                                if((leapFrameCounter - iSwipeFrameCounter) >= FramesToSkip &&
                                    iSwipeGestureID != swipe.Id &&
                                    swipe.State == Gesture.GestureState.STATESTOP)
                                {
                                    iSwipeFrameCounter = leapFrameCounter;
                                    iSwipeGestureID = swipe.Id;
                                    fSwipeProgress = 1f;  // swipe.Progress

                                    gestureTrackingAtTime = Time.realtimeSinceStartup + MinTimeBetweenGestures;

                                    leapSwipeDir = LeapToUnity(swipe.Direction, false);
                                    leapSwipeSpeed = LeapToUnity(swipe.Position - swipe.StartPosition, true);

                                    if(swipe.DurationSeconds != 0)
                                        leapSwipeSpeed /= swipe.DurationSeconds;
                                    else
                                        leapSwipeSpeed = Vector3.zero;
                                }
                                else if(swipe.State != Gesture.GestureState.STATESTOP)
                                {
                                    fSwipeProgress = 0.5f;
                                }
                                break;

                            case Gesture.GestureType.TYPEKEYTAP:
                                KeyTapGesture keytap = new KeyTapGesture (gesture);

                                if((leapFrameCounter - iKeyTapFrameCounter) >= FramesToSkip &&
                                    iKeyTapGestureID != keytap.Id &&
                                    keytap.State == Gesture.GestureState.STATESTOP)
                                {
                                    iKeyTapFrameCounter = leapFrameCounter;
                                    iKeyTapGestureID = keytap.Id;
                                    fKeyTapProgress = 1f;

                                    gestureTrackingAtTime = Time.realtimeSinceStartup + MinTimeBetweenGestures;
                                }
                                else if(keytap.Progress < 1f)
                                {
                                    fKeyTapProgress = keytap.Progress;
                                }
                                break;

                            case Gesture.GestureType.TYPESCREENTAP:
                                ScreenTapGesture screentap = new ScreenTapGesture (gesture);

                                if((leapFrameCounter - iScreenTapFrameCounter) >= FramesToSkip &&
                                    iScreenTapGestureID != screentap.Id &&
                                    screentap.State == Gesture.GestureState.STATESTOP)
                                {
                                    iScreenTapFrameCounter = leapFrameCounter;
                                    iScreenTapGestureID = screentap.Id;
                                    fScreenTapProgress = 1f;

                                    gestureTrackingAtTime = Time.realtimeSinceStartup + MinTimeBetweenGestures;
                                }
                                else if(screentap.Progress < 1f)
                                {
                                    fScreenTapProgress = screentap.Progress;
                                }
                                break;

                            default:
                                Debug.LogError("Unknown gesture type.");
                                break;
                        }
                    }

                    // check for extra gestures
                    int listGestureSize = extraGesturesData.Count;
                    float timestampNow = Time.realtimeSinceStartup;

                    for(int g = 0; g < listGestureSize; g++)
                    {
                        LeapExtraGestures.ExtraGestureData gestureData = extraGesturesData[g];

                        if(timestampNow >= gestureData.startTrackingAtTime)
                        {
                            LeapExtraGestures.CheckForGesture(ref gestureData, Time.realtimeSinceStartup, this);
                            extraGesturesData[g] = gestureData;

                            if(gestureData.complete)
                            {
                                gestureTrackingAtTime = Time.realtimeSinceStartup + MinTimeBetweenGestures;
                            }
                        }
                    }
                }

                if(DebugCamera)
                {
                    DoDisplayFingers();
                }
            }
        }
    }
Exemplo n.º 24
0
        public override void OnFrame(Controller cntrlr)
        {
            Frame currentFrame = cntrlr.Frame();

            currentTime    = currentFrame.Timestamp;
            timeDifference = currentTime - previousTime;

            if (timeDifference > 1000)
            {
                if (!currentFrame.Hands.IsEmpty)  //van kéz az aktuális Frame-ben



                {
                    Hand   RightHand = currentFrame.Hands.Rightmost;
                    Hand   LeftHand  = currentFrame.Hands.Leftmost;
                    Finger finger    = RightHand.Fingers.Frontmost;

                    Leap.Screen screen = cntrlr.LocatedScreens.ClosestScreenHit(finger);
                    if (screen.IsValid)
                    {
                        var tipVel = (int)finger.TipVelocity.Magnitude;

                        if (tipVel > 25)
                        {
                            var xScreenIntersect = screen.Intersect(finger, true).x;
                            var yScreenIntersect = screen.Intersect(finger, true).y;

                            if (xScreenIntersect.ToString() != "NaN")
                            {
                                int x = (int)(xScreenIntersect * screen.WidthPixels);
                                int y = (int)(screen.HeightPixels - (yScreenIntersect * screen.HeightPixels));
                                if (RightHand.Fingers.Count < 3)
                                {
                                    Cursor.MoveCursor(x, y);
                                }

                                GestureList gestures = currentFrame.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);

                                        String clockwiseness;
                                        if (circle.Pointable.Direction.AngleTo(circle.Normal) <= Math.PI / 4)
                                        {
                                            //Clockwise if angle < 90°
                                            clockwiseness = "clockwise";
                                        }
                                        else
                                        {
                                            clockwiseness = "counterclockwise";
                                        }
                                        if (currentFrame.Hands.Count == 1 && currentFrame.Fingers.Count == 1)
                                        {
                                            if (currentTime - VolTime > TipPause)
                                            {
                                                VolTime = currentTime;
                                                if (clockwiseness.Equals("clockwise"))
                                                {
                                                    Cursor.keybd_event((byte)Keys.VolumeUp, 0, 0, 0);
                                                }
                                                if (clockwiseness.Equals("counterclockwise"))
                                                {
                                                    Cursor.keybd_event((byte)Keys.VolumeDown, 0, 0, 0);
                                                }
                                            }
                                        }
                                        float sweptAngle = 0;


                                        if (circle.State != Gesture.GestureState.STATESTART)
                                        {
                                            CircleGesture previousUpdate = new CircleGesture(cntrlr.Frame(1).Gesture(circle.Id));
                                            sweptAngle = (circle.Progress - previousUpdate.Progress) * 360;
                                        }

                                        Console.WriteLine("Circle id: " + circle.Id
                                                          + ", " + circle.State
                                                          + ", progress: " + circle.Progress
                                                          + ", radius: " + circle.Radius
                                                          + ", angle: " + sweptAngle
                                                          + ", " + clockwiseness);
                                        break;

                                    case Gesture.GestureType.TYPESWIPE:
                                        if (currentFrame.Fingers.Count >= 5 && currentFrame.Hands.Count == 1)
                                        {
                                            if (currentTime - swipeTime > TipPause)
                                            {
                                                swipeTime = currentTime;
                                                SwipeGesture swipe = new SwipeGesture(gesture);
                                                Console.WriteLine("Swipe id: " + swipe.Id
                                                                  + ", " + swipe.State
                                                                  + ", position: " + swipe.Position
                                                                  + ", direction: " + swipe.Direction
                                                                  + ", speed: " + swipe.Speed);

                                                if (swipe.Direction.x < 0)
                                                {
                                                    System.Windows.Forms.SendKeys.SendWait("%{LEFT}");     // alt+leftarrow
                                                    Console.WriteLine("back");
                                                }
                                                if (swipe.Direction.x > 0)
                                                {
                                                    System.Windows.Forms.SendKeys.SendWait("%{RIGHT}");     // alt+rightarrow
                                                    Console.WriteLine("fwd");
                                                }
                                            }
                                        }

                                        break;

                                    case Gesture.GestureType.TYPEKEYTAP:
                                        KeyTapGesture keytap = new KeyTapGesture(gesture);
                                        Console.WriteLine("Tap id: " + keytap.Id
                                                          + ", " + keytap.State
                                                          + ", position: " + keytap.Position
                                                          + ", direction: " + keytap.Direction);
                                        break;

                                    case Gesture.GestureType.TYPESCREENTAP:
                                        ScreenTapGesture screentap = new ScreenTapGesture(gesture);
                                        Console.WriteLine("Tap id: " + screentap.Id
                                                          + ", " + screentap.State
                                                          + ", position: " + screentap.Position
                                                          + ", direction: " + screentap.Direction);
                                        break;

                                    default:
                                        Console.WriteLine("Unknown gesture");
                                        break;
                                    }
                                }
                            }
                        }

                        if (currentFrame.Hands.Count == 2 && LeftHand.Fingers.Count <= 2)
                        {
                            if (Extensions.IsTapping(LeftHand.Fingers.Frontmost))
                            {
                                //Mouse.LeftClick();
                                if ((currentTime - MouseDown) / 2 > TipPause)
                                {
                                    MouseDown = currentTime;
                                    Console.WriteLine("Left " + i);
                                    Cursor.mouse_event(0x02 | 0x04, (uint)x, (uint)y, 0, 0);
                                }
                                i = i + 1;
                                return;
                            }

                            if (Extensions.IsTapping(LeftHand.Fingers.Rightmost))
                            {
                                //Mouse.RightClick();
                                if ((currentTime - MouseDown) / 2 > TipPause)
                                {
                                    MouseDown = currentTime;
                                    Console.WriteLine("Right " + i);
                                    Cursor.mouse_event(0x08 | 0x10, (uint)x, (uint)y, 0, 0);
                                }
                                i = i + 1;
                                return;
                            }
                        }

                        if (currentFrame.Hands.Count == 2 && LeftHand.Fingers.Count >= 4 && RightHand.Fingers.Count <= 2)
                        {
                            //scrl dwn
                            if (LeftHand.Direction.y > 0.5)
                            {
                                Console.WriteLine("scrl up" + i);

                                //Cursor.keybd_event(38, 0, 0, 0); // 40 == up arw key

                                System.Windows.Forms.SendKeys.SendWait("{UP}");

                                i = i + 1;
                            }

                            if (LeftHand.Direction.y < 0)
                            {
                                Console.WriteLine("scrl down " + i);
                                //   Cursor.keybd_event(40, 0, 0, 0); // 38 == dwn arw key

                                System.Windows.Forms.SendKeys.SendWait("{DOWN}");

                                i = i + 1;
                            }
                            return;
                        }

                        if (currentFrame.Hands.Count == 2 && LeftHand.Fingers.Count >= 4 && RightHand.Fingers.Count >= 4)
                        {
                            if (oskIsOpened == false)
                            {
                                Process.Start(@"C:\Windows\System32\osk.exe");
                                oskIsOpened = true;
                            }
                        }
                    }
                }

                previousTime = currentTime;
            }
        }
Exemplo n.º 25
0
        /// <summary>
        /// Performs the gesture detection
        /// </summary>
        /// <param name="frame">The actual frame</param>
        public override void GestureDetection(Frame frame)
        {
            // when the Leap API is used, we collect the list of gestures
            GestureList gestures = frame.Gestures();

            // and raised the corresponding events
            for (int i = 0; i < gestures.Count; i++)
            {
                Gesture gesture = gestures[i];
                switch (gesture.Type)
                {
                    case Gesture.GestureType.TYPEKEYTAP:
                        KeyTapGesture keyTap = new KeyTapGesture(gesture);
                        RaiseTapGestureEvent(0.0f, keyTap.Direction, frame.Timestamp);
                        break;

                    case Gesture.GestureType.TYPESCREENTAP:
                        ScreenTapGesture screenTap = new ScreenTapGesture(gesture);
                        RaisePushGestureEvent(0.0f, screenTap.Direction, frame.Timestamp);
                        break;

                    // for swipes and circles, there is a little more calculations
                    case Gesture.GestureType.TYPESWIPE:
                        ProcessSwipe(gesture);
                        break;

                    case Gesture.GestureType.TYPECIRCLE:
                        ProcessCircle(gesture);
                        break;
                }
            }
        }
Exemplo n.º 26
0
        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;
                }
            }
        }
Exemplo n.º 27
0
        public string getGesture()
        {
            Frame       frame    = _controller.Frame();
            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
                    String clockwiseness;
                    if (circle.Pointable.Direction.AngleTo(circle.Normal) <= Math.PI / 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 != Gesture.GestureState.STATESTART)
                    {
                        CircleGesture previousUpdate = new CircleGesture(_controller.Frame(1).Gesture(circle.Id));
                        sweptAngle = (circle.Progress - previousUpdate.Progress) * 360;
                    }

                    return("Circle id: " + circle.Id
                           + ", " + circle.State
                           + ", progress: " + circle.Progress
                           + ", radius: " + circle.Radius
                           + ", angle: " + sweptAngle
                           + ", " + clockwiseness);

                case Gesture.GestureType.TYPESWIPE:
                    SwipeGesture swipe = new SwipeGesture(gesture);
                    return("Swipe id: " + swipe.Id
                           + ", " + swipe.State
                           + ", position: " + swipe.Position
                           + ", direction: " + swipe.Direction
                           + ", speed: " + swipe.Speed);

                case Gesture.GestureType.TYPEKEYTAP:
                    KeyTapGesture keytap = new KeyTapGesture(gesture);
                    return("Tap id: " + keytap.Id
                           + ", " + keytap.State
                           + ", position: " + keytap.Position
                           + ", direction: " + keytap.Direction);

                case Gesture.GestureType.TYPESCREENTAP:
                    ScreenTapGesture screentap = new ScreenTapGesture(gesture);
                    return("Tap id: " + screentap.Id
                           + ", " + screentap.State
                           + ", position: " + screentap.Position
                           + ", direction: " + screentap.Direction);

                default:
                    return("Unknown gesture type.");
                }
            }
            return("Unknown gesture type.");
        }
Exemplo n.º 28
0
        public override void OnFrame(Controller controller)
        {
            // Get the most recent frame and report some basic information
            Frame frame = controller.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);

            UpdateFrame(frame);

            if (!frame.Hands.Empty)
            {
                // Get the first hand
                Hand hand = frame.Hands[0];

                // Check if the hand has any fingers
                FingerList fingers = hand.Fingers;
                if (!fingers.Empty)
                {
                    // Calculate the hand's average finger tip position
                    Vector avgPos = Vector.Zero;
                    foreach (Finger finger in fingers)
                    {
                        avgPos += finger.TipPosition;
                    }
                    avgPos /= fingers.Count;
                    //SafeWriteLine("Hand has " + fingers.Count
                    //            + " fingers, average finger tip position: " + avgPos);
                }

                // 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
                Vector normal    = hand.PalmNormal;
                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");
            }

            // 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:

                    if (OnCircleGesture == null)
                    {
                        break;
                    }

                    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 / 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 != Gesture.GestureState.STATESTART)
                    {
                        CircleGesture previousUpdate = new CircleGesture(controller.Frame(1).Gesture(circle.Id));
                        sweptAngle = (circle.Progress - previousUpdate.Progress) * 360;
                    }

                    var cargs = new LeapListenerArgs(circle);

                    cargs.logdata = "Circle id: " + circle.Id
                                    + ", " + circle.State
                                    + ", progress: " + circle.Progress
                                    + ", radius: " + circle.Radius
                                    + ", angle: " + sweptAngle
                                    + ", " + clockwiseness;

                    OnCircleGesture(this, cargs);

                    //SafeWriteLine("Circle id: " + circle.Id
                    //               + ", " + circle.State
                    //               + ", progress: " + circle.Progress
                    //               + ", radius: " + circle.Radius
                    //               + ", angle: " + sweptAngle
                    //               + ", " + clockwiseness);


                    break;

                case Gesture.GestureType.TYPESWIPE:

                    if (OnSwipeGesture == null)
                    {
                        break;
                    }

                    SwipeGesture swipe = new SwipeGesture(gesture);

                    var sargs = new LeapListenerArgs(swipe);

                    sargs.logdata = "Swipe id: " + swipe.Id
                                    + ", " + swipe.State
                                    + ", position: " + swipe.Position
                                    + ", direction: " + swipe.Direction
                                    + ", speed: " + swipe.Speed;



                    OnSwipeGesture(this, sargs);

                    //SafeWriteLine("Swipe id: " + swipe.Id
                    //               + ", " + swipe.State
                    //               + ", position: " + swipe.Position
                    //               + ", direction: " + swipe.Direction
                    //               + ", speed: " + swipe.Speed);
                    break;

                case Gesture.GestureType.TYPEKEYTAP:

                    if (OnKeyTapGesture == null)
                    {
                        break;
                    }

                    KeyTapGesture keytap = new KeyTapGesture(gesture);

                    var kargs = new LeapListenerArgs(keytap);

                    kargs.logdata = "Tap id: " + keytap.Id
                                    + ", " + keytap.State
                                    + ", position: " + keytap.Position
                                    + ", direction: " + keytap.Direction;

                    OnKeyTapGesture(this, kargs);

                    //SafeWriteLine("Tap id: " + keytap.Id
                    //               + ", " + keytap.State
                    //               + ", position: " + keytap.Position
                    //               + ", direction: " + keytap.Direction);
                    break;

                case Gesture.GestureType.TYPESCREENTAP:

                    if (OnScreenTapGesture == null)
                    {
                        break;
                    }

                    ScreenTapGesture screentap = new ScreenTapGesture(gesture);

                    var targs = new LeapListenerArgs(screentap);

                    targs.logdata = "Tap id: " + screentap.Id
                                    + ", " + screentap.State
                                    + ", position: " + screentap.Position
                                    + ", direction: " + screentap.Direction;

                    OnScreenTapGesture(this, targs);

                    //SafeWriteLine("Tap id: " + screentap.Id
                    //               + ", " + screentap.State
                    //               + ", position: " + screentap.Position
                    //               + ", direction: " + screentap.Direction);
                    break;

                default:
                    //SafeWriteLine("Unknown gesture type.");
                    break;
                }
            }

            if (!frame.Hands.Empty || !frame.Gestures().Empty)
            {
                //SafeWriteLine("");
            }
        }
Exemplo n.º 29
0
        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;
                }
            }
        }
Exemplo n.º 30
0
	// Update is called once per frame
	void Update()
	{
		Frame frame = controller.Frame();    //frame 
		GestureList gestures = frame.Gestures(); //frame 안의 gesture 인식
		HandList hands = frame.Hands;    //frame 안의 hands 인식
		int num_hands = hands.Count;    //hand의 수

		if (sceneZoomIn == true)	//f
		{
			SceneChangeZoom(sceneZoomIn,sceneZoomOut);			
		}


		if (num_hands < 1) // 인식된 손이 없다면
		{
			return;
		}
		else
		{
			Hand left = hands.Leftmost;     //왼쪽손 
			Hand right = hands.Rightmost;   //오른쪽 손
			
			FingerList fingerList = left.Fingers;  //왼쪽 손의 손가락들!
			Finger leftFinger = fingerList.Frontmost;  //왼손에서 제일 앞에 있는 손가락
			
			rigid = GameObject.Find("RigidHand(Clone)");
			if (rigid == null)
			{
				Debug.LogWarning("RigidHand is null");
				return;
			}
			
			cursorPointer = GameObject.Find("RigidHand(Clone)/index/bone3");
			if (cursorPointer == null)
			{
				Debug.LogWarning("CursorPointer is null");
				return;
			}
			
			//여기에서 립모션 손모양 오븥젝트의 Collision 을 해체하여 Raycast에 충돌 하지 않게 한다.
			Collider[] cols = rigid.GetComponentsInChildren<Collider>();
			for (int i = 0; i < cols.Length; i++)
			{
				cols[i].enabled = false;
			}
			
			
			//팁핑 포지션으로 커서를 이동
			if (rigid != null)
			{
				//Debug.Log ("Rigid finded");
				Vector3 temp = Tipping();
				cursorModel.transform.position = temp;
			}
			
			//손바닥을 UnityScale로 좌표 변환 , Handcontroller TransformPoint로 Transform 형식에 맞게 변환, 이후 왼쪽 카메라 기준으로 월드 스크린으로 변환 
			Vector2 screenPoint = leftCamera.camera.WorldToScreenPoint(cursorPointer.transform.position);
			Ray r = leftCamera.camera.ScreenPointToRay(screenPoint);      // ScreentPoint로부터 Ray를 쏜다
			Debug.DrawRay(r.origin, r.direction * 1000, Color.red);
			
			RaycastHit hit; //rayCast에서 부딛힌 객체 관리
			
			if (Physics.Raycast(r, out hit, Mathf.Infinity))
			{
				if(hit.collider != null)
				{
					target.transform.position = hit.transform.position;
					if(hit.collider.gameObject.tag == "StreetviewPoint")
					{
						StreetView_Pointed = hit.collider.gameObject.GetComponent<StreetviewPoint>();
						if(StreetView_Pointed != null)
						{
							// TODO : Mouse Enter (SHJO)
							StreetView_Pointed.Pointed() ;
							
						}
					}
				}
			}
			else
			{
				// TODO : Mouse Exit (SHJO)
				if(StreetView_Pointed != null)
				{
					StreetView_Pointed.PointedOut();
					StreetView_Pointed = null;
				}
			}
			
			//립모션 제스쳐 감지 
			for (int i = 0; i < gestures.Count; i++)
			{
				Gesture gesture = gestures[i];
				HandList handsForGesture = gesture.Hands;
				if (num_hands == 1)                                 
				{
					
					// Key Tap
					if (gesture.Type == Gesture.GestureType.TYPE_KEY_TAP)
					{
						KeyTapGesture keyTap = new KeyTapGesture(gesture);
						Debug.Log("TYPE_KEY_TAP - Duration : " + keyTap.DurationSeconds.ToString());
						cursorModel.renderer.material.color = Color.blue;
						
						GameObject particleObj = Instantiate(clickParticle, Tipping () , Quaternion.identity) as GameObject;
						
						Destroy (particleObj,2f);
						
						if(StreetView_Pointed != null)
						{
							// TODO : Click (SHJO)	
							if(sceneZoomOut==true)
								SceneChangeZoom(sceneZoomIn,sceneZoomOut);

							Application.LoadLevel("StreetViewer");
						}
					}
					// Screen Tap
					else if (gesture.Type == Gesture.GestureType.TYPE_SCREEN_TAP) 
					{
						ScreenTapGesture screenTap = new ScreenTapGesture(gesture);
                        print("Screen Tap " + screenTap.Duration.ToString());

						cursorModel.renderer.material.color = Color.red;
						
						if(StreetView_Pointed != null)
						{
							// TODO : Click - Optional (SHJO)
							if(sceneZoomOut==true)
								//SceneChangeZoom(sceneZoomIn,sceneZoomOut);

							Application.LoadLevel("StreetViewer");
						}
					}
					// Swipe
					else if (gesture.Type == Gesture.GestureType.TYPE_SWIPE) 
					{
						SwipeGesture swipe = new SwipeGesture(gesture);
						print("Swipe Speed : " + swipe.Speed.ToString());
						print("Swipe Start : " + swipe.StartPosition.ToString());
						print("Swipe End : " + swipe.Position.ToString());
						
						// TODO : Swipe (SHJO)
						if(swipe.StartPosition.x > swipe.Position.x) // swipe.direction을 써도됨
						{
							earth.transform.Rotate(new Vector3(0, -Time.deltaTime * swipeSpeed, 0));
						}
						else
						{
							earth.transform.Rotate(new Vector3(0, Time.deltaTime * swipeSpeed, 0));
						}
						
					}
					// Circle
					else if (gesture.Type == Gesture.GestureType.TYPE_CIRCLE)
					{
						CircleGesture circleGesture = new CircleGesture(gesture);
						print("Circle");
						
						// TODO : Circle (SHJO)
						if (circleGesture.Pointable.Direction.AngleTo(circleGesture.Normal) <= Math.PI / 2) // Clockwise
						{
							earth.transform.Rotate(new Vector3(0, -Time.deltaTime * swipeSpeed, 0));
						}
						else                                                                                // Counterclockwise
						{
							earth.transform.Rotate(new Vector3(0, Time.deltaTime * swipeSpeed, 0)); 
						}
						
					}
				}
				
				// ZOOM IN OUT Motion
				if (num_hands == 2)                                 
				{
					if (handsForGesture[0].IsLeft && gesture.Type == Gesture.GestureType.TYPESWIPE)
					{
						Debug.Log("left zoom");
						SwipeGesture Swipe = new SwipeGesture(gesture);
						Vector swipeDirection = Swipe.Direction;
						if (swipeDirection.x < 0)
						{
							if (leftCamera.camera.fieldOfView < maxFov)
							{
								leftCamera.camera.fieldOfView += zoomScale;
								rightCamera.camera.fieldOfView += zoomScale;
							}
							
						}
						else if (swipeDirection.x > 0)
						{
							if (leftCamera.camera.fieldOfView > minFov)
							{
								leftCamera.camera.fieldOfView -= zoomScale;
								rightCamera.camera.fieldOfView -= zoomScale;
							}
						}
					}
					
					else if ((!handsForGesture[0].IsLeft) && gesture.Type == Gesture.GestureType.TYPESWIPE)
					{
						Debug.Log("right zoom");
						SwipeGesture Swipe = new SwipeGesture(gesture);
						Vector swipeDirection = Swipe.Direction;
						if (swipeDirection.x > 0)
						{
							if (leftCamera.camera.fieldOfView < maxFov)
							{
								leftCamera.camera.fieldOfView += zoomScale;
								rightCamera.camera.fieldOfView += zoomScale;
							}
						}
						else if (swipeDirection.x < 0)
						{
							if (leftCamera.camera.fieldOfView > minFov)
							{
								leftCamera.camera.fieldOfView -= zoomScale;
								rightCamera.camera.fieldOfView -= zoomScale;
							}
						}
					}
					
				} // END OF ZOOM IN GESTURE
			} // END OF GESTURE RECOGNITION LOOP
			
		} // END OF IF
	}
Exemplo n.º 31
0
        public override void OnFrame(Controller cntrlr)
        {
            // Get the current frame.
            Frame currentFrame = cntrlr.Frame();

            currentTime = currentFrame.Timestamp;
            timeChange = currentTime - previousTime;
            if (timeChange > FramePause)
            {

                //pointable jari
                if (!currentFrame.Hands.IsEmpty)
                {
                    // Get the first finger in the list of fingers
                    Pointable finger = currentFrame.Pointables[0];
                    // Get the closest screen intercepting a ray projecting from the finger
                    Screen screen = cntrlr.LocatedScreens.ClosestScreenHit(finger);

                    if (screen != null && screen.IsValid)
                    {
                        // Get the velocity of the finger tip
                        //var tipVelocity = (int)finger.TipVelocity.Magnitude;
                        Hand hand = currentFrame.Hands.Frontmost;
                        
                        // Use tipVelocity to reduce jitters when attempting to hold
                        // the cursor steady
                        if (finger.TipVelocity.Magnitude > 25)
                        {
                            float xScreenIntersect = (float)screen.Intersect(finger, true).x;
                            float yScreenIntersect = (float)(1 - screen.Intersect(finger, true).y);
                            float zScreenIntersect = screen.DistanceToPoint(finger.TipPosition);

                            if (xScreenIntersect.ToString() != "NaN")
                            {
                            
                                if (fingerPoint.Count <= 0)
                                {
                                    fingerPoint.Add(new FingerPointStorage(xScreenIntersect, yScreenIntersect, zScreenIntersect, false, 0, 0));
                                }
                                else
                                {

                                    ////////////////////gesture
                                    if (currentFrame.Pointables.Count > 2)
                                    {
                                        if (currentFrame.Gestures().Count > 0)
                                        {
                                            //debugbox1.Text = "Gesture" + frame.Gestures()[0].ToString();
                                            int numGestures = currentFrame.Gestures().Count;
                                            if (numGestures > 0)
                                            {
                                                for (int i = 0; i < numGestures; i++)
                                                {
                                                    if (currentFrame.Gestures()[i].Type == Leap.Gesture.GestureType.TYPESCREENTAP)
                                                    {
                                                        ScreenTapGesture tap = new ScreenTapGesture(currentFrame.Gestures()[i]);
                                                        fingerPoint[0].g_Tap = tap.Position.z;
                                                    }
                                                    else if (currentFrame.Gestures()[i].Type == Leap.Gesture.GestureType.TYPECIRCLE)
                                                    {
                                                        CircleGesture circle = new CircleGesture(currentFrame.Gestures()[i]);
                                                        fingerPoint[0].g_circle = circle.Progress;

                                                    }
                                                }
                                            }
                                        }
                                    }
                                    ///////////////////////////////////
                                    
                                    fingerPoint[0].g_X = xScreenIntersect;
                                    fingerPoint[0].g_Y = yScreenIntersect;
                                    fingerPoint[0].g_Z = zScreenIntersect;
                                    fingerPoint[0].isActive = true;
                                    if (currentFrame.Hands.Leftmost.Equals(currentFrame.Hands.Rightmost))
                                        fingerPoint[0].numHand = false;
                                    else
                                        fingerPoint[0].numHand = true;
                                    //Console.WriteLine("leap x-axis: {0},y-axis: {1},z-axis: {2}", fingerPoint[0].g_X, fingerPoint[0].g_Y, fingerPoint[0].g_Z);
                                }
                            }
                        }
                    }
                }
                previousTime = currentTime;
            }
        }
    //Gesture Event for ScreenTap
    void ScreenTap(Gesture gesture,RaycastHit hit)
    {
        ScreenTapGesture screenTap = new ScreenTapGesture(gesture);
        Debug.Log("TYPE_SCREEN_TAP");
        cursorModel.renderer.material.color = Color.red;

        if(hit.collider.gameObject.tag=="Button")
        {
            pointed.Touch ();
        }
    }
Exemplo n.º 33
0
    void Update()
    {
        Frame frame = controller.Frame();

        // do something with the tracking data in the frame...
        if (!frame.Hands.IsEmpty)
        {
            var hand     = frame.Hands[0];
            var gestures = frame.Gestures();

            for (int i = 0; i < hand.Fingers.Count; i++)
            {
                //人差し指
                if (hand.Fingers[i].Type() == Finger.FingerType.TYPE_INDEX)
                {
                    //Debug.Log (hand.Fingers[i].TipPosition.x);
                    var fingerPosition = hand.Fingers[i].TipPosition;

                    for (int gi = 0; gi < gestures.Count; gi++)
                    {
                        // ジェスチャー結果取得&表示
                        Gesture gesture = gestures[gi];
                        switch (gesture.Type)
                        {
                        case Gesture.GestureType.TYPECIRCLE:
                            var circleGesture = new CircleGesture(gesture);
                            Debug.Log("Circle");
                            if (circleGesture.State == Gesture.GestureState.STATEUPDATE)
                            {
                                //そっちを向かせる(ドラッグと同じ
                                LAppLive2DManager.Instance.TouchesMoved(new Vector3((fingerPosition.x - 20.0f + (UnityEngine.Screen.width / 2)), (fingerPosition.y * 2 - (UnityEngine.Screen.height) / 2), 0));
                            }
                            break;

                        case Gesture.GestureType.TYPEKEYTAP:
                            var keytapGesture = new KeyTapGesture(gesture);
                            Debug.Log("KeyTap");
                            if (keytapGesture.State == Gesture.GestureState.STATESTOP)
                            {
                                //Debug.Log (fingerPosition.x+","+fingerPosition.y+","+fingerPosition.z);
                                //20.0fはx軸に対するずれ軽減用
                                LAppLive2DManager.Instance.TouchesEnded(new Vector3((fingerPosition.x - 20.0f + (UnityEngine.Screen.width / 2)), (fingerPosition.y * 2 - (UnityEngine.Screen.height) / 2), 0));
                            }
                            break;

                        case Gesture.GestureType.TYPESCREENTAP:
                            var screenTapGesture = new ScreenTapGesture(gesture);
                            Debug.Log("ScreenTap");
                            break;

                        case Gesture.GestureType.TYPE_SWIPE:
                            var swipeGesture = new SwipeGesture(gesture);
                            Debug.Log("Swipe");
                            //LAppLive2DManager.Instance.ChangeModel(); //モデル変更
                            break;

                        default:
                            break;
                        }
                    }
                }
            }
        }
    }
Exemplo n.º 34
0
    //Gesture Event for ScreenTap
    void ScreenTap(Gesture gesture)
    {
        ScreenTapGesture screenTap = new ScreenTapGesture(gesture);
        print("Screen Tap " + screenTap.Duration.ToString());

        GameObject particleObj = Instantiate(clickParticle, GetTippingPos(), Quaternion.identity) as GameObject;

        Destroy(particleObj, 2f);

        if (hitObject != null)
        {
            OnClicked(hitObject);
        }
    }
Exemplo n.º 35
0
    void Update()
    {
        if(leapInitialized && leapController != null)
        {
            Leap.Frame frame = leapController.Frame();

            if(frame.IsValid && (frame.Id != lastFrameID))
            {
                leapFrame = frame;
                lastFrameID = leapFrame.Id;
                leapFrameCounter++;

        //				// fix unfinished leap gesture progress
        //				if(fCircleProgress > 0f && fCircleProgress < 1f)
        //					fCircleProgress = 0f;
        //				if(fSwipeProgress > 0f && fSwipeProgress < 1f)
        //					fSwipeProgress = 0f;
        //				if(fKeyTapProgress > 0f && fKeyTapProgress < 1f)
        //					fKeyTapProgress = 0f;
        //				if(fScreenTapProgress > 0f && fScreenTapProgress < 1f)
        //					fScreenTapProgress = 0f;

                // get the prime hand
                leapHand = leapFrame.Hand(leapHandID);
                if(leapHand == null || !leapHand.IsValid)
                {
                    leapHand = GetFrontmostHand();
                    leapHandID = leapHand != null && leapHand.IsValid ? leapHand.Id : 0;
                }

                // get the prime pointable
                leapPointable = leapFrame.Pointable(leapPointableID);
                if(leapPointable == null || !leapPointable.IsValid)
                {
                    leapPointable = leapHand.IsValid ? GetPointingFigner(leapHand) : leapFrame.Pointables.Frontmost;

                    leapPointableID = leapPointable != null && leapPointable.IsValid ? leapPointable.Id : 0;
                    leapPointableHandID = leapPointable != null && leapPointable.IsValid && leapPointable.Hand.IsValid ? leapPointable.Hand.Id : 0;
                }

                if(leapPointable != null && leapPointable.IsValid &&
                    leapPointable.Hand != null && leapPointable.Hand.IsValid &&
                    leapHand != null && leapHand.IsValid && leapPointable.Hand.Id == leapHand.Id)
                {
                    leapPointablePos = LeapToUnity(leapPointable.StabilizedTipPosition, true);
                    leapPointableDir = LeapToUnity(leapPointable.Direction, false);
                    //leapPointableQuat = Quaternion.LookRotation(leapPointableDir);
                }
                else
                {
                    leapPointable = null;

                    leapPointableID = 0;
                    leapPointableHandID = 0;
                }

                Leap.Vector stabilizedPosition = Leap.Vector.Zero;
                if(leapHandID != 0)
                {
                    leapHandPos = LeapToUnity(leapHand.StabilizedPalmPosition, true);
                    stabilizedPosition = leapHand.StabilizedPalmPosition;

                    leapHandFingersCount = leapHand.Fingers.Count;

                    bool bCurrentHandGrip = handGripDetected;
                    handGripDetected = !isHandOpen(leapHand);
                    handReleaseDetected = !handGripDetected;

                    if(controlMouseCursor)
                    {
                        if(!bCurrentHandGrip && handGripDetected)
                        {
                            MouseControl.MouseDrag();
                        }
                        else if(bCurrentHandGrip && handReleaseDetected)
                        {
                            MouseControl.MouseRelease();
                        }
                    }
                }
                else
                {
                    if(controlMouseCursor && handGripDetected)
                    {
                        MouseControl.MouseRelease();
                    }

                    leapHandFingersCount = 0;
                    handGripDetected = false;
                    handReleaseDetected = false;
                }

                // estimate the cursor coordinates
                if(stabilizedPosition.MagnitudeSquared != 0f)
                {
                    Leap.InteractionBox iBox = frame.InteractionBox;
                    Leap.Vector normalizedPosition = iBox.NormalizePoint(stabilizedPosition);

                    cursorNormalPos.x = normalizedPosition.x;
                    cursorNormalPos.y = normalizedPosition.y;
                    cursorScreenPos.x = cursorNormalPos.x * UnityEngine.Screen.width;
                    cursorScreenPos.y = cursorNormalPos.y * UnityEngine.Screen.height;

                    if(controlMouseCursor)
                    {
                        MouseControl.MouseMove(cursorNormalPos);
                    }
                }

                // Gesture analysis
                GestureList gestures = frame.Gestures ();
                for (int i = 0; i < gestures.Count; i++)
                {
                    Gesture gesture = gestures[i];

                    if(Time.realtimeSinceStartup < gestureTrackingAtTime)
                        continue;

                    switch (gesture.Type)
                    {
                        case Gesture.GestureType.TYPECIRCLE:
                            CircleGesture circle = new CircleGesture(gesture);

                            if(iCircleGestureID != circle.Id &&
                                circle.State == Gesture.GestureState.STATESTOP)
                            {
                                iCircleGestureID = circle.Id;
                                fCircleProgress = 1f;

                                gestureTrackingAtTime = Time.realtimeSinceStartup + MinTimeBetweenGestures;
                            }
                            else if(circle.Progress < 1f)
                            {
                                fCircleProgress = circle.Progress;
                            }
                            break;

                        case Gesture.GestureType.TYPESWIPE:
                            SwipeGesture swipe = new SwipeGesture(gesture);

                            if(iSwipeGestureID != swipe.Id &&
                                swipe.State == Gesture.GestureState.STATESTOP)
                            {
                                iSwipeGestureID = swipe.Id;
                                fSwipeProgress = 1f;  // swipe.Progress

                                gestureTrackingAtTime = Time.realtimeSinceStartup + MinTimeBetweenGestures;

                                leapSwipeDir = LeapToUnity(swipe.Direction, false);
                                leapSwipeSpeed = LeapToUnity(swipe.Position - swipe.StartPosition, true);

                                if(swipe.DurationSeconds != 0)
                                    leapSwipeSpeed /= swipe.DurationSeconds;
                                else
                                    leapSwipeSpeed = Vector3.zero;
                            }
                            else if(swipe.State != Gesture.GestureState.STATESTOP)
                            {
                                fSwipeProgress = 0.5f;
                            }
                            break;

                        case Gesture.GestureType.TYPEKEYTAP:
                            KeyTapGesture keytap = new KeyTapGesture (gesture);

        //							if(iKeyTapGestureID != keytap.Id &&
        //								keytap.State == Gesture.GestureState.STATESTOP)
                            {
                                iKeyTapGestureID = keytap.Id;
                                fKeyTapProgress = 1f;

                                gestureTrackingAtTime = Time.realtimeSinceStartup + MinTimeBetweenGestures;
                            }
        //							else if(keytap.Progress < 1f)
        //							{
        //								fKeyTapProgress = keytap.Progress;
        //							}
                            break;

                        case Gesture.GestureType.TYPESCREENTAP:
                            ScreenTapGesture screentap = new ScreenTapGesture (gesture);

        //							if(iScreenTapGestureID != screentap.Id &&
        //								screentap.State == Gesture.GestureState.STATESTOP)
                            {
                                iScreenTapGestureID = screentap.Id;
                                fScreenTapProgress = 1f;

                                gestureTrackingAtTime = Time.realtimeSinceStartup + MinTimeBetweenGestures;
                            }
        //							else if(screentap.Progress < 1f)
        //							{
        //								fScreenTapProgress = screentap.Progress;
        //							}
                            break;

                        default:
                            Debug.LogError("Unknown gesture type.");
                            break;
                    }
                }

                if(DebugCamera)
                {
                    DoDisplayFingers();
                }
            }
        }
    }
Exemplo n.º 36
0
 public LeapListenerArgs(ScreenTapGesture gesture)
 {
     this.screentapgesture = gesture;
 }
Exemplo n.º 37
0
    //Gesture Event for ScreenTap
    void ScreenTap(Gesture gesture)
    {
        ScreenTapGesture screenTap = new ScreenTapGesture(gesture);
        print("Screen Tap " + screenTap.Duration.ToString());

        if(StreetView_Pointed != null)
        {
            // TODO : Click - Optional (SHJO)
            if(sceneZoomOut==true)
                //SceneChangeZoom(sceneZoomIn,sceneZoomOut);

                Application.LoadLevel("StreetViewer");
        }
    }
        private AcceptedGestures SelectOption(Frame frame)
        {
            GestureList gestures = frame.Gestures();

            if (gestures.Count > 0) {
                foreach (Gesture gesture in gestures)
                {
                    if (gesture.Type == Gesture.GestureType.TYPESCREENTAP && gesture.State == Gesture.GestureState.STATESTOP){
                        ScreenTapGesture screenTap = new ScreenTapGesture(gesture);
                        Log("Gesture: Screen Tap");
                        gestureType = AcceptedGestures.SwipeOut;
                        return gestureType;
                    }
                }
            }
            return AcceptedGestures.InvalidGesture;
        }
Exemplo n.º 39
0
    public override void OnFrame(Controller controller)
    {
        // Get the most recent frame and report some basic information
        Frame frame = controller.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);

        foreach (Hand hand in frame.Hands)
        {
            SafeWriteLine("  Hand id: " + hand.Id
                          + ", palm position: " + hand.PalmPosition);
            // Get the hand's normal vector and direction
            Vector normal    = hand.PalmNormal;
            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");

            // Get the Arm bone
            Arm arm = hand.Arm;
            SafeWriteLine("  Arm direction: " + arm.Direction
                          + ", wrist position: " + arm.WristPosition
                          + ", elbow position: " + arm.ElbowPosition);

            // Get fingers
            foreach (Finger finger in hand.Fingers)
            {
                SafeWriteLine("    Finger id: " + finger.Id
                              + ", " + finger.Type.ToString()
                              + ", length: " + finger.Length
                              + "mm, width: " + finger.Width + "mm");

                // Get finger bones
                Bone bone;
                foreach (Bone.BoneType boneType in (Bone.BoneType[])Enum.GetValues(typeof(Bone.BoneType)))
                {
                    bone = finger.Bone(boneType);
                    SafeWriteLine("      Bone: " + boneType
                                  + ", start: " + bone.PrevJoint
                                  + ", end: " + bone.NextJoint
                                  + ", direction: " + bone.Direction);
                }
            }
        }

        // Get tools
        foreach (Tool tool in frame.Tools)
        {
            SafeWriteLine("  Tool id: " + tool.Id
                          + ", position: " + tool.TipPosition
                          + ", direction " + tool.Direction);
        }

        // 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
                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;
                }

                SafeWriteLine("  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);
                SafeWriteLine("  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);
                SafeWriteLine("  Tap id: " + keytap.Id
                              + ", " + keytap.State
                              + ", position: " + keytap.Position
                              + ", direction: " + keytap.Direction);
                break;

            case Gesture.GestureType.TYPE_SCREEN_TAP:
                ScreenTapGesture screentap = new ScreenTapGesture(gesture);
                SafeWriteLine("  Tap id: " + screentap.Id
                              + ", " + screentap.State
                              + ", position: " + screentap.Position
                              + ", direction: " + screentap.Direction);
                break;

            default:
                SafeWriteLine("  Unknown gesture type.");
                break;
            }
        }

        if (!frame.Hands.IsEmpty || !frame.Gestures().IsEmpty)
        {
            SafeWriteLine("");
        }
    }
Exemplo n.º 40
0
        public override void OnFrame(Controller controller)
        {
            // Get the most recent frame and report some basic information
            Frame frame = controller.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);

            foreach (Hand hand in frame.Hands)
            {
                SafeWriteLine("  Hand id: " + hand.Id
                            + ", palm position: " + hand.PalmPosition);
                // Get the hand's normal vector and direction
                Vector normal = hand.PalmNormal;
                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");

                // Get the Arm bone
                Arm arm = hand.Arm;
                SafeWriteLine("  Arm direction: " + arm.Direction
                            + ", wrist position: " + arm.WristPosition
                            + ", elbow position: " + arm.ElbowPosition);

                float pitch = hand.Direction.Pitch;
                float yaw = hand.Direction.Yaw;
                float roll = hand.PalmNormal.Roll;

                //Here, based on the identified Hand and Finger information, we can easily identify all the distinct letters
                Stack candidate_stack = new Stack();
                if (pitch == 0.0 && yaw == 0.0)
                {
                    //candidates are Á, Â, Ä, Ç, É, Ê, Ï, Ñ, Õ, Ö, ×, Ø
                    List<char> current_list = new List<char>();
                    current_list.Add('A');
                    current_list.Add('Â');
                    current_list.Add('Ä');
                    current_list.Add('Ç');
                    current_list.Add('É');
                    current_list.Add('Ê');
                    current_list.Add('Ï');
                    current_list.Add('Ñ');
                    current_list.Add('Õ');
                    current_list.Add('Ö');
                    current_list.Add('×');
                    current_list.Add('Ø');

                    candidate_stack.Push(current_list);
                }
                else if (pitch == 90.0 && yaw == 0.0)
                {
                    //candidates are Ã, Ë, Ì, Í, Ð, Ó, Ô
                    List<char> current_list = new List<char>();
                    current_list.Add('Ã');
                    current_list.Add('Ë');
                    current_list.Add('Ì');
                    current_list.Add('Í');
                    current_list.Add('Ð');
                    current_list.Add('Ó');
                    current_list.Add('Ô');

                    candidate_stack.Push(current_list);
                }
                else if (pitch == 0.0 && yaw == 90.0)
                {
                    //candidates are Å,
                    List<char> current_list = new List<char>();
                    current_list.Add('Å');

                    candidate_stack.Push(current_list);
                }
                else if (pitch == 0.0 && yaw == -90.0)
                {
                    //candidates are Æ, È, Î, Ù
                    List<char> current_list = new List<char>();
                    current_list.Add('Æ');
                    current_list.Add('È');
                    current_list.Add('Î');
                    current_list.Add('Ù');

                    candidate_stack.Push(current_list);
                }

                // Get fingers
                List<bool> fingers_vertical_flags = new List<bool>();
                List<bool> fingers_horizontal_flags = new List<bool>();

                bool is_all_vertical = true;
                bool is_all_horizontal = true;
                int horizontal_count = 0;
                int vertical_count = 0;
                int diagonal_count = 0;
                int inversed_diagonal_count = 0;
                int closed_count = 0;
                foreach (Finger finger in hand.Fingers)
                {
                    SafeWriteLine("    Finger id: " + finger.Id
                                + ", " + finger.Type.ToString()
                                + ", length: " + finger.Length
                                + "mm, width: " + finger.Width + "mm");

                    // Get finger bones
                    Bone bone;

                    List<Vector> bone_directions = new List<Vector>();

                    foreach (Bone.BoneType boneType in (Bone.BoneType[])Enum.GetValues(typeof(Bone.BoneType)))
                    {
                        bone = finger.Bone(boneType);
                        SafeWriteLine("      Bone: " + boneType
                                    + ", start: " + bone.PrevJoint
                                    + ", end: " + bone.NextJoint
                                    + ", direction: " + bone.Direction);

                        bone_directions.Add(bone.Direction);

                        bool is_vertical = false;
                        bool is_horizontal = false;
                        if (bone.Direction.Pitch == 90.0 && bone.Direction.Yaw == 0.0)
                        {
                            is_vertical = true;
                            vertical_count++;
                        }
                        else if (bone.Direction.Pitch == 0.0 && bone.Direction.Yaw == 90.0)
                        {
                            is_horizontal = true;
                            horizontal_count++;
                        }
                        else if (bone.Direction.Pitch == 45.0 && bone.Direction.Yaw == 0.0)
                        {
                            diagonal_count++;
                        }
                        else if (bone.Direction.Pitch == 45.0 && bone.Direction.Yaw == 90.0)
                        {
                            inversed_diagonal_count++;
                        }
                        else if (bone.Direction.Pitch == 0.0 && bone.Direction.Yaw == 0.0)
                        {
                            closed_count++;
                        }

                        if (!is_vertical)
                        {
                            is_all_vertical = false;
                        }
                        if (!is_horizontal)
                        {
                            is_all_horizontal = false;
                        }
                    }

                    fingers_horizontal_flags.Add(is_all_horizontal);
                    fingers_vertical_flags.Add(is_all_vertical);
                }

                //now, based on the vertical, horizontal position, try to identify candidate letters
                bool all_fingers_vertical = true;
                bool all_fingers_horizontal = true;
                for (int i = 0; i < fingers_horizontal_flags.Count; i++)
                {
                    if (!fingers_horizontal_flags[i])
                    {
                        all_fingers_horizontal = false;
                    }
                }
                for (int i = 0; i < fingers_vertical_flags.Count; i++)
                {
                    if (!fingers_vertical_flags[i])
                    {
                        all_fingers_vertical = false;
                    }
                }

                List<char> current_list_2 = new List<char>();

                if (all_fingers_horizontal)
                {
                   //candidates are
                }
                else if (all_fingers_vertical)
                {
                    //candidates are Â
                    current_list_2.Add('B');
                }
                else if (closed_count == 5)
                {
                    current_list_2.Add('A');
                }
                else if (diagonal_count == 2 && closed_count == 3)
                {
                    current_list_2.Add('Ã');
                }
                else if (diagonal_count == 1 && closed_count == 2)
                {
                    current_list_2.Add('Ä');
                    current_list_2.Add('Æ');
                }
                else if (diagonal_count == 1 && closed_count == 3)
                {
                    current_list_2.Add('Ç');
                }
                else if (horizontal_count == 2 && closed_count == 2)
                {
                    current_list_2.Add('È');
                }
                else if (closed_count == 4 && vertical_count == 1)
                {
                    current_list_2.Add('É');
                }
                else if (closed_count == 2 && vertical_count == 1 && horizontal_count == 1)
                {
                    current_list_2.Add('K');
                }
                else if (horizontal_count == 3 && closed_count == 1)
                {
                    current_list_2.Add('Ë');
                    current_list_2.Add('Ì');
                }
                else if (horizontal_count == 3 && closed_count == 2)
                {
                    current_list_2.Add('N');
                    current_list_2.Add('Î');
                }
                else if (diagonal_count == 2 && closed_count == 2)
                {
                    current_list_2.Add('Ð');
                }
                else if (vertical_count == 3 && closed_count == 2)
                {
                    current_list_2.Add('Ï');
                }
                else if (diagonal_count == 1 && inversed_diagonal_count == 1)
                {
                    current_list_2.Add('Ñ');
                }
                else if (closed_count == 5)
                {
                    current_list_2.Add('Ó');
                }
                else if (closed_count == 4 && vertical_count == 1)
                {
                    current_list_2.Add('T');
                }
                else if (closed_count == 3 && vertical_count == 2)
                {
                    current_list_2.Add('Õ');
                }
                else if (horizontal_count == 3)
                {
                    current_list_2.Add('Ö');
                }
                else if (horizontal_count == 2 && closed_count == 1 && diagonal_count == 1)
                {
                    current_list_2.Add('×');
                }
                else if (horizontal_count == 3 && closed_count == 1 && diagonal_count == 1)
                {
                    current_list_2.Add('Ø');
                }
                else
                {
                    current_list_2.Add('Ù');
                }

                candidate_stack.Push(current_list_2);
            }

            // Get tools
            foreach (Tool tool in frame.Tools)
            {
                SafeWriteLine("  Tool id: " + tool.Id
                            + ", position: " + tool.TipPosition
                            + ", direction " + tool.Direction);
            }

            // 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
                        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;
                        }

                        SafeWriteLine("  Circle id: " + circle.Id
                                       + ", " + circle.State
                                       + ", progress: " + circle.Progress
                                       + ", radius: " + circle.Radius
                                       + ", angle: " + sweptAngle
                                       + ", " + clockwiseness);

                        gesture_stack.Push(circle);

                        break;
                    case Gesture.GestureType.TYPE_SWIPE:
                        SwipeGesture swipe = new SwipeGesture(gesture);
                        SafeWriteLine("  Swipe id: " + swipe.Id
                                       + ", " + swipe.State
                                       + ", position: " + swipe.Position
                                       + ", direction: " + swipe.Direction
                                       + ", speed: " + swipe.Speed);
                        gesture_stack.Push(swipe);
                        break;
                    case Gesture.GestureType.TYPE_KEY_TAP:
                        KeyTapGesture keytap = new KeyTapGesture(gesture);
                        SafeWriteLine("  Tap id: " + keytap.Id
                                       + ", " + keytap.State
                                       + ", position: " + keytap.Position
                                       + ", direction: " + keytap.Direction);
                        gesture_stack.Push(keytap);
                        break;
                    case Gesture.GestureType.TYPE_SCREEN_TAP:
                        ScreenTapGesture screentap = new ScreenTapGesture(gesture);
                        SafeWriteLine("  Tap id: " + screentap.Id
                                       + ", " + screentap.State
                                       + ", position: " + screentap.Position
                                       + ", direction: " + screentap.Direction);
                        gesture_stack.Push(screentap);
                        break;
                    default:
                        SafeWriteLine("  Unknown gesture type.");
                        break;
                }
            }

            if (!frame.Hands.IsEmpty || !frame.Gestures().IsEmpty)
            {
                SafeWriteLine("");
            }
        }
Exemplo n.º 41
0
    void Update()
    {
        var frame = controller.Frame();
        var fingerCount = frame.Fingers.Count;
        var gestures = frame.Gestures();
        var interactionBox = frame.InteractionBox;
        if(UIOn){
            for ( int i = 0; i < UIItems.Length; i++ ) {
                ItemControllers[i].SetItem(ItemNames[i],ItemPrices[i],ItemValues[i]);
            }
        }
        if ( frame.Fingers[0].IsValid ) {
            for ( int i = 0; i < FingerObjects.Length; i++ ) {
                var leapFinger = frame.Fingers[i];
                var unityFinger = FingerObjects[i];
          // if(leapFinger.Type == Leap.Finger){
          //    var indexFinger = FingerObjects[i];
          //    SetVisible( indexFinger, leapFinger.IsValid );
          // }
                //Debug.Log(leapFinger.TipPosition);
                //Debug.Log(frame.Hands[0]);
                if ( leapFinger.IsValid ) {
                    Vector normalizedPosition = interactionBox.NormalizePoint(leapFinger.TipPosition);
                    // Debug.Log(normalizedPosition);
                    normalizedPosition *= 10;
                    unityFinger.transform.localPosition = ToVector3( normalizedPosition );
                }
            }
        }else{
            Vector normalizedPosition = interactionBox.NormalizePoint(new Vector(0.5f,0.5f,0.5f));
            // Debug.Log(normalizedPosition);
            normalizedPosition.y+=0.35f;
            normalizedPosition *= 10;
            FingerObjects[0].transform.localPosition = ToVector3( normalizedPosition );
            FingerObjects[0].transform.localPosition = ToVector3( normalizedPosition );
        }

                // ジェスチャー結果取得&表示
                Gesture gesture = gestures[0];
                switch ( gesture.Type ) {
                case Gesture.GestureType.TYPECIRCLE:
                    var circle = new CircleGesture(gesture);
                    // 回転方向を計算
                    string clockwiseness;
                    if (circle.Pointable.Direction.AngleTo(circle.Normal) <= Math.PI / 4)
                    {
                      // 角度が90度以下なら、時計回り
                      clockwiseness = "時計回り";
                    }
                    else
                    {
                      clockwiseness = "反時計回り";
                    }
                    if(circle.State == Gesture.GestureState.STATESTOP){
                        //Debug.Log("stop");
                        if(clockwiseness=="時計回り"){
                                Debug.Log("UIOpen");
                                UIOpened=true;
                                panel.SlideIn();
                        }else{
                                UIOpened=false;
                                panel.SlideOut();
                        }

                }
                    break;
                case Gesture.GestureType.TYPEKEYTAP:
                    var keytapGesture = new KeyTapGesture(gesture);
                    printGesture("KeyTap");
                    break;
                case Gesture.GestureType.TYPESCREENTAP:
                    var screenTapGesture = new ScreenTapGesture(gesture);
                    printGesture("ScreenTap");
                    break;
                case Gesture.GestureType.TYPESWIPE:
                var swipe = new SwipeGesture(gesture);
                    Debug.Log(swipe.Direction.y);
                break;
                default:
                    break;

            }
    }
Exemplo n.º 42
0
        /// <summary>
        /// Allows the game component to update itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        public override void Update(GameTime gameTime)
        {
            // TODO: Add your update code here

            if (controller.IsConnected)
            {
                //clear fingers
                fingerPoints.Clear();

                for (int e = 0; e < fingerarray.Length; e++)
                {
                    fingerarray[e] = new Vector2(-128 - 128);
                }
                //Array.Clear(fingerarray,, fingerarray.Length);

                var frame = controller.Frame();

                debugLine = "";

                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.Empty)
                {
                    // Get the first hand
                    hand = frame.Hands[0];

                    firstHandLoc = new Vector2(NormalizeWidth(hand.SphereCenter.x), NormalizeHeight(hand.SphereCenter.y));
                    // Check if the hand has any fingers
                    fingers = hand.Fingers;
                    if (!fingers.Empty)
                    {
                        // Calculate the hand's average finger tip position
                        Vector avgPos = Vector.Zero;
                        foreach (Finger finger in fingers)
                        {
                            fingerPoints.Add(new Vector2(
                                                 NormalizeWidth(finger.TipPosition.x),
                                                 NormalizeHeight(finger.TipPosition.y)
                                                 )
                                             );

                            avgPos += finger.TipPosition;
                        }
                        //

                        /*
                         * for (int u = 0; u < 5; u++)
                         * {
                         *  fingerarray[0].X = fingers[0].TipPosition.x;
                         *  fingerarray[0].Y = fingers[0].TipPosition.y;
                         *
                         *  fingerarray[1].X = fingers[1].TipPosition.x;
                         *  fingerarray[1].Y = fingers[1].TipPosition.y;
                         *
                         *  fingerarray[2].X = fingers[1].TipPosition.x;
                         *  fingerarray[2].Y = fingers[1].TipPosition.y;
                         * }*/

                        int z = 0;
                        foreach (Finger finger1 in fingers)
                        {
                            fingerarray[z++] = new Vector2(NormalizeWidth(finger1.TipPosition.x), NormalizeHeight(finger1.TipPosition.y));

                            avgPos += finger1.TipPosition;
                        }

                        //  fingers.
                        //   fingerarray[z++] = new Vector2(NormalizeWidth(finger1.TipPosition.x), NormalizeHeight(finger1.TipPosition.y));
                        //
                        avgPos /= fingers.Count;

                        SafeWriteLine("Hand has " + fingers.Count
                                      + " fingers, average finger tip position: " + avgPos);
                    }

                    // 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
                    Vector normal    = hand.PalmNormal;
                    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");
                }

                // Get gestures
                gestures = frame.Gestures();
                Gesture gesture;
                for (int i = 0; i < gestures.Count; i++)
                {
                    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
                        String clockwiseness;
                        if (circle.Pointable.Direction.AngleTo(circle.Normal) <= Math.PI / 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 != Gesture.GestureState.STATESTART)
                        {
                            CircleGesture previousUpdate = new CircleGesture(controller.Frame(1).Gesture(circle.Id));
                            sweptAngle = (circle.Progress - previousUpdate.Progress) * 360;
                        }

                        SafeWriteLine("Circle id: " + circle.Id
                                      + ", " + circle.State
                                      + ", progress: " + circle.Progress
                                      + ", radius: " + circle.Radius
                                      + ", angle: " + sweptAngle
                                      + ", " + clockwiseness);

                        break;

                    case Gesture.GestureType.TYPESWIPE:
                        SwipeGesture swipe = new SwipeGesture(gesture);

                        SafeWriteLine("Swipe id: " + swipe.Id
                                      + ", " + swipe.State
                                      + ", position: " + swipe.Position
                                      + ", direction: " + swipe.Direction
                                      + ", speed: " + swipe.Speed);

                        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);

                        SafeWriteLine("Tap id: " + screentap.Id
                                      + ", " + screentap.State
                                      + ", position: " + screentap.Position
                                      + ", direction: " + screentap.Direction);

                        break;

                    default:
                        SafeWriteLine("Unknown gesture type.");
                        break;
                    }
                }

                if (!frame.Hands.Empty || !frame.Gestures().Empty)
                {
                    //SafeWriteLine("");
                }
            }
            base.Update(gameTime);
        }
Exemplo n.º 43
0
    public override void OnFrame( Controller controller )
    {
        // Get the most recent frame and report some basic information
        Frame frame = controller.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 );

        foreach ( Hand hand in frame.Hands ) {
            SafeWriteLine( "  Hand id: " + hand.Id
                        + ", palm position: " + hand.PalmPosition );
            // Get the hand's normal vector and direction
            Vector normal = hand.PalmNormal;
            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" );

            // Get the Arm bone
            Arm arm = hand.Arm;
            SafeWriteLine( "  Arm direction: " + arm.Direction
                        + ", wrist position: " + arm.WristPosition
                        + ", elbow position: " + arm.ElbowPosition );

            // Get fingers
            foreach ( Finger finger in hand.Fingers ) {
                SafeWriteLine( "    Finger id: " + finger.Id
                            + ", " + finger.Type.ToString()
                            + ", length: " + finger.Length
                            + "mm, width: " + finger.Width + "mm" );

                // Get finger bones
                Bone bone;
                foreach ( Bone.BoneType boneType in (Bone.BoneType[])Enum.GetValues( typeof( Bone.BoneType ) ) ) {
                    bone = finger.Bone( boneType );
                    SafeWriteLine( "      Bone: " + boneType
                                + ", start: " + bone.PrevJoint
                                + ", end: " + bone.NextJoint
                                + ", direction: " + bone.Direction );
                }
            }

        }

        // Get tools
        foreach ( Tool tool in frame.Tools ) {
            SafeWriteLine( "  Tool id: " + tool.Id
                        + ", position: " + tool.TipPosition
                        + ", direction " + tool.Direction );
        }

        // 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
                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;
                }

                SafeWriteLine( "  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 );
                SafeWriteLine( "  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 );
                SafeWriteLine( "  Tap id: " + keytap.Id
                               + ", " + keytap.State
                               + ", position: " + keytap.Position
                               + ", direction: " + keytap.Direction );
                break;
            case Gesture.GestureType.TYPE_SCREEN_TAP:
                ScreenTapGesture screentap = new ScreenTapGesture( gesture );
                SafeWriteLine( "  Tap id: " + screentap.Id
                               + ", " + screentap.State
                               + ", position: " + screentap.Position
                               + ", direction: " + screentap.Direction );
                break;
            default:
                SafeWriteLine( "  Unknown gesture type." );
                break;
            }
        }

        if ( !frame.Hands.IsEmpty || !frame.Gestures().IsEmpty ) {
            SafeWriteLine( "" );
        }
    }
Exemplo n.º 44
0
    void DetectSwipe()
    {
        Frame            frame    = leapController.Frame();
        GestureList      gestures = frame.Gestures();
        Gesture          gesture;
        KeyTapGesture    keyTapGesture;
        ScreenTapGesture screenTapGesture;
        SwipeGesture     swipeGesture;

        for (int i = 0; i < gestures.Count; i++)
        {
            gesture = gestures[i];
            //Debug.Log("Gesture number: " + i + " " + gesture.Type);

            switch (gesture.Type)
            {
            case Gesture.GestureType.TYPECIRCLE:
                break;

            case Gesture.GestureType.TYPEINVALID:
                break;

            case Gesture.GestureType.TYPEKEYTAP:
                keyTapGesture = new KeyTapGesture();
                Debug.Log("Key Tap: " + keyTapGesture.State);
                break;

            case Gesture.GestureType.TYPESCREENTAP:
                screenTapGesture = new ScreenTapGesture();
                Debug.Log("Screen Tap: " + screenTapGesture.State);
                break;

            case Gesture.GestureType.TYPESWIPE:
                swipeGesture = new SwipeGesture(gesture);
                if (swipeGesture.State == Gesture.GestureState.STATE_START)
                {
                    Debug.Log("Swipe StartPosition: " + swipeGesture.StartPosition);
                    Debug.Log("Swipe Position: " + swipeGesture.Position);

                    if (swipeGesture.Position.x - swipeGesture.StartPosition.x < -50)
                    {
                        Debug.Log("Swipe: LEFT");
                    }
                    else if (swipeGesture.Position.x - swipeGesture.StartPosition.x > 50)
                    {
                        Debug.Log("Swipe: RIGHT");
                    }
                    if (swipeGesture.Position.y - swipeGesture.StartPosition.y < -50)
                    {
                        Debug.Log("Swipe: UP");
                    }
                    else if (swipeGesture.Position.y - swipeGesture.StartPosition.y > 50)
                    {
                        Debug.Log("Swipe: DOWN");
                    }
                    if (swipeGesture.Position.z - swipeGesture.StartPosition.z < -50)
                    {
                        Debug.Log("Swipe: FORWARD");
                    }
                }
                else if (swipeGesture.State == Gesture.GestureState.STATE_STOP)
                {
                    Debug.Log("Swipe State: " + swipeGesture.State);
                }
                else if (swipeGesture.State == Gesture.GestureState.STATE_UPDATE)
                {
                    //Debug.Log("Swipe State: " + swipeGesture.State);
                }
                break;
            }

            break;
        }
    }
Exemplo n.º 45
0
        public override void OnFrame(Controller controller)
        {
            // Get the most recent frame and report some basic information
            Frame frame = controller.Frame();

            //grabAndScroll.OnFrame(frame);

            ++FrameCount;
            if (FrameCount < 100 && frame.Gestures().Count == 0)
            {
                return;
            }
            FrameCount = 0;

            //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)
                {
                    // Calculate the hand's average finger tip position
                    Vector avgPos = Vector.Zero;
                    foreach (Finger finger in fingers)
                    {
                        avgPos += finger.TipPosition;
                    }
                    avgPos /= fingers.Count;
                    //SafeWriteLine("Hand has " + fingers.Count + " fingers, average finger tip position: " + avgPos);
                }

                // 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
                Vector normal    = hand.PalmNormal;
                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");
            }

            // 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
                    String clockwiseness = ((circle.Pointable.Direction.AngleTo(circle.Normal) <= Math.PI / 4) ? "clockwise" : "counterclockwise");
                    float  sweptAngle    = 0;

                    // Calculate angle swept since last frame
                    if (circle.State != Gesture.GestureState.STATESTART)
                    {
                        CircleGesture previousUpdate = new CircleGesture(controller.Frame(1).Gesture(circle.Id));
                        sweptAngle = (circle.Progress - previousUpdate.Progress) * 360;
                    }

                    SafeWriteLine("Circle id: " + circle.Id + ", " + circle.State + ", progress: " + circle.Progress + ", radius: " + circle.Radius + ", angle: " + sweptAngle + ", " + clockwiseness);
                    break;

                case Gesture.GestureType.TYPESWIPE:
                    SwipeGesture swipe = new SwipeGesture(gesture);
                    //SafeWriteLine("Swipe id: " + swipe.Id + ", " + swipe.State + ", position: " + swipe.Position + ", direction: " + swipe.Direction + ", speed: " + swipe.Speed);
                    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);
                    //SafeWriteLine("Tap id: " + screentap.Id + ", " + screentap.State + ", position: " + screentap.Position + ", direction: " + screentap.Direction);
                    break;

                default:
                    SafeWriteLine("Unknown gesture type.");
                    break;
                }
            }

            if (!frame.Hands.IsEmpty || !frame.Gestures().IsEmpty)
            {
                //SafeWriteLine("");
            }
        }
Exemplo n.º 46
0
    // Update is called once per frame
    void Update()
    {
        //Need to access the frames of the leap motion
        Frame       frame    = controller.Frame();
        GestureList gestures = frame.Gestures();

        //string poser = frame.Hands[0].PalmPosition.z.ToString();//frame.Finger(1).TipPosition.x.ToString();


        /*
         * Pointable pointable = frame.Pointables.Frontmost;
         * Pointable.Zone zone = pointable.TouchZone;
         * float distance = pointable.TouchDistance;
         *
         * Vector stabilizedPosition = pointable.StabilizedTipPosition;
         * Vector3 g = stabilizedPosition.ToUnityScaled();
         * InteractionBox iBox = frame.InteractionBox;
         * Vector normalizedPosition = iBox.NormalizePoint(stabilizedPosition);
         * Vector3 tmpPos = Camera.main.WorldToScreenPoint(transform.position);
         * float x = normalizedPosition.x * UnityEngine.Screen.width;
         * float y = normalizedPosition.y * UnityEngine.Screen.height;
         *
         *
         * Debug.Log(x + " | " + y); */
        //Debug.Log(g.x*2 + " | " + (g.y*3-1f) + " | " + g.z*3);

        //Debug.Log(poser);

        for (int i = 0; i < gestures.Count; i++)
        {
            Gesture gestureN = gestures[i];

            /*   if (gestureN.Type == Gesture.GestureType.TYPE_SWIPE)
             * {
             *     SwipeGesture Swipe = new SwipeGesture(gestureN);
             *     Vector swipeDirection = Swipe.Direction;
             *
             *     Finger finger = new Finger(Swipe.Pointable);
             *
             *     if (Finger.FingerType.TYPE_THUMB == finger.Type)
             *     {
             *         if (swipeDirection.x < 0)
             *         {
             *             Debug.Log("Left");
             *         }
             *         else if (swipeDirection.x > 0)
             *         {
             *             Debug.Log("Right");
             *         }
             *     }
             * }*/
            if (gestureN.Type == Gesture.GestureType.TYPE_KEY_TAP)
            {
                KeyTapGesture thumbTap    = new KeyTapGesture(gestureN);
                Vector        thumbTapDir = thumbTap.Direction;
                Finger        finger      = new Finger(thumbTap.Pointable);
                //Pointable tappingPointable = thumbTap.Pointable;
                //Finger finger = thumbTap.Pointable as Finger;
                if (Finger.FingerType.TYPE_THUMB == finger.Type)
                {
                    Debug.Log("THUMB TIME" + Random.Range(0f, 20f));
                }
            }
            if (gestureN.Type == Gesture.GestureType.TYPE_SCREEN_TAP)
            {
                ScreenTapGesture thumbTap    = new ScreenTapGesture(gestureN);
                Vector           thumbTapDir = thumbTap.Direction;
                Finger           finger      = new Finger(thumbTap.Pointable);
                //Pointable tappingPointable = thumbTap.Pointable;
                //Finger finger = thumbTap.Pointable as Finger;
                if (Finger.FingerType.TYPE_THUMB == finger.Type)
                {
                    Debug.Log("THUMBSCREEB TIME" + Random.Range(0f, 20f));
                }
            }
        }
    }
Exemplo n.º 47
0
        /// <summary>
        /// performs pre actions before calling callback function
        /// </summary>
        /// <param name="gesture">Screen Tap gesture</param>
        private void PreScreenTap(Gesture gesture)
        {
            ScreenTapGesture screentap = new ScreenTapGesture(gesture);

            if (_onScreenTap != null) _onScreenTap();
        }
Exemplo n.º 48
0
    void Update() {
        var frame = controller.Frame();
        var fingerCount = frame.Fingers.Count;
        var gestures = frame.Gestures();
        var interactionBox = frame.InteractionBox;
        if(UIOn){
            for ( int i = 0; i < UIItems.Length; i++ ) {
                ItemControllers[i].SetItem(ItemNames[i],ItemPrices[i],ItemValues[i]);
            }
        }
        if ( frame.Fingers[0].IsValid ) {
        	for ( int i = 0; i < FingerObjects.Length; i++ ) {
                var leapFinger = frame.Fingers[i];
                var unityFinger = FingerObjects[i];
      // if(leapFinger.Type == Leap.Finger){
      //    var indexFinger = FingerObjects[i];
      //    SetVisible( indexFinger, leapFinger.IsValid );
      // }
                //Debug.Log(leapFinger.TipPosition);
                //Debug.Log(frame.Hands[0]);
                if ( leapFinger.IsValid ) {
                    Vector normalizedPosition = interactionBox.NormalizePoint(leapFinger.TipPosition);
                    // Debug.Log(normalizedPosition);
                    normalizedPosition *= 10;
                    unityFinger.transform.localPosition = ToVector3( normalizedPosition );
                }
            }
        }else{
            Vector normalizedPosition = interactionBox.NormalizePoint(new Vector(0.5f,0.5f,0.5f));
            // Debug.Log(normalizedPosition);
            normalizedPosition.y+=0.35f;
            normalizedPosition *= 10;
            FingerObjects[0].transform.localPosition = ToVector3( normalizedPosition );
            FingerObjects[0].transform.localPosition = ToVector3( normalizedPosition );
        }

                // ジェスチャー結果取得&表示
                Gesture gesture = gestures[0];
                switch ( gesture.Type ) {
                case Gesture.GestureType.TYPECIRCLE:
                    var circle = new CircleGesture(gesture);
                    // 回転方向を計算
                    string clockwiseness;
                    if (circle.Pointable.Direction.AngleTo(circle.Normal) <= Math.PI / 4)
                    {
                      // 角度が90度以下なら、時計回り
                      clockwiseness = "時計回り";
                    }
                    else
                    {
                      clockwiseness = "反時計回り";
                    }
                    if(circle.State == Gesture.GestureState.STATESTOP){
                        //Debug.Log("stop");
                        if(clockwiseness=="時計回り"){
                                Debug.Log("UIOpen");
                                UIOpened=true;
                                panel.SlideIn();
                        }else{
                                UIOpened=false;
                                panel.SlideOut();
                        }

                }
                    break;
                case Gesture.GestureType.TYPEKEYTAP:
                    var keytapGesture = new KeyTapGesture(gesture);
                    printGesture("KeyTap");
                    break;
                case Gesture.GestureType.TYPESCREENTAP:
                    var screenTapGesture = new ScreenTapGesture(gesture);
                    printGesture("ScreenTap");
                    break;
                case Gesture.GestureType.TYPESWIPE:
                var swipe = new SwipeGesture(gesture);
                    Debug.Log(swipe.Direction.y);
                break;
                default:
                    break;

            }
    }
Exemplo n.º 49
0
        private void HandleScreenTapGesture(Gesture gesture)
        {
            //Delay
            if ((Time.time - _lastScreenTap) <= (ScreenTapDelayLimitInMs / 1000)) return;
            _lastScreenTap = Time.time;

            if (gesture.Frame.Fingers.Count < 2) return;
            if (gesture.State != Gesture.GestureState.STATESTOP) return;
            //Reset Timer
            _resetTimer.ResetCounter();

            var screenTap = new ScreenTapGesture(gesture);
            //Debug.Log("ScreenTap ("+gesture.Id+")  IsValuid:" +gesture.IsValid+ " Position" + ((keytap.Position.x > 0) ? "right" : "left") + " - " + keytap.Position.x + " - State: " + gesture.State);

            //on wich side was the tap?
            var right = screenTap.Position.x > 0;

            //Just handle the tap, if we have a selected object and a pointer finger
            if (_activeFinger != null && _lastHittedObject != null)
            {
                //Get the mondrianBehaviour component
                var mondrian = _lastHittedObject.GetComponent<MondrianBehaviour>();

                //Right side? -> Split action
                if (right)
                {
                    //Get the setted Action
                    var actionObject = GameObject.FindGameObjectWithTag("ActiveAction");

                    //And fire action
                    if (actionObject.name.ToLower().Contains("vertical"))
                    {
                        mondrian.SplitVertical(_savedColor);
                    }
                    else if (actionObject.name.ToLower().Contains("horizontal"))
                    {
                        mondrian.SplitHorizontal(_savedColor);
                    }
                }
                //Left side? -> Color change action
                else
                {
                    //Get the setted Color
                    var colorObject = GameObject.FindGameObjectWithTag("ActiveColor");
                    var color = colorObject.renderer.material.color;

                    //And set the new Color
                    mondrian.ChangeColour(color);

                    //overwrite saved color
                    _savedColor = color;
                }
            }
        }
        /// <summary>
        /// Allows the game component to update itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        public override void Update(GameTime gameTime)
        {
            // TODO: Add your update code here
            if (controller.IsConnected)
            {
                //clear fingers
                fingerPoints.Clear();
                var frame = controller.Frame();

                debugLine = "";

                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.Count() == 0 ))
                {
                    // Get the first hand
                    hand = frame.Hands[0];

                    firstHandLoc = new Vector2(NormalizeWidth(hand.SphereCenter.x), NormalizeHeight( hand.SphereCenter.y));
                    // Check if the hand has any fingers
                    fingers = hand.Fingers;
                    if (!(fingers.Count() == 0))
                    {
                        // Calculate the hand's average finger tip position
                        Vector avgPos = Vector.Zero;
                        foreach (Finger finger in fingers)
                        {
                            fingerPoints.Add(new Vector2(
                                NormalizeWidth(finger.TipPosition.x),
                                NormalizeHeight(finger.TipPosition.y)
                                )
                            );
                            avgPos += finger.TipPosition;
                        }
                        avgPos /= fingers.Count;

                        SafeWriteLine("Hand has " + fingers.Count
                                    + " fingers, average finger tip position: " + avgPos);

                    }

                    // 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
                    Vector normal = hand.PalmNormal;
                    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");

                }

                // Get gestures
                gestures = frame.Gestures();
                Gesture gesture;
                for (int i = 0; i < gestures.Count; i++)
                {
                    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
                            String clockwiseness;
                            if (circle.Pointable.Direction.AngleTo(circle.Normal) <= Math.PI / 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 != Gesture.GestureState.STATESTART)
                            {
                                CircleGesture previousUpdate = new CircleGesture(controller.Frame(1).Gesture(circle.Id));
                                sweptAngle = (circle.Progress - previousUpdate.Progress) * 360;
                            }

                            SafeWriteLine("Circle id: " + circle.Id
                                           + ", " + circle.State
                                           + ", progress: " + circle.Progress
                                           + ", radius: " + circle.Radius
                                           + ", angle: " + sweptAngle
                                           + ", " + clockwiseness);

                            break;
                        case Gesture.GestureType.TYPESWIPE:
                            SwipeGesture swipe = new SwipeGesture(gesture);

                            SafeWriteLine("Swipe id: " + swipe.Id
                                           + ", " + swipe.State
                                           + ", position: " + swipe.Position
                                           + ", direction: " + swipe.Direction
                                           + ", speed: " + swipe.Speed);

                            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);

                            SafeWriteLine("Tap id: " + screentap.Id
                                           + ", " + screentap.State
                                           + ", position: " + screentap.Position
                                           + ", direction: " + screentap.Direction);

                            break;
                        default:
                            SafeWriteLine("Unknown gesture type.");
                            break;
                    }
                }

                if (!(frame.Hands.Count() == 0) || !(frame.Gestures().Count ==0))
                {
                    //SafeWriteLine("");
                }
            }
            base.Update(gameTime);
        }
Exemplo n.º 51
0
    // 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;
            }
        }
    }
Exemplo n.º 52
0
        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;
                }
            }
        }
Exemplo n.º 53
0
        /// <summary>
        /// Called many (many) times a second. This system handles all gesture actions and responses
        /// </summary>
        /// <param name="controller"></param>
        public override void OnFrame(Controller controller)
        {
            var frame    = controller.Frame();
            var gestures = frame.Gestures();

            // Grab the current count of objects that the device
            // can see and store that data for later use
            _visibleFingers = frame.Fingers.Count();
            _visibleTools   = frame.Tools.Count();
            _visibleHands   = frame.Hands.Count();

            #if DEBUG
            SendDebugMessage("Fingers: " + _visibleFingers);
            SendDebugMessage("Tools: " + _visibleTools);
            SendDebugMessage("Hands: " + _visibleHands);
            #endif

            // If we're not currently tracking any gestures in this frame, do a cleanup check and don't continue on
            if (!gestures.Any() || (_lastGestureEvent != DateTime.MinValue && DateTime.Now < _lastGestureEvent.AddMilliseconds(TimeBeforeNextAction)))
            {
                if ((DateTime.Now - _lastGestureEvent).TotalSeconds > 2 && _currentlyTracking)
                {
                    _currentlyTracking     = false;
                    _currentlyTrackingType = Gesture.GestureType.TYPEINVALID;

                    #if DEBUG
                    SendDebugMessage("Idle Device - Resetting gestures");
                    #endif
                }

                return;
            }

            // If there's no gesture in progress, make sure our active counts are set to zero
            if (!_currentlyTracking)
            {
                _currentActionFingers = 0;
                _currentActionTools   = 0;
            }
            else
            {
                // Else set all our active counts to the highest amount of objects there are for each type
                if (_currentActionFingers < _visibleFingers)
                {
                    _currentActionFingers = _visibleFingers;
                }

                if (_currentActionTools < _visibleTools)
                {
                    _currentActionTools = _visibleTools;
                }

                if (_currentActionHands < _visibleHands)
                {
                    _currentActionHands = _visibleHands;
                }
            }

            // There may be many, but we only care about the first.
            var thisGesture = gestures.First();

            switch (thisGesture.Type)
            {
            case Gesture.GestureType.TYPESWIPE:
                var swipe = new SwipeGesture(thisGesture);
                ProcessSwipe(swipe);     // Swipe.cs
                break;

            case Gesture.GestureType.TYPESCREENTAP:
                var screenTap = new ScreenTapGesture(thisGesture);
                ProcessScreenTap(screenTap);     // Tap.cs
                break;

            case Gesture.GestureType.TYPEKEYTAP:
                var keyTap = new KeyTapGesture(thisGesture);
                ProcessKeyTap(keyTap);     // Tap.cs
                break;

            case Gesture.GestureType.TYPECIRCLE:
                var circle = new CircleGesture(thisGesture);
                ProcessCircle(circle);     // Circle.cs
                break;
            }
        }
        public override void OnFrame(Controller controller)
        {
            // Get the most recent frame and report some basic information
            Frame frame = controller.Frame();

            //check for only if there is only one hand
            if (frame.Hands.Count == 1)
            {
                //check to see if there is only the index finger is extended
                FingerList fingers = frame.Hands[0].Fingers;
                if (fingers[Finger.FingerType.TYPE_INDEX.GetHashCode()].IsExtended &&
                    !fingers[Finger.FingerType.TYPE_MIDDLE.GetHashCode()].IsExtended &&
                    !fingers[Finger.FingerType.TYPE_RING.GetHashCode()].IsExtended &&
                    !fingers[Finger.FingerType.TYPE_PINKY.GetHashCode()].IsExtended &&
                    !fingers[Finger.FingerType.TYPE_THUMB.GetHashCode()].IsExtended)
                {
                    fingerLocation(fingers[Finger.FingerType.TYPE_INDEX.GetHashCode()], controller.LocatedScreens.ClosestScreenHit(fingers[Finger.FingerType.TYPE_INDEX.GetHashCode()]));
                }
                if (fingers[Finger.FingerType.TYPE_INDEX.GetHashCode()].IsExtended &&
                    !fingers[Finger.FingerType.TYPE_MIDDLE.GetHashCode()].IsExtended &&
                    !fingers[Finger.FingerType.TYPE_RING.GetHashCode()].IsExtended &&
                    !fingers[Finger.FingerType.TYPE_PINKY.GetHashCode()].IsExtended &&
                    fingers[Finger.FingerType.TYPE_THUMB.GetHashCode()].IsExtended)
                {
                    screenTap();
                }
            }

            //check for custom gestures
            CustomGesture cg = new CustomGesture(frame);

            switch (cg.GestureType)
            {
            case CustomGesture.GestureTypes.INVALID:
                // 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
                        string clockwiseness;
                        if (circle.Pointable.Direction.AngleTo(circle.Normal) <= Math.PI / 2)
                        {
                            //Clockwise if angle is less than 90 degrees
                            clockwiseness = "clockwise";
                            ZoomEvent(Zoom.IN);
                        }
                        else
                        {
                            ZoomEvent(Zoom.OUT);
                            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;
                        }

                        break;

                    case Gesture.GestureType.TYPE_SWIPE:
                        SwipeGesture swipe = new SwipeGesture(gesture);
                        if (Math.Abs(swipe.Direction.x) > Math.Abs(swipe.Direction.y)) // Horizontal swipe
                        {
                            if (swipe.Direction.x > 0)                                 // right swipe
                            {
                                SwipeAction(swipe.Hands[0].Fingers, SwipeDirection.Right); Console.WriteLine();
                            }
                            else         // left swipe
                            {
                                SwipeAction(swipe.Hands[0].Fingers, SwipeDirection.Left); Console.WriteLine();
                            }
                        }
                        else                           // Vertical swipe
                        {
                            if (swipe.Direction.y > 0) // upward swipe
                            {
                                SwipeAction(swipe.Hands[0].Fingers, SwipeDirection.Up); Console.WriteLine();
                            }
                            else         // downward swipe
                            {
                                SwipeAction(swipe.Hands[0].Fingers, SwipeDirection.Down); Console.WriteLine();
                            }
                        }

                        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;
                    }
                }
                break;

            case CustomGesture.GestureTypes.PEACE:
                break;

            default:
                break;
            }
        }
Exemplo n.º 55
0
    public override void OnFrame(Controller controller)
    {
        // Get the most recent frame and report some basic information
        Frame frame = controller.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);

        

        StringBuilder dataToSend = new StringBuilder();
        thumb = "(0,0,0)"; index = "(0,0,0)"; palm = "(0,0,0)";
        
        foreach (Hand hand in frame.Hands)
        {
            SafeWriteLine("  Hand id: " + hand.Id
                        + ", palm position: " + hand.PalmPosition);
            // Get the hand's normal vector and direction
            Vector normal = hand.PalmNormal;
            Vector direction = hand.Direction;


            palm = hand.PalmPosition.ToString();
            //dataToSend.Append("HPOS_" + hand.Id + " " + hand.PalmPosition.ToString());

            //sendToClient("HPOS_" + hand.Id + " " + hand.PalmPosition.ToString());// + " " + normal.y.ToString("0.0000") + " " + normal.z.ToString("0.0000"));

            /*
            // 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");
            */
            /*
            // Get the Arm bone
            Arm arm = hand.Arm;
            SafeWriteLine("  Arm direction: " + arm.Direction
                        + ", wrist position: " + arm.WristPosition
                        + ", elbow position: " + arm.ElbowPosition);
            */
            // Get fingers
            foreach (Finger finger in hand.Fingers)
            {
                //SafeWriteLine("    Finger id: " + finger.Id
                 //           + ", " + finger.Type.ToString()
                 //           + ", length: " + finger.Length
                 //           + "mm, width: " + finger.Width + "mm");

                if (finger.Type == Finger.FingerType.TYPE_THUMB)
                    thumb = finger.TipPosition.ToString();
                else if(finger.Type == Finger.FingerType.TYPE_INDEX)
                    index = finger.TipPosition.ToString();

                if (thumb != "(0,0,0)" && index != "(0,0,0)")
                    break;

                // Get finger bones
                /*
                Bone bone;
                foreach (Bone.BoneType boneType in (Bone.BoneType[])Enum.GetValues(typeof(Bone.BoneType)))
                {
                    bone = finger.Bone(boneType);
                    SafeWriteLine("      Bone: " + boneType
                                + ", start: " + bone.PrevJoint
                                + ", end: " + bone.NextJoint
                                + ", direction: " + bone.Direction);
                }
                 */
            }

            //sendToClient(dataToSend.Append(thumb).Append(index).ToString());

        }

        /*
        // Get tools
        foreach (Tool tool in frame.Tools)
        {
            SafeWriteLine("  Tool id: " + tool.Id
                        + ", position: " + tool.TipPosition
                        + ", direction " + tool.Direction);
        }
        */
        ///*
        // Get gestures
        GestureList gestures = frame.Gestures();
        
        if(gestures.Count > 0 && frame.Id - latestGestureFrame > 90 )
        {
            latestGestureFrame = frame.Id;
      
            
            for (int i = 0; i < gestures.Count; i++)
            {
                Gesture gesture = gestures[i];
                
                
                /*
                if(gesture.Type == latestGesture.Type)
                {
                    gestureCounter++;
                }
                else
                {
                    latestGesture = gesture;
                    gestureCounter = 0;
                }
                */
                //if (gesture.DurationSeconds > 0.1 || gesture.Type == Gesture.GestureType.TYPE_SWIPE) //(gesture.State == Gesture.GestureState.STATE_UPDATE)/
                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";
                            gestureInfo = "c" + frame.Id;
                        }
                        else
                        {
                            clockwiseness = "counterclockwise";
                            gestureInfo = "C" + frame.Id;
                        }

                        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;
                        }

                        SafeWriteLine("  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);

                        gestureInfo = "S" + frame.Id;

                        SafeWriteLine("  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);

                        gestureInfo = "K" + frame.Id;

                        SafeWriteLine("  Tap id: " + keytap.Id
                                       + ", " + keytap.State
                                       + ", position: " + keytap.Position
                                       + ", direction: " + keytap.Direction);
                        break;
                    case Gesture.GestureType.TYPE_SCREEN_TAP:
                        ScreenTapGesture screentap = new ScreenTapGesture(gesture);

                        gestureInfo = "T" + frame.Id;

                        SafeWriteLine("  Tap id: " + screentap.Id
                                       + ", " + screentap.State
                                       + ", position: " + screentap.Position
                                       + ", direction: " + screentap.Direction);
                        break;
                    default:
                        SafeWriteLine("  Unknown gesture type.");
                        break;
                }
            }
        }

        if (frame.Id % frameSkip == 0)
        {
            dataToSend.Append(gestureInfo + " ").Append(palm).Append(thumb).Append(index);
            sendToClient(dataToSend.ToString());
        }
        //*/
        if (!frame.Hands.IsEmpty || !frame.Gestures().IsEmpty)
        {
            SafeWriteLine("");
        }
    }
Exemplo n.º 56
0
    public static void OnFrame(Controller controller)
    {
        if (controller.IsConnected)
        {
            Frame frame = controller.Frame();

            if (!frame.Hands.IsEmpty)
            {
                handInScene = true;

                Hand hand = frame.Hands[0];

                Vector direction = hand.Direction;
                Vector normal    = hand.PalmNormal;

                pitch = direction.Pitch * 180.0f / (float)Mathf.PI;
                roll  = normal.Roll * 180.0f / (float)Mathf.PI;
                yaw   = direction.Yaw * 180.0f / (float)Mathf.PI;

                //	Debug.Log("Pitch: " + pitch + " Roll: " + roll + " Yaw: " + yaw);
            }
            else
            {
                handInScene = false;
            }

            GestureList gestures = frame.Gestures();

            for (int i = 0; i < gestures.Count; i++)
            {
                Gesture gesture = gestures[i];

                switch (gesture.Type)
                {
                case Gesture.GestureType.TYPECIRCLE:

                    CircleGesture circleGesture = new CircleGesture(gesture);

                    if (circleGesture.Pointable.Direction.AngleTo(circleGesture.Normal) <= Mathf.PI / 4)
                    {
                        jump = true;
                    }
                    else
                    {
                        lateral = true;
                        // jump = true;
                    }

                    break;

                case Gesture.GestureType.TYPESWIPE:

                    SwipeGesture swipe = new SwipeGesture(gesture);

                    break;

                case Gesture.GestureType.TYPEKEYTAP:

                    KeyTapGesture keyTap = new KeyTapGesture(gesture);

                    break;

                case Gesture.GestureType.TYPESCREENTAP:

                    ScreenTapGesture screenTap = new ScreenTapGesture(gesture);

                    break;
                }
            }
        }
    }
Exemplo n.º 57
0
        public override void OnFrame(Controller cntrlr)
        {
            // Get the current frame.
            Frame currentFrame = cntrlr.Frame();

            currentTime = currentFrame.Timestamp;
            timeChange = currentTime - previousTime;
            if (timeChange > FramePause)
            {

                //pointable jari
                if (!currentFrame.Hands.IsEmpty)
                {
                    // Get the first finger in the list of fingers
                    Pointable finger = currentFrame.Pointables[0];
                    // Get the closest screen intercepting a ray projecting from the finger
                    Screen screen = cntrlr.LocatedScreens.ClosestScreenHit(finger);

                    if (screen != null && screen.IsValid)
                    {
                        // Get the velocity of the finger tip
                        //var tipVelocity = (int)finger.TipVelocity.Magnitude;
                        Hand hand = currentFrame.Hands.Frontmost;
                        // Use tipVelocity to reduce jitters when attempting to hold
                        // the cursor steady
                        //if (tipVelocity > 25)
                        if (finger.TipVelocity.Magnitude > 25)
                        {
                            float xScreenIntersect = (float)screen.Intersect(finger, true).x;
                            float yScreenIntersect = (float)(1 - screen.Intersect(finger, true).y);
                            //float zScreenIntersect = finger.TipPosition.z;
                            float zScreenIntersect = screen.DistanceToPoint(finger.TipPosition);

                            if (xScreenIntersect.ToString() != "NaN")
                            {
                                //var x = (int)(xScreenIntersect * screen.WidthPixels);
                                //var y = (int)(screen.HeightPixels - (yScreenIntersect * screen.HeightPixels));

                                if (fingerPoint.Count <= 0)
                                {
                                    fingerPoint.Add(new FingerPointStorage(xScreenIntersect, yScreenIntersect, zScreenIntersect, false,0,0));
                                }
                                else
                                {

                                    ////////////////////gesture
                                    if (currentFrame.Pointables.Count > 2)
                                    {

                                        //Console.WriteLine("embuh: " + currentFrame.Gestures().Count);
                                        // Console.WriteLine("pinch: " + hand.PinchStrength);

                                        if (currentFrame.Gestures().Count > 0)
                                        {
                                            //debugbox1.Text = "Gesture" + frame.Gestures()[0].ToString();
                                            int numGestures = currentFrame.Gestures().Count;
                                            if (numGestures > 0)
                                            {
                                                for (int i = 0; i < numGestures; i++)
                                                {
                                                    if (currentFrame.Gestures()[i].Type == Leap.Gesture.GestureType.TYPESCREENTAP)
                                                    {
                                                        ScreenTapGesture tap = new ScreenTapGesture(currentFrame.Gestures()[i]);

                                                        //Console.WriteLine("position z: " + tap.Position.z);
                                                        //System.Diagnostics.Process.Start(@"D:\465097.jpg");
                                                        // System.Diagnostics.Process.Start(@"D:\KULIAH_NGAJAR\Daspro\C++\GettingStartedCpp_001.pptx");
                                                        // PlayFile(@"D:\a.mp3");

                                                    }
                                                    else if (currentFrame.Gestures()[i].Type == Leap.Gesture.GestureType.TYPECIRCLE)
                                                    {
                                                        CircleGesture circle = new CircleGesture(currentFrame.Gestures()[i]);
                                                        fingerPoint[0].g_circle = circle.Progress;

                                                    }
                                                }
                                            }
                                        }
                                    }
                                    ///////////////////////////////////
                                    fingerPoint[0].g_Pinch = hand.PinchStrength;
                                    fingerPoint[0].g_X = xScreenIntersect;
                                    fingerPoint[0].g_Y = yScreenIntersect;
                                    fingerPoint[0].g_Z = zScreenIntersect;
                                    fingerPoint[0].isActive = true;
                                    if (hand.IsLeft)
                                        fingerPoint[0].numHand = true;
                                    else
                                        fingerPoint[0].numHand = false;
                                    //Console.WriteLine("leap x-axis: {0},y-axis: {1},z-axis: {2}", fingerPoint[0].g_X, fingerPoint[0].g_Y, fingerPoint[0].g_Z);
                                }
                            }
                        }
                    }
                }
                previousTime = currentTime;
            }
        }
Exemplo n.º 58
0
    void TranslateFingerPosition()
    {
        float[] fingerPositionX = new float[5];
        float[] fingerPositionY = new float[5];
        float[] fingerPositionZ = new float[5];

        for (int f = 0; f < RightHand.Fingers.Count; f++)
        {
            fingerPositionX[f] = RightHand.Fingers[f].TipPosition.x * constant;
            fingerPositionY[f] = RightHand.Fingers[f].TipPosition.y * constant;
            fingerPositionZ[f] = RightHand.Fingers[f].TipPosition.z * constant;
        }

        GestureList gesture = frame.Gestures();

        for (int i = 0; i < gesture.Count; i++)
        {
            ScreenTapGesture tap = new ScreenTapGesture(gesture[i]);

            string state       = tap.State.ToString();
            Vector tapPosition = new Vector(tap.Position.x * constant, tap.Position.y * constant, tap.Position.z * -constant);

            //Debug.Log(state + "\n" + tapPosition + "\n" + isSelected + "\n");

            //if(state.Equals("STATE_UPDATE")){



            if (tapPosition.x > transform.position.x - 2.5f && tapPosition.x < transform.position.x + 2.5f &&
                tapPosition.y > transform.position.y - 2.5f && tapPosition.y < transform.position.y + 2.5f && tap.IsValid)
            {
                if (!isSelected)
                {
                    isSelected        = true;
                    renderer.material = ColorRed;
                }
                else
                {
                    isSelected        = false;
                    renderer.material = ColorBlue;
                }
            }


            //}
        }
        if (isSelected)
        {
            if (fingerPositionX[1] > transform.position.x)
            {
                transform.position = new Vector3(transform.position.x + 1f, transform.position.y, transform.position.z);
            }

            if (fingerPositionX[1] <= transform.position.x)
            {
                transform.position = new Vector3(transform.position.x - 1f, transform.position.y, transform.position.z);
            }

            if (fingerPositionY[1] > transform.position.y)
            {
                transform.position = new Vector3(transform.position.x, transform.position.y + 1f, transform.position.z);
            }

            if (fingerPositionY[1] <= transform.position.y)
            {
                transform.position = new Vector3(transform.position.x, transform.position.y - 1f, transform.position.z);
            }
        }
    }
Exemplo n.º 59
0
        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.Hands.Count==2&&frame.Fingers.Count>=2&&LeapFingerReady!=null)
                {
                    Finger first, second;
                    if (frame.Fingers[0].Length > frame.Fingers[1].Length)
                    {
                        first = frame.Fingers[0];
                        second = frame.Fingers[1];
                    }
                    else
                    {
                        first = frame.Fingers[1];
                        second = frame.Fingers[0];
                    }
                    for (int i = 2; i < frame.Fingers.Count;i++ )
                    {
                        if (frame.Fingers[i].Length > second.Length && frame.Fingers[i].Length < first.Length)
                        {
                            second = frame.Fingers[i];
                        }
                        else if (frame.Fingers[i].Length > second.Length && frame.Fingers[i].Length > first.Length)
                        {
                            first = frame.Fingers[i];
                        }
                    }
                    if (first.Length>30&&second.Length>30)
                        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.STATESTOP&&circle.Radius>15&&circle.Progress>0.5)
                        {
                            if(DateTime.Now-lastTime>TimeSpan.FromMilliseconds(1000))
                            {
                                LeapCircleReady(this);
                                lastTime = DateTime.Now;
                            }
                        }

                        break;
                    case Gesture.GestureType.TYPESWIPE:
                        SwipeGesture swipe = new SwipeGesture(gesture);

                        if (swipe.State == Gesture.GestureState.STATESTART&&LeapSwipeReady!=null)
                        {
                           // if (DateTime.Now - lastTime > TimeSpan.FromMilliseconds(600))
                            //{
                                if (swipe.Direction.x < -0.5)
                                {
                                    LeapSwipeReady(this, SwipeType.SwipeLeft);
                                    //lastTime = DateTime.Now;
                                }
                                else if (swipe.Direction.x > 0.5)
                                {
                                    LeapSwipeReady(this, SwipeType.SwipeRight);
                                    //lastTime = DateTime.Now;
                                }
                            //}

                            //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);
                        Finger first = screentap.Frame.Fingers[0];
                        for (int j = 1; j < frame.Fingers.Count; j++)
                        {
                            if ( frame.Fingers[j].Length > first.Length)
                            {
                                first = frame.Fingers[j];
                            }
                        }
                        if ( LeapTapScreenReady!=null&&screentap.State==Gesture.GestureState.STATESTOP&&first.Length>15)
                        {
                            if (DateTime.Now - lastTime > TimeSpan.FromMilliseconds(600))
                            {
                               LeapTapScreenReady(this);
                                lastTime = DateTime.Now;
                            }
                        }
                        break;
                }
            }
        }
Exemplo n.º 60
0
        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("");
                }
            }
        }