// Use this for initialization
 void Start()
 {
     if (XRDevice.GetTrackingSpaceType() == TrackingSpaceType.Stationary)
     {
         transform.position += offsetAmount;
     }
 }
Example #2
0
 // Start is called before the first frame update
 void OnEnable()
 {
     UnityEngine.XR.InputTracking.disablePositionalTracking = true;
     XRDevice.DisableAutoXRCameraTracking(_Camtodisable, disabled);
     gameObject.transform.Translate(0, 0, 0);
     transform.localRotation = Quaternion.identity;
 }
Example #3
0
    public bool SetTrackingSpaceType(TrackingSpaceType newSpaceType)
    {
        TrackingSpaceType current = XRDevice.GetTrackingSpaceType();

        if (current != newSpaceType)
        {
            bool newValue = XRDevice.SetTrackingSpaceType(newSpaceType);
            Debug.Assert(newValue != false, "Failed to set tracking space type");
            current = XRDevice.GetTrackingSpaceType();
            Debug.Assert(current == newSpaceType, "Unexpected space type after set");

            if (origin != null)
            {
                if (current == TrackingSpaceType.Stationary)
                {
                    origin.transform.localPosition = new Vector3(0f, .5f, 0f);
                }
                else
                {
                    origin.transform.localPosition = Vector3.zero;
                }
            }
            StartCoroutine(TraceCameraPosition(3f));
            return(newValue);
        }
        else
        {
            TraceHelper.Log("Ignoring Tracking spaceType " + newSpaceType);
        }
        return(true);
    }
        /// <summary>
        /// Uses the TryGetGeometry call and Unity Bounds to create a volume out of the setup boundary.
        /// </summary>
        public void CalculateBoundaryVolume()
        {
            // TODO: BUG: Unity: Should return true if a floor and boundary has been established by user.
            // But this always returns false with b8.
            //if (!UnityEngine.Experimental.XR.Boundary.configured)
            //{
            //    Debug.Log("Boundary not configured.");
            //    return;
            //}

            if (XRDevice.GetTrackingSpaceType() != TrackingSpaceType.RoomScale)
            {
                Debug.Log("No boundary for stationary scale experiences.");
                return;
            }

            boundaryBounds = new Bounds();
            // Get all the bounds setup by the user.
            var boundaryGeometry = new List <Vector3>(0);

            if (UnityEngine.Experimental.XR.Boundary.TryGetGeometry(boundaryGeometry))
            {
                if (boundaryGeometry.Count > 0)
                {
                    // Create a UnityEngine.Bounds volume with those values.
                    foreach (Vector3 boundaryGeo in boundaryGeometry)
                    {
                        boundaryBounds.Encapsulate(boundaryGeo);
                    }
                }
            }

            // Ensuring that we set height of the bounds volume to be say 10 feet tall.
            boundaryBounds.Encapsulate(new Vector3(0, boundaryHeight, 0));
        }
Example #5
0
        private void Start()
        {
            LeftHandInputDevice = new PlayerHandInputDevice(HumanBodyPart.LeftHand, settings);

            RightHandInputDevice = new PlayerHandInputDevice(HumanBodyPart.RightHand, settings);

            SubsystemManager.GetInstances(_subsystems);

            foreach (var inputSubsystem in _subsystems)
            {
                Debug.Log("Detected subsystem " + inputSubsystem.GetType());
                inputSubsystem.TrySetTrackingOriginMode(TrackingOriginModeFlags.Floor);
            }


            if (_subsystems.Count == 0)
            {
                XRDevice.SetTrackingSpaceType(TrackingSpaceType.RoomScale);
                Debug.LogWarning("No Subsystems detected");
            }

            impulse = new byte[20];

            var caps = new HapticCapabilities();

            int clipCount = (int)(caps.bufferFrequencyHz * 2);

            impulse = new byte[clipCount];

            for (int i = 0; i < clipCount; i++)
            {
                impulse[i] = byte.MaxValue;
            }
        }
Example #6
0
        /// <summary>
        /// Places the player in the specified position of the world
        /// </summary>
        /// <param name="worldPosition"></param>
        public void SetWorldPosition(Vector3 worldPosition)
        {
            // There are two things moving the camera: the camera parent (that this script is attached to)
            // and the user's head (which the MR device is attached to. :)). When setting the world position,
            // we need to set it relative to the user's head in the scene so they are looking/standing where
            // we expect.
            var newPosition = worldPosition - (CameraCache.Main.transform.position - transform.position);

            // If we're Stationary, we'll need to raycast to estimate our height. In RoomScale, that will be accounted for by the offset between the camera and its parent.
#if UNITY_2017_2_OR_NEWER
            if (XRDevice.GetTrackingSpaceType() == TrackingSpaceType.Stationary && !StayOnTheFloor)
#else
            if (VRDevice.GetTrackingSpaceType() == TrackingSpaceType.Stationary && !StayOnTheFloor)
#endif
            {
                RaycastHit hitInfo;
                newPosition.y += (Physics.Raycast(CameraCache.Main.transform.position, Vector3.down, out hitInfo, 5.0f) ? hitInfo.distance : 1.7f);
            }
            else
            {
                newPosition.y = StayOnTheFloor ? transform.position.y : worldPosition.y;
            }

            transform.position = newPosition;
        }
        /// <summary>
        /// Updates the <see cref="TrackingSpaceType"/> on the XR device.
        /// </summary>
        private void SetTrackingSpace()
        {
            TrackingSpaceType trackingSpace;

            // In current versions of Unity, there are two types of tracking spaces. For boundaries, if the scale
            // is not Room or Standing, it currently maps to TrackingSpaceType.Stationary.
            switch (Scale)
            {
            case ExperienceScale.Standing:
            case ExperienceScale.Room:
                trackingSpace = TrackingSpaceType.RoomScale;
                break;

            case ExperienceScale.OrientationOnly:
            case ExperienceScale.Seated:
            case ExperienceScale.World:
                trackingSpace = TrackingSpaceType.Stationary;
                break;

            default:
                trackingSpace = TrackingSpaceType.Stationary;
                Debug.LogWarning("Unknown / unsupported ExperienceScale. Defaulting to Stationary tracking space.");
                break;
            }

            bool trackingSpaceSet = XRDevice.SetTrackingSpaceType(trackingSpace);

            if (!trackingSpaceSet)
            {
                // TODO: how best to handle this scenario?
            }
        }
Example #8
0
        /// <summary>
        /// Initialization.
        /// </summary>
        private IEnumerator Start()
        {
            if (XRDevice.GetTrackingSpaceType() != TrackingSpaceType.RoomScale)
            {
                XRDevice.SetTrackingSpaceType(TrackingSpaceType.RoomScale);
            }

            if (playerSpace == null)
            {
                playerSpace = new GameObject("Play Space");
            }
            //playerSpace.transform.localPosition = InputTracking.GetLocalPosition (XRNode.TrackingReference);
            //playerSpace.transform.localRotation = InputTracking.GetLocalRotation (XRNode.TrackingReference);

            leftHand  = new GameObject("Left Hand");
            rightHand = new GameObject("Right Hand");

            leftHand.transform.SetParent(playerSpace.transform);
            rightHand.transform.SetParent(playerSpace.transform);

            yield return(StartCoroutine(DoSetLanguage(keyboardLayout)));

            validationNotice.SetActive(false);
            infoNotice.SetActive(false);
            successNotice.SetActive(false);

            UpdateDisplayText();
            PlaceholderVisibility();

            initialized = true;
        }
Example #9
0
        void SetCameraHeight()
        {
            float cameraYOffset = m_StationaryCameraYOffset;

            if (m_TrackingSpace == TrackingSpace.Stationary)
            {
                XRDevice.SetTrackingSpaceType(TrackingSpaceType.Stationary);

                // make the user face to the forward direction
                InputTracking.Recenter();
            }

            // if on a room-scale experience, we disregard the height the user entered
            else if (m_TrackingSpace == TrackingSpace.RoomScale)
            {
                if (XRDevice.SetTrackingSpaceType(TrackingSpaceType.RoomScale))
                {
                    cameraYOffset = 0;
                }
            }

            //Move floor offset to correct height
            if (m_CameraFloorOffsetObject)
            {
                m_CameraFloorOffsetObject.transform.localPosition = new Vector3(m_CameraFloorOffsetObject.transform.localPosition.x, cameraYOffset, m_CameraFloorOffsetObject.transform.localPosition.z);
            }
        }
Example #10
0
 void Awake()
 {
     Time.fixedDeltaTime = Time.timeScale / XRDevice.refreshRate;
     rigidbody           = GetComponent <Rigidbody>();
     collider            = GetComponent <CapsuleCollider>();
     XRDevice.SetTrackingSpaceType(TrackingSpaceType.RoomScale);
 }
Example #11
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
            });
        }
Example #12
0
    // Use this for initialization
    void Start()
    {
        rotationalSpeed = 10;
        tcounter        = GameObject.FindGameObjectWithTag("counter").GetComponent <TextMesh>();
        particles       = GameObject.FindGameObjectWithTag("particles").GetComponent <ParticleSystem>();
        a      = GetComponent <Animator>();
        button = GameObject.FindGameObjectWithTag("button");
        if (XRDevice.SetTrackingSpaceType(TrackingSpaceType.RoomScale))
        {
            // RoomScale mode was set successfully.  App can now assume that y=0 in Unity world coordinate represents the floor.
            Debug.Log("Roomscale success");
        }
        else
        {
            Debug.Log("Roomscale not");
            // RoomScale mode was not set successfully.  App cannot make assumptions about where the floor plane is.
        }

        ger = new GestureRecognizer();
        //ger.SetRecognizableGestures(GestureSettings.Tap);
        //ger.SetRecognizableGestures(GestureSettings.Hold);
        ger.TappedEvent        += GestureRecognizer_TappedEvent;
        ger.HoldCompletedEvent += GestureRecognizer_HoldEvent;
        ger.HoldStartedEvent   += GestureRecognizer_HoldStarted;


        ger.StartCapturingGestures();
        conv = GameObject.FindGameObjectWithTag("spawner");
    }
    void SetCameraHeight()
    {
        var cameraYOffset = this.m_StationaryCameraYOffset;

        if (this.m_TrackingSpace == TrackingSpace.Stationary)
        {
            XRDevice.SetTrackingSpaceType(TrackingSpaceType.Stationary);
            InputTracking.Recenter();
        }
        else if (this.m_TrackingSpace == TrackingSpace.RoomScale)
        {
            if (XRDevice.SetTrackingSpaceType(TrackingSpaceType.RoomScale))
            {
                cameraYOffset = 0;
            }
        }

        //Move camera to correct height
        if (this.m_CameraFloorOffsetObject)
        {
            this.m_CameraFloorOffsetObject.transform.localPosition = new Vector3(
                this.m_CameraFloorOffsetObject.transform.localPosition.x,
                cameraYOffset,
                this.m_CameraFloorOffsetObject.transform.localPosition.z);
        }
    }
Example #14
0
 // Use this for initialization
 void Start()
 {
     _lastFramePosition = transform.position;
     XRDevice.SetTrackingSpaceType(TrackingSpaceType.RoomScale);
     _currentGrabObject = null;
     _isGrabbing        = false;
 }
        public bool SetTrackingSpaceType(TrackingSpaceType newSpaceType)
        {
            TrackingSpaceType currentSpaceType = XRDevice.GetTrackingSpaceType();
            bool result = true;

            if (currentSpaceType != newSpaceType)
            {
                result = XRDevice.SetTrackingSpaceType(newSpaceType);
                Debug.Assert(result != false, "Failed to set tracking space type");
                currentSpaceType = XRDevice.GetTrackingSpaceType();
                Debug.Assert(currentSpaceType == newSpaceType, "Unexpected space type after set");
                if (origin != null)
                {
                    if (currentSpaceType == TrackingSpaceType.Stationary)
                    {
                        origin.transform.localPosition = new Vector3(0f, .5f, 0f);
                    }
                    else
                    {
                        origin.transform.localPosition = Vector3.zero;
                    }
                }
            }
            Debug.Log("Space type is now: " + currentSpaceType.ToString());
            return(result);
        }
    void SetCameraHeight()
    {
        float cameraYOffset = m_StationaryCameraYOffset;

        if (m_TrackingSpace == TrackingSpace.Stationary)
        {
            XRDevice.SetTrackingSpaceType(TrackingSpaceType.Stationary);
            // InputTracking.Recenter();
        }
        else if (m_TrackingSpace == TrackingSpace.RoomScale)
        {
            if (XRDevice.SetTrackingSpaceType(TrackingSpaceType.RoomScale))
            {
                cameraYOffset = 0;
            }
        }

        //Move camera to correct height
        if (m_CameraFloorOffsetObject)
        {
            var yOffset = m_StationaryCameraYOffset;
            if (m_InACar)
            {
                yOffset += m_CarHeightOffset;
            }
            m_CameraFloorOffsetObject.transform.localPosition = new Vector3(m_CameraFloorOffsetObject.transform.localPosition.x, yOffset, m_CameraFloorOffsetObject.transform.localPosition.z);
        }
    }
Example #17
0
        internal static XRRig CreateXRRig()
        {
            var xrRigGO = new GameObject("XR Rig");
            xrRigGO.SetActive(false);
            var xrRig = xrRigGO.AddComponent<XRRig>();
            xrRig.rig = xrRigGO;

            // Add camera offset
            var cameraOffsetGO = new GameObject("CameraOffset");
            cameraOffsetGO.transform.SetParent(xrRig.transform,false);
            xrRig.cameraFloorOffsetObject = cameraOffsetGO;

            xrRig.transform.position = Vector3.zero;
            xrRig.transform.rotation = Quaternion.identity;

            // Add camera
            var cameraGO = new GameObject("Camera");
            var camera = cameraGO.AddComponent<Camera>();

            cameraGO.transform.SetParent(cameraOffsetGO.transform, false);
            xrRig.cameraGameObject = cameraGO;
            xrRigGO.SetActive(true);

            XRDevice.DisableAutoXRCameraTracking(camera, true);

            return xrRig;
        }
Example #18
0
        /// <summary>
        /// Updates the <see href="https://docs.unity3d.com/ScriptReference/XR.TrackingSpaceType.html">TrackingSpaceType</see> on the XR device.
        /// </summary>
        protected override void SetTrackingSpace()
        {
            if (Application.isPlaying)
            {
                TrackingSpaceType trackingSpace;

                // In current versions of Unity, there are two types of tracking spaces. For boundaries, if the scale
                // is not Room or Standing, it currently maps to TrackingSpaceType.Stationary.
                switch (Scale)
                {
                case ExperienceScale.Standing:
                case ExperienceScale.Room:
                    trackingSpace = TrackingSpaceType.RoomScale;
                    break;

                case ExperienceScale.OrientationOnly:
                case ExperienceScale.Seated:
                case ExperienceScale.World:
                    trackingSpace = TrackingSpaceType.Stationary;
                    break;

                default:
                    trackingSpace = TrackingSpaceType.Stationary;
                    Debug.LogWarning("Unknown / unsupported ExperienceScale. Defaulting to Stationary tracking space.");
                    break;
                }

                InputTracking.disablePositionalTracking = Scale == ExperienceScale.OrientationOnly;

                if (!XRDevice.SetTrackingSpaceType(trackingSpace))
                {
                    Debug.LogWarning($"MRTK was unable to set Tracking Space to {trackingSpace}");
                }
            }
        }
Example #19
0
    void Init()
    {
        var devices = new List <InputDevice>();

        InputDevices.GetDevicesAtXRNode(XRNode.LeftHand, devices);
        if (devices.Count == 1)
        {
            ld = devices[0];
        }
        devices = new List <InputDevice>();
        InputDevices.GetDevicesAtXRNode(XRNode.RightHand, devices);
        if (devices.Count == 1)
        {
            rd = devices[0];
        }
        XRDevice.SetTrackingSpaceType(TrackingSpaceType.RoomScale);
        Vector3 p1, p2;

        ld.TryGetFeatureValue(CommonUsages.devicePosition, out p1);
        rd.TryGetFeatureValue(CommonUsages.devicePosition, out p2);
        if (p1 == Vector3.zero || p2 == Vector3.zero)
        {
            Invoke("Init", 1.0f);
        }
    }
        void SetCameraHeight()
        {
            float cameraYOffset = _stationaryCameraYOffset;

            if (_trackingSpace == TrackingSpace.Stationary)
            {
                XRDevice.SetTrackingSpaceType(TrackingSpaceType.Stationary);
                InputTracking.Recenter();
            }
            else if (_trackingSpace == TrackingSpace.RoomScale)
            {
                if (XRDevice.SetTrackingSpaceType(TrackingSpaceType.RoomScale))
                {
                    cameraYOffset = 0;
                }
            }
            if (_cameraFloorOffsetObject)
            {
                _cameraFloorOffsetObject.transform.localPosition = new Vector3(
                    _cameraFloorOffsetObject.transform.localPosition.x,
                    cameraYOffset,
                    _cameraFloorOffsetObject.transform.localPosition.z
                    );
            }
        }
        protected override void Awake()
        {
            base.Awake();

#if UNITY_WSA && UNITY_2017_2_OR_NEWER
            if (HolographicSettings.IsDisplayOpaque)
            {
                XRDevice.SetTrackingSpaceType(opaqueTrackingSpaceType);
            }
            else
            {
                // Removed for now, until the HoloLens tracking space type story is more clear.
                //XRDevice.SetTrackingSpaceType(transparentTrackingSpaceType);

                Destroy(this);
                return;
            }

            // Render the floor based on if you are in editor or immersive device.
            RenderFloorQuad();

            // Render boundary if configured.
            SetBoundaryRendering();

            // Create a volume out of the specified user boundary.
            CalculateBoundaryVolume();
        }
        protected override void Awake()
        {
            base.Awake();

#if UNITY_WSA
            if (HolographicSettings.IsDisplayOpaque)
            {
                XRDevice.SetTrackingSpaceType(opaqueTrackingSpaceType);
            }
            else
            {
                XRDevice.SetTrackingSpaceType(transparentTrackingSpaceType);

                Destroy(this);
                return;
            }

            // Render the floor based on if you are in editor or immersive device.
            RenderFloorQuad();

            // Render boundary if configured.
            SetBoundaryRendering();

            // Create a volume out of the specified user boundary.
            CalculateBoundaryVolume();
#endif
        }
Example #23
0
 void Start()
 {
     rigidBody_        = GetComponent <Rigidbody>();
     collider_         = GetComponent <Collider>();
     collider_.enabled = false;
     XRDevice.DisableAutoXRCameraTracking(GetComponent <Camera>(), true);
 }
Example #24
0
    // Use this for initialization
    void Start()
    {
        target.transform.position = new Vector3(0, 10, 0);
        target.transform.rotation = Quaternion.Euler(0, 0, 0);

        XRDevice.DisableAutoXRCameraTracking(target, true);
    }
Example #25
0
        private IEnumerator SetContentHeight()
        {
            if (frameWaitHack < 1)
            {
                // Not waiting a frame often caused the camera's position to be incorrect at this point. This seems like a Unity bug.
                frameWaitHack++;
                yield return(null);
            }

            if (alignmentType == AlignmentType.UsePresetPositions || alignmentType == AlignmentType.UsePresetXAndZWithHeadHeight)
            {
                if (XRDevice.GetTrackingSpaceType() == TrackingSpaceType.RoomScale)
                {
                    containerObject.position = roomScaleSpaceTypePosition;
                }
                else if (XRDevice.GetTrackingSpaceType() == TrackingSpaceType.Stationary)
                {
                    containerObject.position = stationarySpaceTypePosition;
                }
            }

            if (alignmentType == AlignmentType.AlignWithHeadHeight || alignmentType == AlignmentType.UsePresetXAndZWithHeadHeight)
            {
                contentPosition.x = containerObject.position.x;
                contentPosition.y = containerObject.position.y + CameraCache.Main.transform.position.y;
                contentPosition.z = containerObject.position.z;

                containerObject.position = contentPosition;
            }
        }
Example #26
0
 private void SetTrackingSpaceType()
 {
     if (XRDevice.isPresent)
     {
         XRDevice.SetTrackingSpaceType(TrackingSpace);
         Debug.Log("Tracking Space: " + XRDevice.GetTrackingSpaceType());
     }
 }
Example #27
0
   public static bool IsRoomScale()
   {
 #if UNITY_2017_2_OR_NEWER
       return(XRDevice.GetTrackingSpaceType() == TrackingSpaceType.RoomScale);
 #else
       return(VRDevice.GetTrackingSpaceType() == TrackingSpaceType.RoomScale);
 #endif
   }
Example #28
0
 private void SetTrackingSpaceType()
 {
     if (XRDevice.isPresent)
     {
         XRDevice.SetTrackingSpaceType(WebXRManager.Instance.TrackingSpace);
         Debug.Log("Tracking Space: " + XRDevice.GetTrackingSpaceType());
     }
 }
 protected virtual void Awake()
 {
     this.CacheLocalPosition();
     if (this.HasStereoCamera())
     {
         XRDevice.DisableAutoXRCameraTracking(base.GetComponent <Camera>(), true);
     }
 }
Example #30
0
    //private bool _isGrabbing;

    void Start()
    {
        animator           = GetComponent <Animator>();
        _lastFramePosition = transform.position;
        XRDevice.SetTrackingSpaceType(TrackingSpaceType.RoomScale);
        _currentGrabObject = null;
        //_isGrabbing = false;
    }