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
 public static VyroGesture CreateFromLeapGesture(CircleGesture gesture)
 {
     var c = new VyroGestureCircle { Gesture = gesture };
     c._Radius.Initialize(Convert.ToInt64(c.Gesture.Radius));
     c.IsClockwise = (c.Gesture.Pointable.Direction.AngleTo(c.Gesture.Normal) <= Math.PI / 4);
     return c;
 }
Exemplo n.º 3
0
        // Function that detects the gesture to lock or unlock screen cursor using Leap
        public Boolean lockOrUnlock()
        {
            if (gesture_detected != null)
            {
                CircleGesture circle = new CircleGesture(gesture_detected);

                //circle.Progress indicates number of times circle is detected in a row
                if (circle.Progress >= 1 && circle.DurationSeconds <= 0.5)
                {
                    // Calculate clock direction using the angle between circle normal and pointable
                    if (circle.Pointable.Direction.AngleTo(circle.Normal) <= Math.PI / 4)
                    {
                        //Clockwise to unlock
                        lock_status = false;
                    }
                    else
                    {
                        //anti-clockwise to lock
                        lock_status = true;
                    }
                }

                gesture_detected = null;
            }

            //Lock the screen if it exceeds configured number of frames
            lockScreenAfterTimeout();

            return(lock_status);
        }
Exemplo n.º 4
0
    // Update is called once per frame
    void Update()
    {
        gestureTimeout -= Time.deltaTime;
        if (gestureTimeout > 0.0f)
        {
            return;
        }
        Frame       frame    = cont.Frame();
        GestureList gestures = frame.Gestures();

        foreach (Gesture gesture in gestures)
        {
            if (gesture.Type == Gesture.GestureType.TYPE_CIRCLE)
            {
                CircleGesture circle = new CircleGesture(gesture);
                if (testCircle(circle))
                {
                    gestureTimeout = 0.5f;
                    break;
                }
            }
            else if (gesture.State == Gesture.GestureState.STATE_STOP)
            {
                SwipeGesture swipe = new SwipeGesture(gesture);
                if (testGesture(swipe))
                {
                    gestureTimeout = 0.5f;
                    break;
                }
            }
        }
    }
Exemplo n.º 5
0
    void Update()
    {
        if (!MyNetworkLobbyManager.s_singleton.IsTutorial)
        {
            if (!isLocalPlayer) return;
            if (GetComponent<GameEndDirector>().IsStart) return;
        }

        foreach (var hand in hand_controller_.GetFrame().Hands)
        {
            if (!hand.IsLeft) continue;

            var gesture_list = hand.Frame.Gestures();

            foreach (Gesture gesture in gesture_list)
            {
                var magic_type = player_magic_manager_.MagicType;
                if (magic_type == -1) break;
                var circle_gesture = new CircleGesture(gesture);

                if (circle_gesture.IsValid)
                {
                    if (!hand.IsLeft) continue;
                    if (gesture.DurationSeconds < TURN_SECOND) continue;
                    if (!player_magic_manager_.MagicExecute()) continue;
                    magic_action_list_[magic_type]();

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

            // Get gestures
            // Only handles swipe gesture for now...
            GestureList gestures = frame.Gestures();

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

                switch (gesture.Type)
                {
                case Gesture.GestureType.TYPE_SWIPE:
                    SwipeGesture swipe = new SwipeGesture(gesture);
                    OnGesture("swipe", swipe.Id, swipe.State.ToString(), swipe.Position.ToFloatArray(), swipe.Direction.ToFloatArray());
                    break;

                case Gesture.GestureType.TYPECIRCLE:
                    CircleGesture circle = new CircleGesture(gesture);
                    OnCircleGesture("circle", circle.Id, circle.State.ToString(), circle.Progress, circle.Normal, circle.Pointable);
                    break;
                }
            }
        }
Exemplo n.º 7
0
        protected override VyroGestureState UpdateGestureImpl(Frame frame)
        {
            Gesture = new CircleGesture(frame.Gesture(Gesture.Id));

            switch (Gesture.State)
            {
            case Leap.Gesture.GestureState.STATEINVALID:
                return(VyroGestureState.Invalid);

            case Leap.Gesture.GestureState.STATESTOP:
                return(VyroGestureState.ContinuousComplete);

            case Leap.Gesture.GestureState.STATEUPDATE:
                _Radius.Update(Convert.ToInt64(Gesture.Radius), frame);
                if (Gesture.Progress > (Progress + 1.0))
                {
                    Progress = Convert.ToInt32(Math.Floor(Gesture.Progress));
                    return(VyroGestureState.IterationComplete);
                }
                return(VyroGestureState.Progressing);

            default:
                return(VyroGestureState.Progressing);
            }
        }
        public override void OnFrame(Controller controller)
        {
            // Get the most recent frame and report some basic information
            Frame frame = controller.Frame();

            // Get gestures
            // Only handles swipe gesture for now...
            GestureList gestures = frame.Gestures();
            for (int i = 0; i < gestures.Count; i++)
            {
                Gesture gesture = gestures[i];

                switch (gesture.Type)
                {
                    case Gesture.GestureType.TYPE_SWIPE:
                        SwipeGesture swipe = new SwipeGesture(gesture);
                        OnGesture("swipe", swipe.Id, swipe.State.ToString(), swipe.Position.ToFloatArray(), swipe.Direction.ToFloatArray());
                        break;
                    case Gesture.GestureType.TYPECIRCLE:
                        CircleGesture circle = new CircleGesture(gesture);
                        OnCircleGesture("circle", circle.Id, circle.State.ToString(), circle.Progress, circle.Normal, circle.Pointable);
                        break;
                }
            }
        }
Exemplo n.º 9
0
    void checkForGestures()
    {
        if (!leap_hand.IsLeft)
        {
            return;
        }

        Debug.Log(selectedObject);

        Frame frame = LEAPcontroller.Frame();

        GestureList gesturesInFrame = frame.Gestures();

        if (!gesturesInFrame.IsEmpty)
        {
            foreach (Gesture gesture in gesturesInFrame)
            {
                switch (gesture.Type)
                {
                //CIRCLE = GROW/SHRINK
                case Gesture.GestureType.TYPECIRCLE:
                    CircleGesture circleGesture = new CircleGesture(gesture);
                    float         turns         = circleGesture.Progress / 1000;

                    //grow if rotating clockwise
                    if (circleGesture.Pointable.Direction.AngleTo(circleGesture.Normal) <= Mathf.PI / 2)
                    {
                        if (targetScale <= 10.0f)
                        {
                            targetScale += turns;
                        }
                    }
                    else
                    {
                        if (targetScale >= 1.0f)
                        {
                            targetScale -= turns;
                        }
                    }

                    v3Scale = new Vector3(targetScale, targetScale, targetScale);
                    selectedObject.transform.localScale = Vector3.Lerp(selectedObject.transform.localScale, v3Scale, Time.deltaTime * shrinkSpeed);

                    break;

                case Gesture.GestureType.TYPESWIPE:
                    SwipeGesture swipe          = new SwipeGesture(gesture);
                    Vector       swipeDirection = swipe.Direction;
                    //left swipe
                    if (swipeDirection.x > 0)
                    {
                        Debug.Log("rightSwipe");
                        selectedObject.transform.GetComponent <MeshRenderer> ().material.color = previousColour;
                        selectedObject = null;
                    }
                    break;
                }
            }
        }
    }
Exemplo n.º 10
0
    // Update is called once per frame
    void Update()
    {
        curFrame = controller.Frame();

        Finger curFinger = curFrame.Fingers[0];
        Vector curFingerPos = curFinger.TipPosition;

        bool canMove = true;
        if( Mathf.Abs(curFingerPos.x - prevFingerPos.x) > 15 ) {
            canMove = false;
        }
        if( Mathf.Abs(curFingerPos.y - prevFingerPos.y) > 15 ) {
            canMove = false;
        }

        //Debug.Log (pointerFingerPosition.x + " " + prevPointerPosition.x + " " + canMove);

        if(canMove == true) {
            Vector3 pos = Camera.main.ScreenToWorldPoint( new Vector3( (curFingerPos.x + 35) * 10, (curFingerPos.y - 40) * 7, 10) );
            transform.position = pos;
        }
        if(curFrame.Gestures().Count > 0) {
            CircleGesture circleItem = new CircleGesture(curFrame.Gestures()[0]);
            Vector circlePos = new Vector( (circleItem.Center.x + 35) * 10, (circleItem.Center.y - 40) * 7, 10);
            Ray ray = Camera.main.ScreenPointToRay(new Vector3(circlePos.x, circlePos.y, 0)); // Ray from the camera to the mouse position
            Debug.DrawRay(Camera.main.ScreenToWorldPoint(new Vector3(circlePos.x, circlePos.y, 0)), Vector3.forward);
            RaycastHit hit; // Raycast Hit information
            if( Physics.Raycast(ray, out hit) ) { // If the raycast hits something
                hit.transform.gameObject.GetComponent<Rotate>().dropping = true;
            }
        }
        prevFingerPos = curFingerPos;
    }
Exemplo n.º 11
0
    // funzione per la rotazione tramite la circle gesture
    void PinchRotation()
    {
        string clockwiseness = null;

        if (LeftHand.IsValid && RightHand.IsValid)
        {
            GestureList gesture = frame.Gestures();

            for (int i = 0; i < gesture.Count; i++)
            {
                CircleGesture circle = new CircleGesture(gesture [i]);
                string        state  = circle.State.ToString();

                if (state.Equals("STATE_UPDATE"))
                {
                    if (circle.Pointable.Direction.AngleTo(circle.Normal) <= Math.PI / 2)
                    {
                        //clockwiseness
                        transform.Rotate(Vector3.up, Time.deltaTime * -90f, Space.World);
                    }

                    else
                    {
                        //clockwiseness
                        transform.Rotate(Vector3.up, Time.deltaTime * 90f, Space.World);
                    }
                }
            }
        }
    }
Exemplo n.º 12
0
 public void OnCircleGestureUpdate(CircleGesture g)
 {
     //Debug.Log("Circle Update " + g.Id);
     CircleGestureDisplay circle = circleGestures[g.Id];
     if (circle != null)
         circle.circleGesture = g;
 }
    private void handleScroll(Frame frame, CircleGesture circle)
    {
        int     speed       = scroll_speed;
        Boolean isClockwise = checkClockwise(circle);
        float   scroll_distance;

        LastCircleGesture newCircleGesture = new LastCircleGesture();

        newCircleGesture.circle      = circle;
        newCircleGesture.isClockwise = isClockwise;

        if (lastCircleGesture == null || isClockwise != lastCircleGesture.isClockwise || circle.Id != lastCircleGesture.circle.Id)
        {
            lastCircleGesture = newCircleGesture;
            return;
        }

        scroll_distance = getScrollDistance(frame, newCircleGesture);

        if (scroll_distance != 0)
        {
            if (circle.State != Leap.Gesture.GestureState.STATE_STOP)
            {
                mouse_event(MOUSEEVENTF_SCROLL, (uint)0, (uint)0, (uint)scroll_distance, (UIntPtr)0);
            }
        }

        lastCircleGesture = (circle.State == Leap.Gesture.GestureState.STATE_STOP) ? null : newCircleGesture;
    }
Exemplo n.º 14
0
 bool testCircle(CircleGesture circle)
 {
     if(circle.DurationSeconds >= 0.5f) {
         disp.circle(circle.DurationSeconds);
         return true;
     }
     return false;
 }
Exemplo n.º 15
0
 public void OnCircleGestureStop(CircleGesture g)
 {
     //Debug.LogError("Circle Stop " + g.Id);
     CircleGestureDisplay circle = circleGestures[g.Id];
     if (circle != null)
         circle.circleGesture = g;
     circleGestures.Remove (g.Id);
 }
Exemplo n.º 16
0
 // Circle Lifecycle Events
 public void OnCircleGestureStart(CircleGesture g)
 {
     //Debug.LogWarning("Circle Start " + g.Id);
     GameObject go = (GameObject) GameObject.Instantiate(circleGesturePrefab);
     CircleGestureDisplay circle = go.GetComponent<CircleGestureDisplay>();
     circle.circleGesture = g;
     circleGestures[g.Id] = circle;
 }
    void OnTriggerStay2D(Collider2D other)
    {
        Frame frame = controller.Frame ();
        Hand hand = frame.Hands [0];
        Hand otherHand = frame.Hands [1];
        Gesture gesture = frame.Gestures () [0];

        if (!images.Contains (image) && hand.PinchStrength + otherHand.PinchStrength > 0.7f && timer.ElapsedMilliseconds > 700) {
            print ("Selected: " + this.gameObject.name);
            print ("Added: " + this.gameObject.name);
            images.Add (image);
            this.gameObject.GetComponent<SpriteRenderer>().color = Color.cyan;
        }

        // Unselect images.
        if (gesture.Type == Gesture.GestureType.TYPEKEYTAP) {
            images.Clear ();
            this.gameObject.GetComponent<SpriteRenderer>().color = Color.white;
            timer.Reset ();
        }
        // Rotate images.
        else if (images.Contains (image) && gesture.Type == Gesture.GestureType.TYPECIRCLE) {
            CircleGesture circle = new CircleGesture (frame.Gestures () [0]);
            Vector centerPoint = circle.Center;
            Pointable circlePointable = circle.Pointable;

            if (circle.Pointable.Direction.AngleTo (circle.Normal) <= 3.1415 / 2) {
                image.transform.Rotate (Vector3.back, 45 * Time.deltaTime);
            } else {
                image.transform.Rotate (Vector3.forward, 45 * Time.deltaTime);
            }
        }
        // Order images.
        else if (images.Contains(image) && hand.PinchStrength > 0.7f)
        {
            Vector3 v = otherHand.Direction.ToUnity();
            print("Other hand: " + v);

            if(v.x > 0.0f)
            {
            }

            int depth = this.gameObject.GetComponent<SpriteRenderer>().sortingOrder;
            this.gameObject.GetComponent<SpriteRenderer>().sortingOrder = depth;
        }

        // If nothing is selected and cursor is hovering over an image start Zoom.
        if (images.Count == 0 && timer.ElapsedMilliseconds > 1500) {

            float z = hand.Fingers [0].TipPosition.z > enterZ ? 0.5f : -0.5f;

            // Limit zoom level.
            if (transform.localScale.x > 300 && z == -0.5f || transform.localScale.x < 50 && z == 0.5f)
                return;

            transform.localScale = new Vector2 (transform.localScale.x - z, transform.localScale.y - z);
        }
    }
Exemplo n.º 18
0
        protected override void SplitGesture(Gesture gesture)
        {
            var g = new CircleGesture(gesture);

            FCenterOut.Add(g.Center.ToVector3DPos());
            FNormalOut.Add(g.Normal.ToVector3DDir());
            FRadiusOut.Add(g.Radius * 0.001f);
            FProgressOut.Add(g.Progress);
        }
Exemplo n.º 19
0
    // Circle Lifecycle Events
    public void OnCircleGestureStart(CircleGesture g)
    {
        //Debug.LogWarning("Circle Start " + g.Id);
        GameObject           go     = (GameObject)GameObject.Instantiate(circleGesturePrefab);
        CircleGestureDisplay circle = go.GetComponent <CircleGestureDisplay>();

        circle.circleGesture = g;
        circleGestures[g.Id] = circle;
    }
Exemplo n.º 20
0
 bool testCircle(CircleGesture circle)
 {
     if (circle.DurationSeconds >= 0.5f)
     {
         disp.circle(circle.DurationSeconds);
         return(true);
     }
     return(false);
 }
	private void Update(){

		//Client code
		if (Network.player == owner ) {
			string id = networkView.viewID.ToString ();
			int networkID_ = -1; 
			int.TryParse (id.Replace ("AllocatedID: ", ""), out networkID_);		
			bool enable_ = ComboBox_scripts.newNetIDStatic [ComboBox_scripts.selectedItem_].Equals (networkID_);
			// Select only the gameObject from the combo box
			if (enable_) {
				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);
						if (circle.Pointable.Direction.AngleTo (circle.Normal) <= Mathf.PI / 2) {
							transform.localScale += new Vector3 (scale, scale, scale);
							networkView.RPC ("SendScale", RPCMode.Server, transform.lossyScale);
						} else {
							transform.localScale -= new Vector3 (scale, scale, scale);
						}
					}
					if (gesture.Type == Gesture.GestureType.TYPEKEYTAP) {
						zoom_ = !zoom_;
					}
				}
					// Verify if we can update the view
					if (Mathf.Abs (lastClientScale.x - transform.localScale.x) > variation
						&& Mathf.Abs (lastClientScale.y - transform.localScale.y) > variation
				    && Mathf.Abs (lastClientScale.z - transform.localScale.z) > variation ) {
						if (Network.isClient) {
							networkView.RPC ("SendScale", RPCMode.Server, transform.lossyScale);
							lastClientScale = transform.lossyScale;
						}
					}
				
					if (Mathf.Abs (lastClientScale.x - updateVector.x) > variation
						&& Mathf.Abs (lastClientScale.y - updateVector.y) > variation
						&& Mathf.Abs (lastClientScale.z - updateVector.z) > variation) {
						if (Network.isClient) {
							string msg = "has done a Scaling on object. Variation : " + transform.localScale.ToString () + ".\nAt : " + System.DateTime.Now;
							GameObject.Find ("logTransform").gameObject.networkView.RPC ("ApplyGlobalLogText", RPCMode.AllBuffered, GUILogTransform_scripts.playerName, msg);
							updateVector = lastClientScale;
						}
					}
			}
		}
		//Server movement code
		if (Network.isServer) {//To also enable this on the client itself, use: "|| Network.player==owner){|"
			//Actually move the player using his/her input
			transform.localScale = serverCurrentScale;
		}


	}
Exemplo n.º 22
0
    public void OnCircleGestureUpdate(CircleGesture g)
    {
        //Debug.Log("Circle Update " + g.Id);
        CircleGestureDisplay circle = circleGestures[g.Id];

        if (circle != null)
        {
            circle.circleGesture = g;
        }
    }
Exemplo n.º 23
0
        public static VyroGesture CreateFromLeapGesture(CircleGesture gesture)
        {
            var c = new VyroGestureCircle {
                Gesture = gesture
            };

            c._Radius.Initialize(Convert.ToInt64(c.Gesture.Radius));
            c.IsClockwise = (c.Gesture.Pointable.Direction.AngleTo(c.Gesture.Normal) <= Math.PI / 4);
            return(c);
        }
Exemplo n.º 24
0
    void Update()
    {
        if (!MyNetworkLobbyManager.s_singleton.IsTutorial)
        {
            if (!isLocalPlayer)
            {
                return;
            }
            if (GetComponent <GameEndDirector>().IsStart)
            {
                return;
            }
        }

        foreach (var hand in hand_controller_.GetFrame().Hands)
        {
            if (!hand.IsLeft)
            {
                continue;
            }

            var gesture_list = hand.Frame.Gestures();

            foreach (Gesture gesture in gesture_list)
            {
                var magic_type = player_magic_manager_.MagicType;
                if (magic_type == -1)
                {
                    break;
                }
                var circle_gesture = new CircleGesture(gesture);

                if (circle_gesture.IsValid)
                {
                    if (!hand.IsLeft)
                    {
                        continue;
                    }
                    if (gesture.DurationSeconds < TURN_SECOND)
                    {
                        continue;
                    }
                    if (!player_magic_manager_.MagicExecute())
                    {
                        continue;
                    }
                    magic_action_list_[magic_type]();

                    AudioManager.Instance.PlaySe(11);
                    break;
                }
            }
            break;
        }
    }
Exemplo n.º 25
0
    public void OnCircleGestureStop(CircleGesture g)
    {
        //Debug.LogError("Circle Stop " + g.Id);
        CircleGestureDisplay circle = circleGestures[g.Id];

        if (circle != null)
        {
            circle.circleGesture = g;
        }
        circleGestures.Remove(g.Id);
    }
 private Boolean checkClockwise(CircleGesture circle)
 {
     if (circle.Pointable.Direction.AngleTo(circle.Normal) <= Math.PI / 2)
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
Exemplo n.º 27
0
        public void OnFrame(Frame frame)
        {
            if (!_ActiveHand.Update(frame))
            {
                _IsGrabbed = false;
                if (!frame.Hands.IsEmpty)
                    _ActiveHand.Initialize(frame.Hands.Leftmost);
            }

            if (!_ActiveHand.IsFinalized)
                _LogAction(_ActiveHand.Dump());

            // Do nothing if the hand is not yet stabilized
            if (!_ActiveHand.IsStabilized)
                return;

            // We have the same Hand as in the past and we're still grabbed.
            if (_IsGrabbed)
            {
                if (_ActiveHand.CurrentHand.Fingers.Count >= 3)
                {
                    _IsGrabbed = false;
                }
                else
                {
                    var startY = _ActiveHand.StabilizedHand.StabilizedPalmPosition.y;
                    var y = _ActiveHand.CurrentHand.StabilizedPalmPosition.y;
                    //_LogAction(String.Format("Hand {0} now at {1:0.0} was grabbed at {2:0.0}.", _ActiveHand.Id, y, startY));
                    if (y < startY - 15)
                        for (var i = 0; i < Math.Floor((startY - y) / 20); i++)
                            Native.ScrollActiveWindow(false);
                    else if (y > startY + 15)
                        for (var i = 0; i < Math.Floor((y - startY) / 20); i++)
                            Native.ScrollActiveWindow(true);
                }
            }
            else if (_ActiveHand.CurrentHand.Fingers.Count < 2)
            {
                _IsGrabbed = true;
            }

            foreach (var g in frame.Gestures().Where(g => g.Type == Gesture.GestureType.TYPECIRCLE))
            {
                var circle = new CircleGesture(g);

                var isClockwise = (circle.Pointable.Direction.AngleTo(circle.Normal) <= Math.PI / 4);

                if (circle.Progress < _Progress || circle.Progress > _Progress + 1)
                {
                    Native.ScrollActiveWindow(!isClockwise);
                    _Progress = Convert.ToInt32(Math.Floor(circle.Progress));
                }
            }
        }
Exemplo n.º 28
0
    //Gesture Event for Circle
    void Circle(Gesture gesture)
    {
        CircleGesture circleGesture = new CircleGesture(gesture);
        print("Circle");

        // TODO : Circle (SHJO)
        if (circleGesture.Pointable.Direction.AngleTo(circleGesture.Normal) <= Math.PI / 2) // Clockwise
        {
        }
        else
        {
        }
    }
Exemplo n.º 29
0
    //Gesture Event for Circle
    void Circle(Gesture gesture)
    {
        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));
        }
    }
Exemplo n.º 30
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;
                }

            }
        }
    }
    // Update is called once per frame
    void Update()
    {
        foreach (Gesture g in LeapInputEx.Controller.Frame().Gestures())
        {
            if (g.Type == Gesture.GestureType.TYPECIRCLE)
            {
                CircleGesture cgesture = new CircleGesture(g);

                if (cgesture.Progress >= 2)
                {
                    count = 0;
                    ResetLine();

                    int x = 1;
                }
            }
        }
    }
Exemplo n.º 33
0
        internal void ProcessCircle(CircleGesture circle)
        {
            if (circle.State == Gesture.GestureState.STATESTART && _visibleHands > 1)
            {
                _currentlyTracking     = true;
                _currentlyTrackingType = circle.Type;
                _lastGestureEvent      = DateTime.Now;

                #if DEBUG
                SendDebugMessage(string.Format("Circle Start (normX:{0} normY:{1} fing:{2} tool:{3})", circle.Normal.x, circle.Normal.y, _visibleFingers, _visibleTools));
                #endif
            }
            else if (circle.State == Gesture.GestureState.STATEUPDATE && _visibleHands > 1 && _currentlyTracking && _currentlyTrackingType == circle.Type)
            {
                if (circle.Pointable.Direction.AngleTo(circle.Normal) <= (Math.PI / 4))
                {
                    if (OnCircleClockwise != null)
                    {
                        OnCircleClockwise();
                    }
                }
                else
                {
                    if (OnCircleCounterclockwise != null)
                    {
                        OnCircleCounterclockwise();
                    }
                }

                _lastGestureEvent = DateTime.Now;

                #if DEBUG
                SendDebugMessage(string.Format("Circle Update (dir:{0} fing:{1} tool:{2})", circle.Pointable.Direction.AngleTo(circle.Normal) <= (Math.PI / 4) ? "clockwise" : "counterclockwise", _visibleFingers, _visibleTools));
                #endif
            }
            else if (circle.State == Gesture.GestureState.STATESTOP && _currentlyTracking && _currentlyTrackingType == circle.Type)
            {
                _currentlyTracking = false;

                #if DEBUG
                SendDebugMessage(string.Format("Circle Stop (normX:{0} normY:{1} fing:{2} tool:{3})", circle.Normal.x, circle.Normal.y, _visibleFingers, _visibleTools));
                #endif
            }
        }
Exemplo n.º 34
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.º 35
0
    public override void OnFrame(Controller controller)
    {
        // Get the most recent frame and report some basic information
        Frame frame = controller.Frame();


        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;

            if (hand.Fingers[1].IsExtended)
            {
                Debug.WriteLine("�L�тĂ�");
            }
        }

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


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

        if (!frame.Hands.IsEmpty || !frame.Gestures().IsEmpty)
        {
            SafeWriteLine("");
        }
    }
Exemplo n.º 36
0
 // Update is called once per frame
 void Update()
 {
     Frame frame = controller.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);
             Object wood;
             if (circle.Pointable.Direction.AngleTo (circle.Normal) <= 3.14 / 2) {
                 //Clockwise if angle is less than 90 degrees
                 wood = Object.Instantiate (woodTypeA, new Vector3(0, 10, -3), new Quaternion ());
                 ((GameObject) wood).GetComponent<Rigidbody>().isKinematic = false;
     //					GameObject instance = Instantiate(Resources.Load("Assets/Sphere", typeof(GameObject))) as GameObject;
     //					instance.transform.position = new Vector3(0, 10, -3);
             } else {
                 wood = Object.Instantiate (woodTypeB, new Vector3(0, 10, -3), new Quaternion ());
                 ((GameObject) wood).GetComponent<Rigidbody>().isKinematic = false;
     //					GameObject instance = Instantiate(Resources.Load("Assets/Cube", typeof(GameObject))) as GameObject;
     //					instance.transform.position = new Vector3(0, 10, -3);
             }
             break;
         case Gesture.GestureType.TYPE_SWIPE:
     //				SwipeGesture swipe = new SwipeGesture (gesture);
     //				Object cube = Object.Instantiate(GameObject.Find("Cube"), new Vector3(0, 10, -3), new Quaternion());
             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:
             Debug.Log ("  Unknown gesture type.");
             break;
         }
     }
 }
Exemplo n.º 37
0
    void GestureUpdate()
    {
        is_attack_ = false;
        if (!MyNetworkLobbyManager.s_singleton.IsTutorial)
        {
            CmdTellServerAttack(false);
        }
        foreach (var hand in hand_controller_.GetFrame().Hands)
        {
            if (!hand.IsRight)
            {
                continue;
            }
            var gesture_list = hand.Frame.Gestures();

            foreach (Gesture gesture in gesture_list)
            {
                var circle_gesture = new CircleGesture(gesture);

                if (circle_gesture.IsValid)
                {
                    if (circle_gesture.DurationSeconds < TURN_SECOND)
                    {
                        return;
                    }
                    CmdTellServerAttack(true);
                    is_attack_ = true;
                    var apple_num = tubo_in_destory_.GetApumonCount();
                    var lemon_num = tubo_in_destory_.GetLemonCount();
                    CmdTellServerFruitNum(
                        apple_num,
                        lemon_num);
                    apple_num_ = apple_num;
                    lemon_num_ = lemon_num;
                    break;
                }
            }
        }
    }
Exemplo n.º 38
0
        protected override VyroGestureState UpdateGestureImpl(Frame frame)
        {
            Gesture = new CircleGesture(frame.Gesture(Gesture.Id));

            switch (Gesture.State)
            {
                case Leap.Gesture.GestureState.STATEINVALID:
                    return VyroGestureState.Invalid;
                case Leap.Gesture.GestureState.STATESTOP:
                    return VyroGestureState.ContinuousComplete;
                case Leap.Gesture.GestureState.STATEUPDATE:
                    _Radius.Update(Convert.ToInt64(Gesture.Radius), frame);
                    if (Gesture.Progress > (Progress + 1.0))
                    {
                        Progress = Convert.ToInt32(Math.Floor(Gesture.Progress));
                        return VyroGestureState.IterationComplete;
                    }
                    return VyroGestureState.Progressing;
                default:
                    return VyroGestureState.Progressing;
            }
        }
Exemplo n.º 39
0
    // Update is called once per frame
    void Update()
    {
        curFrame = controller.Frame();

        Finger curFinger    = curFrame.Fingers[0];
        Vector curFingerPos = curFinger.TipPosition;

        bool canMove = true;

        if (Mathf.Abs(curFingerPos.x - prevFingerPos.x) > 15)
        {
            canMove = false;
        }
        if (Mathf.Abs(curFingerPos.y - prevFingerPos.y) > 15)
        {
            canMove = false;
        }

        //Debug.Log (pointerFingerPosition.x + " " + prevPointerPosition.x + " " + canMove);

        if (canMove == true)
        {
            Vector3 pos = Camera.main.ScreenToWorldPoint(new Vector3((curFingerPos.x + 35) * 10, (curFingerPos.y - 40) * 7, 10));
            transform.position = pos;
        }
        if (curFrame.Gestures().Count > 0)
        {
            CircleGesture circleItem = new CircleGesture(curFrame.Gestures()[0]);
            Vector        circlePos  = new Vector((circleItem.Center.x + 35) * 10, (circleItem.Center.y - 40) * 7, 10);
            Ray           ray        = Camera.main.ScreenPointToRay(new Vector3(circlePos.x, circlePos.y, 0)); // Ray from the camera to the mouse position
            Debug.DrawRay(Camera.main.ScreenToWorldPoint(new Vector3(circlePos.x, circlePos.y, 0)), Vector3.forward);
            RaycastHit hit;                                                                                    // Raycast Hit information
            if (Physics.Raycast(ray, out hit))                                                                 // If the raycast hits something
            {
                hit.transform.gameObject.GetComponent <Rotate>().dropping = true;
            }
        }
        prevFingerPos = curFingerPos;
    }
Exemplo n.º 40
0
    void Update()
    {
        if (this.tag == "Wound")
        {
            foreach (Gesture g in LeapInputEx.Controller.Frame().Gestures())
            {
                if (g.Type == Gesture.GestureType.TYPECIRCLE)
                {
                    CircleGesture cgesture = new CircleGesture(g);

                    if (cgesture.Progress >= 2)
                    {
                        GameObject bandage = GameObject.Find("Bandage Parent");
                        bandage.GetComponentInChildren <MeshRenderer>().enabled = false;

                        GameObject wound = GameObject.Find("Decals Wound/Decals Mesh Renderer");
                        wound.GetComponentInChildren <MeshRenderer>().enabled = true;
                        woundFixed = false;
                    }
                }
            }
        }
    }
Exemplo n.º 41
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.º 42
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("");
        }
    }
        private AcceptedGestures Rotate(Frame frame)
        {
            GestureList gestures = frame.Gestures();

            if (gestures.Count > 0) {
                foreach (Gesture gesture in gestures) {
                    if (gesture.Type == Gesture.GestureType.TYPECIRCLE && gesture.State == Gesture.GestureState.STATESTOP) {
                        CircleGesture circle = new CircleGesture(gesture);
                        if (circle.Pointable.Direction.AngleTo(circle.Normal) <= Math.PI / 4 && circle.Progress > 0.80) {
                            Log("Gesture: Clockwise Rotation");
                            gestureType = AcceptedGestures.RotateClockwise;
                            return gestureType;
                        }
                        else if (circle.Progress > 0.80)
                        {
                            Log("Gesture: Anti-Clockwise Rotation");
                            gestureType = AcceptedGestures.RotateAntiClockwise;
                            return gestureType;
                        }
                    }
                }
            }
            return AcceptedGestures.InvalidGesture;
        }
Exemplo n.º 44
0
	void Update()
    {
        // Find all the tools in the scene
        ToolModel[] tools = GameObject.FindObjectsOfType<ToolModel>();
        foreach (ToolModel tool in tools)
        {
            // Find center x position of the wand (Tip position minus half length in wand direction)
            float wandcenteroffset = tool.GetLeapTool().TipPosition.z - (tool.GetLeapTool().Direction.z * tool.GetLeapTool().Length / 2);

            // Decide which player's wand this is
            int player = 0;
            if (wandcenteroffset > CenterOffset) // Player 2 (array 1)
            {
                player = 1;
            }
            Player_Tool[player] = tool;
            {
                float difference = tool.GetLeapTool().TipPosition.y - Player_Tool_LastY[player];
                if (difference < -20)
                {
                    //print(difference);
                    Player_Cast[player] = true;
                }
            }
            Player_Tool_LastY[player] = tool.GetLeapTool().TipPosition.y;
        }

        // Ensure the editor has LeapController set
        if (LeapController)
        {
            // Get the actual Leap controller, with useful data
            Controller controller = LeapController.leap_controller_;
            if (controller.IsConnected)
            {
                // Get the status of the Leap Motion this frame
                Frame frame = controller.Frame();
                if (frame.IsValid)
                {
                    // Find any gestures in this frame
                    GestureList gestures = frame.Gestures();
                    foreach (Gesture gesture in gestures)
                    {
                        // Gesture exists
                        if (gesture.IsValid)
                        {
                            // Gesture type recognition
                            if (gesture.Type == Gesture.GestureType.TYPE_CIRCLE) // Circle
                            {
                                CircleGesture circlegesture = new CircleGesture(gesture);
                            }
                            else if (gesture.Type == Gesture.GestureType.TYPE_SWIPE) // Swipe, line
                            {
                                SwipeGesture swipegesture = new SwipeGesture(gesture);
                                if (Mathf.Abs(swipegesture.Direction.y) > 0.3f) // Moving up and down
                                {
                                    if (Mathf.Abs(swipegesture.Direction.x) < 0.8f) // Not moving much left and right
                                    {
                                        // TODO: Add error handle/checks
                                        float wandcenteroffset = swipegesture.StartPosition.z;
                                        if (wandcenteroffset < CenterOffset)
                                        {
                                            //Player_Cast[0] = true;
                                        }
                                        else if (wandcenteroffset > CenterOffset)
                                        {
                                            //Player_Cast[1] = true;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
Exemplo n.º 45
0
    // Update is called once per frame
    void Update()
    {
        Frame frame = controller.Frame();

        for (int g = 0; g < frame.Gestures().Count; g++)
        {
            Gesture gesture = frame.Gestures()[g];
            switch (gesture.Type)
            {
            case Gesture.GestureType.TYPE_CIRCLE:
                CircleGesture circleGesture = new CircleGesture(gesture);

                if (circleGesture.Progress >= 1.0f)
                {
                    if (!IsIdInOldGesturesOrAdd(circleGesture.Id))
                    {
                        //Debug.Log ("CIRCLE: " + circleGesture.Id.ToString());
                    }
                }

                //Handle circle gestures
                break;

            case Gesture.GestureType.TYPE_SWIPE:
                SwipeGesture swipeGesture = new SwipeGesture(gesture);

                if (gesture.State == Gesture.GestureState.STATE_UPDATE && swipeGesture.Duration > durationDetectionThreshold)
                {
                    if (!IsIdInOldGesturesOrAdd(swipeGesture.Id))
                    {
                        Vector direction = swipeGesture.Direction;

                        if (direction.z > directionDetectionThreshold)
                        {
                            GameController.Instance.OnGestureSwipe(Direction.Pull);
                        }
                        else if (direction.z < -directionDetectionThreshold)
                        {
                            GameController.Instance.OnGestureSwipe(Direction.Push);
                        }
                        else if (direction.x > directionDetectionThreshold)
                        {
                            GameController.Instance.OnGestureSwipe(Direction.ToRight);
                        }
                        else if (direction.x < -directionDetectionThreshold)
                        {
                            GameController.Instance.OnGestureSwipe(Direction.ToLeft);
                        }
                    }
                }

                // Handle swipe gestures
                break;
            }
        }

        if (frame.Hands.Count == 2)
        {
            Hand h1 = frame.Hands[0];
            Hand h2 = frame.Hands[1];

            const float downVectorYThreshold = -0.75f;
            float       normalYSum           = h1.PalmNormal.y + h2.PalmNormal.y;
            if (normalYSum < downVectorYThreshold * 2)
            {
                GameController.Instance.OnGestureHelp();
            }
        }
    }
Exemplo n.º 46
0
        /// <summary>
        /// performs pre actions before calling callback function
        /// </summary>
        /// <param name="gesture">Circle gesture</param>
        private void PreCircle(Gesture gesture)
        {
            CircleGesture circle = new CircleGesture(gesture);

            if (!_activeGesture)
            {
                _activeGesture = true;
            }

            Boolean clockwise = circle.Pointable.Direction.AngleTo(circle.Normal) <= Math.PI / 2 ? true : false;

            if (_onCircle != null) _onCircle(clockwise);
        }
Exemplo n.º 47
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;
                }
            }
        }
    private void Update()
    {
        //Client code
        if (Network.player == owner)
        {
            string id         = networkView.viewID.ToString();
            int    networkID_ = -1;
            int.TryParse(id.Replace("AllocatedID: ", ""), out networkID_);
            bool enable_ = ComboBox_scripts.newNetIDStatic [ComboBox_scripts.selectedItem_].Equals(networkID_);
            // Select only the gameObject from the combo box
            if (enable_)
            {
                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);
                        if (circle.Pointable.Direction.AngleTo(circle.Normal) <= Mathf.PI / 2)
                        {
                            transform.localScale += new Vector3(scale, scale, scale);
                            networkView.RPC("SendScale", RPCMode.Server, transform.lossyScale);
                        }
                        else
                        {
                            transform.localScale -= new Vector3(scale, scale, scale);
                        }
                    }
                    if (gesture.Type == Gesture.GestureType.TYPEKEYTAP)
                    {
                        zoom_ = !zoom_;
                    }
                }
                // Verify if we can update the view
                if (Mathf.Abs(lastClientScale.x - transform.localScale.x) > variation &&
                    Mathf.Abs(lastClientScale.y - transform.localScale.y) > variation &&
                    Mathf.Abs(lastClientScale.z - transform.localScale.z) > variation)
                {
                    if (Network.isClient)
                    {
                        networkView.RPC("SendScale", RPCMode.Server, transform.lossyScale);
                        lastClientScale = transform.lossyScale;
                    }
                }

                if (Mathf.Abs(lastClientScale.x - updateVector.x) > variation &&
                    Mathf.Abs(lastClientScale.y - updateVector.y) > variation &&
                    Mathf.Abs(lastClientScale.z - updateVector.z) > variation)
                {
                    if (Network.isClient)
                    {
                        string msg = "has done a Scaling on object. Variation : " + transform.localScale.ToString() + ".\nAt : " + System.DateTime.Now;
                        GameObject.Find("logTransform").gameObject.networkView.RPC("ApplyGlobalLogText", RPCMode.AllBuffered, GUILogTransform_scripts.playerName, msg);
                        updateVector = lastClientScale;
                    }
                }
            }
        }
        //Server movement code
        if (Network.isServer)          //To also enable this on the client itself, use: "|| Network.player==owner){|"
        //Actually move the player using his/her input
        {
            transform.localScale = serverCurrentScale;
        }
    }
Exemplo n.º 49
0
        public void OnFrame(Frame frame)
        {
            if (!_ActiveHand.Update(frame))
            {
                _IsGrabbed = false;
                if (!frame.Hands.IsEmpty)
                {
                    _ActiveHand.Initialize(frame.Hands.Leftmost);
                }
            }

            if (!_ActiveHand.IsFinalized)
            {
                _LogAction(_ActiveHand.Dump());
            }

            // Do nothing if the hand is not yet stabilized
            if (!_ActiveHand.IsStabilized)
            {
                return;
            }

            // We have the same Hand as in the past and we're still grabbed.
            if (_IsGrabbed)
            {
                if (_ActiveHand.CurrentHand.Fingers.Count >= 3)
                {
                    _IsGrabbed = false;
                }
                else
                {
                    var startY = _ActiveHand.StabilizedHand.StabilizedPalmPosition.y;
                    var y      = _ActiveHand.CurrentHand.StabilizedPalmPosition.y;
                    //_LogAction(String.Format("Hand {0} now at {1:0.0} was grabbed at {2:0.0}.", _ActiveHand.Id, y, startY));
                    if (y < startY - 15)
                    {
                        for (var i = 0; i < Math.Floor((startY - y) / 20); i++)
                        {
                            Native.ScrollActiveWindow(false);
                        }
                    }
                    else if (y > startY + 15)
                    {
                        for (var i = 0; i < Math.Floor((y - startY) / 20); i++)
                        {
                            Native.ScrollActiveWindow(true);
                        }
                    }
                }
            }
            else if (_ActiveHand.CurrentHand.Fingers.Count < 2)
            {
                _IsGrabbed = true;
            }

            foreach (var g in frame.Gestures().Where(g => g.Type == Gesture.GestureType.TYPECIRCLE))
            {
                var circle = new CircleGesture(g);

                var isClockwise = (circle.Pointable.Direction.AngleTo(circle.Normal) <= Math.PI / 4);

                if (circle.Progress < _Progress || circle.Progress > _Progress + 1)
                {
                    Native.ScrollActiveWindow(!isClockwise);
                    _Progress = Convert.ToInt32(Math.Floor(circle.Progress));
                }
            }
        }
Exemplo n.º 50
0
        private void HandleCircleGestureForTurnables(Gesture gesture)
        {
            if (!ActionEnabled()) return;

            //Reset Timer
            _resetTimer.ResetCounter();

            var circle = new CircleGesture(gesture);

            //No mini circles
            if (circle.Radius < CircleRadiusIgnoreLimit) return;

            //Only with two hands - we are in action mode ;)
            if (gesture.Frame.Hands.Count < 2) return;

            //Just Stop and Update events allowed
            if (gesture.State == Gesture.GestureState.STATESTART || gesture.State == Gesture.GestureState.STATEINVALID)
                return;

            var circleCenter = circle.Center.ToUnityScaled();

            //calc the direction of the circle
            var clockwise = (circle.Pointable.Direction.AngleTo(circle.Normal) <= Math.PI/2);

            //For all registered turnables wich are in the right position
            foreach (
                var turnable in
                    turnables.Select(x => x.GetComponent(typeof (ITurnable)))
                        .Where(x => x != null)
                        .Cast<ITurnable>()
                        .Where(turnable => turnable.InRange(circleCenter)))
            {
                //Turn =)
                if (clockwise) turnable.TurnClockwise();
                else turnable.TurnCounterClockwise();
            }
        }
Exemplo n.º 51
0
        private void HandleCircleGestureForViewChange(Gesture gesture)
        {
            //Reset Timer
            _resetTimer.ResetCounter();

            var circle = new CircleGesture(gesture);

            //Just one hand - we handle view mode
            if (circle.Frame.Hands.Count > 1) return;

            //if (circle.Radius < CircleRadiusChangeViewLimit) return;

            //Just stop events
            if (gesture.State != Gesture.GestureState.STATESTOP) return;

            //Get the needed components
            var mondrianContainer = GameObject.Find("MondrianContainer");
            var camComponent = Camera.main.GetComponent<LeapCamControl>();
            var mondrianComponent = mondrianContainer.GetComponent<LeapObjectControl>();

            //Run only once at time
            if (_runCamChange) return;

            //Are we in view or in action mode?
            if (!ActionEnabled())
            {
                //Back to action mode
                camComponent.enabled = false;
                mondrianComponent.enabled = true;

                //Reset Cam position
                StartCoroutine(MoveCamToOriginPosition(_originCamPosition, mondrianComponent.transform.position, 1));
            }
            else
            {
                //Lets go into view mode
                camComponent.enabled = true;
                mondrianComponent.enabled = false;

                //Move cam a little up to signal view mode
                StartCoroutine(MoveCamToOriginPosition(new Vector3(_originCamPosition.x, _originCamPosition.y + 2, _originCamPosition.z), mondrianComponent.transform.position, 1));
            }
        }
Exemplo n.º 52
0
 void GestureUpdate()
 {
     var gesture_list = leap_controller_.Frame().Gestures();
       if (gesture_list[0].IsValid)
       {
       CircleGesture gesture = new CircleGesture(gesture_list[0]);
       if (gesture.Progress < turn_num_) return;
       if (gesture.State != Gesture.GestureState.STATE_STOP) return;
       is_attack_ = true;
       Debug.Log("OK");
       }
       else
       {
       is_attack_ = false;
       }
 }
Exemplo n.º 53
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.º 54
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.º 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);

		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.º 56
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.º 57
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.º 58
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.º 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 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;
            }
        }