示例#1
0
    private Vector3 GetHeadOrientation()
    {
#if UNITY_EDITOR
        Camera cam = Camera.main;
        if (cam == null)
        {
            // Use the first one found.
            cam = Camera.allCameras[0];
        }
        return(cam.transform.forward);
#else
        return(InputTracking.GetLocalRotation(VRNode.Head) * Vector3.forward);
#endif // UNITY_EDITOR
    }
    /// <summary>
    /// Before the ZED is ready, lock the quads in front of the cameras as latency correction isn't available yet.
    /// This allows us to see the loading messages (and other virtual objects if desired) while the ZED is still loading.
    /// Called by Camera.OnPreRender anytime any camera renders.
    /// </summary>
    /// <param name="cam">Cam.</param>
    public void PreRender(Camera cam)
    {
        if (cam == finalLeftEye || cam == finalRightEye)
        {
            if ((!manager.IsZEDReady && manager.IsStereoRig))
            {
                quadLeft.localRotation = InputTracking.GetLocalRotation(XRNode.Head);
                quadLeft.localPosition = InputTracking.GetLocalPosition(XRNode.Head) + quadLeft.localRotation * offset;

                quadRight.localRotation = InputTracking.GetLocalRotation(XRNode.Head);
                quadRight.localPosition = InputTracking.GetLocalPosition(XRNode.Head) + quadRight.localRotation * offset;
            }
        }
    }
        public Quaternion GetLocalRotation(ControllerSide side)
        {
            switch (side)
            {
            case ControllerSide.Left:
                return(InputTracking.GetLocalRotation(XRNode.LeftHand));

            case ControllerSide.Right:
                return(InputTracking.GetLocalRotation(XRNode.RightHand));

            default:
                return(Quaternion.identity);
            }
        }
示例#4
0
    public void Update()
    {
        var lHandPosition = InputTracking.GetLocalPosition(XRNode.LeftHand);
        var lHandRotation = InputTracking.GetLocalRotation(XRNode.LeftHand);

        lHandTrans.localPosition = Vector3.Lerp(lHandTrans.localPosition, lHandPosition, Time.deltaTime * damping);
        lHandTrans.localRotation = Quaternion.Slerp(lHandTrans.localRotation, lHandRotation, Time.deltaTime * rotationDamping);

        var rHandPosition = InputTracking.GetLocalPosition(XRNode.RightHand);
        var rHandRotation = InputTracking.GetLocalRotation(XRNode.RightHand);

        rHandTrans.localPosition = Vector3.Lerp(rHandTrans.localPosition, rHandPosition, Time.deltaTime * damping);
        rHandTrans.localRotation = Quaternion.Slerp(rHandTrans.localRotation, rHandRotation, Time.deltaTime * rotationDamping);
    }
    /// <summary>
    /// Compute the delayed position and rotation from the history stored in the poseData dictionary.
    /// </summary>
    /// <param name="keyindex"></param>
    /// <param name="timeDelay"></param>
    /// <returns></returns>
    private sl.Pose GetValuePosition(int keyindex, float timeDelay)
    {
        sl.Pose p = new sl.Pose();
        if (poseData.ContainsKey(keyindex))
        {
            //Get the saved position & rotation.
            p.translation = poseData[keyindex][poseData[keyindex].Count - 1].position;
            p.rotation    = poseData[keyindex][poseData[keyindex].Count - 1].rotation;

            float idealTS = (Time.time - timeDelay);

            for (int i = 0; i < poseData[keyindex].Count; ++i)
            {
                if (poseData[keyindex][i].timestamp > idealTS)
                {
                    int currentIndex = i;
                    if (currentIndex > 0)
                    {
                        //Calculate the time between the pose and the delayed pose.
                        float timeBetween = poseData[keyindex][currentIndex].timestamp - poseData[keyindex][currentIndex - 1].timestamp;
                        float alpha       = ((Time.time - poseData[keyindex][currentIndex - 1].timestamp) - timeDelay) / timeBetween;

                        //Lerp to the next position based on the time determined above.
                        Vector3    pos = Vector3.Lerp(poseData[keyindex][currentIndex - 1].position, poseData[keyindex][currentIndex].position, alpha);
                        Quaternion rot = Quaternion.Lerp(poseData[keyindex][currentIndex - 1].rotation, poseData[keyindex][currentIndex].rotation, alpha);

                        //Apply new values.
                        p             = new sl.Pose();
                        p.translation = pos;
                        p.rotation    = rot;

                        //Add drift correction, but only if the user hasn't disabled it, it's on an actual controller, and the zedRigRoot position won't be affected.
                        if (correctControllerDrift == true &&
                            (deviceToTrack == Devices.LeftController || deviceToTrack == Devices.RightController) &&
                            (zedManager != null && zedManager.IsStereoRig == true && !zedManager.transform.IsChildOf(transform)))
                        {
                            //Compensate for positional drift by measuring the distance between HMD and ZED rig root (the head's center).
                            Vector3 zedhmdposoffset = zedRigRoot.position - InputTracking.GetLocalPosition(XRNode.Head);
                            p.translation += zedhmdposoffset;
                        }

                        //Removes used elements from the dictionary.
                        poseData[keyindex].RemoveRange(0, currentIndex - 1);
                    }
                    return(p);
                }
            }
        }
        return(p);
    }
        public Vector3 GetLocalPosition(ControllerSide side)
        {
            switch (side)
            {
            case ControllerSide.Left:
                return(InputTracking.GetLocalPosition(XRNode.LeftHand));

            case ControllerSide.Right:
                return(InputTracking.GetLocalPosition(XRNode.RightHand));

            default:
                return(Vector2.zero);
            }
        }
    // Update is called once per frame
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.Q))
        {
            InputTracking.Recenter();
            Debug.Log("Orientation Recentered.");
        }

        if (Input.GetKeyDown(KeyCode.W))
        {
            InputTracking.disablePositionalTracking = !InputTracking.disablePositionalTracking;
            Debug.Log("InputTracking.disablePositionalTracking set to " + InputTracking.disablePositionalTracking);
        }
    }
示例#8
0
    // Update is called once per frame
    void Update()
    {
        Vector3    headsetPos = InputTracking.GetLocalPosition(nodeType);
        Quaternion headsetRot = InputTracking.GetLocalRotation(nodeType);

        transform.localPosition = headsetPos;
        transform.localRotation = headsetRot;

        playerCollider.transform.rotation = Quaternion.identity;
        playerCollider.height             = headsetPos.y / transform.localScale.y + headCollider.radius;
        playerCollider.center             = new Vector3(playerCollider.center.x, -playerCollider.height / 2f + headCollider.radius, playerCollider.center.z);

        //transform.parent.position = Vector3.zero;
    }
示例#9
0
    public void RecordTransforms(float deltaTime)
    {
        var posL = InputTracking.GetLocalPosition(XRNode.LeftHand);
        var posR = InputTracking.GetLocalPosition(XRNode.RightHand);

        var rotL = InputTracking.GetLocalRotation(XRNode.LeftHand);
        var rotR = InputTracking.GetLocalRotation(XRNode.RightHand);

        positionL = Vector3.Lerp(positionL, posL, deltaTime * positionDamping);
        positionR = Vector3.Lerp(positionR, posR, deltaTime * positionDamping);

        rotationL = Quaternion.Slerp(rotationL, rotL, deltaTime * rotationDamping);
        rotationR = Quaternion.Slerp(rotationR, rotR, deltaTime * rotationDamping);
    }
示例#10
0
        protected override void GenerateCurrentStatus()
        {
            //Position and Rotation
            cPos = InputTracking.GetLocalPosition(node);
            cRot = InputTracking.GetLocalRotation(node);

            //Buttons
            cGripAxis    = Input.GetAxis((hand == XRHand.Left ? "L" : "R") + "Grip");
            cTriggerAxis = Input.GetAxis((hand == XRHand.Left ? "L" : "R") + "Trigger");
            string handLabel = this.hand == XRHand.Left ? "L" : "R";

            cThumbstickAxis = new Vector2(Input.GetAxis(handLabel + "ThumbstickX"), Input.GetAxis(handLabel + "ThumbstickY"));;
            cTouchpadAxis   = new Vector2(Input.GetAxis("WMR_" + handLabel + "TouchpadX"), Input.GetAxis("WMR_" + handLabel + "TouchpadY"));
        }
示例#11
0
 private void Awake()
 {
     transform = GetComponent <Transform>();
     InputTracking.Recenter();
     if (useLaserPointer && laserPointerRenderer == null)
     {
         laserPointerRenderer = GetComponent <LineRenderer>();
         if (!laserPointerRenderer)
         {
             print("Requires a line renderer to use laser pointer");
             useLaserPointer = false;
         }
     }
 }
示例#12
0
        void Update()
        {
            // Use Unity XR Input when enabled. When using WebXR, updates are performed onControllerUpdate.
            if (!OUalt.isPresent())
            {
                return;
            }

            SetVisible(true);

            if (this.hand == WebXRControllerHand.LEFT)
            {
                handNode = XRNode.LeftHand;
            }

            if (this.hand == WebXRControllerHand.RIGHT)
            {
                handNode = XRNode.RightHand;
            }

            if (this.simulate3dof)
            {
                _t.localPosition = applyArmModel(
                    InputTracking.GetLocalPosition(XRNode.Head), // we use head position as origin
                    InputTracking.GetLocalRotation(handNode),
                    InputTracking.GetLocalRotation(XRNode.Head));
                _t.localRotation = InputTracking.GetLocalRotation(handNode);
            }
            else
            {
                _t.localPosition = InputTracking.GetLocalPosition(handNode);
                _t.localRotation = InputTracking.GetLocalRotation(handNode);
            }

            foreach (WebXRControllerInput input in inputMap.inputs)
            {
                if (!input.unityInputIsButton)
                {
                    if (Input.GetAxis(input.unityInputName) != 0)
                    {
                        SetButtonState(input.actionName, true, Input.GetAxis(input.unityInputName));
                    }
                    if (Input.GetAxis(input.unityInputName) < 1)
                    {
                        SetButtonState(input.actionName, false, Input.GetAxis(input.unityInputName));
                    }
                }
            }
        }
示例#13
0
    public IEnumerator GazeCheck()
    {
        yield return(SkipFrame(DefaultFrameSkipCount));

        InputTracking.GetNodeStates(xrNodeList);
        yield return(SkipFrame(DefaultFrameSkipCount));

        if (xrNodeList.Count != 0)
        {
            foreach (XRNodeState nodeState in xrNodeList)
            {
                if (nodeState.nodeType == XRNode.CenterEye)
                {
                    nodeState.TryGetPosition(out xrCenterNodePos);
                }
            }

            yield return(SkipFrame(100));

            Ray ray = new Ray(xrCenterNodePos, XrFunctionalTestHelpers.Camera.GetComponent <Camera>().transform.forward);
            Physics.Raycast(ray, 10f);
            yield return(SkipFrame(DefaultFrameSkipCount));

            if (ray.origin == xrCenterNodePos)
            {
                raycastFired = true;
            }

            if (ray.direction != Vector3.zero)
            {
                raycastDirection = true;
            }

            if (XrFunctionalTestHelpers.Cube != null)
            {
                GameObject.Destroy(XrFunctionalTestHelpers.Cube);
            }

            if (Application.platform != RuntimePlatform.IPhonePlayer)
            {
                Assert.IsTrue(raycastFired, "Gaze ray failed to leave the cetner eye position");
                Assert.IsTrue(raycastDirection, "Gaze direction failed to travel!");
            }
        }
        else
        {
            Assert.Fail("Nodes are not being Tracked");
        }
    }
示例#14
0
    /// <summary>
    /// Set the current tracking to a container (TimedPoseData) to be stored in poseData and retrieved/applied after the latency period.
    /// </summary>
    /// <param name="index">Key value in the dictionary.</param>
    /// <param name="position">Tracked object's position from the VR SDK.</param>
    /// <param name="rot">Tracked object's rotation from the VR SDK.</param>
    private void RegisterPosition(int keyindex, Vector3 position, Quaternion rot)
    {
        TimedPoseData currentPoseData = new TimedPoseData();

        currentPoseData.timestamp = Time.time;
        currentPoseData.rotation  = rot;
        currentPoseData.position  = position;

        //Compensate for positional drift by measuring the distance between HMD and ZED rig root (the head's center).
        Vector3 zedhmdposoffset = zedRigRoot.position - InputTracking.GetLocalPosition(VRNode.Head);

        currentPoseData.position += zedhmdposoffset;

        poseData[keyindex].Add(currentPoseData);
    }
示例#15
0
    public static Vector3 GetHeadPosition()
    {
#if UNITY_EDITOR
        if (GvrEditorEmulator.Instance == null)
        {
            Debug.LogWarning("No GvrEditorEmulator instance was found in your scene. Please ensure that" +
                             "GvrEditorEmulator exists in your scene.");
            return(Vector3.zero);
        }

        return(GvrEditorEmulator.Instance.HeadPosition);
#else
        return(InputTracking.GetLocalPosition(XRNode.Head));
#endif // UNITY_EDITOR
    }
示例#16
0
    public static Quaternion GetHeadRotation()
    {
#if UNITY_EDITOR
        if (GvrEditorEmulator.Instance == null)
        {
            Debug.LogWarning("No GvrEditorEmulator instance was found in your scene. Please ensure that" +
                             "GvrEditorEmulator exists in your scene.");
            return(Quaternion.identity);
        }

        return(GvrEditorEmulator.Instance.HeadRotation);
#else
        return(InputTracking.GetLocalRotation(XRNode.Head));
#endif // UNITY_EDITOR
    }
示例#17
0
        void Update()
        {
            var orientation = InputTracking.GetLocalRotation(XRNode.Head);

            // Record orientation
            PoseSamples.Enqueue(new PoseSample(Time.time, orientation));
            if (PoseSamples.Count >= 120)
            {
                PoseSamples.Dequeue();
            }

            // Recognize gestures
            RecognizeNod();
            RecognizeHeadshake();
        }
示例#18
0
        ////////////////////////////////////////////////////////////////////////////////////////////////
        /*--------------------------------------------------------------------------------------------*/
        public static void UpdateOculus()
        {
            if (Input.GetKey(KeyCode.R))
            {
                InputTracking.Recenter();
            }

            if (!VRSettings.enabled || !VRDevice.isPresent || !OVRManager.isHSWDisplayed)
            {
                return;
            }

            OVRManager.DismissHSWDisplay();
            InputTracking.Recenter();
        }
示例#19
0
    // Update is called once per frame

    void Update()
    {
        //フードセンサの位置をHMDのカメラ位置と連動させる
        pos = InputTracking.GetLocalPosition(XRNode.CenterEye);
        transform.position = new Vector3(pos.x, pos.y - 2.5f, pos.z - 1.2f);
        // var trackedObject = GetComponent<SteamVR_TrackedObject>();
        //var device = SteamVR_Controller.Input((int)trackedObject.index);

        if (statemanager.Timeflag == 1)
        {
            //device.TriggerHapticPulse(1000);
            Debug.Log("test");
            //Invoke("Dead",2);
        }
    }
示例#20
0
    public void RecalculatePositions()
    {
#if UNITY_EDITOR
        Vector3 camRot = Camera.main.transform.eulerAngles;
#else
        Vector3 camRot = InputTracking.GetLocalRotation(VRNode.Head).eulerAngles;
#endif
        float rotation = camRot.y;
        float offset   = -(options - 1) * buttonAngle * 0.5f;
        transform.GetChild(0).eulerAngles = new Vector3(0, rotation, 0);
        for (int i = 1; i < transform.childCount; i++)
        {
            transform.GetChild(i).eulerAngles = new Vector3(0, rotation + offset + buttonAngle * (i - 1), 0);
        }
    }
示例#21
0
    private void Start()
    {
        // VR Mode
        if (VRSettings.loadedDevice != VRDeviceType.None)
        {
            newParent = new GameObject("Camera Transformer");
            Vector3 pos = transform.position;
            newParent.transform.SetParent(transform.parent, false);  // Set the new objects transform to the cameras parent.
            transform.SetParent(newParent.transform, false);
            newParent.transform.position = pos;
            transform.localPosition      = Vector2.zero;

            InputTracking.Recenter();
        }
    }
示例#22
0
        ////////////////////////////////////////////////////////////////////////////////////////////////
        /*--------------------------------------------------------------------------------------------*/
        private static void UpdateOculus()
        {
            if (Input.GetKey(KeyCode.R))
            {
                InputTracking.Recenter();
            }

            if (!OVRManager.isHSWDisplayed)
            {
                return;
            }

            OVRManager.DismissHSWDisplay();
            InputTracking.Recenter();
        }
示例#23
0
    void Update()
    {
        //update hand position and rotation
        transform.localPosition = InputTracking.GetLocalPosition(NodeType);
        transform.localRotation = InputTracking.GetLocalRotation(NodeType);

        if (isResizing)
        {
            ResizeGrabbedObject(currentGrabbedObject);
            if (Input.GetAxis(grabInputName) < .01f || Input.GetAxis(OtherHandReference.grabInputName) < .01f)
            {
                isResizing = false;
            }
        }
    }
示例#24
0
   public static void Recenter()
   {
 #if UNITY_2019_3_OR_NEWER
       var devices = new List <InputDevice>();
       InputDevices.GetDevicesWithCharacteristics(InputDeviceCharacteristics.HeadMounted, devices);
       if (devices.Count == 0)
       {
           return;
       }
       var hmdDevice = devices[0];
       hmdDevice.subsystem.TryRecenter();
 #else
       InputTracking.Recenter();
 #endif
   }
    /// <summary>
    /// Return a quaternion for the Y axis of the HMD's orientation.
    /// Used by orientation handlers to track the current heading before processing user input to adjust it.
    /// </summary>
    /// <returns></returns>
    public Quaternion GetHeadRotationY()
    {
#if UNITY_2017_2_OR_NEWER
#pragma warning disable CS0618 // Type or member is obsolete
        Quaternion headRotation = UnityEngine.XR.InputTracking.GetLocalRotation(UnityEngine.XR.XRNode.Head);
#pragma warning restore CS0618 // Type or member is obsolete
#else
        Quaternion headRotation = InputTracking.GetLocalRotation(VRNode.Head);
#endif
        Vector3 euler = headRotation.eulerAngles;
        euler.x      = 0;
        euler.z      = 0;
        headRotation = Quaternion.Euler(euler);
        return(headRotation);
    }
    // Update is called once per frame
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.R))             // let user recenter camera if they want to
        {
            InputTracking.Recenter();
        }

        var vertical   = Input.GetAxis("Vertical");
        var horizontal = Input.GetAxis("Horizontal");

        // move forward in the direction that the VR headset is looking
        controller.Move(vertical * Camera.main.transform.forward * Time.deltaTime * 10f + Physics.gravity);
        // turn left or right
        transform.Rotate(0f, horizontal * Time.deltaTime * 100f, 0f);
    }
示例#27
0
        private void OnEnable()
        {
            _connection = WebServerConnection.Instance;

            var nodes = new List <XRNodeState>();

            InputTracking.GetNodeStates(nodes);
            foreach (var node in nodes)
            {
                AddNode(node);
            }

            InputTracking.nodeAdded   += AddNode;
            InputTracking.nodeRemoved += RemoveNode;
        }
示例#28
0
 // Update is called once per frame
 void Update()
 {
     pos = InputTracking.GetLocalPosition(XRNode.CenterEye);
     //pos.y -= 0.7f;
     transform.position = new Vector3(pos.x, pos.y - 4.7f, pos.z);
     if (Time.timeScale == 0)
     {
         if (flag == 0)
         {
             Debug.Log("2");
             // Invoker.InvokeDelayed(Dead,1);
             flag = 1;
         }
     }
 }
            public IEnumerator XrNodesTracking()
            {
                InputTracking.GetNodeStates(m_NodeList);
                yield return(new WaitForSeconds(1f));

                foreach (XRNodeState nodeState in m_NodeList)
                {
                    if (nodeState.tracked)
                    {
                        m_TrackingNodes = true;
                    }
                }

                Assert.IsTrue(m_TrackingNodes, "Nodes are not tracking");
            }
        void Recenter()
        {
            var headPosition    = InputTracking.GetLocalPosition(XRNode.Head);
            var currentPosition = transform.position;

            currentPosition.x  = -headPosition.x * 0.5f;
            currentPosition.z  = -headPosition.z * 0.5f;
            transform.position = currentPosition;
            var headRot = InputTracking.GetLocalRotation(XRNode.Head).eulerAngles;

            var currentRot = transform.rotation.eulerAngles;

            currentRot.y       = -headRot.y;
            transform.rotation = Quaternion.Euler(currentRot);
        }