Esempio n. 1
0
        public bool GetDeviceTransformByRole(DeviceRole role, out Vector3 position, out Quaternion rotation)
        {
#if MIXCAST_STEAMVR
            if (VRInfo.IsDeviceOpenVR())
            {
                return(GetDeviceTransformByRole_SteamVR(role, out position, out rotation));
            }
#endif
#if MIXCAST_OCULUS
            if (VRInfo.IsDeviceOculus())
            {
                return(GetDeviceTransformByRole_Oculus(role, out position, out rotation));
            }
#endif

            if (Application.isEditor)
            {
                position = Camera.main.transform.localPosition;
                rotation = Camera.main.transform.localRotation;
                return(true);
            }

            position = Vector3.zero;
            rotation = Quaternion.identity;
            return(false);
        }
        void SensorCheck()
        {
#if UNITY_2017_2_OR_NEWER
            if (XRDevice.isPresent && VRInfo.IsVRModelOculus())
#else
            if (VRDevice.isPresent && VRInfo.IsVRModelOculus())
#endif
            {
                Vector3    newPos;
                Quaternion newRot;

                var oldSensorPose = MixCast.Settings.sensorPose;

                var index = MixCast.Settings.sensorIndex;
                if (TrackedDeviceManager.Instance.GetSensorPosition(index, out newPos, out newRot))
                {
                    if (newPos != Vector3.zero || newRot != Quaternion.identity)
                    {
                        if (WasSensorDifferent(oldSensorPose, newPos, newRot))
                        {
                            SetTransformFromOldPoseToNewPose(oldSensorPose, newPos, newRot);

                            if (VRInfo.IsDeviceOpenVR())
                            {
                                Debug.Log(SPACE_CHANGE_WARNING);
                                MixCast.Settings.sensorPose = new MixCastData.SensorPose()
                                {
                                    position = newPos, rotation = newRot
                                };
                            }
                        }
                    }
                }
            }
        }
Esempio n. 3
0
        private void Update()
        {
#if MIXCAST_STEAMVR
            if (VRInfo.IsDeviceOpenVR())
            {
                Update_SteamVR();
            }
#endif
        }
Esempio n. 4
0
        private void OnDestroy()
        {
#if MIXCAST_STEAMVR
            if (VRInfo.IsDeviceOpenVR())
            {
                OnDestroy_SteamVR();
            }
#endif
        }
Esempio n. 5
0
        private void Start()
        {
#if MIXCAST_STEAMVR
            if (VRInfo.IsDeviceOpenVR())
            {
                Start_SteamVR();
            }
#endif
        }
 protected void UpdateTransforms()
 {
     if (VRInfo.IsDeviceOpenVR())
     {
         if (OpenVR.System != null && OpenVR.Compositor != null)
         {
             OpenVR.System.GetDeviceToAbsoluteTrackingPose(OpenVR.Compositor.GetTrackingSpace(), 0, trackedObjects);
             if (OnTransformsUpdated != null)
             {
                 OnTransformsUpdated();
             }
         }
     }
 }
        private void UpdatePoses()
        {
#if MIXCAST_STEAMVR
            if (VRInfo.IsDeviceOpenVR())
            {
                var compositor = Valve.VR.OpenVR.Compositor;
                if (compositor != null)
                {
                    var render = SteamVR_Render.instance;
                    compositor.GetLastPoses(render.poses, render.gamePoses);
                    SteamVR_Events.NewPoses.Send(render.poses);
                    SteamVR_Events.NewPosesApplied.Send();
                }
            }
#endif
            // Oculus updates its poses by default on FixedUpdate()
        }
Esempio n. 8
0
        public bool IsSensorAvailable(int requestIndex)
        {
#if MIXCAST_STEAMVR
            if (VRInfo.IsDeviceOpenVR())
            {
                return(IsSteamSensorAvailable(requestIndex));
            }
#endif
#if MIXCAST_OCULUS
            if (VRInfo.IsDeviceOculus())
            {
                return(IsOculusSensorAvailable(requestIndex));
            }
#endif
            Debug.LogError(UNKNOWN_MESSAGE);
            return(false);
        }
        public bool GetTrackingTransform(out Vector3 position, out Quaternion rotation)
        {
#if MIXCAST_STEAMVR
            if (VRInfo.IsDeviceOpenVR())
            {
                return(GetTrackedTransform_Steam(out position, out rotation));
            }
#endif
#if MIXCAST_OCULUS
            if (VRInfo.IsDeviceOculus())
            {
                return(GetTrackedTransform_Oculus(out position, out rotation));
            }
#endif
            position = Vector3.zero;
            rotation = Quaternion.identity;

            return(false);
        }
Esempio n. 10
0
        public bool GetDeviceTransformByGuid(string guid, out Vector3 position, out Quaternion rotation)
        {
#if MIXCAST_STEAMVR
            if (VRInfo.IsDeviceOpenVR())
            {
                return(GetDeviceTransformByGuid_SteamVR(guid, out position, out rotation));
            }
#endif
#if MIXCAST_OCULUS
            if (VRInfo.IsDeviceOculus())
            {
                return(GetDeviceTransformByGuid_Oculus(guid, out position, out rotation));
            }
#endif

            position = Vector3.zero;
            rotation = Quaternion.identity;
            return(false);
        }
Esempio n. 11
0
        public bool GetSensorPosition(int index, out Vector3 position, out Quaternion rotation)
        {
#if MIXCAST_STEAMVR
            if (VRInfo.IsDeviceOpenVR())
            {
                return(GetSteamSensorPosition(index, out position, out rotation));
            }
#endif
#if MIXCAST_OCULUS
            if (VRInfo.IsDeviceOculus())
            {
                return(GetOculusSensorPosition(index, out position, out rotation));
            }
#endif
            Debug.LogError(UNKNOWN_MESSAGE);
            position = Vector3.zero;
            rotation = Quaternion.identity;
            return(false);
        }
Esempio n. 12
0
        public bool GetTrackingTransform(out Vector3 position, out Quaternion rotation)
        {
            if (!string.IsNullOrEmpty(context.Data.trackedByDeviceId))
            {
                if (TrackedDeviceManager.Instance.GetDeviceTransformByGuid(context.Data.trackedByDeviceId, out position, out rotation))
                {
                    return(true);
                }
            }

#if MIXCAST_STEAMVR
            if (VRInfo.IsDeviceOpenVR())
            {
                //Fall back to index if guid isn't found
                SteamVR_TrackedObject.EIndex deviceIndex = (SteamVR_TrackedObject.EIndex)System.Enum.Parse(typeof(SteamVR_TrackedObject.EIndex), context.Data.trackedByDevice);
                return(TrackedDeviceManager.Instance.GetDeviceTransformByIndex((int)deviceIndex, out position, out rotation));
            }
#endif
#if MIXCAST_OCULUS
            if (VRInfo.IsDeviceOculus())
            {
                switch (context.Data.trackedByDevice)
                {
                case "Hmd":
                    return(TrackedDeviceManager.Instance.GetDeviceTransformByRole(TrackedDeviceManager.DeviceRole.Head, out position, out rotation));

                case "Device1":
                    return(TrackedDeviceManager.Instance.GetDeviceTransformByRole(TrackedDeviceManager.DeviceRole.LeftHand, out position, out rotation));

                case "Device2":
                    return(TrackedDeviceManager.Instance.GetDeviceTransformByRole(TrackedDeviceManager.DeviceRole.RightHand, out position, out rotation));

                default:
                    break;
                }
            }
#endif

            position = Vector3.zero;
            rotation = Quaternion.identity;
            return(false);
        }
Esempio n. 13
0
        bool CalculateNewState()
        {
            if (context.Data == null || context.Data.wasTracked == false)
            {
                return(false);
            }

#if MIXCAST_STEAMVR
            if (VRInfo.IsDeviceOpenVR() && IsTracked_Steam())
            {
                return(true);
            }
#endif
#if MIXCAST_OCULUS
            if (VRInfo.IsDeviceOculus() && IsTracked_Oculus())
            {
                return(true);
            }
#endif

            return(false);
        }
Esempio n. 14
0
        public bool GetDeviceTransform(string guid, string role, out Vector3 position, out Quaternion rotation)
        {
#if MIXCAST_STEAMVR
            if (VRInfo.IsDeviceOpenVR())
            {
                return(GetDeviceTransformByGuid_SteamVR(guid, out position, out rotation));
            }
#endif
#if MIXCAST_OCULUS
            if (VRInfo.IsDeviceOculus())
            {
                DeviceRole vrRole;

                try
                {
                    vrRole = (DeviceRole)Enum.Parse(typeof(DeviceRole), role);
                }
                catch
                {
                    // Invalid role name
                    if (!loggedTrackingError)
                    {
                        // Avoid thousands of logged errors
                        Debug.LogError("Trying to get position for invalid controller role: " + role);
                        loggedTrackingError = true;
                    }
                    position = Vector3.zero;
                    rotation = Quaternion.identity;
                    return(false);
                }

                return(GetDeviceTransformByRole_Oculus(vrRole, out position, out rotation));
            }
#endif

            position = Vector3.zero;
            rotation = Quaternion.identity;
            return(false);
        }