示例#1
0
 //-------------------------------------------------------------------------
 void OnSwipe(SwipeGesture gesture)
 {
     if (onFingerFingerSwipe != null)
     {
         onFingerFingerSwipe(gesture.Direction, gesture.StartPosition, gesture.StartPosition + gesture.Move);
     }
 }
示例#2
0
    void Update()
    {
        Controller controller = handController.GetLeapController ();
        GestureList gestureList = controller.Frame ().Gestures ();
        if(gestureList.Count > 0){
            for(int i = 0; i < gestureList.Count; i++){
                Gesture gesture = gestureList[i];
                if (gesture.Type == Gesture.GestureType.TYPESWIPE){// Gesture.GestureType.TYPESWIPE) {
                    Debug.Log("Swipe");
                    SwipeGesture swipe = new SwipeGesture(gesture);
                    bool isHorizontal = Mathf.Abs(swipe.Direction.x) > Mathf.Abs(swipe.Direction.y);
                    //swipe.Position
                    //start Position choose object
                    ///average swipe.Position and startPosition, closest object

                    if(isHorizontal){
                        Debug.Log("horizontal");
                        Application.LoadLevel("StartScene");
                    }
                    else{
                        if(swipe.Direction.y > 0){
                            //up
                        }
                        else{
                            //down
                        }
                    }
                }
            }
        }
    }
 //-------------------------------------------------------------------------
 void OnSwipe(SwipeGesture gesture)
 {
     if (onFingerFingerSwipe != null)
     {
         onFingerFingerSwipe(gesture.Direction, gesture.StartPosition, gesture.StartPosition + gesture.Move);
     }
 }
示例#4
0
    void Start()
    {
        Application.targetFrameRate = 60;
        GRoot.inst.SetContentScaleFactor(1136, 640);
        Stage.inst.onKeyDown.Add(OnKeyDown);

        UIPackage.AddPackage("UI/Gesture");

        _mainView = UIPackage.CreateObject("Gesture", "Main").asCom;
        _mainView.SetSize(GRoot.inst.width, GRoot.inst.height);
        _mainView.AddRelation(GRoot.inst, RelationType.Size);
        GRoot.inst.AddChild(_mainView);

        GObject holder = _mainView.GetChild("holder");

        _ball = GameObject.Find("Globe").transform;

        SwipeGesture gesture1 = new SwipeGesture(holder);

        gesture1.onMove.Add(OnSwipeMove);
        gesture1.onEnd.Add(OnSwipeEnd);

        LongPressGesture gesture2 = new LongPressGesture(holder);

        gesture2.once = false;
        gesture2.onAction.Add(OnHold);

        PinchGesture gesture3 = new PinchGesture(holder);

        gesture3.onAction.Add(OnPinch);

        RotationGesture gesture4 = new RotationGesture(holder);

        gesture4.onAction.Add(OnRotate);
    }
示例#5
0
 private void OnSwipeBegin(EventContext context)
 {
     if (EnableSwipe)
     {
         SwipeGesture gesture = (SwipeGesture)context.sender;
     }
 }
示例#6
0
    private void EvaluateSwipe(SwipeGesture currentGesture, SwipeGesture inverseGesture)
    {
        if (swipeGesture == currentGesture)
        {
            if (!isLocked)
            {
                isSlided = true;
            }
            animator.SetTrigger("Slide");
        }
        if (!isLocked && LockGesture == currentGesture)
        {
            isLocked = true;
            animator.SetBool("Lock", true);
        }
        if (isLocked && LockGesture == inverseGesture)
        {
            isLocked = false;
            animator.SetBool("Lock", false);
        }

        Closed = isSlided && isLocked && !ColorBallTriggered;
        if (!Closed)
        {
            SoundController.Instance.CloseWindow.Play();
        }
    }
示例#7
0
    void OnSwipe(SwipeGesture gesture)
    {
        //Debug.Log("swipe:::" + gesture.Direction + "," + gesture.Move + "," + gesture.Velocity);

        if (_state == State.FAT)
        {
            //var heading = GetSwipeDirectionVector(gesture.Direction);

            var heading = Vector3.Normalize(gesture.Move);
            rigidbody2D.AddForce(heading * moveForce / 15);

            //var heading = Vector3.Normalize(gesture.Move);
            //var direction = Vector3.Lerp(transform.forward, heading, Time.deltaTime * 4);
            //transform.LookAt(direction);
            //rigidbody2D.AddForce(heading * moveForce / 15);

            // transform.rotation = Quaternion.LookRotation(new Vector3(0,0,heading.z));
        }
        else
        {
            if (gesture.Direction == FingerGestures.SwipeDirection.Down)
            {
                ChangeState("down");
            }
            else if (gesture.Direction == FingerGestures.SwipeDirection.Up)
            {
                ChangeState("up");
            }
        }
    }
示例#8
0
    /// <summary>
    /// 获取触摸移动方向的方法
    /// </summary>
    /// <param name="gesture"></param>
    public void OnSwipe(SwipeGesture gesture)

    {
        // 完整的滑动数据

        Vector2 move = gesture.Move;

        // 滑动的速度

        float velocity = gesture.Velocity;

        // 大概的滑动方向

        FingerGestures.SwipeDirection direction = gesture.Direction;



        if (direction.ToString() == "Left")
        {
            Audiomanagement.B_Click_Audio_Source("Turn_over_aBook");
            print(direction.ToString());
            autoFlip.FlipRightPage();
        }
        else
        {
            Audiomanagement.B_Click_Audio_Source("Turn_over_aBook");
            print(direction.ToString());

            autoFlip.FlipLeftPage();
        }
    }
示例#9
0
    Vector3 CheckSwipeDirection(SwipeGesture gesture)
    {
        var isHorizontal = Mathf.Abs(gesture.Direction.x) > Mathf.Abs(gesture.Direction.y);

        if(isHorizontal)
        {
            if (gesture.Direction.x > 0)
            {
                return Vector3.right;
            }
            else
            {
                return Vector3.left;
            }
        }
        else
        {
            if(gesture.Direction.y > 0)
            {
                return Vector3.up;
            }
            else
            {
                return Vector3.down;
            }
        }
    }
    // Update is called once per frame
    void Update()
    {
        Frame frame = controller.Frame();//the latest data from the current frame of leap motion device
        GestureList gestures = frame.Gestures();//return the list of gestures
        for ( int i = 0; i <gestures.Count; i++)//for each gesture in the list
        {
            Gesture gesture = new Gesture();
            gesture = gestures[i];

            //swipe gesture
            if(gesture.Type == Gesture.GestureType.TYPE_SWIPE)
            {
                SwipeGesture swipe = new SwipeGesture(gesture);
                Vector swipeDirection = swipe.Direction;
                if(swipeDirection.x < 0)
                {
                    Debug.Log("Left");
                }
                else if (swipeDirection.x > 0)
                {
                    Debug.Log("Right");
                }
            }

        }
    }
示例#11
0
    public void OnSwipe(SwipeGesture swipeData)
    {
        if (mMoveSerrureNo < 0)
        {
            return;
        }

        if (swipeData.Direction == FingerGestures.SwipeDirection.Up)
        {
            mCode[mMoveSerrureNo] = (++mCode[mMoveSerrureNo]) % 10;
            setRouletteCode(mMoveSerrureNo, mCode[mMoveSerrureNo]);
        }
        else if (swipeData.Direction == FingerGestures.SwipeDirection.Down)
        {
            mCode[mMoveSerrureNo] = (--mCode[mMoveSerrureNo]) % 10;
            mCode[mMoveSerrureNo] = mCode[mMoveSerrureNo] < 0 ? mCode[mMoveSerrureNo] + 10 : mCode[mMoveSerrureNo];
            setRouletteCode(mMoveSerrureNo, mCode[mMoveSerrureNo]);
        }

        if (controlCode())            // Correct code fund.

        {
            Debug.Log("Code fund.");
            if (unlockedTarget != null)
            {
                unlockedTarget.SendMessage(unlockFctName, SendMessageOptions.DontRequireReceiver);
            }
        }
    }
示例#12
0
    // message sent by SwipeRecognizer
    void OnSwipe( SwipeGesture gesture )
    {
        if( constrained )
        {
            switch( gesture.Direction )
            {
                case FingerGestures.SwipeDirection.Up:
                    emitter.EmitUp();
                    break;

                case FingerGestures.SwipeDirection.Right:
                    emitter.EmitRight();
                    break;

                case FingerGestures.SwipeDirection.Down:
                    emitter.EmitDown();
                    break;

                case FingerGestures.SwipeDirection.Left:
                    emitter.EmitLeft();
                    break;

                default:
                    return;
            }
        }
        else
        {
            Vector3 emitDir = new Vector3( gesture.Move.x, gesture.Move.y, 0 );
            emitter.Emit( emitDir ); 
        }
    }
示例#13
0
    public void OnSwipe( SwipeGesture swipeData )
    {
        if( mMoveSerrureNo < 0 )
            return;

        if( swipeData.Direction == FingerGestures.SwipeDirection.Up ) {

            mCode[mMoveSerrureNo] = ( ++mCode[mMoveSerrureNo] ) % 10;
            setRouletteCode( mMoveSerrureNo, mCode[mMoveSerrureNo] );

        }
        else if( swipeData.Direction == FingerGestures.SwipeDirection.Down ) {

            mCode[mMoveSerrureNo] = ( --mCode[mMoveSerrureNo] ) % 10;
            mCode[mMoveSerrureNo] = mCode[mMoveSerrureNo] < 0 ? mCode[mMoveSerrureNo]+10 : mCode[mMoveSerrureNo];
            setRouletteCode( mMoveSerrureNo, mCode[mMoveSerrureNo] );
        }

        if( controlCode() ) { // Correct code fund.

            Debug.Log( "Code fund." );
            if( unlockedTarget != null )
                unlockedTarget.SendMessage( unlockFctName, SendMessageOptions.DontRequireReceiver );
        }
    }
示例#14
0
    void OnSwipe(SwipeGesture gesture)
    {
        searchType = SearchPathType.SwipeToWalk;
        swipeIndexList.Clear();
        swipeIndexListRaw.Clear();

        foreach (Vector2 item in gesture.VectorsInProgress)
        {
            Vector3 bgPos = CameraHelper.ScreenPosToBackgroundPos(item);
            int     index = m_pathGrid.GetCellIndexClamped(bgPos);
            if (m_pathGrid.IsBlocked(index))
            {
                continue;
            }

            if (swipeIndexListRaw.Count == 0)
            {
                swipeIndexListRaw.Add(index);
                continue;
            }

            if (swipeIndexListRaw[swipeIndexListRaw.Count - 1] != index)
            {
                swipeIndexListRaw.Add(index);
            }
        }

        swipeIndexList = m_pathGrid.CornerIndexs(swipeIndexListRaw);

        swipeIndexListIndex = 0;
        m_navigationAgent.MoveToIndex(swipeIndexList.ToArray());
    }
示例#15
0
    /// <summary>
    /// 离开时做一个惯性动画
    /// </summary>
    /// <param name="context"></param>
    void OnSwipeEnd(EventContext context)
    {
        SwipeGesture gesture = (SwipeGesture)context.sender;
        Vector3      v       = new Vector3();

        if (Mathf.Abs(gesture.velocity.x) > Mathf.Abs(gesture.velocity.y))
        {
            //手指离开时,左右旋转时的加速度
            v.y = -Mathf.Round(Mathf.Sign(gesture.velocity.x) * Mathf.Sqrt(Mathf.Abs(gesture.velocity.x)));
            if (Mathf.Abs(v.y) < 2)
            {
                return;
            }
        }
        else
        {
            v.x = -Mathf.Round(Mathf.Sign(gesture.velocity.y) * Mathf.Sqrt(Mathf.Abs(gesture.velocity.y)));
            if (Mathf.Abs(v.x) < 2)
            {
                return;
            }
        }
        //做一个TO数值过度从V->0经过0.3秒  ,设置目标对象是地球, 每帧调用 lambda表达式传入一个GTweener对象
        //差值旋转
        GTween.To(v, Vector3.zero, 0.3f).SetTarget(_ball).OnUpdate(
            (GTweener tweener) =>
        {
            _ball.Rotate(tweener.deltaValue.vec3, Space.World);
        });
    }
示例#16
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;
                }
            }
        }
示例#17
0
    public void OnSwipe(SwipeGesture gesture)
    {
        Debug.Log("===> 轻扫!" + " move:" + gesture.Move + " dir:" + gesture.Direction + " v:" + gesture.Velocity);

        if (gesture.Direction == FingerGestures.SwipeDirection.Right || gesture.Direction == FingerGestures.SwipeDirection.LowerRightDiagonal || gesture.Direction == FingerGestures.SwipeDirection.UpperRightDiagonal)
        {
            var guidepanelpos = GuidePanel.GetComponent <ScrollRect>().normalizedPosition;
            var d             = (int)(guidepanelpos.x / 0.5f);
            nor = new Vector2(d == 0 ? 0 : d - 0.5f, 0.5f);
            if (guidepanelpos.x >= 0)
            {
                can = true;
            }
            else
            {
                can = false;
            }
        }
        else if (gesture.Direction == FingerGestures.SwipeDirection.Left || gesture.Direction == FingerGestures.SwipeDirection.LowerLeftDiagonal || gesture.Direction == FingerGestures.SwipeDirection.UpperLeftDiagonal)
        {
            var guidepanelpos = GuidePanel.GetComponent <ScrollRect>().normalizedPosition;
            var d             = (int)(guidepanelpos.x / 0.5f);
            nor = new Vector2(d == 2 ? 1 : (d + 0.5f) > 1 ? 1 : (d + 0.5f), 0.5f);
            if (guidepanelpos.x == 1)
            {
                can = false;
                t   = 0;
                loadNextScene("2");
            }
            else
            {
                can = true;
            }
        }
    }
示例#18
0
        public override void OnFrame(Controller leapController)
        {
            Frame currentFrame = leapController.Frame();

            if (handsLastFrame == 0 && currentFrame.Hands.Count > 0 && LeapRegisterFingers != null)
                LeapRegisterFingers(true);
            else if (handsLastFrame > 0 && currentFrame.Hands.Count == 0 && LeapRegisterFingers != null)
                LeapRegisterFingers(false);
            handsLastFrame = currentFrame.Hands.Count;

            if (currentFrame.Hands.Count > 0 &&
                currentFrame.Hands[0].Fingers.Count > 0 &&
                LeapSwipe != null)
            {
                GestureList gestures = currentFrame.Gestures();
                foreach (Gesture gesture in gestures)
                {
                    SwipeGesture swipe = new SwipeGesture(gesture);
                    if (Math.Abs(swipe.Direction.x) > Math.Abs(swipe.Direction.y)) // Horizontal swipe
                    {
                        if (swipe.Direction.x > 0)
                            LeapSwipe(SwipeDirection.Right);
                        else
                            LeapSwipe(SwipeDirection.Left);
                    }
                    else // Vertical swipe
                    {
                        if (swipe.Direction.y > 0)
                            LeapSwipe(SwipeDirection.Up);
                        else
                            LeapSwipe(SwipeDirection.Down);
                    }
                }
            }
        }
示例#19
0
 void OnSwipe(SwipeGesture gesture)
 {
     if (OnSwipeEvent != null)
     {
         OnSwipeEvent(gesture);
     }
 }
示例#20
0
        private void OnSwipe(SwipeGesture gesture)
        {
            if (_currentScrollField == null)
            {
                return;
            }

            RaycastHit hit;

            if (!Physics.Raycast(Camera.main.ScreenPointToRay(gesture.StartPosition), out hit))
            {
                return;
            }

            var touchedScroll = _currentScrollField.ScrollList.Find(x => x.tag.Equals(hit.transform.tag));

            if (touchedScroll == null)
            {
                return;
            }

            if (gesture.Direction == FingerGestures.SwipeDirection.Up)
            {
                touchedScroll.ScrollUp(gesture.Velocity);
            }
            if (gesture.Direction == FingerGestures.SwipeDirection.Down)
            {
                touchedScroll.ScrollDown(gesture.Velocity);
            }
        }
示例#21
0
    void Start()
    {
        _mainView = this.GetComponent <UIPanel>().ui;
        GObject holder = _mainView.GetChild("holder");

        _ball = GameObject.Find("Globe").transform;

        SwipeGesture gesture1 = new SwipeGesture(holder);

        gesture1.onMove.Add(OnSwipeMove);
        gesture1.onEnd.Add(OnSwipeEnd);

        LongPressGesture gesture2 = new LongPressGesture(holder);

        gesture2.once = false;
        gesture2.onAction.Add(OnHold);

        PinchGesture gesture3 = new PinchGesture(holder);

        gesture3.onAction.Add(OnPinch);

        RotationGesture gesture4 = new RotationGesture(holder);

        gesture4.onAction.Add(OnRotate);
    }
示例#22
0
    /// <summary>
    /// Processes the leap input.
    /// </summary>
    public override void processLeapInput()
    {
        // Gets current frame Data
        Frame currentFrame = LeapInput.Frame;

        if (currentFrame.IsValid)
        {
            // Gets current list of gestures
            GestureList leapGestures = currentFrame.Gestures();

            // Iterates trhough all the gestures found in the current frame
            foreach (Gesture gesture in leapGestures)
            {
                SwipeGesture swipeGesture = new SwipeGesture(gesture);

                switch (swipeGesture.State)
                {
                case SwipeGesture.GestureState.STATESTART:
                    storeInitialSwipeValues(swipeGesture);
                    break;

                case SwipeGesture.GestureState.STATESTOP:
                    storeFinalSwipeValues(swipeGesture);
                    processSwipeGesture();
                    break;
                }
            }
        }
    }
示例#23
0
    // Use this for initialization
    void Start()
    {
        GRoot.inst.SetContentScaleFactor(410, 700);
        UIPackage.AddPackage("UI/2048_pkg");
        GComponent mainpanel = UIPackage.CreateObject("2048_pkg", "mainpanel").asCom;

        GRoot.inst.AddChild(mainpanel);



        //for (int i = 0; i < gameLines * gameLines; i++)
        //{
        //    _blocks[i] = _mainView.GetChild("l" + (i + 1).ToString());  //获取contianers l1 ~ l16
        //                                                                // Debug.Log("Block_Name: "+_blocks[i].name);
        //}


        GObject holder = mainpanel.GetChild("Control");
        // Debug.Log("holder: "+holder.id);
        SwipeGesture gesture1 = new SwipeGesture(holder);

        //Debug.Log("swipeleft");
        gesture1.onMove.Add(OnSwipeMove);
        //gesture1.onEnd.Add(OnSwipeEnd);

        mainpanel.onClick.Add(() => { print("onclick"); });
    }
 void Update()
 {
     Frame frame = controller.Frame();
     GestureList gesturelist = frame.Gestures();
     //for dictating which hand
     Hand whichHand = frame.Hands.Frontmost;
     if (whichHand.IsRight)
     {
         for (int i = 0; i < gesturelist.Count; i++)
         {
             Gesture gesture = gesturelist[i];
             if (gesture.Type == Gesture.GestureType.TYPESWIPE)
             {
                 SwipeGesture swipe = new SwipeGesture(gesture);
                 Vector swipeDirection = swipe.Direction;
                 if (swipeDirection.x < 0)
                 {
                     Debug.Log("Left");
                     whatToSpin.transform.Rotate(Vector3.up, spinAngle * Time.deltaTime);
                 }
                 if (swipeDirection.x > 0)
                 {
                     Debug.Log("Right");
                     whatToSpin.transform.Rotate(Vector3.up, -spinAngle * Time.deltaTime);
                 }
             }
         }
     }
 }
示例#25
0
    void OnSwipeEnd(EventContext context)
    {
        SwipeGesture gesture = (SwipeGesture)context.sender;
        Vector3      v       = new Vector3();

        if (Mathf.Abs(gesture.velocity.x) > Mathf.Abs(gesture.velocity.y))
        {
            v.y = -Mathf.Round(Mathf.Sign(gesture.velocity.x) * Mathf.Sqrt(Mathf.Abs(gesture.velocity.x)));
            if (Mathf.Abs(v.y) < 2)
            {
                return;
            }
        }
        else
        {
            v.x = -Mathf.Round(Mathf.Sign(gesture.velocity.y) * Mathf.Sqrt(Mathf.Abs(gesture.velocity.y)));
            if (Mathf.Abs(v.x) < 2)
            {
                return;
            }
        }

        GTween.To(v, Vector3.zero, 0.3f).SetTarget(_ball).OnUpdate(
            (GTweener tweener) =>
        {
            _ball.Rotate(tweener.deltaValue.vec3, Space.World);
        });
    }
示例#26
0
    void Start()
    {
        Inst = this;
        GameEntry.Event.Subscribe(EvtDataUpdated.EventId, OnEvtDataUpdated);
        GameEntry.Event.Subscribe(EvtTempDataUpdated.EventId, OnEvtTempDataUpdated);
        GameEntry.Event.Subscribe(EvtEventTriggered.EventId, OnEvtEventTriggered);
        GameEntry.Event.Subscribe(EvtZooBusinessTriggered.EventId, OnEvtZooBusinessTriggered);
        GameEntry.Event.Subscribe(EvtDataReseted.EventId, OnEvtDataReseted);

        GObject holder = m_GesturePanel.ui.GetChild("holder");

        holder.onClick.Add(OnClick);

        for (int i = 0; i < m_BtnUnlockAreas.Length; i++)
        {
            UIPanel btnPanel = m_BtnUnlockAreas[i];
            btnPanel.ui.data = i + 1;
            btnPanel.ui.onClick.Set(OnClickUnlockArea);
        }

        LongPressGesture      = new LongPressGesture(holder);
        LongPressGesture.once = false;
        LongPressGesture.onAction.Add(OnLongPress);

        SwipeGesture = new SwipeGesture(holder);
        SwipeGesture.onBegin.Add(OnSwipeBegin);
        SwipeGesture.onMove.Add(OnSwipeMove);
        SwipeGesture.onEnd.Add(OnSwipeEnd);

        PinchGesture = new PinchGesture(holder);
        PinchGesture.onAction.Add(OnPinch);

        RotationGesture = new RotationGesture(holder);
        RotationGesture.onAction.Add(OnRotate);
    }
    public override void DealSwipe(SwipeGesture guesture)
    {
        // TODO change the algorithm of top collider computation
        flower.Blow(guesture.Move.normalized, guesture.Velocity * Global.Pixel2Unit);

        UpdateColliderPosition();
    }
    // Update is called once per frame
    void Update()
    {
        Ray   ray;
        Frame frame = controller.Frame();

        fingerCount = frame.Fingers.Count;
        Debug.Log(fingerCount);
        GestureList gestures = frame.Gestures();

        for (int i = 0; i < gestures.Count; i++)
        {
            Gesture gesture = gestures[i];
            if (gesture.Type == Gesture.GestureType.TYPESWIPE)
            {
                SwipeGesture swipe          = new SwipeGesture(gesture);
                Vector       swipeDirection = swipe.Direction;
                if (swipeDirection.y < 0)
                {
                    Debug.Log("Down Gesture");
                    buttons.SetActive(true);
                    iTween.MoveTo(buttons, iTween.Hash("path", iTweenPath.GetPath("mainMenu"), "time", 1f, "easetype", "easeInCubic"
                                                       ));
                }
                else if (swipeDirection.y > 0)
                {
                    Debug.Log("Up Gesture");
                    buttons.SetActive(false);
                }
            }
        }
    }
示例#29
0
    // message sent by SwipeRecognizer
    void OnSwipe(SwipeGesture gesture)
    {
        if (constrained)
        {
            switch (gesture.Direction)
            {
            case FingerGestures.SwipeDirection.Up:
                emitter.EmitUp();
                break;

            case FingerGestures.SwipeDirection.Right:
                emitter.EmitRight();
                break;

            case FingerGestures.SwipeDirection.Down:
                emitter.EmitDown();
                break;

            case FingerGestures.SwipeDirection.Left:
                emitter.EmitLeft();
                break;

            default:
                return;
            }
        }
        else
        {
            Vector3 emitDir = new Vector3(gesture.Move.x, gesture.Move.y, 0);
            emitter.Emit(emitDir);
        }
    }
        public override void OnFrame(Controller controller)
        {
            var frame = controller.Frame();

            foreach (var g in frame.Gestures())
            {
                if (g.Type == Gesture.GestureType.TYPESWIPE && g.State == Gesture.GestureState.STATESTOP)
                {
                    var swipe = new SwipeGesture(g);

                    Vector start   = swipe.StartPosition;
                    Vector current = swipe.Position;

                    var delta = start.x - current.x;

                    if (Math.Abs(delta) >= Sensitivity)
                    {
                        var direction = delta < 0 ? SwipeDirection.Right : SwipeDirection.Left;
                        if (null != OnSwipe)
                        {
                            OnSwipe(this, new SwipeEventArgs(direction));
                        }
                    }
                }
            }
        }
示例#31
0
    void CheckCustomGestures()
    {
        GestureList gestures = controller.GetCustomGestures();

        for (int i = 0; i < gestures.Count; i++)
        {
            Gesture gesture = gestures[i];
            switch (gesture.Type)
            {
            case Gesture.GestureType.TYPESCREENTAP:
                MoveFoward();
                break;

            case Gesture.GestureType.TYPEKEYTAP:
                KeyTapGesture keyTapGesture = new KeyTapGesture(gesture);
                Vector3       vector        = keyTapGesture.Position.ToUnityScaled();
                hudScript.PressButton(controller.transform.TransformPoint(vector));
                break;

            case Gesture.GestureType.TYPESWIPE:
                SwipeGesture swipeGesture = new SwipeGesture(gesture);
                Rotate90(swipeGesture.Direction.x);
                break;

            default:
                break;
            }
        }
    }
示例#32
0
    void TutorialUpdate()
    {
        if (!is_tutroial_)
        {
            return;
        }
        foreach (var hand in hand_controller_.GetFrame().Hands)
        {
            foreach (var gesture in hand.Frame.Gestures())
            {
                if (!hand.IsLeft)
                {
                    continue;
                }
                var swipe_gesture = new SwipeGesture(gesture);
                if (swipe_gesture.IsValid)
                {
                    is_tutroial_ = false;

                    FindObjectOfType <SlideDirector>().FinishSlide();
                    GameObject.Destroy(GameObject.Find("TutorialRoot(Clone)"));
                    GameObject.Destroy(GameObject.Find("UI_Prefab(Clone)"));
                    valid_count_ = 0;
                }
            }
        }
        if (Input.GetKeyDown(KeyCode.D))
        {
            is_tutroial_ = false;

            FindObjectOfType <SlideDirector>().FinishSlide();
            GameObject.Destroy(GameObject.Find("TutorialRoot(Clone)"));
            GameObject.Destroy(GameObject.Find("UI_Prefab(Clone)"));
        }
    }
示例#33
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;
                }
            }
        }
    }
        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;
                }
            }
        }
 void OnSwipeTopBar(SwipeGesture gesture)
 {
     if (gesture.StartSelection == this.gameObject && gesture.Direction == FingerGestures.SwipeDirection.Down)
     {
         Debug.Log("Bringin Down Menu");
     }
 }
示例#36
0
        protected void DetectLeapGesture(Controller leap, Leap.Frame frame)
        {
            GestureList gestures = frame.Gestures();

            foreach (Gesture gesture in gestures)
            {
                if (gesture.State != Gesture.GestureState.STATESTOP)
                {
                    continue;
                }

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

                    if (swipe.StartPosition.x < 0 && swipe.Direction.x > 0)
                    {
                        TurnSlide(-1);
                    }
                    else if (swipe.StartPosition.x > 0 && swipe.Direction.x < 0)
                    {
                        TurnSlide(+1);
                    }
                    break;

                default: break;
                }
            }
        }
        /// <summary>
        /// Backs the swipe.
        /// </summary>
        void OnSwipe(SwipeGesture gesture)
        {
            if (gesture.Selection)
            {
                if (gesture.Direction == FingerGestures.SwipeDirection.Right)
                {
                    if (MypageEventManager.Instance != null)
                    {
                        if (_isProfileChangeState == true)
                        {
                            MypageEventManager.Instance.PanelPopupAnimate(PopupSecondSelectPanel.Instance.gameObject);

                            PopupSecondSelectPanel.Instance.PopClean();
                            PopupSecondSelectPanel.Instance.PopMessageInsert(
                                LocalMsgConst.PROFILE_CHANGE_ANNOUNCE,
                                LocalMsgConst.YES,
                                LocalMsgConst.NO,
                                SaveEvent,
                                SaveCancelEvent
                                );
                            _isProfileChangeState = false;
                            return;
                        }
                    }

                    if (MypageEventManager.Instance != null)
                    {
                        MypageEventManager.Instance.ProfileChangeClose(this.gameObject);
                    }
                }
            }
        }
    // 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;
                }
            }
        }
    }
示例#39
0
    /// <summary>
    /// 移动中触发的事件
    /// </summary>
    /// <param name="context"></param>
    void OnSwipeMove(EventContext context)
    {
        //事件的分发者
        SwipeGesture gesture = (SwipeGesture)context.sender;
        Vector3      v       = new Vector3();

        //X>Y表示的是向左或向右滑动
        if (Mathf.Abs(gesture.delta.x) > Mathf.Abs(gesture.delta.y))
        {
            //向左右滑动 就是地球绕Y轴旋转
            v.y = -Mathf.Round(gesture.delta.x);
            //消除手抖的影响 移动距离小于2则不响应
            if (Mathf.Abs(v.y) < 2)
            {
                return;
            }
        }
        //X<Y表示的是向上或者向下滑动
        else
        {
            //向上下滑动 就是地球绕X轴旋转
            v.x = -Mathf.Round(gesture.delta.y);
            if (Mathf.Abs(v.x) < 2)
            {
                return;
            }
        }
        //Space.World设定旋转本地坐标还是世界坐标
        _ball.Rotate(v, Space.World);
    }
 // Swipe Lifecycle Events
 public void OnSwipeGestureStart(SwipeGesture g)
 {
     //Debug.LogWarning("Circle Start " + g.Id);
     GameObject go = (GameObject) GameObject.Instantiate(swipeGesturePrefab);
     SwipeGestureDisplay swipe = go.GetComponent<SwipeGestureDisplay>();
     swipe.swipeGesture = g;
     swipeGestures[g.Id] = swipe;
 }
	public override void DealSwipe (SwipeGesture guesture)
	{

		// TODO change the algorithm of top collider computation
		flower.Blow( guesture.Move.normalized , guesture.Velocity * Global.Pixel2Unit );

		UpdateColliderPosition();
	}
    void DetectSwipe()
    {
        Frame frame = leapController.Frame ();
        GestureList gestures = frame.Gestures ();
        Gesture gesture;
        KeyTapGesture keyTapGesture;
        ScreenTapGesture screenTapGesture;
        SwipeGesture swipeGesture;

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

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

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

            break;
        }
    }
示例#43
0
 private bool IsRecognized(Frame frame)
 {
     GestureList gestures = frame.Gestures ();
     foreach (Gesture gesture in gestures) {
         if (gesture.Type == Gesture.GestureType.TYPESWIPE) {
             SwipeGesture swipeGesture = new SwipeGesture (gesture);
             return IsAcceptableDirection (swipeGesture.Direction);
         }
     }
     return false;
 }
	void OnSwipe( SwipeGesture gesture )
	{
		if( gesture.StartSelection && gesture.StartSelection.rigidbody )
		{
			Vector2 swipeMotion = gesture.Move;
			float speedScale = 2.0f;
			Vector3 force = new Vector3( speedScale * swipeMotion.x, 0, 0 );
			
			// apply the force on the physic object
			gesture.StartSelection.rigidbody.AddForce( force );
		}
	}
示例#45
0
	/// <summary>
	/// Listens for swipe gestures and takes the player's move
	/// </summary>
	/// <param name="gesture">Gesture.</param>
	void HandleOnGesture (SwipeGesture gesture)
	{

		if (gesture.Direction == FingerGestures.SwipeDirection.Left) {
			TakePlayerMove( GameController.Edge.Right );
		} else if (gesture.Direction == FingerGestures.SwipeDirection.Up) {
			TakePlayerMove( GameController.Edge.Bottom );
		} else if (gesture.Direction == FingerGestures.SwipeDirection.Right) {
			TakePlayerMove( GameController.Edge.Left );
		} else if (gesture.Direction == FingerGestures.SwipeDirection.Down) {
			TakePlayerMove( GameController.Edge.Top );
		}

	}
        public void OnSwipe(SwipeGesture gesture)
        {
            // Check if direction is valid.
            if (!this.IsValidDirection(gesture.Direction))
            {
                return;
            }

            // Forward event.
            if (this.Delegate != null)
            {
                this.Delegate.Invoke();
            }
        }
    // spin the yellow cube when swipping it
    void OnSwipe( SwipeGesture gesture )
    {
        // make sure we started the swipe gesture on our swipe object
        GameObject selection = gesture.StartSelection;  // we use the object the swipe started on, instead of the current one

        if( selection == swipeObject )
        {
            UI.StatusText = "Swiped " + gesture.Direction + " with finger " + gesture.Fingers[0] + " (velocity:" + gesture.Velocity + ", distance: " + gesture.Move.magnitude + " )";
            Debug.Log( UI.StatusText );

            SwipeParticlesEmitter emitter = selection.GetComponentInChildren<SwipeParticlesEmitter>();
            if( emitter )
                emitter.Emit( gesture.Direction, gesture.Velocity );
        }
    }
 private void OnSwipe(SwipeGesture sender)
 {
     switch(sender.LastDetectedSwipe)
     {
         case SwipeGesture.SwipeDirections.Up:
             if (_isBendToogle && _character.MovementController.CanBend())
                 _isBendToogle = false;//Get up, take stand position
             else
                 _isJumpTriggered = _character.MovementController.CanJump();
         break;
         case SwipeGesture.SwipeDirections.Down:
             if(_character.MovementController.CanBend())
                 _isBendToogle = sender.LastDetectedSwipe == SwipeGesture.SwipeDirections.Down;
         break;
     }
 }
示例#49
0
	//blow the patels when swipe
	void OnSwipe( SwipeGesture gesture )
    {
        // if (swipeTime <= 0 )
        //    return;
        // swipeTime = swipeTime - 1;
        
		// make sure we started the swipe gesture on our swipe object
		GameObject selection = gesture.StartSelection;  // we use the object the swipe started on, instead of the current one
        
		if (selection == null )
            return;
		SenseGuesture sense = selection.GetComponent<SenseGuesture>();

		if ( sense != null )
			sense.DealSwipe( gesture );

    }
示例#50
0
        protected override VyroGestureState UpdateGestureImpl(Frame frame)
        {
            Gesture = new SwipeGesture(frame.Gesture(Gesture.Id));

            switch (Gesture.State)
            {
                case Leap.Gesture.GestureState.STATEINVALID:
                    return VyroGestureState.Invalid;
                case Leap.Gesture.GestureState.STATESTOP:
                    return VyroGestureState.DiscreteComplete;
                case Leap.Gesture.GestureState.STATEUPDATE:
                    _Velocity.Update(Convert.ToInt64(Gesture.Speed), frame);
                    return VyroGestureState.Progressing;
                default:
                    return VyroGestureState.Progressing;
            }
        }
    // ジェスチャーを判定する
    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;
                }

            }
        }
    }
示例#52
0
        public override void OnFrame(Controller controller)
        {
            Frame frame = controller.Frame();

            foreach (Gesture gesture in frame.Gestures())
            {
                if (gesture.Type == KeyTapGesture.ClassType())
                {
                    Tap();
                }
                if (gesture.Type == SwipeGesture.ClassType())
                {
                    SwipeGesture swipeGesture = new SwipeGesture(gesture);
                    if (swipeGesture.Direction.x > 0) SwipeRight();
                    else SwipeLeft();
                }
            }
        }
示例#53
0
    void FixedUpdate()
    {
       
        HandList hands = controller.Frame().Hands;

        Frame frame = controller.Frame();
        gestures = frame.Gestures();
        

        foreach(Gesture gesture in gestures){
            if (gesture.Type == Gesture.GestureType.TYPE_SWIPE)
            {
                SwipeGesture swipe = new SwipeGesture(gesture);
                Vector swipeDirection = swipe.Direction;

                float swipe_dot = swipeDirection.Dot(Vector.Left);

                if (swipe_dot < -0.9)
                    rb.rotation *= Quaternion.AngleAxis(-6, Vector3.up);

                else if (swipe_dot > 0.9)
                    rb.rotation *= Quaternion.AngleAxis(6, Vector3.up);
            }
        }


        if (hands.Count != 0)
        {
            Transform camera_transform = Camera.main.transform;

            Vector3 direction = camera_transform.forward;
            if (hands.Count == 2)
            {
                direction *= 0;
            }

            direction.y = 0;
            direction.Normalize();
            direction.y = rb.velocity.y / speed;

            rb.velocity = direction * speed;

        }
    }
示例#54
0
    bool testGesture(SwipeGesture swipe)
    {
        float angle = swipe.Direction.AngleTo(Vector.Left);
        if(angle < 0.8) {
            print("left");
            disp.swipe(Direction.Left, swipe.Speed);
            return true;
        }

        angle = swipe.Direction.AngleTo(Vector.Right);
        if(angle < 0.8) {
            print("right");
            disp.swipe(Direction.Right, swipe.Speed);
            return true;
        }

        angle = swipe.Direction.AngleTo(Vector.Up);
        if(angle < 0.8) {
            print("up");
            disp.swipe(Direction.Up, swipe.Speed);
            return true;
        }
        angle = swipe.Direction.AngleTo(Vector.Down);
        if(angle < 0.8) {
            print("down");
            disp.swipe(Direction.Down, swipe.Speed);
            return true;
        }
        angle = swipe.Direction.AngleTo(Vector.Forward);
        if(angle < 0.8) {
            print("forward");
            disp.swipe(Direction.Forward, swipe.Speed);
            return true;
        }
        angle = swipe.Direction.AngleTo(Vector.Backward);
        if(angle < 0.8) {
            print("backward");
            disp.swipe(Direction.Backward, swipe.Speed);
            return true;
        }
        return false;
    }
示例#55
0
	void OnSwipe(SwipeGesture gesture) {
		if (gesture.Direction == FingerGestures.SwipeDirection.Up && GameController.GetInstance().PlayerIsTriggered == true) {
			//上机器人
			GameController.GetInstance().intoRobot = true;
			StartCoroutine (intoRobotState (1f/Time.frameCount));
		} else if (gesture.Direction == FingerGestures.SwipeDirection.Up && GameController.GetInstance().IsRobot == true && GameController.GetInstance().intoRobot == false) {
			//开始工作
			GameController.GetInstance().intoWork = true;
			StartCoroutine (intoWorkState (1f/Time.frameCount));
		} else if (gesture.Direction == FingerGestures.SwipeDirection.Down && GameController.GetInstance().IsRobot == true) {
			if (GameController.GetInstance().CurrentPlayerTrigger.GetComponent<RobotGameOver> ().isWork == true && GameController.GetInstance().intoWork == false) {
				//结束工作
				GameController.GetInstance().outWork = true;
				StartCoroutine (outWorkState (1f/Time.frameCount));
			}else if(GameController.GetInstance().CurrentPlayerTrigger.GetComponent<RobotGameOver> ().isWork == false){
				//下机器人
				GameController.GetInstance().outRobot = true;
				StartCoroutine(outRobotState(1f/Time.frameCount));
			}
		}
	}
示例#56
0
    // Update is called once per frame
    void Update()
    {
        frame = hc.GetFrame();

        foreach (Gesture gesture in frame.Gestures())
        {

            switch (gesture.Type)
            {
                case (Gesture.GestureType.TYPESCREENTAP):
                    {
                        audioSource.PlayOneShot(SFX_SELECT, SETTINGS.MASTER_VOLUME * SETTINGS.SFX_VOLUME);
                        StartCoroutine(PressSelectedButton());
                        break;
                    }
                case (Gesture.GestureType.TYPESWIPE):
                    {
                        swipe = new SwipeGesture(gesture);

                        if (!isSwiping && swipe.Direction.y > 0)
                        {
                            StartCoroutine(CycleUp(delay));
                        }

                        else if (!isSwiping && swipe.Direction.y < 0)
                        {
                            StartCoroutine(CycleDown(delay));
                        }

                        break;
                    }
                default:
                    {
                        break;
                    }
            }
        }
    }
    void OnSwipe( SwipeGesture gesture )
    {
        FingerGestures.SwipeDirection direction = gesture.Direction;

        if(direction == FingerGestures.SwipeDirection.Right)
        {
            timothy.SendMessage ("TimothyDash", SendMessageOptions.DontRequireReceiver);
        }
        else if(direction == FingerGestures.SwipeDirection.Left)
        {

        }
        else if(direction == FingerGestures.SwipeDirection.Up)
        {
            timothy.SendMessage ("TimothyJump", SendMessageOptions.DontRequireReceiver);
            //timothy.SendMessage("TimothyGoUp", SendMessageOptions.DontRequireReceiver);
        }
        else if(direction == FingerGestures.SwipeDirection.Down)
        {
            timothy.SendMessage("TimothySwipedDown", SendMessageOptions.DontRequireReceiver);
            //timothy.SendMessage("TimothyGoDown", SendMessageOptions.DontRequireReceiver);
        }
    }
示例#58
0
 // Update is called once per frame
 void Update()
 {
     if (cooldown > 0)
     {
         cooldown -= Time.deltaTime;
         if (state == RotationState.right)
             foreach (Transform child in transform)
                 child.RotateAround(Vector3.zero, Vector3.up, 288 * Time.deltaTime);
         else if (state == RotationState.left)
             foreach (Transform child in transform)
                 child.RotateAround(Vector3.zero, Vector3.up, -288 * Time.deltaTime);
     }
     else
     {
         state = RotationState.stay;
         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.TYPESWIPE)
             {
                 SwipeGesture swipe = new SwipeGesture(gesture);
                 Vector dir = swipe.Direction;
                 if (dir.y < -Mathf.Abs(dir.x) && !Selection.inSelection)
                     Selection.Select();
                 else if (dir.y > Mathf.Abs(dir.x))
                     Selection.Unselect();
                 else if (dir.x < 0 && !Selection.inSelection)
                     state = RotationState.right;
                 else if (!Selection.inSelection)
                     state = RotationState.left;
                 cooldown = 15 * Time.deltaTime;
             }
         }
     }
 }
示例#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;
                }
            }
        }
示例#60
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("");
            }
        }