Пример #1
0
 public MirrorTextureManager(GraphicsDevice gd, VRContext vr, Swapchain sc)
 {
     _Ext_GD   = gd;
     _Ext_VR   = vr;
     _Ext_SC   = sc;
     _Commands = gd.ResourceFactory.CreateCommandList();
 }
Пример #2
0
 public IEnumerable <T> Insert(IEnumerable <T> list)
 {
     using (var db = new VRContext())
     {
         using (var trans = db.Database.BeginTransaction())
         {
             IEnumerable <T> tList = null;
             try
             {
                 tList = db.Set <T>().AddRange(list);
                 db.SaveChanges();
                 trans.Commit(); //Data Saved Successfully. Transaction Commited
                                 //tList = list;
             }
             catch (DbException ex)
             {
                 Logger.Error(ex.Message, ex);
             }
             catch (Exception ex)
             {
                 trans.Rollback();//Error Occured during data saved. Transaction Rolled Back
                 Logger.Error(ex.Message, ex);
             }
             return(tList);
         }
     }
 }
Пример #3
0
        public IEnumerable <T> GetRange(int pageIndex, int pageSize)
        {
            IEnumerable <T> result = null;

            try
            {
                using (var db = new VRContext())
                {
                    result = db.Set <T>().Where(i => !i.IsDeleted).OrderBy(i => i.Id).Skip((pageIndex - 1) * pageSize).Take(pageSize).ToList();
                }
            }
            catch (DbEntityValidationException dbEx)
            {
                foreach (var validationErrors in dbEx.EntityValidationErrors)
                {
                    foreach (var validationError in validationErrors.ValidationErrors)
                    {
                        Logger.Error(string.Format("Property: {0} Error: {1}", validationError.PropertyName, validationError.ErrorMessage));
                    }
                }
            }
            catch (DbException ex)
            {
                Logger.Error(ex.Message, ex);
            }
            catch (Exception ex)
            {
                Logger.Error(ex.Message, ex);
            }

            return(result ?? Enumerable.Empty <T>());
        }
Пример #4
0
        public IEnumerable <T> GetRange(Expression <Func <T, bool> > predicate, int pageIndex, int pageSize, out int count)
        {
            count = 0;
            IEnumerable <T> result = null;

            try
            {
                using (var db = new VRContext())
                {
                    var list = db.Set <T>().Where(i => !i.IsDeleted).Where(predicate).ToList();
                    count  = list.Count();
                    result = list.Skip((pageIndex - 1) * pageSize).Take(pageSize);
                }
            }
            catch (DbEntityValidationException dbEx)
            {
                foreach (var validationErrors in dbEx.EntityValidationErrors)
                {
                    foreach (var validationError in validationErrors.ValidationErrors)
                    {
                        Logger.Error(string.Format("Property: {0} Error: {1}", validationError.PropertyName, validationError.ErrorMessage));
                    }
                }
            }
            catch (DbException ex)
            {
                Logger.Error(ex.Message, ex);
            }
            catch (Exception ex)
            {
                Logger.Error(ex.Message, ex);
            }

            return(result ?? Enumerable.Empty <T>());
        }
Пример #5
0
        private static (GraphicsDevice gd, Swapchain sc) CreateDeviceAndSwapchain(
            Sdl2Window window,
            VRContext vrc,
            GraphicsBackend backend,
            GraphicsDeviceOptions gdo)
        {
            if (backend == GraphicsBackend.Vulkan)
            {
                (string[] instance, string[] device) = vrc.GetRequiredVulkanExtensions();

                var vdo = new VulkanDeviceOptions(instance, device);
                var gd  = GraphicsDevice.CreateVulkan(gdo, vdo);

                var swd = new SwapchainDescription(
                    VeldridStartup.GetSwapchainSource(window),
                    (uint)window.Width, (uint)window.Height,
                    gdo.SwapchainDepthFormat, gdo.SyncToVerticalBlank, true);
                var sc = gd.ResourceFactory.CreateSwapchain(swd);

                return(gd, sc);
            }
            else
            {
                var gd = VeldridStartup.CreateGraphicsDevice(window, gdo, backend);
                var sc = gd.MainSwapchain;
                return(gd, sc);
            }
        }
Пример #6
0
 /// <summary>
 /// We will lose the VR context,when reloading level.
 /// Calling this function per frame can ensure that the anchor is alive.
 /// </summary>
 public virtual bool EnsureAnchor()
 {
     // <!-- TODO: VR Legacy Mode. -->
     // If the X-Hawk isn't connected,the game will run as legacy VR mode(Gets input events with GearVR touchpad).
     if (XDevicePlugin.GetInt(m_Handle, XDevicePlugin.kField_ConnectionStateInt, 0) != (int)DeviceConnectionState.Connected)
     {
         XDevicePlugin.SetInt(m_HmdInput.handle, XDevicePlugin.kField_ConnectionStateInt, (int)DeviceConnectionState.Disconnected);
         return(false);
     }
     //
     if (trackingSpace == null)
     {
         trackingSpace = VRContext.GetAnchor(VRNode.TrackingSpace);
     }
     //
     if (anchor == null)
     {
         Transform centerEyeAnchor = VRContext.GetAnchor(VRNode.CenterEye);
         if (m_IsRequestVR && centerEyeAnchor == null)
         {
             return(false);
         }
         else
         {
             CreateAnchor();
             //
             if (m_IsRequestVR)
             {
                 VRContext.main.onRecenter -= Recenter;
                 VRContext.main.onRecenter += Recenter;
             }
         }
     }
     return(true);
 }
Пример #7
0
        // Update status
        public bool UpdateStatus(int excelDetailId, int newStatus)
        {
            Logger.Info("Update status");
            bool check = false;

            try
            {
                using (var db = new VRContext())
                {
                    var exDetail = db.ExcelDetails.SingleOrDefault(x => x.Id == excelDetailId);
                    if (exDetail != null)
                    {
                        exDetail.TruckStatus = (TruckStatus)newStatus;
                        db.SaveChanges();
                        check = true;
                    }
                    else
                    {
                        check = false;
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Info(ex.Message, ex);
            }

            return(check);
        }
Пример #8
0
        public T SingleBy(Expression <Func <T, bool> > predicate)
        {
            T entity = null;

            try
            {
                using (var db = new VRContext())
                {
                    entity = db.Set <T>().Where(i => !i.IsDeleted).FirstOrDefault(predicate);
                }
            }
            catch (DbEntityValidationException dbEx)
            {
                foreach (var validationErrors in dbEx.EntityValidationErrors)
                {
                    foreach (var validationError in validationErrors.ValidationErrors)
                    {
                        Logger.Error(string.Format("Property: {0} Error: {1}", validationError.PropertyName, validationError.ErrorMessage));
                    }
                }
            }
            catch (DbException ex)
            {
                Logger.Error(ex.Message, ex);
            }
            catch (Exception ex)
            {
                Logger.Error(ex.Message, ex);
            }

            return(entity);
        }
Пример #9
0
        public IEnumerable <T> FindBy(Expression <Func <T, bool> > predicate)
        {
            IEnumerable <T> result = null;

            try
            {
                using (var db = new VRContext())
                {
                    result = db.Set <T>().Where(x => !x.IsDeleted).Where(predicate).ToList();
                }
            }
            catch (DbEntityValidationException dbEx)
            {
                foreach (var validationErrors in dbEx.EntityValidationErrors)
                {
                    foreach (var validationError in validationErrors.ValidationErrors)
                    {
                        Logger.Error(string.Format("Property: {0} Error: {1}", validationError.PropertyName, validationError.ErrorMessage));
                    }
                }
            }
            catch (DbException ex)
            {
                Logger.Error(ex.Message, ex);
            }
            catch (Exception ex)
            {
                Logger.Error(ex.Message, ex);
            }

            return(result ?? Enumerable.Empty <T>());
        }
Пример #10
0
    protected virtual void OnVRContextInited(VRContext context)
    {
        //
        if ((XDevicePlugin.GetInt(XDevicePlugin.ID_CONTEXT, XDevicePlugin.kField_CtxDeviceVersionInt, 0) & 0xF000) != 0x4000)
        {
            Destroy(this);
            Ximmerse.Log.w("TrackedHead", "TrackedHead only works in Outside-in!!!");
            return;
        }
        else
        {
            VRDevice vrDevice = context.vrDevice;
            if (vrDevice.outsideInMarkPose.position != Vector3.zero)
            {
                markTransform.localPosition = vrDevice.outsideInMarkPose.position;
            }
        }
        //
        if (eyeContainer == null)
        {
            eyeContainer = new GameObject("Rotate-Pivot").transform;
            eyeContainer.SetParent(transform);
            //
            eyeContainer.localPosition = Vector3.zero;
            eyeContainer.localRotation = Quaternion.identity;
            eyeContainer.localScale    = Vector3.one;
            //
            if (context.vrDevice != null && context.vrDevice.family != "Dummy")
            {
                markTransform.localPosition = markTransform.localPosition + context.vrDevice.neckToEye;
                eyeContainer.localPosition  = context.vrDevice.neckToEye;
#if UNITY_EDITOR
                // Editor features.
                if (m_Gizmos.Length > 0 && m_Gizmos[0] != null)
                {
                    m_Gizmos[0].transform.localPosition = m_Gizmos[0].transform.localPosition + context.vrDevice.neckToEye;
                }
#endif
            }
        }
        //
        for (int i = 0; i < 3; ++i)
        {
            Transform eye = context.GetAnchor(VRNode.LeftEye + i, null);
            if (eye != null)
            {
                eye.SetParent(eyeContainer, false);
            }
        }
        //
        switch (PlayerPrefsEx.GetInt("XimmerseDevice.type", 0))
        {
        // No head tracking.
        case 0x1010:
            source            = ControllerType.None;
            m_ControllerInput = null;
            break;
        }
    }
Пример #11
0
 /// <summary>
 /// Init X-Hawk for different user environments.
 /// </summary>
 public virtual bool InitInternal()
 {
     //
     XDevicePlugin.SetInt(m_Handle, XDevicePlugin.kField_TrackingOriginInt, (int)VRContext.trackingOrigin);
     XDevicePlugin.SendMessage(m_Handle, XDevicePlugin.kMessage_RecenterSensor, 0, 0);
     //
     if (true)
     {
         int i = 0, imax = m_Controllers.Length;
         controllers = new TrackedControllerInput[imax];
         //
         ControllerInputManager mgr = ControllerInputManager.instance;
         ControllerInput        ci;
         if (mgr != null)
         {
             for (; i < imax; ++i)
             {
                 ci = mgr.GetControllerInput(m_Controllers[i].key);
                 if (ci is TrackedControllerInput)
                 {
                     controllers[i] = ci as TrackedControllerInput;
                     controllers[i].inputTracking = this;
                     controllers[i].node          = m_Controllers[i].value;
                 }
                 else
                 {
                     controllers[i] = CreateControllerInput(m_Controllers[i].key, this, m_Controllers[i].value);
                     if (controllers[i].handle != -1)
                     {
                         mgr.AddControllerInput(controllers[i].name, controllers[i]);
                     }
                     else
                     {
                         controllers[i] = null;
                     }
                 }
                 //
                 if (i < 2)
                 {
                     m_EmulatedHands[i].Controller = controllers[i];
                     m_EmulatedHands[i].followGaze = ArmModel.GazeBehavior.Always;
                     m_EmulatedHands[i].Start();
                 }
             }
         }
     }
     // VR Context
     m_HmdInput = ControllerInputManager.GetInput(ControllerType.Hmd);
     // VRContext must have a CenterEyeAnchor at least.
     m_IsRequestVR = (VRContext.GetAnchor(VRNode.CenterEye) != null);
     EnsureAnchor();
     //
     Log.i("XHawkInput", "Initialize successfully.");
     //
     return(true);
 }
Пример #12
0
    public virtual Vector3 TransformPoint(Transform point)
    {
        Transform trackingSpace = VRContext.GetAnchor(VRNode.TrackingSpace);

        if (trackingSpace != null)
        {
            return(trackingSpace.InverseTransformPoint(point.position));
        }
        return(point.position);
    }
Пример #13
0
 public virtual void OnControllerUpdate()
 {
     if (centerEye == null)
     {
         centerEye     = VRContext.GetAnchor(VRNode.CenterEye);
         trackingSpace = VRContext.GetAnchor(VRNode.TrackingSpace);
     }
     if (unityHelper == null)
     {
         unityHelper = new GameObject("UnityHelper-" + handedness).transform;
         pointer     = new GameObject("Pointer-" + handedness).transform;
         //
         unityHelper.SetParent(trackingSpace);
         unityHelper.localPosition = Vector3.zero;
         unityHelper.localRotation = Quaternion.identity;
         unityHelper.localScale    = Vector3.one;
         pointer.SetParent(unityHelper);
         pointer.localPosition = Vector3.zero;
         pointer.localRotation = Quaternion.identity;
         pointer.localScale    = Vector3.one;
     }
     if (centerEye != null)
     {
         //
         unityHelper.position = centerEye.position                                                                     //@Eye
                                - centerEye.rotation * NECK_TO_EYE                                                     //@Neck
                                + Quaternion.AngleAxis(centerEye.rotation.eulerAngles.y, Vector3.up) * neckToShoulder; //@Shoulder
         //
         Quaternion rotation = Quaternion.LookRotation(Controller.GetRotation() * Vector3.forward, Vector3.up);
         if (trackingSpace != null)
         {
             unityHelper.rotation = trackingSpace.rotation * rotation;
         }
         else
         {
             unityHelper.rotation = rotation;
         }
         //
         if ((XDevicePlugin.GetInt(Controller.handle, XDevicePlugin.kField_TrackingResultInt, 0) & (int)TrackingResult.PositionTracked) == 0)
         {
         }
         else
         {
             if (trackingSpace == null)
             {
                 pointer.position = Controller.GetPosition();
             }
             else
             {
                 pointer.position = trackingSpace.TransformPoint(Controller.GetPosition());
             }
         }
     }
 }
Пример #14
0
    public override void Launch(bool checkOthers)
    {
        //
        XDevicePlugin.Init();
        XDevicePlugin.SetInt(-1, XDevicePlugin.kField_CtxDeviceVersion, 0x3000);
        //
        base.Launch(checkOthers);
        // Create control points in runtime.
        Transform trackingSpace = VRContext.GetAnchor(VRNode.TrackingSpace);

        for (int i = 0; i < 3; ++i)
        {
            if (docks[i] != null)
            {
                GameObject go   = Instantiate(docks[i]);
                Transform  t    = docks[i].transform;
                Transform  newT = go.transform;
                //
                go.name = docks[i].name;

                newT.SetParent(trackingSpace);
                newT.localPosition = t.localPosition;
                newT.localRotation = t.localRotation;
                newT.localScale    = t.localScale;
                //
                docks[i] = go;
            }
        }
        // Initialize play area.
        m_PlayAreaRenderer = docks[2].GetComponentInChildren <PlayAreaRenderer>();
        if (m_PlayAreaRenderer != null)
        {
            m_PlayArea    = m_PlayAreaRenderer.transform;
            m_BoundaryPtr = NativeMethods.Boundary_Alloc(-1, 4, -2.0f, 2.0f);
            for (int i = 0, imax = m_PlayAreaRenderer.corners.Length; i < imax; ++i)
            {
                NativeMethods.Boundary_SetCorner(m_BoundaryPtr, i,
                                                 m_PlayAreaRenderer.corners[i].x, -m_PlayAreaRenderer.corners[i].z
                                                 );
            }
        }
        //
        Transform head = VRContext.GetAnchor(VRNode.Head);

        if (head != null)
        {
            TrackedHead trackedHead = head.GetComponent <TrackedHead>();
            if (trackedHead != null)
            {
                trackedHead.markTransform.localPosition =
                    head.InverseTransformPoint(anchor.position);
            }
        }
    }
Пример #15
0
    public virtual Vector3 TransformPoint(Vector3 point)
    {
        point = m_Transform.TransformPoint(point);
        //
        Transform trackingSpace = VRContext.GetAnchor(VRNode.TrackingSpace);

        if (trackingSpace != null)
        {
            return(trackingSpace.InverseTransformPoint(point));
        }
        return(point);
    }
Пример #16
0
 /// <summary>
 ///
 /// </summary>
 public virtual bool InitInternal()
 {
     if (m_IsInited)
     {
         return(true);
     }
     m_IsInited = true;
     // Plugin context.
     deviceName = "XHawk-0";
     if (m_Handle == -1)
     {
         m_Handle = XDevicePlugin.GetInputDeviceHandle(deviceName);
     }
     XDevicePlugin.SetInt(m_Handle, XDevicePlugin.kField_TrackingOriginInt, (int)VRContext.trackingOrigin);
     XDevicePlugin.SendMessage(m_Handle, XDevicePlugin.kMessage_RecenterSensor, 0, 0);
     //
     if (true)
     {
         int i = 0, imax = m_Controllers.Length;
         controllers = new TrackedControllerInput[imax];
         //
         ControllerInputManager mgr = ControllerInputManager.instance;
         ControllerInput        ci;
         if (mgr != null)
         {
             for (; i < imax; ++i)
             {
                 ci = mgr.GetControllerInput(m_Controllers[i].key);
                 if (ci is TrackedControllerInput)
                 {
                     controllers[i] = ci as TrackedControllerInput;
                     controllers[i].inputTracking = this;
                     controllers[i].node          = m_Controllers[i].value;
                 }
                 else
                 {
                     controllers[i] = CreateControllerInput(m_Controllers[i].key, this, m_Controllers[i].value);
                     mgr.AddControllerInput(controllers[i].name, controllers[i]);
                 }
             }
         }
     }
     // VR Context
     m_HmdInput = ControllerInputManager.GetInput(ControllerType.Hmd);
     // VRContext must have a CenterEyeAnchor at least.
     m_IsRequestVR = (VRContext.GetAnchor(VRNode.CenterEye) != null);
     EnsureAnchor();
     //
     Log.i("XHawkInput", "Initialize successfully.");
     //
     return(true);
 }
Пример #17
0
    protected virtual void Start()
    {
        //
        if (checkParent)
        {
            Transform p = VRContext.GetAnchor(VRNode.TrackingSpace);
            if (p != null)
            {
                target.SetParent(p, true);
            }
        }
        //
        m_ControllerInput = ControllerInputManager.instance.GetControllerInput(source);
        VRNode node = VRNode.None;

        switch (source)
        {
        case ControllerType.LeftController:
            node = VRNode.LeftHand;
            break;

        case ControllerType.RightController:
            node = VRNode.RightHand;
            break;
        }
        if (node != VRNode.None)
        {
            VRContext.SetAnchor(node, target);
        }
        //
        if (m_ControllerInput != null && canRecenter)
        {
            // Like SteamVR,hmd and controllers don't need to reset yaw angle.
            canRecenter = !m_ControllerInput.isAbsRotation;
        }
        //
        if (canRecenter)
        {
            // Invoke Recenter() on VRContext recenter event.
            VRContext ctx = VRContext.main;
            if (ctx != null)
            {
                ctx.onRecenter += Recenter;
            }
        }
        //
        return;

        // TODO:
        enabled = false;
        UpdatePoses.instance.onUpdatePoses += Update;
    }
Пример #18
0
 /// <summary>
 /// The GetHeadsetCamera method returns the Transform of the object that is used to hold the headset camera in the scene.
 /// </summary>
 /// <returns>A transform of the object holding the headset camera in the scene.</returns>
 public override Transform GetHeadsetCamera()
 {
     cachedHeadsetCamera = GetSDKManagerHeadset();
     if (cachedHeadsetCamera == null)
     {
         var foundCamera = VRContext.GetAnchor(VRNode.CenterEye);
         if (foundCamera)
         {
             cachedHeadsetCamera = foundCamera.transform;
         }
     }
     return(cachedHeadsetCamera);
 }
Пример #19
0
 public virtual void AlignHmdDelayed()
 {
     if (PlayerPrefsEx.GetBool("VRDevice.forceFadeOnBadTracking"))
     {
         m_GameStartTime = Time.timeSinceLevelLoad;
         //
         VRContext.main.fadeFx.onBecameVisible.RemoveListener(AlignHmdDelayed);
         VRContext.main.fadeFx.onBecameInvisible.AddListener(AlignHmdFinished);
         VRContext.FadeOut(1.0f, 0.15f);
         //
         StartCoroutine(RecenterAllControllersDelayed(0.99f, GetRawYaw() + m_YawOffset));
     }
 }
Пример #20
0
        public virtual Vector3 GetHeadOrientation()
        {
            Transform centerEye     = VRContext.GetAnchor(VRNode.CenterEye);
            Transform trackingSpace = VRContext.GetAnchor(VRNode.TrackingSpace);

            if (trackingSpace == null)
            {
                return(centerEye.forward);
            }
            else
            {
                return(trackingSpace.InverseTransformDirection(centerEye.forward));
            }
        }
 public override void UpdateAnchor()
 {
     if (m_CenterEye == null)
     {
         m_CenterEye = VRContext.GetAnchor(VRNode.CenterEye);
         if (m_CenterEye == null)
         {
             return;
         }
     }
     //
     anchor.localPosition = m_CenterEye.localPosition + m_CenterEye.localRotation * m_AnchorPosition;
     anchor.localRotation = m_CenterEye.localRotation * m_AnchorRotation;
 }
Пример #22
0
        private static void Draw(VeldridDrawingFactory factory, VRContext vrContext)
        {
            var poses = vrContext.WaitForPoses();

            var lv = poses.CreateView(VREye.Left, _userPosition, -Vector3.UnitZ, Vector3.UnitY);
            var lp = poses.LeftEyeProjection;

            var rv = poses.CreateView(VREye.Right, _userPosition, -Vector3.UnitZ, Vector3.UnitY);
            var rp = poses.RightEyeProjection;

            // why it works reversing the eyes !???

            DrawEye(factory, vrContext.LeftEyeFramebuffer, rv, rp);
            DrawEye(factory, vrContext.RightEyeFramebuffer, lv, lp);
        }
Пример #23
0
        public bool Update(List <T> dtoList)
        {
            using (var db = new VRContext())
            {
                using (var trans = db.Database.BeginTransaction())
                {
                    T entity = null;
                    try
                    {
                        var dbSet = db.Set <T>();
                        dtoList.ForEach(x =>
                        {
                            entity = dbSet.Find(x.Id);
                            if (entity != null)
                            {
                                db.Entry(entity).CurrentValues.SetValues(x);
                            }
                        });

                        db.SaveChanges();
                        trans.Commit();//Data Saved Successfully. Transaction Commited
                        return(true);
                    }
                    catch (DbEntityValidationException dbEx)
                    {
                        foreach (var validationErrors in dbEx.EntityValidationErrors)
                        {
                            foreach (var validationError in validationErrors.ValidationErrors)
                            {
                                Logger.Error(string.Format("Property: {0} Error: {1}", validationError.PropertyName, validationError.ErrorMessage));
                            }
                        }
                        return(false);
                    }
                    catch (DbException ex)
                    {
                        Logger.Error(ex.Message, ex);
                        return(false);
                    }
                    catch (Exception ex)
                    {
                        trans.Rollback();//Error Occured during data saved. Transaction Rolled Back
                        Logger.Error(ex.Message, ex);
                        return(false);
                    }
                }
            }
        }
Пример #24
0
 protected virtual void Update()
 {
     if (m_TrackedHead != null)
     {
         TryFixMarkOffset();
     }
     if (uiRoot.activeSelf)
     {
         //
         if (uiHmdRotation != null)
         {
             uiHmdRotation.value = VRContext.GetAnchor(VRNode.CenterEye).localRotation.eulerAngles;
         }
         //
     }
 }
Пример #25
0
        private float getHmdYaw()
        {
            float yaw = -1;

#if (UNITY_ANDROID && !UNITY_EDITOR)
            yaw = XDeviceGetHmdYaw(m_TempHmdRotation);
#else
            Quaternion rotation = VRContext.GetHmdRotation();
            m_TempHmdRotation[0] = -rotation.x;
            m_TempHmdRotation[1] = -rotation.y;
            m_TempHmdRotation[2] = rotation.z;
            m_TempHmdRotation[3] = rotation.w;
            //
            yaw = XDeviceGetHmdYaw(m_TempHmdRotation);
#endif
            return(yaw);
        }
Пример #26
0
    public override void UpdateTransform(float factor)
    {
        if (m_ControllerInput == null)
        {
            return;
        }
        //
        if ((m_ControllerInput.trackingResult & TrackingResult.PositionTracked) == 0)
        {
            return;
        }
        //
        Vector3 position = m_ControllerInput.GetPosition();
        //
        Vector3   markOffset = markTransform.localPosition;
        Transform centerEyeAnchor;

        switch (trackingType)
        {
        case TrackingType.Inside_Out:
            // Solve order : trackingOrigin->[TrackingInput.anchor]->MarkAnchor->HeadAnchor.
            centerEyeAnchor = VRContext.GetAnchor(VRNode.CenterEye);
            if (centerEyeAnchor != null)
            {
                position = trackingOrigin.localPosition - centerEyeAnchor.localRotation * (position + markOffset);
            }
            break;

        case TrackingType.Outside_In:
            // Solve order : TrackingInput.GetPosition()->MarkAnchor->HeadAnchor.
            centerEyeAnchor = VRContext.GetAnchor(VRNode.CenterEye);
            if (centerEyeAnchor != null)
            {
                position += centerEyeAnchor.localRotation * (-markOffset);
            }
            break;
        }
        if (factor == 1.0f)
        {
            target.localPosition = position;
        }
        else
        {
            target.localPosition = Vector3.Lerp(target.localPosition, position, factor);
        }
    }
        public override Vector3 GetLocalPosition(int node)
        {
            Vector3 position = base.GetLocalPosition(node);

            if (node == m_Controllers[2].value)
            {
                if (m_CenterEye == null)
                {
                    m_CenterEye = VRContext.GetAnchor(VRNode.CenterEye);
                    m_VRDevice  = VRContext.currentDevice;
                }
                if (m_CenterEye != null && m_VRDevice != null)
                {
                    position -= m_CenterEye.localRotation * (m_VRDevice.neckToEye + m_VRDevice.outsideInMarkPose.position);
                }
            }
            return(position);
        }
Пример #28
0
        private static void VeldridRunLoop(Sdl2Window window, GraphicsDevice gd, VRContext vr, Action action)
        {
            while (window.Exists)
            {
                var input = window.PumpEvents();

                if (!window.Exists)
                {
                    continue;
                }

                action();
                vr.SubmitFrame();

                _MirrorTexMgr.Run(MirrorTextureEyeSource.BothEyes);
                gd.SwapBuffers();
            }
        }
Пример #29
0
 public virtual void AlignHmd()
 {
     if (m_IsHmdRecentering)
     {
         return;
     }
     m_IsHmdRecentering = true;
     //
     if (PlayerPrefsEx.GetBool("VRDevice.forceFadeOnBadTracking"))
     {
         VRContext.main.fadeFx.onBecameVisible.AddListener(AlignHmdDelayed);
         VRContext.FadeIn(0.0f, 0.15f);
     }
     else
     {
         m_ForceRecenterHmdFrameCount = Time.frameCount + 1;
         m_IsHmdRecentering           = false;
     }
 }
Пример #30
0
    protected virtual void OnVRContextInited(VRContext context)
    {
        if (eyeContainer == null)
        {
            eyeContainer = new GameObject("Rotate-Pivot").transform;
            eyeContainer.SetParent(transform);
            //
            eyeContainer.localPosition = Vector3.zero;
            eyeContainer.localRotation = Quaternion.identity;
            eyeContainer.localScale    = Vector3.one;
            //
            if (context.vrDevice != null && context.vrDevice.family != "Dummy")
            {
                markTransform.localPosition = markTransform.localPosition + context.vrDevice.neckOffset;
                eyeContainer.localPosition  = context.vrDevice.neckOffset;
#if UNITY_EDITOR
                // Editor features.
                if (m_Gizmos.Length > 0 && m_Gizmos[0] != null)
                {
                    m_Gizmos[0].transform.localPosition = m_Gizmos[0].transform.localPosition + context.vrDevice.neckOffset;
                }
#endif
            }
        }
        //
        for (int i = 0; i < 3; ++i)
        {
            Transform eye = context.GetAnchor(VRNode.LeftEye + i, null);
            if (eye != null)
            {
                eye.SetParent(eyeContainer, false);
            }
        }
        //
        switch (PlayerPrefsEx.GetInt("XimmerseDevice.type", 0))
        {
        // No head tracking.
        case 0x1010:
            source            = ControllerType.None;
            m_ControllerInput = null;
            break;
        }
    }