Ejemplo n.º 1
0
        private bool BackPressed()
        {
            if (controllerIndex >= uint.MaxValue)
            {
                return(false);
            }

            if (canPress && VRTK_SDK_Bridge.IsTriggerPressedOnIndex(controllerIndex) && VRTK_SDK_Bridge.IsGripPressedOnIndex(controllerIndex) && VRTK_SDK_Bridge.IsButtonOnePressedOnIndex(controllerIndex))
            {
                return(true);
            }
            return(false);
        }
Ejemplo n.º 2
0
    private IEnumerator Overlay()
    {
        yield return(null);

#if VRTK_DEFINE_SDK_STEAMVR
        if (VRTK_SDK_Bridge.GetSystemSDK() is SDK_SteamVRSystem)
        {
            // Wait until we have tracking.
            var hmd = SteamVR_Controller.Input((int)Valve.VR.OpenVR.k_unTrackedDeviceIndex_Hmd);
            while (!hmd.hasTracking)
            {
                yield return(null);
            }
        }
#endif

        yield return(new WaitForSecondsRealtime(0.5f));

        Transform headset = null;
        do
        {
            yield return(null);

            headset = VRTK_DeviceFinder.HeadsetTransform();
        }while (headset == null);

        // pos and orientation
        var headPos    = headset.position;
        var pos        = headPos;
        var lookVector = Vector3.ProjectOnPlane(headset.forward, Vector3.up).normalized;
        pos += lookVector * distance;
        transform.position = pos;
        transform.forward  = pos - headPos;

        // logos
        for (int i = 0; i < logos.Count; ++i)
        {
            spriteRend.sprite = logos[i].sprite;
            Vector3 rendScale = spriteRend.transform.localScale;
            spriteRend.transform.localScale = logos[i].scale * rendScale;

            float alpha     = 0;
            float fadeStart = Time.time;
            while (alpha < 1)
            {
                alpha            = 1 - GetFadeAlpha(logos[i].fadeIn, fadeStart, Time.time);
                spriteRend.color = logos[i].color * new Color(1, 1, 1, alpha);
                yield return(null);
            }

            float dur = logos[i].duration;
            if (includeFadesInDuration)
            {
                dur -= logos[i].fadeIn + logos[i].fadeOut;
            }
            dur = Mathf.Max(0, dur);
            yield return(new WaitForSeconds(dur));

            fadeStart = Time.time;
            while (alpha > 0)
            {
                alpha            = GetFadeAlpha(logos[i].fadeOut, fadeStart, Time.time);
                spriteRend.color = logos[i].color * new Color(1, 1, 1, alpha);
                yield return(null);
            }

            spriteRend.transform.localScale = rendScale;
        }

        onFinished.Invoke();
    }
Ejemplo n.º 3
0
 private bool ForwardPressed()
 {
     if (controllerIndex >= uint.MaxValue)
     {
         return(false);
     }
     if (canPress && VRTK_SDK_Bridge.IsTriggerPressedOnIndex(controllerIndex) && VRTK_SDK_Bridge.IsGripPressedOnIndex(controllerIndex) && VRTK_SDK_Bridge.IsTouchpadPressedOnIndex(controllerIndex))
     {
         return(true);
     }
     return(false);
 }
Ejemplo n.º 4
0
        //-------------------------------------------------
        //private void HandAttachedUpdate(Hand hand)
        private void Update()
        {
            if (!isGrab)
            {
                return;
            }
            // Reset transform since we cheated it right after getting poses on previous frame
            transform.localPosition = Vector3.zero;
            transform.localRotation = Quaternion.identity;

            // Update handedness guess
            //EvaluateHandedness();

            if (nocked)
            {
                deferNewPoses = true;

                Vector3 nockToarrowHand = (arrowHand.arrowNockTransform.parent.position - nockRestTransform.position); // Vector from bow nock transform to arrowhand nock transform - used to align bow when drawing

                // Align bow
                // Time lerp value used for ramping into drawn bow orientation
                float lerp = Util.RemapNumberClamped(Time.time, nockLerpStartTime, (nockLerpStartTime + lerpDuration), 0f, 1f);

                float pullLerp = Util.RemapNumberClamped(nockToarrowHand.magnitude, minPull, maxPull, 0f, 1f); // Normalized current state of bow draw 0 - 1

                //Vector3 arrowNockTransformToHeadset = ((Player.instance.hmdTransform.position + (Vector3.down * 0.05f)) - arrowHand.arrowNockTransform.parent.position).normalized;

                Vector3 arrowNockTransformToHeadset = ((VRTK_SDK_Bridge.GetHeadset().position + (Vector3.down * 0.05f)) - arrowHand.arrowNockTransform.parent.position).normalized;
                Vector3 arrowHandPosition           = (arrowHand.arrowNockTransform.parent.position + ((arrowNockTransformToHeadset * drawOffset) * pullLerp)); // Use this line to lerp arrowHand nock position
                                                                                                                                                                //Vector3 arrowHandPosition = arrowHand.arrowNockTransform.position; // Use this line if we don't want to lerp arrowHand nock position

                Vector3 pivotToString      = (arrowHandPosition - pivotTransform.position).normalized;
                Vector3 pivotToLowerHandle = (handleTransform.position - pivotTransform.position).normalized;
                bowLeftVector           = -Vector3.Cross(pivotToLowerHandle, pivotToString);
                pivotTransform.rotation = Quaternion.Lerp(nockLerpStartRotation, Quaternion.LookRotation(pivotToString, bowLeftVector), lerp);

                // Move nock position
                if (Vector3.Dot(nockToarrowHand, -nockTransform.forward) > 0)
                {
                    float distanceToarrowHand = nockToarrowHand.magnitude * lerp;

                    nockTransform.localPosition = new Vector3(0f, 0f, Mathf.Clamp(-distanceToarrowHand, -maxPull, 0f));

                    nockDistanceTravelled = -nockTransform.localPosition.z;

                    arrowVelocity = Util.RemapNumber(nockDistanceTravelled, minPull, maxPull, arrowMinVelocity, arrowMaxVelocity);

                    drawTension = Util.RemapNumberClamped(nockDistanceTravelled, 0, maxPull, 0f, 1f);

                    //this.bowDrawLinearMapping.value = drawTension; // Send drawTension value to LinearMapping script, which drives the bow draw animation
                    longBowAni.Play(0, 0, drawTension);

                    if (nockDistanceTravelled > minPull)
                    {
                        pulled = true;
                    }
                    else
                    {
                        pulled = false;
                    }

                    if ((nockDistanceTravelled > (lastTickDistance + hapticDistanceThreshold)) || nockDistanceTravelled < (lastTickDistance - hapticDistanceThreshold))
                    {
                        ushort hapticStrength = (ushort)Util.RemapNumber(nockDistanceTravelled, 0, maxPull, bowPullPulseStrengthLow, bowPullPulseStrengthHigh);
                        ///手柄震动
                        VRTK_SDK_Bridge.HapticPulse(VRTK_ControllerReference.GetControllerReference(hand), hapticStrength);
                        VRTK_SDK_Bridge.HapticPulse(VRTK_ControllerReference.GetControllerReference(otherHand), hapticStrength);
                        //hand.controller.TriggerHapticPulse(hapticStrength);
                        //hand.otherHand.controller.TriggerHapticPulse(hapticStrength);

                        drawSound.PlayBowTensionClicks(drawTension);

                        lastTickDistance = nockDistanceTravelled;
                    }

                    if (nockDistanceTravelled >= maxPull)
                    {
                        if (Time.time > nextStrainTick)
                        {
                            //hand.controller.TriggerHapticPulse(400);
                            //hand.otherHand.controller.TriggerHapticPulse(400);
                            VRTK_SDK_Bridge.HapticPulse(VRTK_ControllerReference.GetControllerReference(hand), 400);
                            VRTK_SDK_Bridge.HapticPulse(VRTK_ControllerReference.GetControllerReference(otherHand), 400);

                            drawSound.PlayBowTensionClicks(drawTension);

                            nextStrainTick = Time.time + Random.Range(minStrainTickTime, maxStrainTickTime);
                        }
                    }
                }
                else
                {
                    nockTransform.localPosition = new Vector3(0f, 0f, 0f);

                    //this.bowDrawLinearMapping.value = 0f;
                    longBowAni.Play(0, 0, 0);
                }
            }
            else
            {
                if (lerpBackToZeroRotation)
                {
                    float lerp = Util.RemapNumber(Time.time, lerpStartTime, lerpStartTime + lerpDuration, 0, 1);

                    pivotTransform.localRotation = Quaternion.Lerp(lerpStartRotation, Quaternion.identity, lerp);

                    if (lerp >= 1)
                    {
                        lerpBackToZeroRotation = false;
                    }
                }
            }
        }
        public override bool IsConditionOccuring(SDK_BaseGestureLibrary.Hand specificHand, AdvancedGesture advancedGestureInfo)
        {
            SDK_BaseGestureLibrary currentLibrary = VRTK.VRTK_SDK_Bridge.GetHandSDK().GetGestureLibrary();

            if (currentLibrary == null)
            {
                Debug.LogWarning("No gesture library detected for the current Hand SDK");
                return(false);
            }
            Vector3 palmNormal = currentLibrary.GetHandNormal(specificHand);

            if (palmNormal == Vector3.zero)
            {
                // hand tracking lost
                return(false);
            }
            // otherVec is a normal vector that will be compared to the palm vector
            Vector3    otherVec;
            Quaternion rotationToUse = Quaternion.Euler(eulerRotationFromOtherVector);

            if (otherVectorToUse == OtherVector.World)
            {
                switch (otherVectorDirection)
                {
                case VectorType.Forward:
                {
                    otherVec = rotationToUse * Vector3.forward;
                    break;
                }

                case VectorType.Up:
                {
                    otherVec = rotationToUse * Vector3.up;
                    break;
                }

                default:
                {
                    otherVec = rotationToUse * Vector3.up;
                    break;
                }
                }
            }
            else if (otherVectorToUse == OtherVector.Hmd)
            {
                Transform hmd = VRTK_SDK_Bridge.GetHeadset();
                switch (otherVectorDirection)
                {
                case VectorType.Forward:
                {
                    otherVec = hmd.TransformDirection(rotationToUse * Vector3.forward);
                    break;
                }

                case VectorType.Up:
                {
                    otherVec = hmd.TransformDirection(rotationToUse * Vector3.up);
                    break;
                }

                default:
                {
                    otherVec = hmd.TransformDirection(rotationToUse * Vector3.up);
                    break;
                }
                }
            }
            else
            {
                // for whatever reason, otherVec is undefined. return false
                return(false);
            }

            float dotProduct = Vector3.Dot(otherVec, palmNormal);

            // close to 1 -> similar direction
            return(dotProduct >= 1 - tolerance);
        }
        public override bool IsGestureOccuring(SDK_BaseGestureLibrary.Hand specificHand)
        {
            // if not detected, it cannot be gesturing
            if (VRTK_SDK_Bridge.GetHandSDK().GetGestureLibrary() != null && !VRTK_SDK_Bridge.GetHandSDK().GetGestureLibrary().IsHandDetected(specificHand))
            {
                return(false);
            }

            // OpenMG has a habit of claiming gestures are occuring at the start of the scene before hands are even detected.
            // this delay ensures that no gesture fire until the system is fully started
            if (Time.time < startupDelayTime)
            {
                return(false);
            }

            // If this is not the specified hand, then the gesture cannot be occuring
            if (advancedGestureStateList[currentGestureStateIndex].coreGesture.handSpecific &&
                advancedGestureStateList[currentGestureStateIndex].coreGesture.specificHand != specificHand)
            {
                return(false);
            }

            if (!allowedWhileHoldingObjects)
            {
                if (IsHoldingObject(SDK_BaseGestureLibrary.Hand.Left) || IsHoldingObject(SDK_BaseGestureLibrary.Hand.Right))
                {
                    return(false);
                }
            }

            bool isCooldownActive = Time.time <= (gestureCooldownStartTime + gestureCooldown);

            // Condition for cooldown has not been met
            if (!isCooldownActive)
            {
                cooldownHasStarted = false;
            }

            // Check core gesture first
            bool isCurrentStateOccuring = advancedGestureStateList[currentGestureStateIndex].coreGesture.IsGestureOccuring(specificHand);

            // If the core gesture is occuring, then start checking the rest of the avanced gesture states
            if (isCurrentStateOccuring)
            {
                if (!gestureHasStarted)
                {
                    gestureHasStarted = true;
                    gestureStartTime  = Time.time;
                }

                // Check every Advanced Gesture Condition for the current Gesture State
                foreach (AdvancedGestureCondition advCondition in advancedGestureStateList[currentGestureStateIndex].AdvancedGestureConditionList)
                {
                    isCurrentStateOccuring = isCurrentStateOccuring && advCondition.IsConditionOccuring(specificHand, this);
                }

                // Core gesture and all advanced Gesture States have been satisifed
                if (isCurrentStateOccuring && advancedGestureStateList.Count == currentGestureStateIndex + 1)
                {
                    // Gesture hasn't triggered the cool down yet, after this frame, that will change
                    if (!isCooldownActive && !cooldownHasStarted)
                    {
                        gestureCooldownStartTime = Time.time;
                        cooldownHasStarted       = true;

                        return(true);
                    }
                    // Gesture is in cooldown, but the user hasn't released the first occurrence of the gesture
                    else if (gestureStartTime <= gestureCooldownStartTime)
                    {
                        return(true);
                    }
                    // Gesture is in cooldown, so the gesture cannot occur
                    else
                    {
                        return(false);
                    }
                }
                // Core gesture has occured, but not every Gesture State has occured yet
                else if (isCurrentStateOccuring)
                {
                    currentGestureStateIndex++;
                    prevLeftPalmPosition  = GetLeftHandPosition();
                    prevRightPalmPosition = GetRightHandPosition();
                }
                else
                {
                    if (advancedGestureStateList[currentGestureStateIndex].holdTime != 0 && advancedGestureStateList[currentGestureStateIndex].holdTime + gestureStartTime <= Time.time)
                    {
                        ResetGestureChain();
                    }

                    return(false);
                }
            }
            // Core gesture is not occuring
            else
            {
                gestureHasStarted = false;

                return(false);
            }

            // The advanced gesture is not occuring
            return(false);
        }
Ejemplo n.º 7
0
 protected virtual void ReleaseBlink()
 {
     VRTK_SDK_Bridge.HeadsetFade(Color.clear, _fadeInTime);
 }