Esempio n. 1
0
 //-------------------------------------------------
 // Called every Update() while a Hand is hovering over this object
 //-------------------------------------------------
 private void HandHoverUpdate(VRTRIXGloveGrab hand)
 {
     //Debug.Log(VRTRIXGloveVRInteraction.GetGesture(hand.GetHandType()));
     if (hand.GetStandardInteractionButtonDown())
     {
         if (hand.currentAttachedObject != gameObject)
         {
             isHoveredbyHand = true;
             //Call this to continue receiving HandHoverUpdate messages,
             // and prevent the hand from hovering over anything else
             hand.HoverLock(GetComponent <VRTRIXInteractable>());
             if (hand.GetHandType() == HANDTYPE.LEFT_HAND)
             {
                 // Attach this object to the left hand
                 //hand.AttachObject(gameObject, attachmentFlags);
                 hand.AttachLongBow(gameObject, attachmentFlags, "L_Middle_1");
                 gameObject.transform.localPosition = new Vector3(-0.311f, 0.072f, 0.04f);
                 gameObject.transform.localRotation = Quaternion.Euler(0, 200f, 90f);
             }
             else if (hand.GetHandType() == HANDTYPE.RIGHT_HAND)
             {
                 hand.AttachLongBow(gameObject, attachmentFlags, "R_Middle_1");
                 gameObject.transform.localPosition = new Vector3(-0.311f, 0.072f, 0.04f);
                 gameObject.transform.localRotation = Quaternion.Euler(0, -20f, -90f);
             }
         }
     }
 }
        //-------------------------------------------------
        private Transform GetPointerStartTransform(VRTRIXGloveGrab hand)
        {
            //if (hand.noSteamVRFallbackCamera != null)
            //{
            //    return hand.noSteamVRFallbackCamera.transform;
            //}
            //else
            //{

            if (hand.GetHandType() == HANDTYPE.LEFT_HAND)
            {
                return(GameObject.Find("L_Middle_3").transform);
            }
            else if (hand.GetHandType() == HANDTYPE.RIGHT_HAND)
            {
                return(GameObject.Find("R_Middle_3").transform);
            }
            return(null);
            //}
        }
Esempio n. 3
0
        //-------------------------------------------------
        private void EvaluateHandedness()
        {
            HANDTYPE handType = hand.GetHandType();

            if (handType == HANDTYPE.LEFT_HAND)// Bow hand is further left than arrow hand.
            {
                // We were considering a switch, but the current controller orientation matches our currently assigned handedness, so no longer consider a switch
                if (possibleHandSwitch && currentHandGuess == Handedness.Left)
                {
                    possibleHandSwitch = false;
                }

                // If we previously thought the bow was right-handed, and were not already considering switching, start considering a switch
                if (!possibleHandSwitch && currentHandGuess == Handedness.Right)
                {
                    possibleHandSwitch       = true;
                    timeOfPossibleHandSwitch = Time.time;
                }

                // If we are considering a handedness switch, and it's been this way long enough, switch
                if (possibleHandSwitch && Time.time > (timeOfPossibleHandSwitch + timeBeforeConfirmingHandSwitch))
                {
                    currentHandGuess   = Handedness.Left;
                    possibleHandSwitch = false;
                }
            }
            else // Bow hand is further right than arrow hand
            {
                // We were considering a switch, but the current controller orientation matches our currently assigned handedness, so no longer consider a switch
                if (possibleHandSwitch && currentHandGuess == Handedness.Right)
                {
                    possibleHandSwitch = false;
                }

                // If we previously thought the bow was right-handed, and were not already considering switching, start considering a switch
                if (!possibleHandSwitch && currentHandGuess == Handedness.Left)
                {
                    possibleHandSwitch       = true;
                    timeOfPossibleHandSwitch = Time.time;
                }

                // If we are considering a handedness switch, and it's been this way long enough, switch
                if (possibleHandSwitch && Time.time > (timeOfPossibleHandSwitch + timeBeforeConfirmingHandSwitch))
                {
                    currentHandGuess   = Handedness.Right;
                    possibleHandSwitch = false;
                }
            }
        }
Esempio n. 4
0
        //-------------------------------------------------
        private void UpdatePointer()
        {
            Vector3 pointerStart = pointerStartTransform.position;
            Vector3 pointerEnd;
            Vector3 pointerDir          = (pointerHand.GetHandType() == HANDTYPE.RIGHT_HAND) ? pointerStartTransform.right : -pointerStartTransform.right;
            bool    hitSomething        = false;
            bool    showPlayAreaPreview = false;
            Vector3 playerFeetOffset    = player.trackingOriginTransform.position - player.feetPositionGuess;

            Vector3 arcVelocity = pointerDir * arcDistance;

            VRTRIXTeleportMarkerBase hitTeleportMarker = null;

            //Check pointer angle
            float dotUp             = Vector3.Dot(pointerDir, Vector3.up);
            float dotForward        = Vector3.Dot(pointerDir, player.hmdTransform.forward);
            bool  pointerAtBadAngle = false;

            if ((dotForward > 0 && dotUp > 0.75f) || (dotForward < 0.0f && dotUp > 0.5f))
            {
                pointerAtBadAngle = true;
            }

            //Trace to see if the pointer hit anything
            RaycastHit hitInfo;

            teleportArc.SetArcData(pointerStart, arcVelocity, true, pointerAtBadAngle);
            if (teleportArc.DrawArc(out hitInfo))
            {
                hitSomething      = true;
                hitTeleportMarker = hitInfo.collider.GetComponentInParent <VRTRIXTeleportMarkerBase>();
            }

            if (pointerAtBadAngle)
            {
                hitTeleportMarker = null;
            }

            HighlightSelected(hitTeleportMarker);

            if (hitTeleportMarker != null) //Hit a teleport marker
            {
                if (hitTeleportMarker.locked)
                {
                    teleportArc.SetColor(pointerLockedColor);
#if (UNITY_5_4)
                    pointerLineRenderer.SetColors(pointerLockedColor, pointerLockedColor);
#else
                    pointerLineRenderer.startColor = pointerLockedColor;
                    pointerLineRenderer.endColor   = pointerLockedColor;
#endif
                    destinationReticleTransform.gameObject.SetActive(false);
                }
                else
                {
                    teleportArc.SetColor(pointerValidColor);
#if (UNITY_5_4)
                    pointerLineRenderer.SetColors(pointerValidColor, pointerValidColor);
#else
                    pointerLineRenderer.startColor = pointerValidColor;
                    pointerLineRenderer.endColor   = pointerValidColor;
#endif
                    destinationReticleTransform.gameObject.SetActive(hitTeleportMarker.showReticle);
                }

                offsetReticleTransform.gameObject.SetActive(true);

                invalidReticleTransform.gameObject.SetActive(false);
                Debug.Log("hitTeleportMarker: " + hitTeleportMarker);
                pointedAtTeleportMarker = hitTeleportMarker;
                pointedAtPosition       = hitInfo.point;

                if (showPlayAreaMarker)
                {
                    //Show the play area marker if this is a teleport area
                    VRTRIXGloveTelportArea teleportArea = pointedAtTeleportMarker as VRTRIXGloveTelportArea;
                    if (teleportArea != null && !teleportArea.locked && playAreaPreviewTransform != null)
                    {
                        Vector3 offsetToUse = playerFeetOffset;

                        //Adjust the actual offset to prevent the play area marker from moving too much
                        if (!movedFeetFarEnough)
                        {
                            float distanceFromStartingOffset = Vector3.Distance(playerFeetOffset, startingFeetOffset);
                            if (distanceFromStartingOffset < 0.1f)
                            {
                                offsetToUse = startingFeetOffset;
                            }
                            else if (distanceFromStartingOffset < 0.4f)
                            {
                                offsetToUse = Vector3.Lerp(startingFeetOffset, playerFeetOffset, (distanceFromStartingOffset - 0.1f) / 0.3f);
                            }
                            else
                            {
                                movedFeetFarEnough = true;
                            }
                        }

                        playAreaPreviewTransform.position = pointedAtPosition + offsetToUse;

                        showPlayAreaPreview = true;
                    }
                }

                pointerEnd = hitInfo.point;
            }
            else //Hit neither
            {
                destinationReticleTransform.gameObject.SetActive(false);
                offsetReticleTransform.gameObject.SetActive(false);

                teleportArc.SetColor(pointerInvalidColor);
#if (UNITY_5_4)
                pointerLineRenderer.SetColors(pointerInvalidColor, pointerInvalidColor);
#else
                pointerLineRenderer.startColor = pointerInvalidColor;
                pointerLineRenderer.endColor   = pointerInvalidColor;
#endif
                invalidReticleTransform.gameObject.SetActive(!pointerAtBadAngle);

                //Orient the invalid reticle to the normal of the trace hit point
                Vector3 normalToUse = hitInfo.normal;
                float   angle       = Vector3.Angle(hitInfo.normal, Vector3.up);
                if (angle < 15.0f)
                {
                    normalToUse = Vector3.up;
                }
                invalidReticleTargetRotation     = Quaternion.FromToRotation(Vector3.up, normalToUse);
                invalidReticleTransform.rotation = Quaternion.Slerp(invalidReticleTransform.rotation, invalidReticleTargetRotation, 0.1f);

                //Scale the invalid reticle based on the distance from the player
                float distanceFromPlayer         = Vector3.Distance(hitInfo.point, player.hmdTransform.position);
                float invalidReticleCurrentScale = Util.RemapNumberClamped(distanceFromPlayer, invalidReticleMinScaleDistance, invalidReticleMaxScaleDistance, invalidReticleMinScale, invalidReticleMaxScale);
                invalidReticleScale.x = invalidReticleCurrentScale;
                invalidReticleScale.y = invalidReticleCurrentScale;
                invalidReticleScale.z = invalidReticleCurrentScale;
                invalidReticleTransform.transform.localScale = invalidReticleScale;

                pointedAtTeleportMarker = null;

                if (hitSomething)
                {
                    pointerEnd = hitInfo.point;
                }
                else
                {
                    pointerEnd = teleportArc.GetArcPositionAtTime(teleportArc.arcDuration);
                }

                //Debug floor
                if (debugFloor)
                {
                    floorDebugSphere.gameObject.SetActive(false);
                    floorDebugLine.gameObject.SetActive(false);
                }
            }

            if (playAreaPreviewTransform != null)
            {
                playAreaPreviewTransform.gameObject.SetActive(showPlayAreaPreview);
            }

            if (!showOffsetReticle)
            {
                offsetReticleTransform.gameObject.SetActive(false);
            }

            destinationReticleTransform.position = pointedAtPosition;
            invalidReticleTransform.position     = pointerEnd;
            onActivateObjectTransform.position   = pointerEnd;
            onDeactivateObjectTransform.position = pointerEnd;
            offsetReticleTransform.position      = pointerEnd - playerFeetOffset;

            reticleAudioSource.transform.position = pointedAtPosition;

            pointerLineRenderer.SetPosition(0, pointerStart);
            pointerLineRenderer.SetPosition(1, pointerEnd);
        }