Пример #1
0
        private Pose GetPoseInput(ulong action, XRNodeState node)
        {
            InputPoseActionData_t data = new InputPoseActionData_t();

            var res = OpenVR.Input.GetPoseActionData(
                action,
                XRDevice.GetTrackingSpaceType() == TrackingSpaceType.RoomScale ? ETrackingUniverseOrigin.TrackingUniverseStanding : ETrackingUniverseOrigin.TrackingUniverseSeated,
                0,
                ref data,
                (uint)System.Runtime.InteropServices.Marshal.SizeOf(typeof(InputPoseActionData_t)),
                node.nodeType == XRNode.LeftHand ? leftHand : rightHand
                );

            if (res != EVRInputError.None)
            {
                throw new ApplicationException("Failed to get pose input data " + node.nodeType + ": " + res);
            }

            var matRaw = data.pose.mDeviceToAbsoluteTracking;
            var mat    = new Matrix4x4(
                new Vector4(matRaw.m0, matRaw.m1, matRaw.m2, 0),
                new Vector4(matRaw.m4, matRaw.m5, matRaw.m6, 0),
                new Vector4(matRaw.m8, matRaw.m9, matRaw.m10, 0),
                new Vector4(0, 0, 0, 1)
                );
            var rot = mat.rotation;

//		rot.x *= -1;
            rot.z *= -1;

            return(new Pose {
                pos = new Vector3(matRaw.m3, matRaw.m7, -matRaw.m11),
                rot = rot
            });
        }
Пример #2
0
        /// <summary><strong>[Should not be called by user code]</strong>
        /// Updates the data for this action and this input source. Sends related events.
        /// </summary>
        public virtual void UpdateValue(bool skipStateAndEventUpdates)
        {
            lastChanged         = changed;
            lastPoseActionData  = poseActionData;
            lastLocalPosition   = localPosition;
            lastLocalRotation   = localRotation;
            lastVelocity        = velocity;
            lastAngularVelocity = angularVelocity;

            EVRInputError err = OpenVR.Input.GetPoseActionData(handle, universeOrigin, predictedSecondsFromNow,
                                                               ref poseActionData, poseActionData_size, inputSourceHandle);

            if (err != EVRInputError.None)
            {
                Debug.LogError("<b>[SteamVR]</b> GetPoseActionData error (" + fullPath + "): " + err.ToString() +
                               " Handle: " + handle.ToString() + ". Input source: " + inputSource.ToString());
            }

            SetCacheVariables();
            changed = GetChanged();

            if (changed)
            {
                changedTime = updateTime + predictedSecondsFromNow;
            }

            if (skipStateAndEventUpdates == false)
            {
                CheckAndSendEvents();
            }
        }
Пример #3
0
        internal override void UpdateData()
        {
            _actionData = OpenVRFacade.GetPoseActionData(handle);
            HmdMatrix34_t rawMatrix = _actionData.pose.mDeviceToAbsoluteTracking;

            _pose = new Pose(rawMatrix.GetPosition(), rawMatrix.GetRotation());
        }
Пример #4
0
            public ActionTransform transform = null;  //姿勢

            public PoseAction(InputPoseActionData_t Data, OriginSource OriginInfo)
            {
                Available = Data.bActive;
                Origin    = OriginInfo;

                TrackedDevicePose_t Pose = Data.pose;

                SteamVR_Utils.RigidTransform trans = new SteamVR_Utils.RigidTransform(Pose.mDeviceToAbsoluteTracking);
                transform = new ActionTransform();

                if (OriginInfo != null)
                {
                    transform.deviceid = OriginInfo.DeviceIndex;
                }
                else
                {
                    transform.deviceid = InvalidDeviceIndex;
                }

                //右手系・左手系の変換をした
                transform.velocity[0]        = Pose.vVelocity.v0;
                transform.velocity[1]        = Pose.vVelocity.v1;
                transform.velocity[2]        = -Pose.vVelocity.v2;
                transform.angularVelocity[0] = -Pose.vAngularVelocity.v0;
                transform.angularVelocity[1] = -Pose.vAngularVelocity.v1;
                transform.angularVelocity[2] = Pose.vAngularVelocity.v2;

                transform.position = trans.pos;
                transform.rotation = trans.rot;
            }
Пример #5
0
        //姿勢を取得する(生データ)
        private void GetPoseActionDataRaw(string ActionPath, out InputPoseActionData_t data, ETrackingUniverseOrigin UniverseOrigin = ETrackingUniverseOrigin.TrackingUniverseStanding, string RestrictToDevicePath = "")
        {
            ReadyCheck(); //実行可能な状態かチェック

            EVRInputError inputError = EVRInputError.None;

            data = new InputPoseActionData_t();

            var   size   = (uint)System.Runtime.InteropServices.Marshal.SizeOf(typeof(InputPoseActionData_t));
            ulong handle = GetActionHandle(ActionPath); //無効なハンドルならthrowされる

            //制約デバイス指定されていれば適用
            ulong DeviceHandle = OpenVR.k_ulInvalidInputValueHandle;

            if (RestrictToDevicePath != "")
            {
                DeviceHandle = GetInputSourceHandle(RestrictToDevicePath); //無効なハンドルならthrowされる
            }

            //取得処理
            inputError = vrinput.GetPoseActionData(handle, UniverseOrigin, PredictedTime, ref data, size, DeviceHandle);
            if (inputError == EVRInputError.WrongType)
            {
                //姿勢ではない
                throw new ArgumentException(inputError.ToString());
            }
            if (inputError != EVRInputError.None)
            {
                //致命的エラー
                throw new IOException(inputError.ToString());
            }

            return;
        }
Пример #6
0
        public static void UpdateOrAddPoseInputActionData(InputPoseActionData_t data, InputActionInfo info)
        {
            var source = handleToSource[info.sourceHandle];

            if (!poseInputActionData.ContainsKey(source))
            {
                poseInputActionData[source] = new ConcurrentDictionary <string, Pose>();
            }
            poseInputActionData[source][info.pathEnd] = new Pose(data.pose);
        }
Пример #7
0
        private void GetActionData()
        {
            if (_lastFrame != Time.frameCount)
            {
                _actionData = OpenVRWrapper.GetPoseActionDataForNextFrame(handle);
                HmdMatrix34_t rawMatrix = _actionData.pose.mDeviceToAbsoluteTracking;
                _pose = new Pose(GetPosition(rawMatrix), GetRotation(rawMatrix));
            }

            _lastFrame = Time.frameCount;
        }
Пример #8
0
        internal static InputPoseActionData_t GetPoseActionData(ulong actionHandle, ETrackingUniverseOrigin origin = ETrackingUniverseOrigin.TrackingUniverseStanding)
        {
            InputPoseActionData_t actionData = default;

            EVRInputError error = OpenVR.Input.GetPoseActionData(actionHandle, origin, 0, ref actionData, (uint)Marshal.SizeOf(typeof(InputPoseActionData_t)), OpenVR.k_ulInvalidInputValueHandle);

            if (error != EVRInputError.None && error != EVRInputError.NoData)
            {
                throw new OpenVRInputException($"Could not get pose data for action with handle {actionHandle}: {error}", error);
            }

            return(actionData);
        }
Пример #9
0
        public ControllerEvent()
        {
            switch (EventType())
            {
            case EventTypeEmun.Digital:
                Digital = new InputDigitalActionData_t();
                break;

            case EventTypeEmun.Analog:
                Analog = new InputAnalogActionData_t();
                break;

            case EventTypeEmun.Pose:
                Pose     = new InputPoseActionData_t();
                Position = new HmdVector3_t();
                break;
            }
        }
        /// <summary><strong>[Should not be called by user code]</strong>
        /// Updates the data for this action and this input source. Sends related events.
        /// </summary>
        public virtual void UpdateValue(bool skipStateAndEventUpdates)
        {
            lastChanged         = changed;
            lastPoseActionData  = poseActionData;
            lastLocalPosition   = localPosition;
            lastLocalRotation   = localRotation;
            lastVelocity        = velocity;
            lastAngularVelocity = angularVelocity;

            EVRInputError err;

            if (framesAhead == 0)
            {
                err = OpenVR.Input.GetPoseActionDataForNextFrame(handle, universeOrigin, ref poseActionData, poseActionData_size, inputSourceHandle);
            }
            else
            {
                err = OpenVR.Input.GetPoseActionDataRelativeToNow(handle, universeOrigin, framesAhead * (Time.timeScale / SteamVR.instance.hmd_DisplayFrequency), ref poseActionData, poseActionData_size, inputSourceHandle);
            }

            if (err != EVRInputError.None)
            {
                Debug.LogError("<b>[SteamVR]</b> GetPoseActionData error (" + fullPath + "): " + err.ToString() + " Handle: " + handle.ToString() + ". Input source: " + inputSource.ToString());
            }

            if (active)
            {
                SetCacheVariables();
                changed = GetChanged();
            }

            if (changed)
            {
                changedTime = updateTime;
            }

            if (skipStateAndEventUpdates == false)
            {
                CheckAndSendEvents();
            }
        }