GetControllerPositionTracked() 공개 정적인 메소드

Returns true if the given Controller's position is currently tracked. Only supported for Oculus LTouch and RTouch controllers. Non-tracked controllers will return false.
public static GetControllerPositionTracked ( OVRInput, controllerType ) : bool
controllerType OVRInput,
리턴 bool
예제 #1
0
    private void LateUpdate()
    {
        // If the handset is held with right hand or left hand
        leftHanded = OVRInput.GetControllerPositionTracked(OVRInput.Controller.LTouch);
        OVRInput.Controller c = leftHanded ? OVRInput.Controller.LTouch : OVRInput.Controller.RTouch;

        if (OVRInput.GetControllerPositionTracked(c) && !isDead)
        {
            // Rotating the player spine according to handset rotation
            spine.transform.rotation      = OVRInput.GetLocalControllerRotation(c);
            spine.transform.localRotation = spineInitialLocalRotation * spine.transform.localRotation;

            if (Quaternion.Angle(Quaternion.identity, spine.transform.localRotation) > 30.0f) // Limiting the spine rotation
            {
                Quaternion currentLocalRotation = spine.transform.localRotation;
                spine.transform.localRotation = Quaternion.Slerp(Quaternion.identity, currentLocalRotation, 30.0f / Quaternion.Angle(Quaternion.identity, spine.transform.localRotation)); //Spherical interpolation of the spine rotation
            }
        }


        if (!isDead) // Rotating the character according to headset rotation.
        {
            transform.rotation = Quaternion.LookRotation(new Vector3(CameraObject.transform.forward.x, 0.0f, CameraObject.transform.forward.z).normalized, Vector3.up);
        }

        if (!isDead) // Moving the camera to a predifined position according to spine position and rotation
        {
            CameraParent.transform.position = CameraPlace.transform.position;
        }
        else // Moving camera to a fixed point when the player is killed
        {
            CameraParent.transform.position = cameraFinalPos.transform.position;
        }
    }
예제 #2
0
        private void SendTrackingEvents(OVRInput.Controller ovrController, int ovrIndex, int deviceIndex)
        {
            if (!OVRInput.GetControllerPositionTracked(ovrController))
            {
                return;
            }

            var localPosition = OVRInput.GetLocalControllerPosition(ovrController);
            var localRotation = OVRInput.GetLocalControllerRotation(ovrController);

            if (localPosition == m_LastPositionValues[ovrIndex] && localRotation == m_LastRotationValues[ovrIndex])
            {
                return;
            }

            var inputEvent = InputSystem.CreateEvent <VREvent>();

            inputEvent.deviceType    = typeof(VRInputDevice);
            inputEvent.deviceIndex   = deviceIndex;
            inputEvent.localPosition = localPosition;
            inputEvent.localRotation = localRotation;

            m_LastPositionValues[ovrIndex] = inputEvent.localPosition;
            m_LastRotationValues[ovrIndex] = inputEvent.localRotation;

            InputSystem.QueueEvent(inputEvent);
        }
예제 #3
0
        //records controller transforms from either interaction player or behaviour poses
        static void InitializeControllers()
        {
            if (controllers == null)
            {
                controllers = new ControllerInfo[2];
            }

            if (controllers[0] == null)
            {
                controllers[0] = new ControllerInfo()
                {
                    transform = CameraRig.leftHandAnchor, isRight = false, id = 1
                };
                controllers[0].connected = OVRInput.IsControllerConnected(OVRInput.Controller.LTouch);
                controllers[0].visible   = OVRInput.GetControllerPositionTracked(OVRInput.Controller.LTouch);
            }

            if (controllers[1] == null)
            {
                controllers[1] = new ControllerInfo()
                {
                    transform = CameraRig.rightHandAnchor, isRight = true, id = 2
                };
                controllers[1].connected = OVRInput.IsControllerConnected(OVRInput.Controller.RTouch);
                controllers[1].visible   = OVRInput.GetControllerPositionTracked(OVRInput.Controller.RTouch);
            }
        }
예제 #4
0
        void Update()
        {
            //TODO move this stuff into cognitivevr_manager and get states from there
            if (!OVRInput.GetControllerPositionTracked(OVRInput.Controller.RTouch) && RightControllerVisible)
            {
                RightControllerVisible = false;
                new CustomEvent("cvr.tracking").SetProperty("device", "right controller").SetProperty("visible", false).Send();
            }
            if (OVRInput.GetControllerPositionTracked(OVRInput.Controller.RTouch) && !RightControllerVisible)
            {
                new CustomEvent("cvr.tracking").SetProperty("device", "right controller").SetProperty("visible", true).Send();
                RightControllerVisible = true;
            }

            if (!OVRInput.GetControllerPositionTracked(OVRInput.Controller.LTouch) && LeftControllerVisible)
            {
                LeftControllerVisible = false;
                new CustomEvent("cvr.tracking").SetProperty("device", "left controller").SetProperty("visible", false).Send();
            }
            if (OVRInput.GetControllerPositionTracked(OVRInput.Controller.LTouch) && !LeftControllerVisible)
            {
                new CustomEvent("cvr.tracking").SetProperty("device", "left controller").SetProperty("visible", true).Send();
                LeftControllerVisible = true;
            }
        }
예제 #5
0
        bool IsTracked_Oculus()
        {
            if (string.IsNullOrEmpty(context.Data.trackedByDevice))
            {
                return(false);
            }

            try {
                OVRInput.Controller controller = OVRInput.Controller.None;
                if (context.Data.trackedByDevice == "Device1")
                {
                    controller = OVRInput.Controller.LTouch;
                }
                else if (context.Data.trackedByDevice == "Device2")
                {
                    controller = OVRInput.Controller.RTouch;
                }

                return(OVRInput.IsControllerConnected(controller) && OVRInput.GetControllerPositionTracked(controller) && OVRInput.GetControllerOrientationTracked(controller));
            }
            catch (System.Exception)
            {
                return(false);
            }
        }
예제 #6
0
    void Awake()
    {
#if UNITY_EDITOR
        leftHanded = false; // (whichever you want to test here)
#else
        leftHanded = OVRInput.GetControllerPositionTracked(OVRInput.Controller.LTrackedRemote);
#endif
    }
예제 #7
0
 void Update()
 {
     OVRInput.Controller c = leftHanded ? OVRInput.Controller.LTrackedRemote : OVRInput.Controller.RTrackedRemote;
     if (OVRInput.GetControllerPositionTracked(c))
     {
         controller.localRotation = OVRInput.GetLocalControllerRotation(c);
         controller.localPosition = OVRInput.GetLocalControllerPosition(c);
     }
 }
예제 #8
0
 protected void UpdateController(OVRInput.Controller controller, Handedness handedness)
 {
     if (OVRInput.IsControllerConnected(controller) && OVRInput.GetControllerPositionTracked(controller))
     {
         var touchController = GetOrAddController(handedness);
         touchController.UpdateController(controller, cameraRig.trackingSpace);
     }
     else
     {
         RemoveControllerDevice(handedness);
     }
 }
예제 #9
0
    void Update()
    {
        OVRInput.Controller c = leftHanded ? OVRInput.Controller.LTouch : OVRInput.Controller.RTouch;
        if (OVRInput.GetControllerPositionTracked(c))
        {
            //controller.localRotation = OVRInput.GetLocalControllerRotation(c);
            //controller.localPosition = OVRInput.GetLocalControllerPosition(c);

            //controllerRotation = controller.localRotation;


            rotation = OVRInput.GetLocalControllerRotation(c);
            //Debug.Log("ControllerRotation: " + rotation.ToString());
        }
    }
예제 #10
0
        /// Updates IsTrackedObjectValid and Behavior.transform
        public void UpdatePosesAndValidity()
        {
            // OVRInput.Controller.Touch checks both (LTouch | RTouch)
            bool bothTouchControllersConnected =
                (OVRInput.GetConnectedControllers() & OVRInput.Controller.Touch)
                == OVRInput.Controller.Touch;

            OVRInput.Controller input = m_ControllerType;
            IsTrackedObjectValid = OVRInput.GetControllerOrientationTracked(input) ||
                                   OVRInput.GetControllerPositionTracked(input) &&
                                   bothTouchControllersConnected;
            Transform t = Behavior.transform;

            t.localRotation = OVRInput.GetLocalControllerRotation(input);
            t.localPosition = OVRInput.GetLocalControllerPosition(input);
        }
예제 #11
0
 public static bool IsSpatialDeviceTracked(int i)
 {
     if (CurrentVRDevice == Device.OculusRift)
     {
         OVRInput.Controller controller = (i == 0) ? OVRInput.Controller.LTouch : OVRInput.Controller.RTouch;
         return(OVRInput.GetControllerPositionTracked(controller));
     }
     else if (CurrentVRDevice == Device.HTCVive)
     {
         var device = (i == 0) ? LeftViveControllerDevice : RightViveControllerDevice;
         return(device.hasTracking);
     }
     else
     {
         return(false);
     }
 }
        bool GetTrackedTransform_Oculus(out Vector3 pos, out Quaternion rot)
        {
            pos = Vector3.zero;
            rot = Quaternion.identity;

            if (string.IsNullOrEmpty(context.Data.trackedByDevice))
            {
                return(false);
            }

            try
            {
                OVRInput.Controller controller = OVRInput.Controller.None;
                if (context.Data.trackedByDevice == "Device1")
                {
                    controller = OVRInput.Controller.LTouch;
                }
                else if (context.Data.trackedByDevice == "Device2")
                {
                    controller = OVRInput.Controller.RTouch;
                }

                if (!OVRInput.IsControllerConnected(controller) || !OVRInput.GetControllerPositionTracked(controller) || !OVRInput.GetControllerOrientationTracked(controller))
                {
                    return(false);
                }

                pos = OVRInput.GetLocalControllerPosition(controller);
                rot = OVRInput.GetLocalControllerRotation(controller);

                if (trackedByOculusDevice != context.Data.trackedByDevice)
                {
                    trackedByOculusDevice = context.Data.trackedByDevice;

                    OnTrackedDeviceSwitchAndReady();
                }

                return(true);
            }
            catch (System.Exception)
            {
                return(false);
            }
        }
예제 #13
0
    void Update()
    {
        if (!ZeldaInput.AreAnyTouchControllersActive())
        {
            return;
        }
        if (!OVRInput.GetControllerPositionTracked(OVRInput.Controller.RTouch))
        {
            return;
        }

        _controllerPos = OVRInput.GetLocalControllerPosition(OVRInput.Controller.RTouch);

        if (_prevControllerPos != Vector3.zero)
        {
            _controllerVelocity = (_controllerPos - _prevControllerPos) / Time.deltaTime;
        }

        //UpdateScale(_controllerVelocity);
    }
예제 #14
0
        void Update()
        {
            if (initResponse != Error.None)
            {
                return;
            }

            Core.InvokeUpdateEvent(Time.deltaTime);
            UpdateSendHotkeyCheck();

#if CVR_STEAMVR || CVR_STEAMVR2
            var system = Valve.VR.OpenVR.System;
            if (system != null)
            {
                var vrEvent = new Valve.VR.VREvent_t();
                var size    = (uint)System.Runtime.InteropServices.Marshal.SizeOf(typeof(Valve.VR.VREvent_t));
                for (int i = 0; i < 64; i++)
                {
                    if (!system.PollNextEvent(ref vrEvent, size))
                    {
                        break;
                    }
                    OnPoseEvent((Valve.VR.EVREventType)vrEvent.eventType);
                }
            }
#endif

#if CVR_OCULUS
            if (GameplayReferences.GetControllerInfo(false, out tempControllerInfo))
            {
                tempControllerInfo.connected = OVRInput.IsControllerConnected(OVRInput.Controller.LTouch);
                tempControllerInfo.visible   = OVRInput.GetControllerPositionTracked(OVRInput.Controller.LTouch);
            }

            if (GameplayReferences.GetControllerInfo(true, out tempControllerInfo))
            {
                tempControllerInfo.connected = OVRInput.IsControllerConnected(OVRInput.Controller.RTouch);
                tempControllerInfo.visible   = OVRInput.GetControllerPositionTracked(OVRInput.Controller.RTouch);
            }
#endif
        }
예제 #15
0
        void Update()
        {
            if (!OVRInput.GetControllerPositionTracked(OVRInput.Controller.RTouch) && string.IsNullOrEmpty(rRouchGUID))
            {
                rRouchGUID = Util.GetUniqueId();
                new CustomEvent("cvr.tracking").SetProperty("device", "right controller").SetProperty("visible", false).Send();
            }
            if (OVRInput.GetControllerPositionTracked(OVRInput.Controller.RTouch) && !string.IsNullOrEmpty(rRouchGUID))
            {
                new CustomEvent("cvr.tracking").SetProperty("device", "right controller").SetProperty("visible", true).Send();
                rRouchGUID = string.Empty;
            }

            if (!OVRInput.GetControllerPositionTracked(OVRInput.Controller.LTouch) && string.IsNullOrEmpty(lTouchGUID))
            {
                lTouchGUID = Util.GetUniqueId();
                new CustomEvent("cvr.tracking").SetProperty("device", "left controller").SetProperty("visible", false).Send();
            }
            if (OVRInput.GetControllerPositionTracked(OVRInput.Controller.LTouch) && !string.IsNullOrEmpty(lTouchGUID))
            {
                new CustomEvent("cvr.tracking").SetProperty("device", "left controller").SetProperty("visible", true).Send();
                lTouchGUID = string.Empty;
            }
        }
예제 #16
0
    void UpdateState()
    {
        if (Side == TxBodyInput.SideType.None)
        {
            return;
        }

        var t = (Side == TxBodyInput.SideType.Right) ? OVRInput.Controller.RTouch : OVRInput.Controller.LTouch;


        float   Index = 0;
        float   Hand  = 0;
        Vector2 Thumb = Vector2.zero;

        if (t == OVRInput.Controller.LTouch)
        {
            Index = OVRInput.Get(OVRInput.Axis1D.PrimaryIndexTrigger);
            Hand  = OVRInput.Get(OVRInput.Axis1D.PrimaryHandTrigger);
            Thumb = OVRInput.Get(OVRInput.Axis2D.PrimaryThumbstick);
        }
        else if (t == OVRInput.Controller.RTouch)
        {
            Index = OVRInput.Get(OVRInput.Axis1D.SecondaryIndexTrigger);
            Hand  = OVRInput.Get(OVRInput.Axis1D.SecondaryHandTrigger);
            Thumb = OVRInput.Get(OVRInput.Axis2D.SecondaryThumbstick);
        }

        if (OVRInput.Get(OVRInput.Button.One, t))
        {
            if (!_APressed)
            {
                AEvent.Invoke();
            }
            _APressed = true;
        }
        else
        {
            _APressed = false;
        }

        if (OVRInput.Get(OVRInput.Button.Two, t))
        {
            if (!_BPressed)
            {
                BEvent.Invoke();
            }
            _BPressed = true;
        }
        else
        {
            _BPressed = false;
        }

        IndexEvent.Invoke(Index);
        HandEvent.Invoke(Hand);
        ThumbEvent.Invoke(Thumb);

        if (!OVRInput.GetControllerPositionTracked(t))
        {
            return;
        }

        _wrist.Position = OVRInput.GetLocalControllerPosition(t);
        _wrist.Rotation = OVRInput.GetLocalControllerRotation(t);

        Wrist.Invoke(_wrist);
    }
예제 #17
0
    // Update is called once per frame
    void Update()
    {
        if (!OVRInput.GetControllerPositionTracked(MyController))
        {
            Debug.Log("No traking");
        }

        Quaternion HandQ = OVRInput.GetLocalControllerRotation(MyController);

        transform.localPosition = OVRInput.GetLocalControllerPosition(MyController) + new Vector3(0f, 0.6f, 0f);
        transform.rotation      = Quaternion.Euler(HandQ.eulerAngles.x, HandQ.eulerAngles.y + HandsParent.plusRot, HandQ.eulerAngles.z);

        if (OVRInput.Get(GrabButton) > 0.5)
        {
            AnimatorHand.SetBool("Grab", true);
            if (PosibleObjectGrab && !ObjectGrab)
            {
                ObjectGrab = PosibleObjectGrab;
                ObjectGrab.transform.position = Vector3.zero;
                ObjectGrab.transform.rotation = Quaternion.identity;
                ObjectGrab.GetComponent <Rigidbody>().useGravity = false;
                ObjectGrab.transform.SetParent(Hand.transform);
                if (ObjectGrab.GetComponent <SphereCollider>())
                {
                    ObjectGrab.GetComponent <SphereCollider>().enabled = false;
                }
                if (ObjectGrab.GetComponent <BoxCollider>())
                {
                    ObjectGrab.GetComponent <BoxCollider>().enabled = false;
                }
            }
        }
        else
        {
            AnimatorHand.SetBool("Grab", false);
            if (ObjectGrab)
            {
                ObjectGrab.GetComponent <Rigidbody>().useGravity = true;
                ObjectGrab.GetComponent <Rigidbody>().velocity   = OVRInput.GetLocalControllerVelocity(MyController);
                ObjectGrab.transform.parent = null;
                if (ObjectGrab.GetComponent <SphereCollider>())
                {
                    ObjectGrab.GetComponent <SphereCollider>().enabled = true;
                }
                if (ObjectGrab.GetComponent <BoxCollider>())
                {
                    ObjectGrab.GetComponent <BoxCollider>().enabled = true;
                }
                ObjectGrab = null;
            }
        }

        if (ObjectGrab)
        {
            ObjectGrab.transform.position = Hand.transform.position;
            ObjectGrab.transform.rotation = Hand.transform.rotation;
            if (OVRInput.Get(AcctionButton) > 0.5)
            {
                ObjectGrab.SendMessage("Touch_Acction");
            }
        }

        if (!PosibleObjectGrab)
        {
            AnimatorHand.SetBool("Interact", false);
        }
        else
        {
            AnimatorHand.SetBool("Interact", true);
        }
    }
예제 #18
0
    private void Update()
    {
        if (OVRInput.GetControllerPositionTracked(LTouch))
        {
            touchControllerLeft.localPosition = OVRInput.GetLocalControllerPosition(LTouch);
            touchControllerLeft.localRotation = OVRInput.GetLocalControllerRotation(LTouch);
        }


        if (OVRInput.GetControllerPositionTracked(RTouch))
        {
            touchControllerRight.localPosition = OVRInput.GetLocalControllerPosition(RTouch);
            touchControllerRight.localRotation = OVRInput.GetLocalControllerRotation(RTouch);
        }

        if (OVRInput.GetDown(OVRInput.Button.One, LTouch))
        {
            Debug.Log("1");
        }

        if (OVRInput.GetDown(OVRInput.Button.Two, LTouch))
        {
            Debug.Log("2");
        }

        if (OVRInput.GetDown(OVRInput.Button.One, RTouch))
        {
            Debug.Log("3");
        }

        if (OVRInput.GetDown(OVRInput.Button.Two, RTouch))
        {
            Debug.Log("4");
        }

        if (OVRInput.GetDown(OVRInput.Button.PrimaryIndexTrigger, LTouch))
        {
            Debug.Log("PrimaryIndexTrigger");
            //raycastController.EmitRaycast(touchControllerLeft.position, touchControllerLeft.forward);
            emitterLeft.StartShooting();
            audioSource.clip = shootSoundLeft;
            audioSource.loop = true;
            audioSource.Play();
        }

        if (OVRInput.GetUp(OVRInput.Button.PrimaryIndexTrigger, LTouch))
        {
            Debug.Log("PrimaryIndexTrigger");
            //raycastController.EmitRaycast(touchControllerLeft.position, touchControllerLeft.forward);
            emitterLeft.StopShooting();
            audioSource.Stop();
        }

        if (OVRInput.GetDown(OVRInput.Button.PrimaryIndexTrigger, RTouch))
        {
            Debug.Log("SecondaryIndexTrigger");
            //raycastController.EmitRaycast(touchControllerRight.position, touchControllerRight.forward);
            emitterRight.StartShooting();
            audioSource.PlayOneShot(shootSoundRight);
        }

        if (OVRInput.GetUp(OVRInput.Button.PrimaryIndexTrigger, RTouch))
        {
            Debug.Log("SecondaryIndexTrigger");
            //raycastController.EmitRaycast(touchControllerRight.position, touchControllerRight.forward);
            emitterRight.StopShooting();
        }

        if (OVRInput.GetDown(OVRInput.Button.PrimaryHandTrigger, LTouch))
        {
            Debug.Log("PrimaryHandTrigger");
        }

        if (OVRInput.GetDown(OVRInput.Button.PrimaryHandTrigger, RTouch))
        {
            Debug.Log("SecondaryHandTrigger");
        }

        if (OVRInput.GetDown(OVRInput.Button.Start))
        {
            Debug.Log("Start");
        }
    }
예제 #19
0
        private bool IsOculusTouchTrackingBone(HumanBodyBones bone)
        {
            // We assume that the left controller is used to track bones on the left side
            // and the right controller is used to track the bones on the right side
            switch (bone)
            {
            // Left bones
            case HumanBodyBones.LeftEye:
            case HumanBodyBones.LeftShoulder:
            case HumanBodyBones.LeftUpperLeg:
            case HumanBodyBones.LeftLowerLeg:
            case HumanBodyBones.LeftFoot:
            case HumanBodyBones.LeftToes:
            case HumanBodyBones.LeftUpperArm:
            case HumanBodyBones.LeftLowerArm:
            case HumanBodyBones.LeftHand:
            case HumanBodyBones.LeftIndexDistal:
            case HumanBodyBones.LeftIndexIntermediate:
            case HumanBodyBones.LeftIndexProximal:
            case HumanBodyBones.LeftLittleDistal:
            case HumanBodyBones.LeftLittleIntermediate:
            case HumanBodyBones.LeftLittleProximal:
            case HumanBodyBones.LeftMiddleDistal:
            case HumanBodyBones.LeftMiddleIntermediate:
            case HumanBodyBones.LeftMiddleProximal:
            case HumanBodyBones.LeftRingDistal:
            case HumanBodyBones.LeftRingIntermediate:
            case HumanBodyBones.LeftRingProximal:
            case HumanBodyBones.LeftThumbDistal:
            case HumanBodyBones.LeftThumbIntermediate:
            case HumanBodyBones.LeftThumbProximal:
                return(OVRInput.GetControllerPositionTracked(OVRInput.Controller.LTouch) && OVRInput.GetControllerOrientationTracked(OVRInput.Controller.LTouch));

            // Right bones
            case HumanBodyBones.RightEye:
            case HumanBodyBones.RightShoulder:

            case HumanBodyBones.RightUpperLeg:
            case HumanBodyBones.RightLowerLeg:
            case HumanBodyBones.RightFoot:
            case HumanBodyBones.RightToes:

            case HumanBodyBones.RightUpperArm:
            case HumanBodyBones.RightLowerArm:
            case HumanBodyBones.RightHand:
            case HumanBodyBones.RightIndexDistal:
            case HumanBodyBones.RightIndexIntermediate:
            case HumanBodyBones.RightIndexProximal:
            case HumanBodyBones.RightLittleDistal:
            case HumanBodyBones.RightLittleIntermediate:
            case HumanBodyBones.RightLittleProximal:
            case HumanBodyBones.RightMiddleDistal:
            case HumanBodyBones.RightMiddleIntermediate:
            case HumanBodyBones.RightMiddleProximal:
            case HumanBodyBones.RightRingDistal:
            case HumanBodyBones.RightRingIntermediate:
            case HumanBodyBones.RightRingProximal:
            case HumanBodyBones.RightThumbDistal:
            case HumanBodyBones.RightThumbIntermediate:
            case HumanBodyBones.RightThumbProximal:
                return(OVRInput.GetControllerPositionTracked(OVRInput.Controller.RTouch) && OVRInput.GetControllerOrientationTracked(OVRInput.Controller.RTouch));

            default:
                Debug.LogWarningFormat("IKTarget IsOculusTouchTrackingBone: Invalid bone for Oculus Touch: {0} - returning false", bone);
                return(false);
            }
        }