Example #1
0
        public static void UpdateTrackableDevicePosition()
        {
            VRControllerState_t controllerState = new VRControllerState_t();
            var             size                 = (uint)Marshal.SizeOf(typeof(VRControllerState_t));
            HmdVector3_t    position             = new HmdVector3_t();
            HmdQuaternion_t quaternion           = new HmdQuaternion_t();
            uint            LeftControllerIndex  = OpenVR.System.GetTrackedDeviceIndexForControllerRole(ETrackedControllerRole.LeftHand),
                            RightControllerIndex = OpenVR.System.GetTrackedDeviceIndexForControllerRole(ETrackedControllerRole.RightHand);

            OpenVR.System.GetDeviceToAbsoluteTrackingPose(ETrackingUniverseOrigin.TrackingUniverseStanding, 1 / Program.DataFrameRate, TrackedDevicePose_t);
            if (TrackedDevicePose_t[0].bPoseIsValid)
            {
                GetPosition(TrackedDevicePose_t[0].mDeviceToAbsoluteTracking, ref position);
                GetRotation(TrackedDevicePose_t[0].mDeviceToAbsoluteTracking, ref quaternion);
                VREventCallback.NewPoseEvent(VREventCallback.DeviceType.HMD, position, quaternion);
            }

            OpenVR.System.GetControllerStateWithPose(ETrackingUniverseOrigin.TrackingUniverseStanding, LeftControllerIndex, ref controllerState, size, ref LeftControllerPose);
            if (LeftControllerPose.bPoseIsValid)
            {
                GetPosition(LeftControllerPose.mDeviceToAbsoluteTracking, ref position);
                GetRotation(LeftControllerPose.mDeviceToAbsoluteTracking, ref quaternion);
                VREventCallback.NewPoseEvent(VREventCallback.DeviceType.LeftController, position, quaternion);
            }
            OpenVR.System.GetControllerStateWithPose(ETrackingUniverseOrigin.TrackingUniverseStanding, RightControllerIndex, ref controllerState, size, ref RightControllerPose);
            if (RightControllerPose.bPoseIsValid)
            {
                GetPosition(RightControllerPose.mDeviceToAbsoluteTracking, ref position);
                GetRotation(RightControllerPose.mDeviceToAbsoluteTracking, ref quaternion);
                VREventCallback.NewPoseEvent(VREventCallback.DeviceType.RightController, position, quaternion);
            }
        }
Example #2
0
        public InputAnalogActionData_t AnalogFetchEventResult()
        {
            var size = (uint)Marshal.SizeOf(typeof(InputAnalogActionData_t));

            OpenVR.Input.GetAnalogActionData(ActionHandle, ref Analog, size, controller.ControllerHandle);
            // Result
            if (Analog.deltaX != 0 || Analog.deltaY != 0 || Analog.deltaZ != 0)
            {
                VREventCallback.NewAnalogEvent(controller.ControllerType, (AnalogControllerEvent)this, Analog);
            }
            return(Analog);
        }
Example #3
0
        public bool DigitalFetchEventResult()
        {
            var size = (uint)Marshal.SizeOf(typeof(InputDigitalActionData_t));

            OpenVR.Input.GetDigitalActionData(ActionHandle, ref Digital, size, controller.ControllerHandle);
            // Result
            if (Digital.bChanged)
            {
                VREventCallback.NewDigitalEvent(controller.ControllerType, (DigitalControllerEvent)this, Digital.bState);
            }
            return(Digital.bState);
        }
Example #4
0
        public InputPoseActionData_t PoseFetchEventResult()
        {
            var size = (uint)Marshal.SizeOf(typeof(InputPoseActionData_t));

            OpenVR.Input.GetPoseActionData(ActionHandle, ETrackingUniverseOrigin.TrackingUniverseStanding, 1 / Program.DataFrameRate, ref Pose, size, controller.ControllerHandle);
            if (Pose.pose.bDeviceIsConnected == true && Pose.pose.bPoseIsValid == true)
            {
                HmdVector3_t    position   = new HmdVector3_t();
                HmdQuaternion_t quaternion = new HmdQuaternion_t();
                TrackableDeviceInfo.GetPosition(Pose.pose.mDeviceToAbsoluteTracking, ref position);
                TrackableDeviceInfo.GetRotation(Pose.pose.mDeviceToAbsoluteTracking, ref quaternion);
                VREventCallback.NewPoseEvent(controller.ControllerType, (PoseControllerEvent)this, position, quaternion);
            }
            return(Pose);
        }