Esempio n. 1
0
    private void TapGestures()
    {
        GestureList gestures = controller.GetCustomGestures();

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

            foreach (Button button in buttons)
            {
                Vector3[]     corners   = new Vector3 [4];
                RectTransform rectTrans = button.gameObject.GetComponent <RectTransform>();
                rectTrans.GetWorldCorners(corners);
                if (ContainInWorld(corners, vect))
                {
                    button.onClick.Invoke();
                }
            }
        }
    }
Esempio n. 2
0
        private void ProcessKeyTap(KeyTapGesture tap)
        {
            if (_visibleFingers != TapFingersRequired)
            {
                #if DEBUG
                SendDebugMessage("Key Tap -- invalid finger count: " + _visibleFingers);
                #endif

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

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

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

            _lastGestureEvent = DateTime.Now;
        }
Esempio n. 3
0
    void objectOperationWithLeapMotion()
    {
        Frame frame = controller.Frame();

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

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

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

                default:
                    break;
                }
            }
        }
    }
Esempio n. 4
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;
            }
        }
    }
 /*-------------------------------------------------------------------------
  * Leap Gesture Events
  * ----------------------------------------------------------------------*/
 // Key Tap Event
 public void OnKeyTapGesture(KeyTapGesture g)
 {
     GameObject go = (GameObject) GameObject.Instantiate(keyTapGesturePrefab);
     KeyTapGestureDisplay keyTap = go.GetComponent<KeyTapGestureDisplay>();
     keyTap.gesture = g;
     //Debug.Log("OnKeyTapGesture " + g.Id);
 }
Esempio n. 6
0
    void objectOperationWithLeapMotion()
    {
        Frame frame = controller.Frame();
        FingerCount = frame.Fingers.Count;
        GestureList gestures = frame.Gestures();
        InteractionBox interactionBox = frame.InteractionBox;
        if(frame.Fingers[0].IsValid){
            for(int n=0; n<gestures.Count; n++){

                Gesture gesture =gestures[n];
                Debug.Log(gesture.Type);
                switch(gesture.Type){
                    case Gesture.GestureType.TYPEKEYTAP:
                        KeyTapGesture keytapGesture = new KeyTapGesture(gesture);
                            Debug.Log("KeyTap");
                    break;
                    case Gesture.GestureType.TYPESCREENTAP:
                        ScreenTapGesture screenTapGesture = new ScreenTapGesture(gesture);
                        Debug.Log("ScreenTap");
                    break;
                    default:
                    break;
                }
          		}
        }
    }
Esempio n. 7
0
    /*-------------------------------------------------------------------------
     * Leap Gesture Events
     * ----------------------------------------------------------------------*/

    // Key Tap Event
    public void OnKeyTapGesture(KeyTapGesture g)
    {
        GameObject           go     = (GameObject)GameObject.Instantiate(keyTapGesturePrefab);
        KeyTapGestureDisplay keyTap = go.GetComponent <KeyTapGestureDisplay>();

        keyTap.gesture = g;
        //Debug.Log("OnKeyTapGesture " + g.Id);
    }
Esempio n. 8
0
        protected override void SplitGesture(Gesture gesture)
        {
            var g = new KeyTapGesture(gesture);

            FDirectinOut.Add(g.Direction.ToVector3DDir());
            FPositionOut.Add(g.Position.ToVector3DPos());
            FProgressOut.Add(g.Progress);
        }
    private void handleTap(Frame frame, KeyTapGesture tap)
    {
        if (!sendingKey)
        {
            SendKeys.SendWait("{DOWN}");
        }

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

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

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

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

            break;
        }
    }
 public override void Start()
 {
     if (gesture == null || gesture.Type != Gesture.GestureType.TYPEKEYTAP)
         Destroy (this);
     else
     {
         keyTapGesture = new KeyTapGesture(gesture);
         transform.position = keyTapGesture.Position.ToUnityTranslated();
     }
 }
Esempio n. 12
0
 void processKeyTaps(KeyTapGesture gesture)
 {
     Debug.Log(System.String.Format("Key tap dirn {0}", gesture));
     Vector pos = gesture.Position.Normalized;
     Debug.Log(System.String.Format("Pos: {0}", pos.ToString()));
     float dist = Vector3.Distance(buttonPos, new Vector3(pos.x, pos.y, pos.z));
     Debug.Log(System.String.Format("Distance: {0}", dist));
     if (dist <= epsilon + 0.05F)
     {
         addObject();
     }
 }
Esempio n. 13
0
 public override void Start()
 {
     if (gesture == null || gesture.Type != Gesture.GestureType.TYPEKEYTAP)
     {
         Destroy(this);
     }
     else
     {
         keyTapGesture      = new KeyTapGesture(gesture);
         transform.position = keyTapGesture.Position.ToUnityTranslated();
     }
 }
Esempio n. 14
0
    void processKeyTaps(KeyTapGesture gesture)
    {
        Debug.Log(System.String.Format("Key tap dirn {0}", gesture));
        Vector pos = gesture.Position.Normalized;

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

        Debug.Log(System.String.Format("Distance: {0}", dist));
        if (dist <= epsilon + 0.05F)
        {
            addObject();
        }
    }
Esempio n. 15
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];
            if(gesture.Type == Gesture.GestureType.TYPE_CIRCLE){
                KeyTapGesture key = new KeyTapGesture(gesture);

                    //do barrel roll
                    player.transform.Rotate(Vector3.forward, 10);
                    print("circle");

            }
            if(gesture.Type == Gesture.GestureType.TYPE_KEY_TAP){
                KeyTapGesture key = new KeyTapGesture(gesture);

                //do barrel roll
                //player.transform.Rotate(Vector3.forward, 10);
                print("keytap");

            }
            if(gesture.Type == Gesture.GestureType.TYPE_SCREEN_TAP){
                KeyTapGesture key = new KeyTapGesture(gesture);

                //do barrel roll
                //player.transform.Rotate(Vector3.forward, 10);
                print("screen");

            }
            if(gesture.Type == Gesture.GestureType.TYPE_SWIPE){
                KeyTapGesture key = new KeyTapGesture(gesture);

                //do barrel roll
                //player.transform.Rotate(Vector3.forward, 10);
                print("swipe");

            }
            if(gesture.Type == Gesture.GestureType.TYPE_INVALID){
                KeyTapGesture key = new KeyTapGesture(gesture);

                //do barrel roll
                //player.transform.Rotate(Vector3.forward, 10);
                print("invalid");

            }

        }
    }
Esempio n. 16
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;
                }

            }
        }
    }
Esempio n. 18
0
 // Update is called once per frame
 void Update()
 {
     Frame frame = controller.Frame();
     GestureList gestures = frame.Gestures();
     foreach (Gesture gesture in gestures)
     {
         if (gesture.Type == Gesture.GestureType.TYPE_SCREEN_TAP)
         {
             ScreenTapGesture screentapGesture = new ScreenTapGesture(gesture);
             processScreenTaps(screentapGesture);
         }
         else if (gesture.Type == Gesture.GestureType.TYPE_KEY_TAP)
         {
             KeyTapGesture keyTapGesture = new KeyTapGesture(gesture);
             processKeyTaps(keyTapGesture);
         }
     }
 }
 // Update is called once per frame
 void Update()
 {
     Frame frame = controller.Frame();
     GestureList gestures = frame.Gestures();
     for(int i=0; i<gestures.Count; i++)
         if(gestures[i].Type == Gesture.GestureType.TYPE_KEY_TAP)
         {
             //Do some stuff
             KeyTapGesture key_tap = new KeyTapGesture(gestures[i]);
             Vector3 pos = key_tap.Position.ToUnityScaled();
             float x = pos.x;
             float y = pos.y;
             float z = pos.z;
             print("LM Coordinates: (" + key_tap.Position.x + ", " + key_tap.Position.y + ", " + key_tap.Position.z + ")");
             print("Unity coordinates: (" + x + ", " + y + ", " + z + ")");
             //Vector3 scaledPos = pos *
         }
 }
Esempio n. 20
0
    // Update is called once per frame
    void Update()
    {
        Frame       frame    = controller.Frame();
        GestureList gestures = frame.Gestures();

        foreach (Gesture gesture in gestures)
        {
            if (gesture.Type == Gesture.GestureType.TYPE_SCREEN_TAP)
            {
                ScreenTapGesture screentapGesture = new ScreenTapGesture(gesture);
                processScreenTaps(screentapGesture);
            }
            else if (gesture.Type == Gesture.GestureType.TYPE_KEY_TAP)
            {
                KeyTapGesture keyTapGesture = new KeyTapGesture(gesture);
                processKeyTaps(keyTapGesture);
            }
        }
    }
    public override void OnFrame(Controller controller)
    {
        GestureList gestures = controller.Frame().Gestures();

        if (!gestures.IsEmpty)
        {
            SwipeGesture gesture = new SwipeGesture(gestures[0]);
            if (gesture.State == Gesture.GestureState.STATE_STOP && gesture.IsValid)
            {
                Vector3 direction = new Vector3(gesture.Direction.x, gesture.Direction.y, gesture.Direction.z);
                myLeapController.ShouldSwipe(direction);
            }

            KeyTapGesture tap = new KeyTapGesture(gestures[0]);
            if (tap.State == Gesture.GestureState.STATE_STOP && tap.IsValid)
            {
                myLeapController.Tap(tap);
            }
        }
    }
    public virtual void CheckGesture()
    {
        this._lastFrame = this._leap_controller.Frame(0);
        this.Hands = this._lastFrame.Hands;
        this._gestures = this._lastFrame.Gestures();

        foreach(Hand hand in Hands)
        {
            tempHand = hand;
            _fingers = hand.Fingers;

            if (WhichSide.IsEnableGestureHand(this))
            {
                this._fingers = hand.Fingers;

                foreach (Gesture gesture in _gestures)
                {

                    if ((gesture.Type == Gesture.GestureType.TYPE_KEY_TAP) && WhichSide.capturedSide(hand, _useArea, _mountType))
                    {
                        _keytab_gesture = new KeyTapGesture(gesture);
                        this.GetDirection();
                        this.GetPointable();
                        this.GestureInvokePosition();

                        this._isChecked = true;
                        break;

                    }
                }
            }

            if (this._isChecked)
                break;
        }
       
        if (this._isChecked)
        {
            DoAction();
        }
    }
Esempio n. 23
0
    public virtual void CheckGesture()
    {
        this._lastFrame = this._leap_controller.Frame(0);
        this.Hands      = this._lastFrame.Hands;
        this._gestures  = this._lastFrame.Gestures();

        foreach (Hand hand in Hands)
        {
            tempHand = hand;
            _fingers = hand.Fingers;

            if (WhichSide.IsEnableGestureHand(this))
            {
                this._fingers = hand.Fingers;

                foreach (Gesture gesture in _gestures)
                {
                    if ((gesture.Type == Gesture.GestureType.TYPE_KEY_TAP) && WhichSide.capturedSide(hand, _useArea, _mountType))
                    {
                        _keytab_gesture = new KeyTapGesture(gesture);
                        this.GetDirection();
                        this.GetPointable();
                        this.GestureInvokePosition();

                        this._isChecked = true;
                        break;
                    }
                }
            }

            if (this._isChecked)
            {
                break;
            }
        }

        if (this._isChecked)
        {
            DoAction();
        }
    }
Esempio n. 24
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();
                }
            }
        }
    }
Esempio n. 25
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 ("");
		}
	}
Esempio n. 26
0
        /// <summary>
        /// performs pre actions before calling callback function
        /// </summary>
        /// <param name="gesture">Key Tap gesture</param>
        private void PreKeyTap(Gesture gesture)
        {
            KeyTapGesture keytap = new KeyTapGesture(gesture);

            if (!_activeGesture)
            {
                _activeGesture = true;
            }

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

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

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

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

        SafeWriteLine( "Frame id: " + frame.Id
                    + ", timestamp: " + frame.Timestamp
                    + ", hands: " + frame.Hands.Count
                    + ", fingers: " + frame.Fingers.Count
                    + ", tools: " + frame.Tools.Count
                    + ", gestures: " + frame.Gestures().Count );

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

            // Calculate the hand's pitch, roll, and yaw angles
            SafeWriteLine( "  Hand pitch: " + direction.Pitch * 180.0f / (float)Math.PI + " degrees, "
                        + "roll: " + normal.Roll * 180.0f / (float)Math.PI + " degrees, "
                        + "yaw: " + direction.Yaw * 180.0f / (float)Math.PI + " degrees" );

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

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

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

        }

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

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

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

                // Calculate clock direction using the angle between circle normal and pointable
                String clockwiseness;
                if ( circle.Pointable.Direction.AngleTo( circle.Normal ) <= Math.PI / 2 ) {
                    //Clockwise if angle is less than 90 degrees
                    clockwiseness = "clockwise";
                }
                else {
                    clockwiseness = "counterclockwise";
                }

                float sweptAngle = 0;

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

                SafeWriteLine( "  Circle id: " + circle.Id
                               + ", " + circle.State
                               + ", progress: " + circle.Progress
                               + ", radius: " + circle.Radius
                               + ", angle: " + sweptAngle
                               + ", " + clockwiseness );
                break;
            case Gesture.GestureType.TYPE_SWIPE:
                SwipeGesture swipe = new SwipeGesture( gesture );
                SafeWriteLine( "  Swipe id: " + swipe.Id
                               + ", " + swipe.State
                               + ", position: " + swipe.Position
                               + ", direction: " + swipe.Direction
                               + ", speed: " + swipe.Speed );
                break;
            case Gesture.GestureType.TYPE_KEY_TAP:
                KeyTapGesture keytap = new KeyTapGesture( gesture );
                SafeWriteLine( "  Tap id: " + keytap.Id
                               + ", " + keytap.State
                               + ", position: " + keytap.Position
                               + ", direction: " + keytap.Direction );
                break;
            case Gesture.GestureType.TYPE_SCREEN_TAP:
                ScreenTapGesture screentap = new ScreenTapGesture( gesture );
                SafeWriteLine( "  Tap id: " + screentap.Id
                               + ", " + screentap.State
                               + ", position: " + screentap.Position
                               + ", direction: " + screentap.Direction );
                break;
            default:
                SafeWriteLine( "  Unknown gesture type." );
                break;
            }
        }

        if ( !frame.Hands.IsEmpty || !frame.Gestures().IsEmpty ) {
            SafeWriteLine( "" );
        }
    }
Esempio n. 29
0
    //Gesture Event for Keytap
    void KeyTap(Gesture gesture)
    {
        KeyTapGesture keyTap = new KeyTapGesture(gesture);
        Debug.Log("TYPE_KEY_TAP - Duration : " + keyTap.DurationSeconds.ToString());

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

        Destroy (particleObj,2f);

        if(StreetView_Pointed != null)
        {
            // TODO : Click (SHJO)
            if(sceneZoomOut==true)
                SceneChangeZoom(sceneZoomIn,sceneZoomOut);
            Application.LoadLevel("StreetViewer");
        }
    }
Esempio n. 30
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("");
            }
        }
    // Update is called once per frame
    void Update()
    {
        //Need to access the frames of the leap motion
        Frame       frame    = controller.Frame();
        GestureList gestures = frame.Gestures();

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


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

        //Debug.Log(poser);

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

            /*   if (gestureN.Type == Gesture.GestureType.TYPE_SWIPE)
             * {
             *     SwipeGesture Swipe = new SwipeGesture(gestureN);
             *     Vector swipeDirection = Swipe.Direction;
             *
             *     Finger finger = new Finger(Swipe.Pointable);
             *
             *     if (Finger.FingerType.TYPE_THUMB == finger.Type)
             *     {
             *         if (swipeDirection.x < 0)
             *         {
             *             Debug.Log("Left");
             *         }
             *         else if (swipeDirection.x > 0)
             *         {
             *             Debug.Log("Right");
             *         }
             *     }
             * }*/
            if (gestureN.Type == Gesture.GestureType.TYPE_KEY_TAP)
            {
                KeyTapGesture thumbTap    = new KeyTapGesture(gestureN);
                Vector        thumbTapDir = thumbTap.Direction;
                Finger        finger      = new Finger(thumbTap.Pointable);
                //Pointable tappingPointable = thumbTap.Pointable;
                //Finger finger = thumbTap.Pointable as Finger;
                if (Finger.FingerType.TYPE_THUMB == finger.Type)
                {
                    Debug.Log("THUMB TIME" + Random.Range(0f, 20f));
                }
            }
            if (gestureN.Type == Gesture.GestureType.TYPE_SCREEN_TAP)
            {
                ScreenTapGesture thumbTap    = new ScreenTapGesture(gestureN);
                Vector           thumbTapDir = thumbTap.Direction;
                Finger           finger      = new Finger(thumbTap.Pointable);
                //Pointable tappingPointable = thumbTap.Pointable;
                //Finger finger = thumbTap.Pointable as Finger;
                if (Finger.FingerType.TYPE_THUMB == finger.Type)
                {
                    Debug.Log("THUMBSCREEB TIME" + Random.Range(0f, 20f));
                }
            }
        }
    }
Esempio n. 32
0
 public LeapListenerArgs(KeyTapGesture gesture)
 {
     this.keytapgesture = gesture;
 }
Esempio n. 33
0
        public override void OnFrame(Controller controller)
        {
            // Get the most recent frame and report some basic information
            Frame frame = controller.Frame();

            SafeWriteLine("Frame id: " + frame.Id
                          + ", timestamp: " + frame.Timestamp
                          + ", hands: " + frame.Hands.Count
                          + ", fingers: " + frame.Fingers.Count
                          + ", tools: " + frame.Tools.Count
                          + ", gestures: " + frame.Gestures().Count);

            UpdateFrame(frame);

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

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

                // Get the hand's sphere radius and palm position
                //SafeWriteLine("Hand sphere radius: " + hand.SphereRadius.ToString("n2")
                //            + " mm, palm position: " + hand.PalmPosition);

                // Get the hand's normal vector and direction
                Vector normal    = hand.PalmNormal;
                Vector direction = hand.Direction;

                // Calculate the hand's pitch, roll, and yaw angles
                //SafeWriteLine("Hand pitch: " + direction.Pitch * 180.0f / (float)Math.PI + " degrees, "
                //            + "roll: " + normal.Roll * 180.0f / (float)Math.PI + " degrees, "
                //            + "yaw: " + direction.Yaw * 180.0f / (float)Math.PI + " degrees");
            }

            // Get gestures


            GestureList gestures = frame.Gestures();

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

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

                    if (OnCircleGesture == null)
                    {
                        break;
                    }

                    CircleGesture circle = new CircleGesture(gesture);

                    // Calculate clock direction using the angle between circle normal and pointable
                    String clockwiseness;
                    if (circle.Pointable.Direction.AngleTo(circle.Normal) <= Math.PI / 4)
                    {
                        //Clockwise if angle is less than 90 degrees
                        clockwiseness = "clockwise";
                    }
                    else
                    {
                        clockwiseness = "counterclockwise";
                    }

                    float sweptAngle = 0;

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

                    var cargs = new LeapListenerArgs(circle);

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

                    OnCircleGesture(this, cargs);

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


                    break;

                case Gesture.GestureType.TYPESWIPE:

                    if (OnSwipeGesture == null)
                    {
                        break;
                    }

                    SwipeGesture swipe = new SwipeGesture(gesture);

                    var sargs = new LeapListenerArgs(swipe);

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



                    OnSwipeGesture(this, sargs);

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

                case Gesture.GestureType.TYPEKEYTAP:

                    if (OnKeyTapGesture == null)
                    {
                        break;
                    }

                    KeyTapGesture keytap = new KeyTapGesture(gesture);

                    var kargs = new LeapListenerArgs(keytap);

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

                    OnKeyTapGesture(this, kargs);

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

                case Gesture.GestureType.TYPESCREENTAP:

                    if (OnScreenTapGesture == null)
                    {
                        break;
                    }

                    ScreenTapGesture screentap = new ScreenTapGesture(gesture);

                    var targs = new LeapListenerArgs(screentap);

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

                    OnScreenTapGesture(this, targs);

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

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

            if (!frame.Hands.Empty || !frame.Gestures().Empty)
            {
                //SafeWriteLine("");
            }
        }
Esempio n. 34
0
	// Update is called once per frame
	void Update()
	{
		Frame frame = controller.Frame();    //frame 
		GestureList gestures = frame.Gestures(); //frame 안의 gesture 인식
		HandList hands = frame.Hands;    //frame 안의 hands 인식
		int num_hands = hands.Count;    //hand의 수

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


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

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

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

							Application.LoadLevel("StreetViewer");
						}
					}
					// Swipe
					else if (gesture.Type == Gesture.GestureType.TYPE_SWIPE) 
					{
						SwipeGesture swipe = new SwipeGesture(gesture);
						print("Swipe Speed : " + swipe.Speed.ToString());
						print("Swipe Start : " + swipe.StartPosition.ToString());
						print("Swipe End : " + swipe.Position.ToString());
						
						// TODO : Swipe (SHJO)
						if(swipe.StartPosition.x > swipe.Position.x) // swipe.direction을 써도됨
						{
							earth.transform.Rotate(new Vector3(0, -Time.deltaTime * swipeSpeed, 0));
						}
						else
						{
							earth.transform.Rotate(new Vector3(0, Time.deltaTime * swipeSpeed, 0));
						}
						
					}
					// Circle
					else if (gesture.Type == Gesture.GestureType.TYPE_CIRCLE)
					{
						CircleGesture circleGesture = new CircleGesture(gesture);
						print("Circle");
						
						// TODO : Circle (SHJO)
						if (circleGesture.Pointable.Direction.AngleTo(circleGesture.Normal) <= Math.PI / 2) // Clockwise
						{
							earth.transform.Rotate(new Vector3(0, -Time.deltaTime * swipeSpeed, 0));
						}
						else                                                                                // Counterclockwise
						{
							earth.transform.Rotate(new Vector3(0, Time.deltaTime * swipeSpeed, 0)); 
						}
						
					}
				}
				
				// ZOOM IN OUT Motion
				if (num_hands == 2)                                 
				{
					if (handsForGesture[0].IsLeft && gesture.Type == Gesture.GestureType.TYPESWIPE)
					{
						Debug.Log("left zoom");
						SwipeGesture Swipe = new SwipeGesture(gesture);
						Vector swipeDirection = Swipe.Direction;
						if (swipeDirection.x < 0)
						{
							if (leftCamera.camera.fieldOfView < maxFov)
							{
								leftCamera.camera.fieldOfView += zoomScale;
								rightCamera.camera.fieldOfView += zoomScale;
							}
							
						}
						else if (swipeDirection.x > 0)
						{
							if (leftCamera.camera.fieldOfView > minFov)
							{
								leftCamera.camera.fieldOfView -= zoomScale;
								rightCamera.camera.fieldOfView -= zoomScale;
							}
						}
					}
					
					else if ((!handsForGesture[0].IsLeft) && gesture.Type == Gesture.GestureType.TYPESWIPE)
					{
						Debug.Log("right zoom");
						SwipeGesture Swipe = new SwipeGesture(gesture);
						Vector swipeDirection = Swipe.Direction;
						if (swipeDirection.x > 0)
						{
							if (leftCamera.camera.fieldOfView < maxFov)
							{
								leftCamera.camera.fieldOfView += zoomScale;
								rightCamera.camera.fieldOfView += zoomScale;
							}
						}
						else if (swipeDirection.x < 0)
						{
							if (leftCamera.camera.fieldOfView > minFov)
							{
								leftCamera.camera.fieldOfView -= zoomScale;
								rightCamera.camera.fieldOfView -= zoomScale;
							}
						}
					}
					
				} // END OF ZOOM IN GESTURE
			} // END OF GESTURE RECOGNITION LOOP
			
		} // END OF IF
	}
    // Update is called once per frame
    void Update()
    {
        timer = timer - 1;
        if (timer < 0)
        {
            timer = 0;
        }
        timerInactive = timerInactive - 1;
        if (timerInactive < 0)
        {
            timerInactive = 0;
        }
        Frame    f     = myLeap.GetFrame();
        HandList hands = f.Hands;
        Hand     Hand  = hands.GetEnumerator().Current;

        if (Hand != null && Hand.IsValid && timerInactive <= 0)
        {
            Finger     index = null;
            FingerList flist = Hand.Fingers.Extended();
            foreach (Finger p in flist)
            {
                if (p.IsFinger && (p).Type().Equals(Finger.FingerType.TYPE_INDEX))
                {
                    index = p;
                }
            }

            if (Hand.Pointables.Extended().Count < 3 && index != null && index.IsValid)
            {
                leapIndex = false;
                leapPalm  = false;
                leapFist  = false;
                leapIndex = true;
                //Debug.Log("index");
            }
            else if (Hand.Pointables.Extended().Count >= 3)
            {
                leapIndex = false;
                leapPalm  = false;
                leapFist  = false;
                leapPalm  = true;
                //Debug.Log("palm");
            }
            else if (Hand.Pointables.Extended().Count == 0)
            {
                //Debug.Log("fist");
                if (grabbedObj != null)
                {
                    Rigidbody rb = grabbedObj.GetComponent <Rigidbody>();
                    if (rb != null)
                    {
                        rb.isKinematic = false;
                    }
                    grabbedObj.SetActive(true);
                    //detachOject(grabbedObj);
                    grabbedObj = null;
                }
                else if (!leapFist)
                {
                    //toggle menu
                    if (onMenu)
                    {
                        menu.GetComponent <CanvasScaler>().scaleFactor = 1.0f;
                        //myLeap.GetLeapController().EnableGesture(Gesture.GestureType.TYPE_SWIPE,false);
                        timer = 0;
                    }
                    else if (!onPlacement)
                    {
                        menu.GetComponent <CanvasScaler>().scaleFactor = 2.0f;
                        timer = leapWait;
                    }
                    onMenu = !onMenu;
                }
                leapIndex = false;
                leapPalm  = false;
                leapFist  = false;
                Destroy(ghostObject);
                onPlacement = false;
                leapFist    = true;
            }
            if (onMenu)
            {
                foreach (Gesture g in f.Gestures())
                {
                    SwipeGesture swipeGesture = new SwipeGesture(g);
                    if (g.Type == Gesture.GestureType.TYPE_SWIPE && g.Duration > 30 && prevSwipeId != g.Id && timer <= 0 && Math.Abs(swipeGesture.Direction.x) > 0.6)
                    {
                        //Debug.Log("swiper no swiping");

                        //Debug.Log(swipeGesture.Direction);
                        if (swipeGesture.Direction.x > 0)
                        {
                            spCubeScript.cycleObjectsForward();
                        }
                        else if (swipeGesture.Direction.x < 0)
                        {
                            spCubeScript.cycleObjectsBackwards();
                        }
                        prevSwipeId = g.Id;
                        timer       = leapWait;
                    }
                }
            }
            if (grabbedObj != null)
            {
                HandModel[] PHands = myLeap.GetAllPhysicsHands();
                if (ghostObject == null)
                {
                    Rigidbody rb = grabbedObj.GetComponent <Rigidbody>();
                    if (rb != null)
                    {
                        rb.isKinematic = true;
                    }
                    grabbedObj.SetActive(false);

                    if (PHands != null && PHands.Length > 0)
                    {
                        prevRot = new Quaternion();
                        //onPlacement = true;
                        inhibitGhost = true;
                        if (grabbedObj.name.Contains("Mur"))
                        {
                            ghostObject = ((GameObject)Instantiate(spCubeScript.murFantome, PHands[0].palm.transform.position, PHands[0].palm.transform.rotation));
                            ghostObject.transform.Translate(new Vector3(0.0f, 0.0f, 0.0f));
                        }
                        else if (grabbedObj.name.Contains("Cube"))
                        {
                            ghostObject = ((GameObject)Instantiate(spCubeScript.cubeFantome, PHands[0].palm.transform.position, PHands[0].palm.transform.rotation));
                            ghostObject.transform.Translate(new Vector3(0.0f, 0.0f, 0.0f));
                        }
                        else if (grabbedObj.name.Contains("Pack"))
                        {
                            ghostObject = ((GameObject)Instantiate(spCubeScript.healthPackFantome, PHands[0].palm.transform.position, PHands[0].palm.transform.rotation));
                            ghostObject.transform.Translate(new Vector3(0.0f, 0.0f, 0.0f));
                        }
                    }
                }
                if (PHands != null && PHands.Length > 0)
                {
                    //Debug.Log("moving ghost");
                    // Debug.Log(grabbedObj.transform.Find("attachPoint").transform.localPosition);

                    ghostObject.transform.position = PHands[0].palm.transform.position;//grabbedObj.transform.Find("attachPoint").transform.localPosition;// - grabbedObj.GetComponentsInParent ;// + PHands[0].transform.position;
                    //grabbedObj.transform.RotateAround(PHands[0].palm.transform.position - new Vector3(0.0f, 0.45f, 0.0f), grabbedObj.transform.up, PHands[0].palm.transform.rotation.eulerAngles.y- prevRot.eulerAngles.y);
                    //grabbedObj.transform.RotateAround(PHands[0].palm.transform.position - new Vector3(0.0f, 0.45f, 0.0f), grabbedObj.transform.forward, PHands[0].palm.transform.rotation.eulerAngles.x - prevRot.eulerAngles.x);
                    //grabbedObj.transform.RotateAround(PHands[0].palm.transform.position - new Vector3(0.0f, 0.45f, 0.0f), grabbedObj.transform.right,-( PHands[0].palm.transform.rotation.eulerAngles.z - prevRot.eulerAngles.z));
                    ghostObject.transform.rotation = PHands[0].palm.transform.rotation;
                    ghostObject.transform.Translate(new Vector3(0.0f, -1.6f, 0.0f));
                    prevRot = PHands[0].palm.transform.rotation;

                    /*
                     * Vector3 distance = PHands[0].palm.position - grabbedObj.transform.position;
                     * //distance.Normalize();
                     * grabbedObj.GetComponent<Rigidbody>().AddForce(distance * GrabForce);*/
                }
                foreach (Gesture g in f.Gestures())
                {
                    KeyTapGesture keytapGesture = new KeyTapGesture(g);
                    if (g.Type == Gesture.GestureType.TYPE_KEY_TAP && keytapGesture.Pointable.IsFinger && (new Finger(keytapGesture.Pointable)).Type().Equals(Finger.FingerType.TYPE_INDEX))
                    {
                        detachOject(grabbedObj);
                        grabbedObj = null;
                        return;
                    }
                }

                /*
                 * HandModel[] PHands = myLeap.GetAllPhysicsHands();
                 * if(PHands != null && PHands.Length > 0)
                 * {
                 *  // Debug.Log(grabbedObj.transform.Find("attachPoint").transform.localPosition);
                 *  Rigidbody rb = grabbedObj.GetComponentInChildren<Rigidbody>();
                 *  if(rb != null)
                 *      rb.isKinematic = false;
                 *  grabbedObj.transform.position = PHands[0].palm.transform.position ;//grabbedObj.transform.Find("attachPoint").transform.localPosition;// - grabbedObj.GetComponentsInParent ;// + PHands[0].transform.position;
                 *  //grabbedObj.transform.RotateAround(PHands[0].palm.transform.position - new Vector3(0.0f, 0.45f, 0.0f), grabbedObj.transform.up, PHands[0].palm.transform.rotation.eulerAngles.y- prevRot.eulerAngles.y);
                 *  //grabbedObj.transform.RotateAround(PHands[0].palm.transform.position - new Vector3(0.0f, 0.45f, 0.0f), grabbedObj.transform.forward, PHands[0].palm.transform.rotation.eulerAngles.x - prevRot.eulerAngles.x);
                 *  //grabbedObj.transform.RotateAround(PHands[0].palm.transform.position - new Vector3(0.0f, 0.45f, 0.0f), grabbedObj.transform.right,-( PHands[0].palm.transform.rotation.eulerAngles.z - prevRot.eulerAngles.z));
                 *  grabbedObj.transform.rotation = PHands[0].palm.transform.rotation;
                 *  if(grabbedObj.name.Contains("Mur"))
                 *  {
                 *      Debug.Log("picked up mur");
                 *      grabbedObj.transform.Translate(new Vector3(0.0f, +0.45f, 0.0f));
                 *  }
                 *  else if (grabbedObj.name.Contains("Cube"))
                 *  {
                 *      Debug.Log("picked up cube");
                 *      grabbedObj.transform.Translate(new Vector3(0.0f, -0.45f, 0.0f));
                 *  }
                 *  else if (grabbedObj.name.Contains("Pack"))
                 *  {
                 *      Debug.Log("picked up pack");
                 *      grabbedObj.transform.Translate(new Vector3(0.0f, -0.45f, 0.0f));
                 *  }
                 *  if (rb != null)
                 *      rb.isKinematic = true;
                 *  prevRot = PHands[0].palm.transform.rotation;
                 *  /*
                 *  Vector3 distance = PHands[0].palm.position - grabbedObj.transform.position;
                 *  //distance.Normalize();
                 *  grabbedObj.GetComponent<Rigidbody>().AddForce(distance * GrabForce);*/

                //}
            }
            if (grabbedObj == null && !onMenu)
            {
                foreach (Gesture g in f.Gestures())
                {
                    KeyTapGesture keytapGesture = new KeyTapGesture(g);
                    if (g.Type == Gesture.GestureType.TYPE_KEY_TAP && keytapGesture.Pointable.IsFinger && (new Finger(keytapGesture.Pointable)).Type().Equals(Finger.FingerType.TYPE_INDEX))
                    {
                        if (onPlacement)
                        {
                            Destroy(ghostObject);
                            HandModel[] PHands = myLeap.GetAllPhysicsHands();
                            if (PHands != null && PHands.Length > 0)
                            {
                                switch (varGlobales.idObjet)
                                {
                                case 0:
                                    ((GameObject)Instantiate(spCubeScript.cube, PHands[0].palm.transform.position, PHands[0].palm.transform.rotation)).transform.Translate(new Vector3(0.0f, -1.6f, 0.0f));
                                    break;

                                case 1:
                                    ((GameObject)Instantiate(spCubeScript.mur, PHands[0].palm.transform.position, PHands[0].palm.transform.rotation)).transform.Translate(new Vector3(0.0f, -1.6f, 0.0f));
                                    break;

                                case 2:
                                    ((GameObject)Instantiate(spCubeScript.healthPack, PHands[0].palm.transform.position, PHands[0].palm.transform.rotation)).transform.Translate(new Vector3(0.0f, -1.6f, 0.0f));
                                    break;

                                default:
                                    Debug.Log("Erreur : Objet inconnu");
                                    break;
                                }
                                prevRot       = new Quaternion();
                                onPlacement   = false;
                                timerInactive = leapWaitGeneral;
                            }
                        }
                        else
                        {
                            HandModel[] PHands = myLeap.GetAllPhysicsHands();
                            if (PHands != null && PHands.Length > 0)
                            {
                                prevRot     = new Quaternion();
                                onPlacement = true;
                                switch (varGlobales.idObjet)
                                {
                                case 0:
                                    ghostObject = ((GameObject)Instantiate(spCubeScript.cubeFantome, PHands[0].palm.transform.position, PHands[0].palm.transform.rotation));
                                    ghostObject.transform.Translate(new Vector3(0.0f, 0.0f, 0.0f));
                                    break;

                                case 1:
                                    ghostObject = ((GameObject)Instantiate(spCubeScript.murFantome, PHands[0].palm.transform.position, PHands[0].palm.transform.rotation));
                                    ghostObject.transform.Translate(new Vector3(0.0f, 0.0f, 0.0f));
                                    break;

                                case 2:
                                    ghostObject = ((GameObject)Instantiate(spCubeScript.healthPackFantome, PHands[0].palm.transform.position, PHands[0].palm.transform.rotation));
                                    ghostObject.transform.Translate(new Vector3(0.0f, 0.0f, 0.0f));
                                    break;

                                default:
                                    Debug.Log("Erreur : Objet inconnu");
                                    break;
                                }
                                onPlacement = true;
                            }
                        }
                        //Debug.Log("tappety tap tap");
                    }
                }
            }
            if (onPlacement)
            {
                HandModel[] PHands = myLeap.GetAllPhysicsHands();
                if (PHands != null && PHands.Length > 0)
                {
                    // Debug.Log(grabbedObj.transform.Find("attachPoint").transform.localPosition);

                    ghostObject.transform.position = PHands[0].palm.transform.position;//grabbedObj.transform.Find("attachPoint").transform.localPosition;// - grabbedObj.GetComponentsInParent ;// + PHands[0].transform.position;
                    //grabbedObj.transform.RotateAround(PHands[0].palm.transform.position - new Vector3(0.0f, 0.45f, 0.0f), grabbedObj.transform.up, PHands[0].palm.transform.rotation.eulerAngles.y- prevRot.eulerAngles.y);
                    //grabbedObj.transform.RotateAround(PHands[0].palm.transform.position - new Vector3(0.0f, 0.45f, 0.0f), grabbedObj.transform.forward, PHands[0].palm.transform.rotation.eulerAngles.x - prevRot.eulerAngles.x);
                    //grabbedObj.transform.RotateAround(PHands[0].palm.transform.position - new Vector3(0.0f, 0.45f, 0.0f), grabbedObj.transform.right,-( PHands[0].palm.transform.rotation.eulerAngles.z - prevRot.eulerAngles.z));
                    ghostObject.transform.rotation = PHands[0].palm.transform.rotation;
                    ghostObject.transform.Translate(new Vector3(0.0f, -1.6f, 0.0f));
                    prevRot = PHands[0].palm.transform.rotation;

                    /*
                     * Vector3 distance = PHands[0].palm.position - grabbedObj.transform.position;
                     * //distance.Normalize();
                     * grabbedObj.GetComponent<Rigidbody>().AddForce(distance * GrabForce);*/
                }
            }
        }
    }
    //Gesture Event for Keytap
    void KeyTap(Gesture gesture,RaycastHit hit)
    {
        KeyTapGesture keyTap = new KeyTapGesture(gesture);
        Debug.Log ("TYPE_KEY_TAP");
        cursorModel.renderer.material.color = Color.blue;

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

        Destroy (particleObj,2f);

        //if(pointed != null)
        if(hit.collider.gameObject.tag != null)
        {
            // TODO : Click (SHJO)
            if(hit.collider.gameObject.tag=="Button")
            {
                Debug.Log ("Button Touch");
                pointed.Touch ();
            }
            else if(hit.collider.gameObject.tag=="MainMenu")
            {
                MainMenu_pointed.Clicked();
            }
            else if (hit.collider.gameObject.tag == "Information")      //add Jin
            {
                Information_pointed.Clicked();
            }
            else if (hit.collider.gameObject.tag == "InformationCanvas")      //add Jin
            {
                InfoCanvas_pointed.Clicked();
            }
        }
    }
Esempio n. 37
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("");
        }
    }
Esempio n. 38
0
    public static void OnFrame(Controller controller)
    {
        if (controller.IsConnected)
        {
            Frame frame = controller.Frame();

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

                Hand hand = frame.Hands[0];

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

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

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

            GestureList gestures = frame.Gestures();

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

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

                    CircleGesture circleGesture = new CircleGesture(gesture);

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

                    break;

                case Gesture.GestureType.TYPESWIPE:

                    SwipeGesture swipe = new SwipeGesture(gesture);

                    break;

                case Gesture.GestureType.TYPEKEYTAP:

                    KeyTapGesture keyTap = new KeyTapGesture(gesture);

                    break;

                case Gesture.GestureType.TYPESCREENTAP:

                    ScreenTapGesture screenTap = new ScreenTapGesture(gesture);

                    break;
                }
            }
        }
    }
Esempio n. 39
0
    // Update is called once per frame
    void Update()
    {
        Frame frame = new Frame();
        frame = controller.Frame(); // each frame object contains a snapshot of the scene's data (i.e. postions, entities)
        GestureList gestures = frame.Gestures(lastFrame); //List of the Gesture objects within that frame, note they are not reported as events
        lastFrame = frame;                                //Instead they are added to the frames that are within the life time of the gesture
        /*
        for (int i = 0; i < gestures.Count; i++)
        {
            Gesture gesture = gestures[i];
            if (gesture.Type == Gesture.GestureType.TYPE_KEY_TAP && gesture.Hands[0].IsRight)
            {
                KeyTapGesture tap = new KeyTapGesture(gesture);
                GameObject newCube = Instantiate(cube);
                newCube.transform.position = box.transform.position;
                newCube.transform.rotation = box.transform.rotation;
                newCube.transform.parent = box.transform;

                Vector tapPosition = tap.Position;
                Vector3 correctedPos = handController.transform.TransformPoint(tapPosition.ToUnityScaled());
                //correctedPos.y = correctedPos.y - 1.5f;
                //correctedPos.z = correctedPos.z - 0.3f;
                //newCube.transform.position = SnapToGrid(correctedPos);
                snapPos = SnapToGrid(correctedPos);
                SpawnObject(curPlayer, snapPos);
                Vector3 arrayPos = UnityToArrayIndex(snapPos);
                xStr = "X: " + ((int)arrayPos.x).ToString();
                yStr = "Y: " + ((int)arrayPos.y).ToString();
                zStr = "Z: " + ((int)arrayPos.z).ToString();

                Debug.Log(correctedPos + " | " + snapPos);
            }
        }       */

        //Find the current position of the index finger and display it in a text box

        HandList hands = frame.Hands; //List of Hand's present in the scene, can recognize up to 5?
        Vector3 currentPos; //Tuple for the position vector in Unity's coordinates
        Vector tipPos; // Tuple for the position of index finger tip in Leap Motion coordinates
        foreach (Hand hand in hands)
        {
            if (hand.IsRight) //Only recognize a key tap from the right hand
            {
                foreach (Finger finger in hand.Fingers)
                {
                    if ( (int)finger.Type == 1) // referes to index finger
                    {
                        for (int i = 0; i < gestures.Count; i++)
                        {
                            Gesture gesture = gestures[i];
                            if (gesture.Type == Gesture.GestureType.TYPE_KEY_TAP && gesture.Hands[0].IsRight)
                            {
                                // tapping will terminate the end game screen and restart the game
                                if (gameOver == 1)
                                {
                                    // the Transform refers to the object's position, rotation, scale
                                    foreach (Transform child in objects.transform) // basically destroys every object
                                        Destroy(child.gameObject);
                                    logic.reInitializeArray();
                                    //if (objects != null)
                                    //objects = GameObject.Find("Objects");
                                    gameOver = 0;
                                    curPlayer = 1;
                                    winStr = "";
                                }
                                else
                                {

                                    KeyTapGesture tap = new KeyTapGesture(gesture);
                                    /*newCube.transform.position = box.transform.position;
                                    newCube.transform.rotation = box.transform.rotation;
                                    newCube.transform.parent = box.transform;
                                    */
                                    // Convert Leap coordinates to Unity coordinates
                                    Vector tapPosition = tap.Position;
                                    Vector3 correctedPos = handController.transform.TransformPoint(tapPosition.ToUnityScaled()); //taken from documentation
                                    //correctedPos.y = correctedPos.y - 1.5f;
                                    //correctedPos.z = correctedPos.z - 0.3f;
                                    //newCube.transform.position = SnapToGrid(correctedPos);
                                    snapPos = SnapToGrid(correctedPos);
                                    if (snapPos.x > 3f || snapPos.y > 3f || snapPos.z > 3f) //tapping out side the cube undos the last move
                                    {
                                        Undo(lastMove); // lastMove is the GameObject representing the players token
                                        if (curPlayer == 1)
                                        {
                                            //Debug.Log("hello");
                                            curPlayer = 2;
                                        }
                                        else
                                            curPlayer = 1;
                                    }else{
                                        SpawnObject(curPlayer, snapPos); //placed the corresponding player token at that location
                                    }
                                    Vector3 arrayPos = UnityToArrayIndex(snapPos); // to be used in the logic
                                }
                            }
                        }

                        // live display of the index fingers current position (index of 3d array)
                        tipPos = finger.TipPosition; // get the position of the index finger
                        currentPos = handController.transform.TransformPoint(tipPos.ToUnityScaled());
                        snapPos = SnapToGrid(currentPos);
                        Vector3 gridPos = UnityToArrayIndex(snapPos);
                        xStr = "X: " + ((int)gridPos.x).ToString();
                        yStr = "Y: " + ((int)gridPos.y).ToString();
                        zStr = "Z: " + ((int)gridPos.z).ToString();
                    }

                }
            }

        }
    }
Esempio n. 40
0
    void stdGesture()
    {
        for (int i = 0; i < frame.Gestures().Count; i++)
        {
            Gesture gesture = frame.Gestures()[i];

            if (gesture.Type == Gesture.GestureType.TYPE_CIRCLE)
            {
                CircleGesture circleGesture = new CircleGesture(gesture);

                float radius       = circleGesture.Radius;
                bool  closewise    = circleGesture.Pointable.Direction.AngleTo(circleGesture.Normal) <= Mathf.PI / 2;
                float speed        = circleGesture.Pointable.TipVelocity.Magnitude;
                float angularSpeed = closewise ? speed / radius : -speed / radius;

                int directionId = getDirectionId(circleGesture.Normal);
                if (directionId == 0)
                {
                    circleX(angularSpeed);
                }
                else if (directionId == 1)
                {
                    circleY(angularSpeed);
                }
                else if (directionId == 2)
                {
                    circleZ(angularSpeed);
                }
            }
            else if (gesture.Type == Gesture.GestureType.TYPE_SWIPE)
            {
                SwipeGesture swipeGesture = new SwipeGesture(gesture);

                Vector direction   = swipeGesture.Direction;
                float  speed       = swipeGesture.Speed;
                int    directionId = getDirectionId(direction);
                if (directionId == 0)
                {
                    swipeX(speed);
                }
                else if (directionId == 1)
                {
                    swipeY(speed);
                }
                else if (directionId == 2)
                {
                    swipeZ(speed);
                }
            }
            else if (gesture.Type == Gesture.GestureType.TYPE_SCREEN_TAP)
            {
                sreenTap();
            }
            else if (gesture.Type == Gesture.GestureType.TYPE_KEY_TAP)
            {
                KeyTapGesture keyTapGesture = new KeyTapGesture(gesture);

                int id = keyTapGesture.Id;

                keyTap();
            }
        }
    }
Esempio n. 41
0
    void Update()
    {
        Frame frame = controller.Frame();

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

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

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

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

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

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

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

                debugLine = "";

                SafeWriteLine("Frame id: " + frame.Id
                        + ", timestamp: " + frame.Timestamp
                        + ", hands: " + frame.Hands.Count
                        + ", fingers: " + frame.Fingers.Count
                        + ", tools: " + frame.Tools.Count
                        + ", gestures: " + frame.Gestures().Count);

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

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

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

                    }

                    // Get the hand's sphere radius and palm position

                    SafeWriteLine("Hand sphere radius: " + hand.SphereRadius.ToString("n2")
                                + " mm, palm position: " + hand.PalmPosition);

                    // Get the hand's normal vector and direction
                    Vector normal = hand.PalmNormal;
                    Vector direction = hand.Direction;

                    // Calculate the hand's pitch, roll, and yaw angles

                    SafeWriteLine("Hand pitch: " + direction.Pitch * 180.0f / (float)Math.PI + " degrees, "
                                + "roll: " + normal.Roll * 180.0f / (float)Math.PI + " degrees, "
                                + "yaw: " + direction.Yaw * 180.0f / (float)Math.PI + " degrees");

                }

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

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

                            // Calculate clock direction using the angle between circle normal and pointable
                            String clockwiseness;
                            if (circle.Pointable.Direction.AngleTo(circle.Normal) <= Math.PI / 4)
                            {
                                //Clockwise if angle is less than 90 degrees
                                clockwiseness = "clockwise";
                            }
                            else
                            {
                                clockwiseness = "counterclockwise";
                            }

                            float sweptAngle = 0;

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

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

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

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

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

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

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

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

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

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

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

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

            switch (cg.GestureType)
            {
            case CustomGesture.GestureTypes.INVALID:
                // Get gestures
                GestureList gestures = frame.Gestures();
                for (int i = 0; i < gestures.Count; i++)
                {
                    Gesture gesture = gestures[i];

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

                        // Calculate clock direction using the angle between circle normal and pointable
                        string clockwiseness;
                        if (circle.Pointable.Direction.AngleTo(circle.Normal) <= Math.PI / 2)
                        {
                            //Clockwise if angle is less than 90 degrees
                            clockwiseness = "clockwise";
                            ZoomEvent(Zoom.IN);
                        }
                        else
                        {
                            ZoomEvent(Zoom.OUT);
                            clockwiseness = "counterclockwise";
                        }

                        float sweptAngle = 0;

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

                        break;

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

                        break;

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

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

                    default:
                        break;
                    }
                }
                break;

            case CustomGesture.GestureTypes.PEACE:
                break;

            default:
                break;
            }
        }
Esempio n. 45
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;
            }
        }
Esempio n. 46
0
        /// <summary>
        /// Called many (many) times a second. This system handles all gesture actions and responses
        /// </summary>
        /// <param name="controller"></param>
        public override void OnFrame(Controller controller)
        {
            var frame    = controller.Frame();
            var gestures = frame.Gestures();

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

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

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

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

                return;
            }

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

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

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

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

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

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

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

            case Gesture.GestureType.TYPECIRCLE:
                var circle = new CircleGesture(thisGesture);
                ProcessCircle(circle);     // Circle.cs
                break;
            }
        }
Esempio n. 47
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);
        }
Esempio n. 48
0
    void Update()
    {
        if(leapInitialized && leapController != null)
        {
            Leap.Frame frame = leapController.Frame();

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

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

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

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

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

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

                    leapPointableID = 0;
                    leapPointableHandID = 0;
                }

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

                    leapHandFingersCount = leapHand.Fingers.Count;

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

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

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

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

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

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

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

                    if(Time.realtimeSinceStartup < gestureTrackingAtTime)
                        continue;

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

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

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

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

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

                                gestureTrackingAtTime = Time.realtimeSinceStartup + MinTimeBetweenGestures;

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

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

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

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

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

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

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

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

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

                if(DebugCamera)
                {
                    DoDisplayFingers();
                }
            }
        }
    }
        void newFrameHandler(Leap.Frame frame)
        {
            currentTime = frame.Timestamp;
            timeChange = currentTime - previousTime;

            HandList hands = frame.Hands;
            Hand firstHand = hands[0];
            Hand secondHand = hands[1];
            if (timeChange > 100000)
            {
                if (hands[0].IsValid)
                {
                    if (hands[1].IsValid)
                    {
                        //Console.WriteLine(hands[1].PinchStrength);

                    }else{
                       // Console.WriteLine("only 0");
                    }
                }

                var handVelocity = (int)firstHand.PalmVelocity.Magnitude;
                if (handVelocity > 10000)//1500
                {
                    Console.WriteLine(handVelocity);
                    this.displayImageCount.Content = "손빠르기";
                }
                else
                {

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

                                //this.displayImageCount.Content = frame.Gesture(g).ToString() + "의 지름은 " + cir.Radius + "그리고 상태는 " + frame.Gesture(g).State + "=" + frame.Gestures()[g].State;
                                this.displayImageCount.Content = "원" +frame.Gesture(g).ToString() + "의 지름은 " + cir.Radius + "그리고 상태는 " + frame.Gesture(g).State;
                                break;
                            case Gesture.GestureType.TYPE_KEY_TAP:
                                //Handle key tap gestures
                                KeyTapGesture keytapGesture = new KeyTapGesture(frame.Gesture(g));
                                this.displayImageCount.Content = "키탭";
                                Console.WriteLine(frame.Gesture(g).ToString() + "의 방향은 " + keytapGesture.Direction + "그리고 상태는 " + frame.Gesture(g).State + "=" + frame.Gestures()[g].State);
                                Console.WriteLine(frame.Gesture(g).ToString() + "의 포인터은 " + keytapGesture.Pointable + "그리고" + keytapGesture.Position);

                                break;
                            case Gesture.GestureType.TYPE_SCREEN_TAP:
                                //Handle screen tap gestures
                                this.displayImageCount.Content = "스크린탭";
                                ScreenTapGesture screentapGesture = new ScreenTapGesture(frame.Gesture(g));
                                Console.WriteLine(screentapGesture.Direction);
                                break;
                            case Gesture.GestureType.TYPE_SWIPE:
                                this.displayImageCount.Content = "쓸기";

                                break;
                            default:
                                //this.displayImageCount.Content = 0;
                                break;
                        }
                    }

                    this.displayID.Content = frame.Id.ToString();
                    this.displayTimestamp.Content = frame.Timestamp.ToString();
                    this.displayFPS.Content = frame.CurrentFramesPerSecond.ToString();
                    this.displayIsValid.Content = frame.IsValid.ToString();
                    this.displayGestureCount.Content = frame.Gestures().Count.ToString();
                    //this.displayImageCount.Content = frame.Images.Count.ToString();
                }
                previousTime = currentTime;

            }
        }
    private void handleTap(Frame frame, KeyTapGesture tap)
    {
        if (!sendingKey)
        {
            SendKeys.SendWait("{DOWN}");

        }

        setKeyTimer();
    }
    // Update is called once per frame
    void Update()
    {
        Frame frame = controller.Frame();    //frame 
        GestureList gestures = frame.Gestures(); //frame 안의 gesture 인식
        HandList hands = frame.Hands;    //frame 안의 hands 인식
        int num_hands = hands.Count;    //hand의 수

        if (num_hands < 1) // 인식된 손이 없다면
        {
            return;
        }
        else
        {
            Hand left = hands.Leftmost;     //왼쪽손 
            Hand right = hands.Rightmost;   //오른쪽 손

            FingerList fingerList = left.Fingers;  //왼쪽 손의 손가락들!
            Finger leftFinger = fingerList.Frontmost;  //왼손에서 제일 앞에 있는 손가락

            rigid = GameObject.Find("RigidHand(Clone)");
            if (rigid == null)
            {
                Debug.LogWarning("RigidHand is null");
                return;
            }

            cursorPointer = GameObject.Find("RigidHand(Clone)/index/bone3");
            if (cursorPointer == null)
            {
                Debug.LogWarning("CursorPointer is null");
                return;
            }

            //여기에서 립모션 손모양 오븥젝트의 Collision 을 해체하여 Raycast에 충돌 하지 않게 한다.
            Collider[] cols = rigid.GetComponentsInChildren<Collider>();
            for (int i = 0; i < cols.Length; i++)
            {
                cols[i].enabled = false;
            }

            GameObject handController = GameObject.Find("HandController");  //HandCOnroller 오브젝트 접근
            //팁핑 포지션으로 커서를 이동
            if (rigid != null)
            {
                //Debug.Log ("Rigid finded");
                Vector3 temp = Tipping();
                cursorModel.transform.position = temp;
            }

            //손바닥을 UnityScale로 좌표 변환 , Handcontroller TransformPoint로 Transform 형식에 맞게 변환, 이후 왼쪽 카메라 기준으로 월드 스크린으로 변환 
            //Vector2 screenPoint=leftCamera.camera.WorldToScreenPoint (handController.transform.TransformPoint(left.PalmPosition.ToUnityScaled()));
            Vector2 screenPoint = leftCamera.camera.WorldToScreenPoint(cursorPointer.transform.position);
            Ray r = leftCamera.camera.ScreenPointToRay(screenPoint);      // ScreentPoint로부터 Ray를 쏜다
            Debug.DrawRay(r.origin, r.direction * 1000, Color.red);

            RaycastHit hit; //rayCast에서 부딛힌 객체 관리
            
            if (Physics.Raycast(r, out hit, Mathf.Infinity))
            {
				//Debug.Log("hit - ObjName : " + hit.collider.name + 
				         // ", Flag - " +hit.collider.gameObject.tag );
                if(hit.collider != null)
                {
                    target.transform.position = hit.transform.position;
                    if(hit.collider.gameObject.tag == "Button")
                    {
						pointed = hit.collider.gameObject.GetComponent<Button>();
						if(pointed != null)
                        {
							pointed.Pointed();
                        }
                    }
					else if(hit.collider.gameObject.tag == "MainMenu")
					{
						MainMenu_pointed = hit.collider.gameObject.GetComponent<MainMenu>();
						if(MainMenu_pointed != null)
						{
							// TODO : Mouse Enter (HJOOn)
							MainMenu_pointed.Pointed();
						}
					}
                    else if (hit.collider.gameObject.tag == "Information")                              //Information 버튼 구현(add Jin)
                    {
                        Information_pointed = hit.collider.gameObject.GetComponent<Information>();
                        if (Information_pointed != null)
                        {
                            Information_pointed.Pointed();
                        }
                    }
				}
			}
			else
			{
				// TODO : Mouse Exit (SHJO)
				if(pointed != null)
                {
					//hit.collider.gameObject.renderer.material.color=Color.red;
					pointed.PointedOut();
					pointed=null;
                }
				else if(MainMenu_pointed !=null)
				{
					MainMenu_pointed.PointedOut();
					MainMenu_pointed = null;
				}
                else if (Information_pointed != null)      //add Jin
                {
                    Information_pointed.PointedOut();
                    Information_pointed = null;
                }
            }

            //립모션 제스쳐 감지 
            for (int i = 0; i < gestures.Count; i++)
            {
                Gesture gesture = gestures[i];

				HandList handsForGesture = gesture.Hands;
				if (num_hands == 1)                                 
				{

                // Key Tap
                if (gesture.Type == Gesture.GestureType.TYPE_KEY_TAP)
                {
                    KeyTapGesture keyTap = new KeyTapGesture(gesture);
					Debug.Log ("TYPE_KEY_TAP");
					cursorModel.renderer.material.color = Color.blue;  

						
					GameObject particleObj = Instantiate(clickParticle, Tipping () , Quaternion.identity) as GameObject;
						
					Destroy (particleObj,2f);

                    //if(pointed != null)
					if(hit.collider.gameObject.tag != null)
                    {
                        // TODO : Click (SHJO)
						if(hit.collider.gameObject.tag=="Button")
						{	
                            Debug.Log ("Button Touch");
							pointed.Touch ();
						}
						else if(hit.collider.gameObject.tag=="MainMenu")
						{
							MainMenu_pointed.Clicked();
						}
                        else if (hit.collider.gameObject.tag == "Information")      //add Jin
                        {
                            Information_pointed.Clicked();
                        }
                    }
                }
                // Screen Tap
                else if (gesture.Type == Gesture.GestureType.TYPE_SCREEN_TAP) 
                {
                    ScreenTapGesture screenTap = new ScreenTapGesture(gesture);
                    Debug.Log("TYPE_SCREEN_TAP");
                    cursorModel.renderer.material.color = Color.red;

					if(hit.collider.gameObject.tag=="Button")
					{
						pointed.Touch ();
					}
                }
                // Swipe
                else if (gesture.Type == Gesture.GestureType.TYPE_SWIPE) 
                {
                  

                }
                // Circle
                else if (gesture.Type == Gesture.GestureType.TYPE_CIRCLE)
                {                   

                }
				}
                // ZOOM IN OUT Motion
                if (num_hands == 2)                                 
                {
					if (handsForGesture[0].IsLeft && gesture.Type == Gesture.GestureType.TYPESWIPE)
					{
						Debug.Log("left zoom");
						SwipeGesture Swipe = new SwipeGesture(gesture);
						Vector swipeDirection = Swipe.Direction;
						if (swipeDirection.x < 0)
						{
							if (leftCamera.camera.fieldOfView < maxFov)
							{
								leftCamera.camera.fieldOfView += zoomScale;
								rightCamera.camera.fieldOfView += zoomScale;
							}
							
						}
						else if (swipeDirection.x > 0)
						{
							if (leftCamera.camera.fieldOfView > minFov)
							{
								leftCamera.camera.fieldOfView -= zoomScale;
								rightCamera.camera.fieldOfView -= zoomScale;
							}
						}
					}
					
					else if ((!handsForGesture[0].IsLeft) && gesture.Type == Gesture.GestureType.TYPESWIPE)
					{
						Debug.Log("right zoom");
						SwipeGesture Swipe = new SwipeGesture(gesture);
						Vector swipeDirection = Swipe.Direction;
						if (swipeDirection.x > 0)
						{
							if (leftCamera.camera.fieldOfView < maxFov)
							{
								leftCamera.camera.fieldOfView += zoomScale;
								rightCamera.camera.fieldOfView += zoomScale;
							}
						}
						else if (swipeDirection.x < 0)
						{
							if (leftCamera.camera.fieldOfView > minFov)
							{
								leftCamera.camera.fieldOfView -= zoomScale;
								rightCamera.camera.fieldOfView -= zoomScale;
							}
						}
					}
                } // END OF ZOOM IN GESTURE
            } // END OF GESTURE RECOGNITION LOOP
        
        } // END OF IF
    }
Esempio n. 52
0
    //Gesture Event for Keytap
    void KeyTap(Gesture gesture)
    {
        KeyTapGesture keyTap = new KeyTapGesture(gesture);
        Debug.Log("TYPE_KEY_TAP - Duration : " + keyTap.DurationSeconds.ToString());

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

        Destroy(particleObj, 2f);

        if(hitObject != null)
        {
            OnClicked(hitObject);
        }
    }
Esempio n. 53
0
    void Update()
    {
        var frame = controller.Frame();
        var fingerCount = frame.Fingers.Count;
        var gestures = frame.Gestures();
        var interactionBox = frame.InteractionBox;

        if ( frame.Fingers[0].IsValid ) {
             for ( int i = 0; i < FingerObjects.Length; i++ ) {
          var leapFinger = frame.Fingers[i];
          var unityFinger = FingerObjects[i];
          SetVisible( unityFinger, leapFinger.IsValid );
          if ( leapFinger.IsValid ) {
        Vector normalizedPosition = interactionBox.NormalizePoint(leapFinger.TipPosition );
        normalizedPosition *= 10;
        normalizedPosition.z = -normalizedPosition.z;
        unityFinger.transform.localPosition = ToVector3( normalizedPosition );
          }
        }
            for ( int i = 0 ; i < gestures.Count ; i++ ) {
                // ジェスチャー結果取得&表示
                Gesture gesture = gestures[i];
                switch ( gesture.Type ) {
                case Gesture.GestureType.TYPECIRCLE:
                    var circle = new CircleGesture(gesture);
                        // 回転方向を計算
                        string clockwiseness;
                        if (circle.Pointable.Direction.AngleTo(circle.Normal) <= Math.PI / 4)
                        {
                          // 角度が90度以下なら、時計回り
                          clockwiseness = "時計回り";
                        }
                        else
                        {
                          clockwiseness = "反時計回り";
                        }
                        Debug.Log(clockwiseness);
                        Send(clockwiseness);
                    break;
                case Gesture.GestureType.TYPEKEYTAP:
                    var keytapGesture = new KeyTapGesture(gesture);
                    printGesture("KeyTap");
                    break;
                case Gesture.GestureType.TYPESCREENTAP:
                    var screenTapGesture = new ScreenTapGesture(gesture);
                    printGesture("ScreenTap");
                    break;
              	case Gesture.GestureType.TYPESWIPE:
              	var swipe = new SwipeGesture(gesture);
              	if(swipe.State == Gesture.GestureState.STATESTART){
              		swipeStart=swipe.Direction.y;
              	}
              	if(swipe.State == Gesture.GestureState.STATESTOP){
              		swipeStop=swipe.Direction.y;
              	}
                    Debug.Log(swipe.Direction.y);
                break;
                default:
                    break;
                }
            }
        }
    }
Esempio n. 54
0
        public override void OnFrame(Controller controller)
        {
            // Get the most recent frame and report some basic information
            Leap.Frame frame = controller.Frame();

            if (!frame.Hands.Empty)
            {
                if (frame.Fingers.Count >= 2 && LeapFingerReady != null)
                {
                    LeapFingerReady(this, frame.Fingers[0], frame.Fingers[1]);
                }
            }

            // Get gestures
            GestureList gestures = frame.Gestures();

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

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

                    // Calculate clock direction using the angle between circle normal and pointable
                    if (circle.State == Gesture.GestureState.STATESTART)
                    {
                        Thread.Sleep(500);
                        LeapCircleReady(this);
                    }

                    break;

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

                    if (swipe.State == Gesture.GestureState.STATESTART && LeapSwipeReady != null)
                    {
                        if (swipe.Direction.x < -0.5)
                        {
                            LeapSwipeReady(this, SwipeType.SwipeLeft);
                        }
                        else if (swipe.Direction.x > 0.5)
                        {
                            LeapSwipeReady(this, SwipeType.SwipeRight);
                        }
                        //else if (swipe.Direction.z < -0.2)
                        //{
                        //    LeapSwipeReady(this, SwipeType.SwpieIn);
                        //}
                        //else if (swipe.Direction.z > 0.2)
                        //{
                        //    Thread.Sleep(300);
                        //    LeapSwipeReady(this, SwipeType.SwipeOut);
                        //}
                    }
                    break;

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

                    break;

                case Gesture.GestureType.TYPESCREENTAP:
                    ScreenTapGesture screentap = new ScreenTapGesture(gesture);
                    if (screentap.State == Gesture.GestureState.STATESTOP && LeapTapScreenReady != null)
                    {
                        if (frame.Fingers.Count > 1)
                        {
                            Thread.Sleep(800);
                        }
                        LeapTapScreenReady(this);
                    }
                    break;
                }
            }
        }
Esempio 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);

            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("");
            }
        }
Esempio n. 56
0
    public override void OnFrame(Controller controller)
    {
        // Get the most recent frame and report some basic information
        Frame frame = controller.Frame();

        SafeWriteLine("Frame id: " + frame.Id
                      + ", timestamp: " + frame.Timestamp
                      + ", hands: " + frame.Hands.Count
                      + ", fingers: " + frame.Fingers.Count
                      + ", tools: " + frame.Tools.Count
                      + ", gestures: " + frame.Gestures().Count);

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

            // Calculate the hand's pitch, roll, and yaw angles
            SafeWriteLine("  Hand pitch: " + direction.Pitch * 180.0f / (float)Math.PI + " degrees, "
                          + "roll: " + normal.Roll * 180.0f / (float)Math.PI + " degrees, "
                          + "yaw: " + direction.Yaw * 180.0f / (float)Math.PI + " degrees");

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

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

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

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

        // Get gestures
        GestureList gestures = frame.Gestures();

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

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

                // Calculate clock direction using the angle between circle normal and pointable
                String clockwiseness;
                if (circle.Pointable.Direction.AngleTo(circle.Normal) <= Math.PI / 2)
                {
                    //Clockwise if angle is less than 90 degrees
                    clockwiseness = "clockwise";
                }
                else
                {
                    clockwiseness = "counterclockwise";
                }

                float sweptAngle = 0;

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

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

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

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

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

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

        if (!frame.Hands.IsEmpty || !frame.Gestures().IsEmpty)
        {
            SafeWriteLine("");
        }
    }
    public void Tap(KeyTapGesture gesture)
    {
        /**/
        Hand hand = gesture.Hands [0];

        if (controllingHandType == HandType.RightHand && hand.IsRight || controllingHandType == HandType.LeftHand && hand.IsLeft)
        {
            if (gesture.Pointable.IsFinger)
            {
                Finger finger = new Finger(gesture.Pointable);
                if (finger.Type() == Finger.FingerType.TYPE_INDEX)
                {
                    shouldClick = true;
                }
            }
        }
    }

    public void ShouldSwipe(Vector3 direction)
    {
        if (shouldSwipe == false)
        {
            shouldSwipe    = true;
            swipeDirection = direction;
        }
    }

    ////ze stranek leapu, pro zruseni zaseknuti na konci hry
        #if UNITY_STANDALONE_WIN
    [DllImport("mono", SetLastError = true)]
    static extern void mono_thread_exit();
        #endif
    void OnApplicationQuit()
    {
        controller.RemoveListener(leapListener);
        controller.Dispose();
        leapListener.Dispose();                                                 //&& UNITY_3_5 //keca to, potreubju to i tady
                #if UNITY_STANDALONE_WIN && !UNITY_EDITOR
        mono_thread_exit();
                #endif
    }

    void Awake()
    {
        controller   = new Controller();
        leapListener = new MyLeapListener(this);          //listener muze zpusobit ze hra nejde zavrit
        controller.AddListener(leapListener);

        string inputs = "";

        //chybejici inputs.txt
        try{
            inputs = System.IO.File.ReadAllText(Application.dataPath + "/inputs.txt");
        }
        catch (System.IO.IOException e) {
            //Time.timeScale = 0.0f;
            return;
        }
        isFile = true;


        /*nacteni kalibrace ze souboru*/
        var parsed = JSON.Parse(inputs);

        calwidth  = parsed ["width"].AsInt;
        calheight = parsed ["height"].AsInt;

        rvec [0] = parsed ["rvecs"] [0][0].AsDouble;
        rvec [1] = parsed ["rvecs"] [1][0].AsDouble;
        rvec [2] = parsed ["rvecs"] [2][0].AsDouble;

        tvec [0] = parsed ["tvecs"] [0][0].AsDouble;
        tvec [1] = parsed ["tvecs"] [1][0].AsDouble;
        tvec [2] = parsed ["tvecs"] [2][0].AsDouble;


        mtx [0] = parsed ["mtx"] [0][0].AsDouble;
        mtx [1] = parsed ["mtx"] [0][1].AsDouble;
        mtx [2] = parsed ["mtx"] [0][2].AsDouble;
        mtx [3] = parsed ["mtx"] [1][0].AsDouble;
        mtx [4] = parsed ["mtx"] [1][1].AsDouble;
        mtx [5] = parsed ["mtx"] [1][2].AsDouble;
        mtx [6] = parsed ["mtx"] [2][0].AsDouble;
        mtx [7] = parsed ["mtx"] [2][1].AsDouble;
        mtx [8] = parsed ["mtx"] [2][2].AsDouble;

        dist [0] = parsed ["dist"] [0][0].AsDouble;
        dist [1] = parsed ["dist"] [0][1].AsDouble;
        dist [2] = parsed ["dist"] [0][2].AsDouble;
        dist [3] = parsed ["dist"] [0][3].AsDouble;
        dist [4] = parsed ["dist"] [0][4].AsDouble;


        eventSystem = EventSystem.current;  //pro ovladani slideru a jinych selecatables
        frame       = controller.Frame();   //poprve tady a pak v kazdym updatu
        lastSeenControlHandFrame = frame;

        /*nastaveni parametru pro Leap Motion*/
        controller.SetPolicy(Controller.PolicyFlag.POLICY_OPTIMIZE_HMD | Controller.PolicyFlag.POLICY_BACKGROUND_FRAMES);
        controller.EnableGesture(Gesture.GestureType.TYPEKEYTAP);
        controller.Config.SetFloat("Gesture.KeyTap.MinDownVelocity", 30.0f);
        controller.Config.SetFloat("Gesture.KeyTap.HistorySeconds", .1f);
        controller.Config.SetFloat("Gesture.KeyTap.MinDistance", 0.5f);
        controller.Config.Save();
    }
Esempio n. 58
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;
                }
            }
        }
Esempio 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;
                }
            }
        }
Esempio n. 60
0
        /// <summary>
        /// Performs the gesture detection
        /// </summary>
        /// <param name="frame">The actual frame</param>
        public override void GestureDetection(Frame frame)
        {
            // when the Leap API is used, we collect the list of gestures
            GestureList gestures = frame.Gestures();

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

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

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

                    case Gesture.GestureType.TYPECIRCLE:
                        ProcessCircle(gesture);
                        break;
                }
            }
        }