예제 #1
0
    // Update is called once per frame
    void FixedUpdate()
    {
        Leap.Hand mHand = myLeapManagerInstance.frontmostHand();

        if (mHand.IsValid)
        {
            if (!swordUp)
            {
                audio.Play();
            }

            swordUp = true;
        }
        else
        {
            if (swordUp)
            {
                AudioSource.PlayClipAtPoint(swordSheath, transform.position, 0.25f);
            }

            swordUp = false;
        }

        Vector3    targetPos = getTargetPos(mHand);
        Quaternion targetRot = getTargetRot(mHand);

        //moveWithForce(targetPos);
        moveWithMovePos(targetPos, targetRot);
    }
예제 #2
0
    // Update is called once per frame
    void Update()
    {
        if (_leapManager.frontmostHand().IsValid&& LeapManager.isHandOpen(_leapManager.frontmostHand()))
        {
            Hand    hand         = _leapManager.frontmostHand();
            Vector3 handLocation = hand.PalmPosition.ToUnityTranslated();

            if (hand.Id != _lastHandId)
            {
                _handPositionOnAquire = handLocation;
                _lastHandId           = hand.Id;
            }

            handLocation = _lastHandPositionOnLoss + (handLocation - _handPositionOnAquire);

            handLocation.y = Mathf.Clamp(handLocation.y, _controlMin.y, _controlMax.y);

            _lastHandPosition = handLocation;

            Quaternion yRotation = Quaternion.Euler(new Vector3(
                                                        0,
                                                        (((handLocation.x - _controlMin.x) / (_controlMax.x - _controlMin.x)) * 180.0f) + 90.0f,
                                                        0
                                                        ));

            Quaternion xRotation = Quaternion.Euler(new Vector3(
                                                        ((1 - ((handLocation.y - _controlMin.y) / (_controlMax.y - _controlMin.y))) * 180.0f) + 90.0f,
                                                        0,
                                                        0));

            Vector3 directionVector = yRotation * xRotation * Vector3.forward;

            float dist = ((1.0f - Mathf.Clamp((handLocation.z - _controlMin.z) / (_controlMax.z - _controlMin.x), 0.0f, 1.0f)) * (_distanceLimits.y - _distanceLimits.x)) + _distanceLimits.x;
            gameObject.transform.position = directionVector * dist;
            gameObject.transform.LookAt(_targetObject.transform);
        }
        else
        {
            _lastHandId             = -1;
            _lastHandPositionOnLoss = _lastHandPosition;
        }
    }
예제 #3
0
    // Update is called once per frame
    void Update()
    {
        Hand primeHand = _leapManager.frontmostHand();

        normalOutput = primeHand.PalmNormal.ToUnity();
        height       = primeHand.PalmPosition.ToUnity().y;

        if (handVisible && primeHand.IsValid)
        {
            Vector3[] fingerPositions = _leapManager.getWorldFingerPositions(primeHand);
            gameObject.transform.position = primeHand.PalmPosition.ToUnityTranslated();
            if (gameObject.renderer.enabled != true)
            {
                gameObject.renderer.enabled = true;
            }

            for (int i = 0; i < fingers.GetLength(0); i++)
            {
                if (i < fingerPositions.GetLength(0))
                {
                    fingers[i].transform.position = fingerPositions[i];
                    if (fingers[i].renderer.enabled == false)
                    {
                        fingers[i].renderer.enabled = true;
                    }

                    if (colliders != null && i < colliders.GetLength(0))
                    {
                        (colliders[i].GetComponent(typeof(SphereCollider)) as SphereCollider).enabled = true;
                    }
                }
                else
                {
                    fingers[i].renderer.enabled = false;
                    if (colliders != null && i < colliders.GetLength(0))
                    {
                        (colliders[i].GetComponent(typeof(SphereCollider)) as SphereCollider).enabled = false;
                    }
                }
            }
        }
        else
        {
            gameObject.renderer.enabled = false;

            foreach (GameObject finger in fingers)
            {
                if (finger.renderer.enabled == true)
                {
                    finger.renderer.enabled = false;
                }
            }
        }
    }
    // Update is called once per frame
    void Update()
    {
        Hand primeHand = _leapManager.frontmostHand();

        if (primeHand.IsValid)
        {
            Vector3[] fingerPositions = _leapManager.getWorldFingerPositions(primeHand);
            gameObject.transform.position = primeHand.PalmPosition.ToUnityTranslated();
            if (gameObject.GetComponent <Renderer>().enabled != true)
            {
                gameObject.GetComponent <Renderer>().enabled = true;
            }

            for (int i = 0; i < fingers.GetLength(0); i++)
            {
                if (i < fingerPositions.GetLength(0))
                {
                    fingers[i].transform.position = fingerPositions[i];
                    if (fingers[i].GetComponent <Renderer>().enabled == false)
                    {
                        fingers[i].GetComponent <Renderer>().enabled = true;
                    }

                    if (colliders != null && i < colliders.GetLength(0))
                    {
                        (colliders[i].GetComponent(typeof(SphereCollider)) as SphereCollider).enabled = true;
                    }
                }
                else
                {
                    fingers[i].GetComponent <Renderer>().enabled = false;
                    if (colliders != null && i < colliders.GetLength(0))
                    {
                        (colliders[i].GetComponent(typeof(SphereCollider)) as SphereCollider).enabled = false;
                    }
                }
            }
        }
        else
        {
            gameObject.GetComponent <Renderer>().enabled = false;

            foreach (GameObject finger in fingers)
            {
                if (finger.GetComponent <Renderer>().enabled == true)
                {
                    finger.GetComponent <Renderer>().enabled = false;
                }
            }
        }
        mouse_x = (int)fingers[0].transform.position.x;
        mouse_y = (int)fingers[0].transform.position.y;
        //	Debug.Log(mouse_x);
    }
예제 #5
0
    // Update is called once per frame
    void Update()
    {
        if (_leapManager)
        {
            if (_leapManager.pointerAvailible && !LeapManager.isHandOpen(_leapManager.frontmostHand()))
            {
                Vector2 pointerPositionScreen = _leapManager.pointerPositionScreen;
                pointerPositionScreen.y = pointerPositionScreen.y + 30;

                m_button1.UpdateState(pointerPositionScreen);
                m_button2.UpdateState(pointerPositionScreen);
            }
        }
    }
예제 #6
0
    // Update is called once per frame
    void Update()
    {
        if (_leapManager.frontmostHand().IsValid&& LeapManager.isHandOpen(_leapManager.frontmostHand()))
        {
            Vector3 handLocation = _leapManager.frontmostHand().PalmPosition.ToUnityTranslated();

            Quaternion yRotation = Quaternion.Euler(new Vector3(
                                                        0,
                                                        360 - (Mathf.Clamp((handLocation.x - _controlMin.x) / (_controlMax.x - _controlMin.x), 0, 1.0f) * 360.0f) + 90.0f,
                                                        0
                                                        ));

            Quaternion xRotation = Quaternion.Euler(new Vector3(
                                                        (Mathf.Clamp((handLocation.y - _controlMin.y) / (_controlMax.y - _controlMin.y), 0, 1.0f) * 180.0f) + 90.0f,
                                                        0,
                                                        0));

            Vector3 directionVector = yRotation * xRotation * Vector3.forward;

            float dist = ((1.0f - Mathf.Clamp((handLocation.z - _controlMin.z) / (_controlMax.z - _controlMin.x), 0.0f, 1.0f)) * (_distanceLimits.y - _distanceLimits.x)) + _distanceLimits.x;
            gameObject.transform.position = directionVector * dist;
            gameObject.transform.LookAt(_targetObject.transform);
        }
    }
예제 #7
0
    // Update is called once per frame
    void Update()
    {
        if (_leapManager)
        {
            if (_leapManager.pointerAvailible && !LeapManager.isHandOpen(_leapManager.frontmostHand()) /* && !any_menu_active*/)
            {
                arrowTexture[0].SetActive(true);

                gameObject.transform.position = new Vector3(_leapManager.pointerPositionScreen.x / Camera.main.pixelWidth, _leapManager.pointerPositionScreen.y / Camera.main.pixelHeight, 0.0f);
            }
            else
            {
                arrowTexture[0].SetActive(false);
            }
        }
    }
예제 #8
0
        void Update()
        {
            bool    actionOccured = false;
            Gesture swipeGesture  = null;

            if (Input.GetKeyDown(KeyCode.Space))
            {
                loadBallsPostion(ballsFirstPosition);
                Start();
            }
            else if (Input.GetKeyDown(KeyCode.Escape))
            {
                Application.Quit();
            }
            else
            {
                if (currentState == GameState.CameraManualAdjust || currentState == GameState.Aiming)
                {
                    Hand hand = leapManager.frontmostHand();

                    if (currentState == GameState.CameraManualAdjust && handState.Equals(HandState.NoAction))
                    {
                        Frame frame = leapManager.currentFrame;

                        GestureList gestures = frame.Gestures();
                        foreach (var gesture in gestures)
                        {
                            if (gesture.Type == Gesture.GestureType.TYPE_SWIPE && gesture.IsValid)
                            {
                                actionOccured = true;
                                swipeGesture  = gesture;
                            }
                        }
                    }
                    if (!actionOccured && hand.IsValid)
                    {
                        HandState mHandState = momentHandState();
                        switch (mHandState)
                        {
                        case HandState.Fisting:
                            if (currentState == GameState.CameraManualAdjust && handState.Equals(HandState.NoAction))
                            {
                                fistingDuration += Time.deltaTime;
                                //StartCoroutine (lerpAlpha (viewAdjustmentStateIcon, fistingDuration / fistingDetectionTime));
                            }
                            break;

                        case HandState.Pointing:
                            if (handState.Equals(HandState.NoAction))
                            {
                                pointingDuration += Time.deltaTime;
                                //StartCoroutine (lerpAlpha (aimingStateIcon, pointingDuration / pointingDetectionTime));
                            }
                            break;

                        case HandState.NoAction:
                            if (!handState.Equals(HandState.NoAction))
                            {
                                noActionDuration += Time.deltaTime;
                            }
                            break;
                        }
                    }

                    if (actionOccured)
                    {
                        //if swiped call swipe delegates and reset
                        noActionDuration = 0.0f;
                        pointingDuration = 0.0f;
                        fistingDuration  = 0.0f;
                        onSwipeAction(swipeGesture);
                        Debug.Log("Swiped");
                    }
                    else
                    {
                        float accumTime = noActionDuration + pointingDuration + fistingDuration;
                        if (pointingDuration / accumTime > actionDetectionAccuracy && pointingDuration > pointingDetectionTime)
                        {
                            //	if poiting for the most of passed time call noaction delegates and reset
                            handState     = HandState.Pointing;
                            actionOccured = true;
                            onPointAction();
                        }
                        else if (fistingDuration / accumTime > actionDetectionAccuracy && fistingDuration > fistingDetectionTime)
                        {
                            //	if fisting for the most of passed time call noaction delegates and reset
                            handState     = HandState.Fisting;
                            actionOccured = true;
                            onFistAction();
                        }
                        else if (noActionDuration / accumTime > actionDetectionAccuracy && noActionDuration > noActionDetectionTime)
                        {
                            //	if noaction for the most of passed time call noaction delegates and reset
                            handState     = HandState.NoAction;
                            actionOccured = true;
                            onNoAction();
                        }

                        if (accumTime > actionDetectionWindow)
                        {
                            float minTime = Mathf.Min(Mathf.Min(noActionDuration, fistingDuration), pointingDuration);
                            noActionDuration -= minTime;
                            fistingDuration  -= minTime;
                            pointingDuration -= minTime;
                        }
                        //Debug.Log ("na: " + noActionDuration + " pt: " + pointingDuration + " ft: " + fistingDuration + " dtr: " + accumTime + " hs: " + handState + " pnt? " + leapManager.pointerAvailible);
                    }
                }
                else if (currentState == GameState.AfterShot)
                {
                    bool shotEnded = true;
                    if (cueBall.rigidbody.velocity.magnitude == 0)
                    {
                        for (int i = 0; i < balls.Count; i++)
                        {
                            if (balls [i].rigidbody.velocity.magnitude > 0)
                            {
                                shotEnded = false;
                                break;
                            }
                        }
                    }
                    else
                    {
                        shotEnded = false;
                    }
                    if (shotEnded)
                    {
                        doTurnEnd();
                    }
                }
            }
        }
예제 #9
0
 // Update is called once per frame
 void Update()
 {
     text.text = "Hand Open: " + LeapManager.isHandOpen(_leapManager.frontmostHand());
 }
 // Update is called once per frame
 void Update()
 {
     text.text = "Finger Count: " + _leapManager.frontmostHand().Fingers.Count;
 }
예제 #11
0
    // Update is called once per frame
    void Update()
    {
        Hand primeHand = _leapManager.frontmostHand();

        if (primeHand.IsValid)
        {
            Vector3[] fingerPositions = _leapManager.getWorldFingerPositions(primeHand);
            gameObject.transform.position = primeHand.PalmPosition.ToUnityTranslated();
            if (gameObject.GetComponent <Renderer>().enabled != true)
            {
                gameObject.GetComponent <Renderer>().enabled = true;
            }

            for (int i = 0; i < fingers.GetLength(0); i++)
            {
                if (i < fingerPositions.GetLength(0))
                {
                    fingers [i].transform.position = fingerPositions [i];
                    if (fingers [i].GetComponent <Renderer>().enabled == false)
                    {
                        fingers [i].GetComponent <Renderer>().enabled = true;
                    }

                    if (colliders != null && i < colliders.GetLength(0))
                    {
                        (colliders [i].GetComponent(typeof(SphereCollider)) as SphereCollider).enabled = true;
                    }
                }
                else
                {
                    fingers [i].GetComponent <Renderer>().enabled = false;
                    if (colliders != null && i < colliders.GetLength(0))
                    {
                        (colliders [i].GetComponent(typeof(SphereCollider)) as SphereCollider).enabled = false;
                    }
                }
            }
        }
        else
        {
            gameObject.GetComponent <Renderer>().enabled = false;

            foreach (GameObject finger in fingers)
            {
                if (finger.GetComponent <Renderer>().enabled == true)
                {
                    finger.GetComponent <Renderer>().enabled = false;
                }
            }
        }
        mouse_x = (int)fingers [1].transform.position.x;
        mouse_y = (int)fingers [1].transform.position.y;
        Debug.Log(mouse_x);
        if (timer > 1)
        {
            if (counter >= 12)
            {
                pinchAns = 1;
            }
            else if (counter <= -12)
            {
                pinchAns = -1;
            }
            else
            {
                pinchAns = 0;
            }
            timer   = 0;
            counter = 0;
        }
        timer += Time.deltaTime * 1;
        if (fingers [0].GetComponent <Renderer>().enabled&& fingers [1].GetComponent <Renderer>().enabled)
        {
            pintiV = Vector3.Distance(fingers [0].transform.position, fingers [1].transform.position);
            if (pintiV > pintiVa)
            {
                counter++;
            }
            else
            {
                counter--;
            }
            pintiVa = pintiV;
        }
    }