Beispiel #1
0
 void Start()
 {
     if (VRInfo.IsDeviceOculus())
     {
         OffsetTransform();
     }
 }
Beispiel #2
0
        private void Update()
        {
#if UNITY_2017_2_OR_NEWER
            if (XRDevice.isPresent)
#else
            if (VRDevice.isPresent)
#endif
            {
                if (VRInfo.IsVRModelOculus())
                {
                    bool sensor1 = TrackedDeviceManager.Instance.IsSensorAvailable(0);
                    bool sensor2 = TrackedDeviceManager.Instance.IsSensorAvailable(1);
                    if (!sensor1 || !sensor2)
                    {
                        var popUpWindow = GetComponent <GameObjects.OpenPopupWindow>();

                        if (!popUpWindow)
                        {
                            return;
                        }

                        popUpWindow.Open();
                    }
                }
                Destroy(this.gameObject);
            }
        }
        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
                                };
                            }
                        }
                    }
                }
            }
        }
Beispiel #4
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);
        }
Beispiel #5
0
        private void Update()
        {
#if MIXCAST_STEAMVR
            if (VRInfo.IsDeviceOpenVR())
            {
                Update_SteamVR();
            }
#endif
        }
Beispiel #6
0
        private void OnDestroy()
        {
#if MIXCAST_STEAMVR
            if (VRInfo.IsDeviceOpenVR())
            {
                OnDestroy_SteamVR();
            }
#endif
        }
Beispiel #7
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()
        }
Beispiel #10
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);
        }
Beispiel #12
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);
        }
Beispiel #13
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);
        }
Beispiel #14
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);
        }
Beispiel #15
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);
        }
 private void Update_SteamVR()
 {
     for (int i = 0; i < trackedObjects.Length; i++)
     {
         TrackedDevicePose_t pose = trackedObjects[i];
         if (pose.bDeviceIsConnected)
         {
             if (string.IsNullOrEmpty(trackedObjectGuids[i]))
             {
                 string checkGuid = VRInfo.GetDeviceSerial((uint)i);
                 if (!string.IsNullOrEmpty(checkGuid))
                 {
                     trackedObjectGuids[i] = checkGuid;
                 }
             }
         }
         else
         {
             trackedObjectGuids[i] = null;
         }
     }
 }
Beispiel #17
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);
        }
        bool GetTrackedTransform_Steam(out Vector3 pos, out Quaternion rot)
        {
            pos = Vector3.zero;
            rot = Quaternion.identity;

            if (string.IsNullOrEmpty(context.Data.trackedByDeviceId))
            {
                lastTrackingDeviceId = null;
                if (!string.IsNullOrEmpty(context.Data.trackedByDevice))
                {
                    SteamVR_TrackedObject.EIndex deviceIndex = (SteamVR_TrackedObject.EIndex)System.Enum.Parse(typeof(SteamVR_TrackedObject.EIndex), context.Data.trackedByDevice);
                    context.Data.trackedByDeviceId = VRInfo.GetDeviceSerial((uint)deviceIndex);
                }
                else
                {
                    return(false);
                }
            }

            try
            {
                if (lastTrackingDeviceId != context.Data.trackedByDeviceId)
                {
                    if (trackedObject == null)
                    {
                        var proxy = new GameObject("Tracking Proxy");
                        proxy.transform.parent = transform;
                        trackedObject          = proxy.AddComponent <SteamVR_TrackedObject>();
                    }

                    lastTrackingDeviceId = null;

                    for (int i = 0; i < Valve.VR.OpenVR.k_unMaxTrackedDeviceCount; i++)
                    {
                        string deviceId = VRInfo.GetDeviceSerial((uint)i);
                        if (deviceId == context.Data.trackedByDeviceId)
                        {
                            trackedObject.SetDeviceIndex(i);
                            trackedObject.enabled = false;  //Reset component so trackedObject.isValid will be helpful again
                            trackedObject.enabled = true;
                            lastTrackingDeviceId  = context.Data.trackedByDeviceId;
                            break;
                        }
                    }
                    newPosesAppliedAction.enabled = true;
                    isTrackedDeviceReady          = false;

                    return(false);
                }

                if (!isTrackedDeviceReady ||
                    string.IsNullOrEmpty(lastTrackingDeviceId) ||
                    trackedObject == null ||
                    !trackedObject.isValid)
                {
                    return(false);
                }

                pos = trackedObject.transform.localPosition;
                rot = trackedObject.transform.localRotation;

                return(true);
            }
            catch (System.Exception)
            {
                return(false);
            }
        }