コード例 #1
0
    /// <summary>
    /// Collects the position of the HMD with a timestamp, to be looked up later to correct for latency.
    /// </summary>
    public void CollectPose()
    {
        if (manager == null)
        {
            return;
        }

        KeyPose k = new KeyPose();

#if UNITY_2019_1_OR_NEWER
        InputTracking.GetNodeStates(nodeStates);
        XRNodeState nodeState = nodeStates.Find(node => node.nodeType == XRNode.Head);
        nodeState.TryGetRotation(out k.Orientation);
        nodeState.TryGetPosition(out k.Translation);
#else
        k.Orientation = InputTracking.GetLocalRotation(XRNode.Head);
        k.Translation = InputTracking.GetLocalPosition(XRNode.Head);
#endif

        if (manager.zedCamera.IsCameraReady)
        {
            k.Timestamp = manager.zedCamera.GetCurrentTimeStamp();
            if (k.Timestamp >= 0)
            {
                dllz_latency_corrector_add_key_pose(ref k.Translation, ref k.Orientation, k.Timestamp);                 //Poses are handled by the wrapper.
            }
        }
    }
コード例 #2
0
    private void CheckPlayerPos()
    {
        // circle of bubble:
        // compare against center of sphere

        InputTracking.GetNodeStates(nodeStatesCache);
        Vector3 hmd_pos = new Vector3();

        for (int i = 0; i < nodeStatesCache.Count; i++)
        {
            XRNodeState nodeState = nodeStatesCache[i];
            if (nodeState.nodeType == XRNode.CenterEye)
            {
                nodeState.TryGetPosition(out hmd_pos);
            }
        }

        if (Vector2.Distance(new Vector2(hmd_pos.x, hmd_pos.y), new Vector2(0, 0)) < bubble_visual.transform.localScale.x / 1.5)
        {
            // within - fine
        }
        else
        {
            state_handler.SetState(GameState.GAMEOVER);
        }
    }
コード例 #3
0
ファイル: Hand.cs プロジェクト: Fangh/Shoot-n-Drive
    // Update is called once per frame
    private void Update()
    {
        UpdateControllerNode();
        if (controllerNode.tracked)
        {
            controllerNode.TryGetPosition(out controllerPosition);
            controllerNode.TryGetRotation(out controllerRotation);

            if (controllerPosition != Vector3.zero)
            {
                lastKnowedControllerPosition = controllerPosition;
            }
            if (controllerRotation != Quaternion.identity)
            {
                lastKnowedControllerRotation = controllerRotation;
            }

            //Debug.Log($"controller {controllerNode.nodeType} is tracked and its position = {controllerPosition}", this);
        }
        else
        {
            Debug.Log($"controller {controllerNode.nodeType} is not tracked", this);
        }
        transform.localPosition = lastKnowedControllerPosition;
        transform.localRotation = lastKnowedControllerRotation;
    }
コード例 #4
0
ファイル: ArmsController.cs プロジェクト: clemf/Subnautica
        public void UpdateHandPositions()
        {
            InputTracking.GetNodeStates(nodeStatesCache);
            Vector3    rightHandPosition = new Vector3();
            Quaternion rightHandRotation = Quaternion.identity;
            Vector3    leftHandPosition  = new Vector3();
            Quaternion leftHandRotation  = Quaternion.identity;

            for (int i = 0; i < nodeStatesCache.Count; i++)
            {
                XRNodeState nodeState = nodeStatesCache[i];
                if (nodeState.nodeType == XRNode.RightHand)
                {
                    nodeState.TryGetPosition(out rightHandPosition);
                    nodeState.TryGetRotation(out rightHandRotation);
                }
                if (nodeState.nodeType == XRNode.LeftHand)
                {
                    nodeState.TryGetPosition(out leftHandPosition);
                    nodeState.TryGetRotation(out leftHandRotation);
                }
            }

            rightController.transform.localPosition = rightHandPosition + new Vector3(0f, -0.13f, -0.14f);
            rightController.transform.localRotation = rightHandRotation * Quaternion.Euler(35f, 190f, 270f);

            leftController.transform.localPosition = leftHandPosition + new Vector3(0f, -0.13f, -0.14f);
            leftController.transform.localRotation = leftHandRotation * Quaternion.Euler(270f, 90f, 0f);

            InventoryItem heldItem = Inventory.main.quickSlots.heldItem;

            if (heldItem?.item.GetComponent <PropulsionCannon>())
            {
                ik.solver.leftHandEffector.target  = null;
                ik.solver.rightHandEffector.target = null;
            }
            else if (heldItem?.item.GetComponent <StasisRifle>())
            {
                ik.solver.leftHandEffector.target  = null;
                ik.solver.rightHandEffector.target = null;
            }
            else
            {
                ik.solver.leftHandEffector.target  = leftController.transform;
                ik.solver.rightHandEffector.target = rightController.transform;
            }
        }
コード例 #5
0
ファイル: VRInput.cs プロジェクト: rricarda24/Go_Masterthesis
        /// <summary>
        /// Returns where the hand is pointing right now. (z+ forward)
        /// </summary>
        /// <param name="node"></param>
        /// <returns></returns>
        public virtual Pose GetPose(XRNodeState node)
        {
            Pose ret = new Pose();

            node.TryGetPosition(out ret.pos);
            node.TryGetRotation(out ret.rot);
            return(ret);
        }
コード例 #6
0
    void Update()
    {
        if (NodeTitle_Text != null)
        {
            NodeTitle_Text.text = m_Node.ToString();
        }

        var nodeStates = new List <XRNodeState>();

        UnityEngine.XR.InputTracking.GetNodeStates(nodeStates);

        XRNodeState?state = null;

        foreach (XRNodeState nodeState in nodeStates)
        {
            if (nodeState.nodeType == m_Node)
            {
                state = nodeState;
                break;
            }
        }

        if (state.HasValue)
        {
            XRNodeState node = state.Value;
            Vector3     tempVector;
            Quaternion  tempQuaternion;

            // Translation Information
            SetImageColor(Position_Image, node.TryGetPosition(out tempVector));
            Position_Text.text = Vector3ToFieldText(tempVector);
            SetImageColor(Velocity_Image, node.TryGetVelocity(out tempVector));
            Velocity_Text.text = Vector3ToFieldText(tempVector);
            SetImageColor(Acceleration_Image, node.TryGetAcceleration(out tempVector));
            Acceleration_Text.text = Vector3ToFieldText(tempVector);

            // Rotation Information
            SetImageColor(Rotation_Image, node.TryGetRotation(out tempQuaternion));
            Rotation_Text.text = QuaternionToFieldText(tempQuaternion);
            SetImageColor(AngularVelocity_Image, node.TryGetAngularVelocity(out tempVector));
            AngularVelocity_Text.text = Vector3ToFieldText(tempVector);
            SetImageColor(AngularAcceleration_Image, node.TryGetAngularAcceleration(out tempVector));
            AngularAcceleration_Text.text = Vector3ToFieldText(tempVector);
        }
        else
        {
            // Translation Information
            SetImageColor(Position_Image, false);
            SetImageColor(Velocity_Image, false);
            SetImageColor(Acceleration_Image, false);

            // Rotation Information
            SetImageColor(Rotation_Image, false);
            SetImageColor(AngularVelocity_Image, false);
            SetImageColor(AngularAcceleration_Image, false);
        }
    }
コード例 #7
0
        /// <summary>
        /// Update the "Controller" input from the device
        /// </summary>
        protected void UpdateControllerData(XRNodeState state)
        {
            Profiler.BeginSample("[MRTK] GenericOpenVRController.UpdateControllerData");

            var lastState = TrackingState;

            LastControllerPose = CurrentControllerPose;

            if (nodeType == XRNode.LeftHand || nodeType == XRNode.RightHand)
            {
                // The source is either a hand or a controller that supports pointing.
                // We can now check for position and rotation.
                IsPositionAvailable   = state.TryGetPosition(out CurrentControllerPosition);
                IsPositionApproximate = false;

                IsRotationAvailable = state.TryGetRotation(out CurrentControllerRotation);

                // Devices are considered tracked if we receive position OR rotation data from the sensors.
                TrackingState = (IsPositionAvailable || IsRotationAvailable) ? TrackingState.Tracked : TrackingState.NotTracked;

                CurrentControllerPosition = MixedRealityPlayspace.TransformPoint(CurrentControllerPosition);
                CurrentControllerRotation = MixedRealityPlayspace.Rotation * CurrentControllerRotation;
            }
            else
            {
                // The input source does not support tracking.
                TrackingState = TrackingState.NotApplicable;
            }

            CurrentControllerPose.Position = CurrentControllerPosition;
            CurrentControllerPose.Rotation = CurrentControllerRotation;

            // Raise input system events if it is enabled.
            if (lastState != TrackingState)
            {
                CoreServices.InputSystem?.RaiseSourceTrackingStateChanged(InputSource, this, TrackingState);
            }

            if (TrackingState == TrackingState.Tracked && LastControllerPose != CurrentControllerPose)
            {
                if (IsPositionAvailable && IsRotationAvailable)
                {
                    CoreServices.InputSystem?.RaiseSourcePoseChanged(InputSource, this, CurrentControllerPose);
                }
                else if (IsPositionAvailable && !IsRotationAvailable)
                {
                    CoreServices.InputSystem?.RaiseSourcePositionChanged(InputSource, this, CurrentControllerPosition);
                }
                else if (!IsPositionAvailable && IsRotationAvailable)
                {
                    CoreServices.InputSystem?.RaiseSourceRotationChanged(InputSource, this, CurrentControllerRotation);
                }
            }

            Profiler.EndSample(); // UpdateControllerData
        }
コード例 #8
0
    public static Vector3?Position(this XRNodeState s)
    {
        Vector3 result;

        if (s.TryGetPosition(out result))
        {
            return(result);
        }
        return(null);
    }
コード例 #9
0
 private static void UpdateSensorState(XRNodeState nodeState, ref SensorState sensorState)
 {
     sensorState.tracked            = nodeState.tracked;
     sensorState.positionConfidence = nodeState.TryGetPosition(out sensorState.position) ? 0.9F : 0;
     if (sensorState.position.sqrMagnitude == 0)
     {
         sensorState.positionConfidence = 0;
     }
     sensorState.rotationConfidence = nodeState.TryGetRotation(out sensorState.rotation) ? 0.9F : 0;
     if (sensorState.rotation.eulerAngles.sqrMagnitude == 0)
     {
         sensorState.rotationConfidence = 0;
     }
 }
コード例 #10
0
        /// <summary>
        /// Update the "Controller" input from the device
        /// </summary>
        /// <param name="state"></param>
        protected void UpdateControllerData(XRNodeState state)
        {
            var lastState = TrackingState;

            LastControllerPose = CurrentControllerPose;

            if (nodeType == XRNode.LeftHand || nodeType == XRNode.RightHand)
            {
                // The source is either a hand or a controller that supports pointing.
                // We can now check for position and rotation.
                IsPositionAvailable   = state.TryGetPosition(out CurrentControllerPosition);
                IsPositionApproximate = false;

                IsRotationAvailable = state.TryGetRotation(out CurrentControllerRotation);

                // Devices are considered tracked if we receive position OR rotation data from the sensors.
                TrackingState = (IsPositionAvailable || IsRotationAvailable) ? Definitions.Devices.TrackingState.Tracked : Definitions.Devices.TrackingState.NotTracked;
            }
            else
            {
                // The input source does not support tracking.
                TrackingState = Definitions.Devices.TrackingState.NotApplicable;
            }

            CurrentControllerPose.Position = CurrentControllerPosition;
            CurrentControllerPose.Rotation = CurrentControllerRotation;

            // Raise input system events if it is enabled.
            if (lastState != TrackingState)
            {
                MixedRealityToolkit.InputSystem?.RaiseSourceTrackingStateChanged(InputSource, this, TrackingState);
            }

            if (TrackingState == Definitions.Devices.TrackingState.Tracked && LastControllerPose != CurrentControllerPose)
            {
                if (IsPositionAvailable && IsRotationAvailable)
                {
                    MixedRealityToolkit.InputSystem?.RaiseSourcePoseChanged(InputSource, this, CurrentControllerPose);
                }
                else if (IsPositionAvailable && !IsRotationAvailable)
                {
                    MixedRealityToolkit.InputSystem?.RaiseSourcePositionChanged(InputSource, this, CurrentControllerPosition);
                }
                else if (!IsPositionAvailable && IsRotationAvailable)
                {
                    MixedRealityToolkit.InputSystem?.RaiseSourceRotationChanged(InputSource, this, CurrentControllerRotation);
                }
            }
        }
コード例 #11
0
        void GetValue()
        {
            GetNodeState();

            if (_nodeState.TryGetPosition(out _position))
            {
                position.Value = _position;
            }
            else
            {
                _position = Vector3.zero;
            }

            rotation.Value = _nodeState.TryGetRotation(out _rotation) ? _rotation : Quaternion.identity;
        }
コード例 #12
0
    public static bool TryGetThrownObjectVelAngVel(XRNodeState throwingControllerState, Vector3 thrownObjectCenterOfMass, out Vector3 objectVelocity, out Vector3 objectAngularVelocity)
    {
        Vector3 controllerPos, controllerVelocity, controllerAngularVelocity;

        if (!throwingControllerState.TryGetPosition(out controllerPos) ||
            !throwingControllerState.TryGetVelocity(out controllerVelocity) ||
            !throwingControllerState.TryGetAngularVelocity(out controllerAngularVelocity))
        {
            objectVelocity = objectAngularVelocity = default(Vector3);
            return(false);
        }

        GetThrownObjectVelAngVel(controllerPos, controllerVelocity, controllerAngularVelocity, thrownObjectCenterOfMass, out objectVelocity, out objectAngularVelocity);
        return(true);
    }
コード例 #13
0
    // Update is called once per frame
    void Update()
    {
        // Get the node
        List <XRNodeState> states = new List <XRNodeState>();

        InputTracking.GetNodeStates(states);

        // Grab the position and rotation
        Vector3     position  = Vector3.zero;
        Quaternion  rotation  = Quaternion.identity;
        XRNodeState nodeState = states.Where(state => state.nodeType == xrNode).First();

        nodeState.TryGetPosition(out position);
        nodeState.TryGetRotation(out rotation);

        // Set the transform's position and rotation
        transform.localPosition = position;
        transform.localRotation = rotation;
    }
コード例 #14
0
        public void Update(XRNodeState nodeState)
        {
            _position            = Vector3.zero;
            _rotation            = new Quaternion();
            _acceleration        = Vector3.zero;
            _angularAcceleration = Vector3.zero;
            _velocity            = Vector3.zero;
            _angularVelocity     = Vector3.zero;

            isTracked = nodeState.tracked;

            if (nodeState.TryGetPosition(out _position))
            {
                position = _position;
            }

            if (nodeState.TryGetRotation(out _rotation))
            {
                rotation = _rotation;
            }

            if (nodeState.TryGetVelocity(out _velocity))
            {
                velocity = _velocity;
            }

            if (nodeState.TryGetAngularVelocity(out _angularVelocity))
            {
                angularVelocity = _angularVelocity;
            }

            if (nodeState.TryGetAcceleration(out _acceleration))
            {
                acceleration = _acceleration;
            }

            if (nodeState.TryGetAngularAcceleration(out _angularAcceleration))
            {
                angularAcceleration = _angularAcceleration;
            }
        }
コード例 #15
0
        void SetPose(List <XRNodeState> states)
        {
            if (index >= states.Count)
            {
                index = 0;
            }
            XRNodeState state           = states[index];
            Vector3     trackerPosition = Vector3.zero;
            Quaternion  trackerRotation = Quaternion.identity;

            if (state.TryGetRotation(out trackerRotation) && state.TryGetPosition(out trackerPosition))
            {
                if (Input.HasOrigin)
                {
                    t.rotation = (Config.rotlerp == 0 ?
                                  Input.OriginRotation * trackerRotation : Quaternion.Slerp(t.rotation, Input.OriginRotation * trackerRotation, Time.unscaledDeltaTime * Config.rotlerp));

                    trackerPosition = (Config.poslerp == 0 ?
                                       Input.OriginRotation * trackerPosition : Vector3.Lerp(t.position, Input.OriginRotation * trackerPosition, Time.unscaledDeltaTime * Config.poslerp));

                    for (int i = 0; i < 3; i++)
                    {
                        trackerPosition[i] *= Input.OriginScale[i];
                    }

                    t.position = trackerPosition;
                }
                else
                {
                    t.localRotation = (Config.rotlerp == 0 ?
                                       trackerRotation : Quaternion.Slerp(t.localRotation, trackerRotation, Time.unscaledDeltaTime * Config.rotlerp));

                    trackerPosition = (Config.poslerp == 0 ?
                                       trackerPosition : Vector3.Lerp(t.localPosition, trackerPosition, Time.unscaledDeltaTime * Config.poslerp));

                    t.localPosition = trackerPosition;
                }
            }
        }
コード例 #16
0
ファイル: Mirror.cs プロジェクト: Unesty/LudumDare48
    private void RenderCamera(Camera camera, Renderer rend, Camera.StereoscopicEye eye, ref RenderTexture portalTexture, ScriptableRenderContext SRC)
    {
        // Create the camera that will render the reflection
        Camera portalCamera;

        CreatePortalCamera(camera, eye, out portalCamera, ref portalTexture);
        CopyCameraProperties(camera, portalCamera); // Copy the properties of the (player) camera

        // find out the reflection plane: position and normal in world space
        Vector3 pos    = transform.position;                                //portalRenderPlane.transform.forward;//
        Vector3 normal = transform.TransformDirection(projectionDirection); // Alex: This is done because sometimes the object reflection direction does not align with what was the default (transform.forward), in this way, the user can specify this.
        //normal.Normalize(); // Alex: normalize in case someone enters a non-normalized vector. Turned off for now because it is a fun effect :P

        // Optionally disable pixel lights for reflection
        int oldPixelLightCount = QualitySettings.pixelLightCount;

        if (m_DisablePixelLights)
        {
            QualitySettings.pixelLightCount = 0;
        }

        // Reflect camera around reflection plane
        float   d = -Vector3.Dot(normal, pos) - m_ClipPlaneOffset;
        Vector4 reflectionPlane = new Vector4(normal.x, normal.y, normal.z, d);

        Matrix4x4 reflection = Matrix4x4.identity;

        CalculateReflectionMatrix(ref reflection, reflectionPlane);

        // Calculate the Eye offsets
        Vector3   oldEyePos;
        Matrix4x4 worldToCameraMatrix;

        if (camera.stereoEnabled)
        {
            Vector3 eyeOffset;
            worldToCameraMatrix = camera.GetStereoViewMatrix(eye);

            InputTracking.GetNodeStates(nodeStates);
            XRNodeState leftEyeState  = findNode(nodeStates, XRNode.LeftEye);
            XRNodeState rightEyeState = findNode(nodeStates, XRNode.RightEye);

            if (eye == Camera.StereoscopicEye.Left)
            {
                leftEyeState.TryGetPosition(out eyeOffset); //eyeOffset = InputTracking.GetLocalPosition(XRNode.LeftEye); //<< Deprecated
            }
            else
            {
                rightEyeState.TryGetPosition(out eyeOffset); //eyeOffset = InputTracking.GetLocalPosition(XRNode.RightEye); //<< Deprecated
            }
            eyeOffset.z = 0.0f;
            oldEyePos   = camera.transform.position + camera.transform.TransformVector(eyeOffset);
        }
        else
        {
            worldToCameraMatrix = camera.worldToCameraMatrix;
            oldEyePos           = camera.transform.position;
        }

        // >>>Transform Camera<<<
        portalCamera.projectionMatrix = camera.projectionMatrix; // Match matrices <<<
        Vector3 newEyePos = reflection.MultiplyPoint(oldEyePos);

        portalCamera.transform.position = newEyePos;

        portalCamera.worldToCameraMatrix = worldToCameraMatrix * reflection;



        // Setup oblique projection matrix so that near plane is our reflection plane. This way we clip everything below/above it for free.
        Vector4 clipPlane = CameraSpacePlane(worldToCameraMatrix * reflection, pos, normal, 1.0f);

        Matrix4x4 projectionMatrix;

        if (camera.stereoEnabled)
        {
            projectionMatrix = camera.GetStereoProjectionMatrix(eye);
        }
        else
        {
            projectionMatrix = camera.projectionMatrix;
        }

        MakeProjectionMatrixOblique(ref projectionMatrix, clipPlane);

        portalCamera.projectionMatrix = projectionMatrix;
        portalCamera.cullingMask      = m_LayerMask.value; // Set culling mask <<<<
        portalCamera.targetTexture    = portalTexture;     // Set the target texture <<<

        GL.invertCulling = true;

        portalCamera.transform.rotation = camera.transform.rotation;

        UniversalRenderPipeline.RenderSingleCamera(SRC, portalCamera); // URP Version of: portalCamera.Render();

        GL.invertCulling = false;

        // Assign the rendertexture to the material
        Material[] materials = rend.sharedMaterials; // Why only get the shared materials?
        string     property  = "_ReflectionTex" + eye.ToString();

        foreach (Material mat in materials)
        {
            if (mat.HasProperty(property))
            {
                mat.SetTexture(property, portalTexture);
            }
        }

        // Restore pixel light count
        if (m_DisablePixelLights)
        {
            QualitySettings.pixelLightCount = oldPixelLightCount;
        }

        s_InsideRendering = false;
    }
コード例 #17
0
    protected override void FillMetadata(HandAnchor anchor, ref XRNodeState xRNode)
    {
        //base.UpdateHandNodeState(hand, ref xRNode);
        float thumb = 0f, index = 0f, middle = 0f;

        //psotion && rotation
        xRNode.TryGetPosition(out anchor.position);
        xRNode.TryGetRotation(out anchor.rotation);

        var    inputSource      = SteamVR_Input_Sources.LeftHand;
        string skeletonHandName = "SkeletonLeftHand";

        if (anchor.type == NodeType.RightHand)
        {
            inputSource      = SteamVR_Input_Sources.RightHand;
            skeletonHandName = "skeletonRightHand";
        }

        //SteamVR_Action_Boolean key_MenuKey = SteamVR_Input.GetBooleanAction("MenuKey");
        //SteamVR_Action_Boolean key_SystemKey = SteamVR_Input.GetBooleanAction("SystemKey");

        //trigger
        SteamVR_Action_Boolean triggerPressed = SteamVR_Input.GetBooleanAction("Trigger");

        //SteamVR_Action_Single triggerTouchValue = SteamVR_Input.GetSingleAction("triggerTouchValue");
        anchor.triggerPressed    = triggerPressed.GetState(inputSource);
        anchor.triggerTouchValue = Mathf.Lerp(anchor.triggerTouchValue, anchor.triggerPressed ? 1f : 0f, Time.deltaTime * 5);
        index = anchor.triggerTouchValue;

        //grip
        SteamVR_Action_Boolean gripPressed = SteamVR_Input.GetBooleanAction("SideTrigger");

        //SteamVR_Action_Single gripTouchValue = SteamVR_Input.GetSingleAction("gripTouchValue");
        anchor.gripPressed    = gripPressed.GetState(inputSource);
        anchor.gripTouchValue = Mathf.Lerp(anchor.gripTouchValue, anchor.gripPressed ? 1f : 0f, Time.deltaTime * 5);
        middle = anchor.gripTouchValue;

        //primary2DAxis
        SteamVR_Action_Vector2 primary2DAxis      = SteamVR_Input.GetVector2Action("ThumbStick");
        SteamVR_Action_Boolean primary2DAxisClick = SteamVR_Input.GetBooleanAction("PadDown");

        anchor.primary2DAxis        = primary2DAxis.GetAxis(inputSource);
        anchor.primary2DAxisTouch   = anchor.primary2DAxis.sqrMagnitude > 0.02f;
        anchor.primary2DAxisPressed = primary2DAxisClick.GetState(inputSource);
        thumb = Mathf.Max(thumb, (anchor.primary2DAxisPressed || anchor.primary2DAxisTouch) ? 1f : 0f);
        thumb = Mathf.Max(thumb, anchor.primary2DAxis.sqrMagnitude > 0.1f ? 1f : 0f);

        //primary
        SteamVR_Action_Boolean primaryPressed = SteamVR_Input.GetBooleanAction("BKey");

        anchor.primaryPressed    = primaryPressed.GetState(inputSource);
        anchor.primaryTouchValue = (anchor.primaryPressed) ? 1f : 0f;
        thumb = Mathf.Max(thumb, anchor.primaryTouchValue);

        //secondary
        SteamVR_Action_Boolean secondaryPressed = SteamVR_Input.GetBooleanAction("AKey");

        anchor.secondaryPressed    = secondaryPressed.GetState(inputSource);
        anchor.secondaryTouchValue = (anchor.secondaryPressed) ? 1f : 0f;
        thumb = Mathf.Max(thumb, anchor.secondaryTouchValue);

        //fingers
        var skeletonHand = SteamVR_Input.GetAction <SteamVR_Action_Skeleton>(skeletonHandName);

        if (skeletonHand.poseIsValid)
        {
            anchor.handPoseChanged = skeletonHand.poseChanged;
            anchor.fingerCurls[0]  = skeletonHand.thumbCurl;
            anchor.fingerCurls[1]  = skeletonHand.indexCurl;
            anchor.fingerCurls[2]  = skeletonHand.middleCurl;
            anchor.fingerCurls[3]  = skeletonHand.ringCurl;
            anchor.fingerCurls[4]  = skeletonHand.pinkyCurl;
        }
        else
        {
            anchor.handPoseChanged = true;
            anchor.fingerCurls[0]  = thumb;
            anchor.fingerCurls[1]  = index;
            anchor.fingerCurls[2]  = middle;
            anchor.fingerCurls[3]  = middle;
            anchor.fingerCurls[4]  = middle;
        }
    }
コード例 #18
0
    protected override void FillMetadata(HandAnchor anchor, ref XRNodeState xRNode)
    {
        var   device = U3DInputDevices.GetDeviceAtXRNode(xRNode.nodeType);
        float thumb = 0f, index = 0f, middle = 0f;

        //psotion && rotation
        xRNode.TryGetPosition(out anchor.position);
        xRNode.TryGetRotation(out anchor.rotation);

        OVRInput.Controller touch = OVRInput.Controller.LTouch;
        if (anchor.type == NodeType.RightHand)
        {
            touch = OVRInput.Controller.RTouch;
        }

        //grip
        anchor.gripTouchValue = OVRInput.Get(OVRInput.Axis1D.PrimaryHandTrigger, touch);
        anchor.gripPressed    = OVRInput.Get(OVRInput.Button.PrimaryHandTrigger, touch);
        middle = anchor.gripTouchValue;

        //trigger
        anchor.triggerTouchValue = OVRInput.Get(OVRInput.Axis1D.PrimaryIndexTrigger, touch);
        anchor.triggerPressed    = OVRInput.Get(OVRInput.Button.PrimaryIndexTrigger, touch);
        index = anchor.triggerTouchValue;

        //system
        device.TryGetFeatureValue(CommonUsages.menuButton, out anchor.systemPressed);
        anchor.systemTouchValue = 0f;
        if (anchor.systemPressed)
        {
            anchor.systemTouchValue = 1f;
        }
        thumb = Mathf.Max(thumb, anchor.systemTouchValue);

        //primary
        anchor.primaryPressed    = OVRInput.Get(OVRInput.Button.One, touch);
        anchor.primaryTouch      = OVRInput.Get(OVRInput.Touch.One, touch);
        anchor.primaryTouchValue = 0f;
        if (anchor.primaryTouch)
        {
            anchor.primaryTouchValue = 0.5f;
        }
        if (anchor.primaryPressed)
        {
            anchor.primaryTouchValue = 1.0f;
        }
        thumb = Mathf.Max(thumb, anchor.primaryTouchValue);

        //secondary
        anchor.secondaryPressed    = OVRInput.Get(OVRInput.Button.Two, touch);
        anchor.secondaryTouch      = OVRInput.Get(OVRInput.Touch.Two, touch);
        anchor.secondaryTouchValue = 0f;
        if (anchor.secondaryTouch)
        {
            anchor.secondaryTouchValue = 0.5f;
        }
        if (anchor.secondaryPressed)
        {
            anchor.secondaryTouchValue = 1.0f;
        }
        thumb = Mathf.Max(thumb, anchor.secondaryTouchValue);

        //primary2DAxis
        anchor.primary2DAxis        = OVRInput.Get(OVRInput.Axis2D.PrimaryThumbstick, touch);
        anchor.primary2DAxisPressed = OVRInput.Get(OVRInput.Button.PrimaryThumbstick, touch);
        anchor.primary2DAxisTouch   = OVRInput.Get(OVRInput.Touch.PrimaryThumbstick, touch);
        thumb = Mathf.Max(thumb, (anchor.primary2DAxisPressed || anchor.primary2DAxisTouch) ? 1f : 0f);
        thumb = Mathf.Max(thumb, anchor.primary2DAxis.sqrMagnitude > 0.1f ? 1f : 0f);

        //secondary2DAxis
        anchor.secondary2DAxis = OVRInput.Get(OVRInput.Axis2D.SecondaryThumbstick, touch);
        thumb = Mathf.Max(thumb, anchor.secondary2DAxis.sqrMagnitude > 0.1f ? 1f : 0f);
        thumb = thumb > 0.06f ? thumb : 0;

        //fingers
        anchor.fingerCurls[0]  = thumb;
        anchor.fingerCurls[1]  = index;
        anchor.fingerCurls[2]  = middle;
        anchor.fingerCurls[3]  = middle;
        anchor.fingerCurls[4]  = middle;
        anchor.handPoseChanged = true;
    }
コード例 #19
0
        virtual protected void FixedUpdate()
        {
#if UNITY_2017_2_OR_NEWER
            if (trackPositionNatively)
            {
                XRNodeState nodeState = GetXRNodeState();
                Vector3     pos       = Vector3.zero;
                Quaternion  rot       = Quaternion.identity;
                nodeState.TryGetPosition(out pos);
                nodeState.TryGetRotation(out rot);
                transform.localPosition = Vector3.Lerp(transform.localPosition, pos, Time.deltaTime * 25);
                transform.localRotation = Quaternion.Lerp(transform.localRotation, rot, Time.deltaTime * 25f);
            }
#endif

            if (trackInputNatively)
            {
                bool trigger = TriggerPressed;
                if (trigger && !_triggerPressedFlag)
                {
                    _triggerPressedFlag = true;
                    TriggerClicked();
                }
                else if (!trigger && _triggerPressedFlag)
                {
                    _triggerPressedFlag = false;
                    TriggerReleased();
                }

                bool thumbstick = PadPressed;
                if (thumbstick && !_padPressedFlag)
                {
                    _padPressedFlag = true;
                    TrackpadDown();
                }
                else if (!thumbstick && _padPressedFlag)
                {
                    _padPressedFlag = false;
                    TrackpadUp();
                }

                bool thumbstickTouch = PadTouched;
                if (thumbstickTouch && !_padTouchedFlag)
                {
                    _padTouchedFlag = true;
                    TrackpadTouch();
                }
                else if (!thumbstickTouch && _padTouchedFlag)
                {
                    _padTouchedFlag  = false;
                    _stickLeftDown   = false;
                    _stickTopDown    = false;
                    _stickBottomDown = false;
                    _stickRightDown  = false;
                    TrackpadUnTouch();
                }
                if (joystickType == JoystickType.Thumbstick && _padTouchedFlag)
                {
                    if (PadLeftPressed && !_stickLeftDown)
                    {
                        _stickLeftDown = true;
                        SendMessageToInteractor(GetAllActionsForButton(Keys.PAD_LEFT, false));
                    }
                    else if (!PadLeftPressed && _stickLeftDown)
                    {
                        _stickLeftDown = false;
                    }

                    if (PadRightPressed && !_stickRightDown)
                    {
                        _stickRightDown = true;
                        SendMessageToInteractor(GetAllActionsForButton(Keys.PAD_RIGHT, false));
                    }
                    else if (!PadRightPressed && _stickRightDown)
                    {
                        _stickRightDown = false;
                    }

                    if (PadBottomPressed && !_stickBottomDown)
                    {
                        _stickBottomDown = true;
                        SendMessageToInteractor(GetAllActionsForButton(Keys.PAD_BOTTOM, false));
                    }
                    else if (!PadBottomPressed && _stickBottomDown)
                    {
                        _stickBottomDown = false;
                    }

                    if (PadTopPressed && !_stickTopDown)
                    {
                        _stickTopDown = true;
                        SendMessageToInteractor(GetAllActionsForButton(Keys.PAD_TOP, false));
                    }
                    else if (!PadTopPressed && _stickTopDown)
                    {
                        _stickTopDown = false;
                    }
                }

                bool grip = GripPressed;
                if (grip && !_grippedFlag)
                {
                    _grippedFlag = true;
                    Gripped();
                }
                else if (!grip && _grippedFlag)
                {
                    _grippedFlag = false;
                    UnGripped();
                }

                bool menu = MenuPressed;
                if (menu && !_menuPressedFlag)
                {
                    _menuPressedFlag = true;
                    MenuClicked();
                }
                else if (!menu && _menuPressedFlag)
                {
                    _menuPressedFlag = false;
                    MenuReleased();
                }

                bool primary = PrimaryButton;
                if (primary && !_Primary_PressedFlag)
                {
                    _Primary_PressedFlag = true;
                    PrimaryClicked();
                }
                else if (!primary && _Primary_PressedFlag)
                {
                    _Primary_PressedFlag = false;
                    PrimaryReleased();
                }

                bool secondary = SecondaryButton;
                if (secondary && !_Secondary_PressedFlag)
                {
                    _Secondary_PressedFlag = true;
                    SecondaryClicked();
                }
                else if (!secondary && _Secondary_PressedFlag)
                {
                    _Secondary_PressedFlag = false;
                    SecondaryReleased();
                }
            }
            else
            {
#if Int_SteamVR2
                foreach (SteamVR_Action_Boolean boolAction in booleanActions)
                {
                    if (boolAction == null)
                    {
                        Debug.LogError("SteamVR Inputs have not been setup. Refer to the SteamVR 2.0 section of the Setup Guide. Found in Assets/VRInteraction/Docs.");
                        continue;
                    }
                    if (boolAction.GetStateDown(handType))
                    {
                        SendMessageToInteractor(boolAction.GetShortName());
                    }
                    if (boolAction.GetStateUp(handType))
                    {
                        SendMessageToInteractor(boolAction.GetShortName() + "Released");
                    }
                }
#endif
            }
        }
コード例 #20
0
ファイル: TrackingEvnBase.cs プロジェクト: nan023062/navevr
        protected void FillPoseMetadata(TrackingAnchor anchor, ref XRNodeState xRNode)
        {
            xRNode.TryGetPosition(out anchor.position);

            xRNode.TryGetRotation(out anchor.rotation);
        }
コード例 #21
0
            public void EyePositionCheck()
            {
                List <XRNodeState> nodeStates = new List <XRNodeState>();

                InputTracking.GetNodeStates(nodeStates);

                XRNodeState LeftEyeNode  = nodeStates.Where(ns => ns.nodeType == XRNode.LeftEye).First();
                XRNodeState RightEyeNode = nodeStates.Where(ns => ns.nodeType == XRNode.RightEye).First();

                Vector3 LeftEye, RightEye;

                Assert.IsTrue(LeftEyeNode.TryGetPosition(out LeftEye), "unable to get left eye");
                Assert.IsTrue(RightEyeNode.TryGetPosition(out RightEye), "unable to get right eye");

                Vector3 LeftEyeInverse  = m_Camera.transform.InverseTransformVector(LeftEye);
                Vector3 RightEyeInverse = m_Camera.transform.InverseTransformVector(RightEye);

                Debug.Log("Eye Left Inverse Position = " + LeftEyeInverse +
                          Environment.NewLine + "Eye Right Inverse Position = " + RightEyeInverse);

                if (EyeZPositionCheck(LeftEyeInverse.z, 0f))
                {
                    Debug.Log("Eyes are in front of the head : " + LeftEyeInverse.z);
                    m_EyesInFront = true;
                }
                else if (!EyeZPositionCheck(LeftEyeInverse.z, 0f))
                {
                    Debug.Log("Eyes are in behind of the head : " + LeftEyeInverse.z);
                    m_EyesInFront = false;
                }

                Vector3 forwardDirLeft = m_Camera.transform.forward;
                float   leftEyeAngle   = Vector3.Angle(LeftEye, forwardDirLeft);

                Vector3 forwardDirRight = m_Camera.transform.forward;
                float   rightEyeAngle   = Vector3.Angle(RightEye, forwardDirRight);

                CheckMathForEyes(m_Camera.GetComponent <Camera>().stereoConvergence, leftEyeAngle);

                // Check to make sure the eye angles from the head are the same
                if (CompareEyeAngles(leftEyeAngle, rightEyeAngle))
                {
                    Debug.Log("Left and Right eye angles are the same : " + leftEyeAngle + " | " + rightEyeAngle);

                    m_EyeAngleCheck = true;
                }
                else if (!CompareEyeAngles(leftEyeAngle, rightEyeAngle))
                {
                    Debug.Log("Left and Right eye angles are not the same : " + leftEyeAngle + " | " + rightEyeAngle);
                    m_EyeAngleCheck = false;
                }

                //Check to make sure the angle from the camera to the left eye is reasonable
                if (!AngleCheck(leftEyeAngle, 60f))
                {
                    Debug.Log("Left eye angle to the head is correct : " + leftEyeAngle);
                    m_LeftEyeAngleCheck = true;
                }
                else if (AngleCheck(leftEyeAngle, 60f))
                {
                    Debug.Log("Left eye angle to the head is incorrect : " + leftEyeAngle);
                    m_LeftEyeAngleCheck = false;
                }

                //Check to make sure the angle from the camera to the right eye is reasonable
                if (!AngleCheck(rightEyeAngle, 60f))
                {
                    Debug.Log("Right eye angle to the head is correct : " + rightEyeAngle);
                    m_RightEyeAngleCheck = true;
                }
                else if (AngleCheck(rightEyeAngle, 60f))
                {
                    Debug.Log("Right eye angle to the head is incorrect : " + rightEyeAngle);
                    m_RightEyeAngleCheck = false;
                }
            }
コード例 #22
0
        protected override void FillMetadata(HandAnchor anchor, ref XRNodeState xRNode)
        {
            var   device = U3DInputDevices.GetDeviceAtXRNode(xRNode.nodeType);
            float thumb = 0f, index = 0f, middle = 0f;

            //psotion && rotation
            xRNode.TryGetPosition(out anchor.position);
            xRNode.TryGetRotation(out anchor.rotation);

            //grip
            device.TryGetFeatureValue(CommonUsages.gripButton, out anchor.gripPressed);
            device.TryGetFeatureValue(CommonUsages.grip, out anchor.gripTouchValue);
            anchor.gripTouchValue = anchor.gripTouchValue > 0.06f ? anchor.gripTouchValue : 0f;
            middle = anchor.gripTouchValue;

            //trigger
            device.TryGetFeatureValue(CommonUsages.triggerButton, out anchor.triggerPressed);
            device.TryGetFeatureValue(CommonUsages.trigger, out anchor.triggerTouchValue);
            anchor.triggerTouchValue = anchor.triggerTouchValue > 0.06f ? anchor.triggerTouchValue : 0f;
            index = anchor.triggerTouchValue;

            //system
            device.TryGetFeatureValue(CommonUsages.menuButton, out anchor.systemPressed);
            anchor.systemTouchValue = 0f;
            if (anchor.systemPressed)
            {
                anchor.systemTouchValue = 1f;
            }
            thumb = Mathf.Max(thumb, anchor.systemTouchValue);

            //primary
            device.TryGetFeatureValue(CommonUsages.primaryButton, out anchor.primaryPressed);
            bool primaryTouch = false;

            device.TryGetFeatureValue(CommonUsages.primaryTouch, out primaryTouch);
            anchor.primaryTouchValue = (anchor.primaryPressed || primaryTouch) ? 1f : 0f;
            thumb = Mathf.Max(thumb, anchor.primaryTouchValue);

            //secondary
            device.TryGetFeatureValue(CommonUsages.secondaryButton, out anchor.secondaryPressed);
            bool secondaryTouch = false;

            device.TryGetFeatureValue(CommonUsages.secondaryTouch, out secondaryTouch);
            anchor.secondaryTouchValue = (anchor.secondaryPressed || secondaryTouch) ? 1f : 0f;
            thumb = Mathf.Max(thumb, anchor.secondaryTouchValue);

            //primary2DAxis
            device.TryGetFeatureValue(CommonUsages.primary2DAxisTouch, out anchor.primary2DAxisTouch);
            device.TryGetFeatureValue(CommonUsages.primary2DAxisClick, out anchor.primary2DAxisPressed);
            device.TryGetFeatureValue(CommonUsages.primary2DAxis, out anchor.primary2DAxis);
            thumb = Mathf.Max(thumb, (anchor.primary2DAxisPressed || anchor.primary2DAxisTouch) ? 1f : 0f);
            thumb = Mathf.Max(thumb, anchor.primary2DAxis.sqrMagnitude > 0.1f ? 1f : 0f);

            //secondary2DAxis
            device.TryGetFeatureValue(CommonUsages.secondary2DAxis, out anchor.secondary2DAxis);
            thumb = Mathf.Max(thumb, anchor.secondary2DAxis.sqrMagnitude > 0.1f ? 1f : 0f);
            thumb = thumb > 0.06f ? thumb: 0;

            //fingers
            anchor.fingerCurls[0]  = thumb;
            anchor.fingerCurls[1]  = index;
            anchor.fingerCurls[2]  = middle;
            anchor.fingerCurls[3]  = middle;
            anchor.fingerCurls[4]  = middle;
            anchor.handPoseChanged = true;
        }