コード例 #1
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);
 }
コード例 #2
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);
 }
コード例 #3
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);
 }
コード例 #4
0
        /// <summary>
        ///
        /// </summary>
        public virtual int GetInputDeviceHandle()
        {
            //
            if (handle >= 0)
            {
                return(handle);
            }
            // Natives
            int ret = XDevicePlugin.GetInputDeviceHandle(name);

            if (ret >= 0)
            {
                XDevicePlugin.RemoveInputDeviceAt(ret);
            }                                                                      // Remove the same name device...
            //
            ret = XDevicePlugin.AddExternalControllerDevice(name, ExternalControllerDevice.GetInputState, ExternalControllerDevice.SendMessage);
            XDevicePlugin.SetInt(ret, XDevicePlugin.kField_ConnectionStateInt, (int)DeviceConnectionState.Connected);
            // Managed
            ExternalControllerDevice.RemoveInputDevice(ExternalControllerDevice.GetInputDevice(name));                    // Remove the same name device...
            ExternalControllerDevice.SetInputDevice(handle = ret, this);
            return(ret);
        }
コード例 #5
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_ConnectionState, 0) != (int)DeviceConnectionState.Connected)
            {
                XDevicePlugin.SetInt(m_HmdHandle, XDevicePlugin.kField_ConnectionState, (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
                {
                    //
                    switch ((XDevicePlugin.GetInt(-1, XDevicePlugin.kField_CtxDeviceVersion, 0x4000) & 0xF000))
                    {
                    case 0x3000:
                        anchor = new GameObject("XHawkAnchor").transform;
                        anchor.SetParent(centerEyeAnchor);
                        anchor.localPosition = anchorPosition;
                        anchor.localRotation = Quaternion.Euler(anchorRotation);
                        //
                        m_UseAnchorProjection = !PlayerPrefsEx.GetBool("XimmerseTracker[Inside-out].fixShake", false);                             //!modifyHierarchy;
                        VRContext.SetAnchor(VRNode.TrackerDefault, anchor);
                        // TODO :

                        /*if(modifyHierarchy) {
                         *      for(int i=0;i<2;++i) {
                         *              Transform hand=VRContext.GetAnchor(VRNode.LeftHand+i);
                         *              if(hand!=null) {
                         *                      hand.SetParent(anchor,true);
                         *              }
                         *      }
                         * }*/
                        if (PlayerPrefsEx.GetBool("XimmerseTracker[Inside-out].fixShake", false))
                        {
                            m_AnchorMatrixQueue = new List <Matrix4x4>(8);
                            m_M2pFrameIndex     = Mathf.CeilToInt(PlayerPrefsEx.GetFloat("XimmerseTracker[Inside-out].m2pLatency", 0.0f) * VRContext.refreshRate);
                            Log.i("XHawkInput", "m_M2pFrameIndex=" + m_M2pFrameIndex);
                        }
                        else
                        {
                            m_AnchorMatrixQueue = null;
                        }
                        break;

                    case 0x4000:
                        //
                        float trackerHeight, trackerDepth, trackerPitch;
                        XDevicePlugin.GetTrackerPose(m_Handle, out trackerHeight, out trackerDepth, out trackerPitch);
                        //
                        anchor = (anchorPrefab == null || !m_IsRequestVR?                          // in 2D mode.
                                  new GameObject():
                                  Object.Instantiate(anchorPrefab)
                                  ).transform;
                        anchor.name = "TrackerAnchor(X-Hawk DK4)";
                        anchor.SetParent(trackingSpace);
                        //
#if XDEVICE_RELEASE
                        if (true)
                        {
                            UpdateAnchorFromPlugin();
                        }
                        else
#endif
                        {
                            anchor.localPosition = new Vector3(0f, VRContext.trackingOrigin == TrackingOrigin.FloorLevel?trackerHeight:0.0f, trackerDepth);
                            anchor.localRotation = Quaternion.Euler(-trackerPitch, 180f, 0f);
                        }
                        //
                        m_TrackerFrustum = anchor.GetComponentInChildren <TrackerFrustum>();
                        //
//#if XDEVICE_RELEASE
//							m_UseAnchorProjection=false;
//#else
                        m_UseAnchorProjection = true;
//#endif
                        VRContext.SetAnchor(VRNode.TrackerDefault, anchor);
                        m_AnchorMatrixQueue = null;
                        break;

                    default:
                        anchor = new GameObject("Dummy Anchor").transform;
                        anchor.SetParent(trackingSpace, false);
                        break;
                    }
                    // Override anchor info.
                    if (m_AnchorInfoCached)
                    {
                        anchor.localPosition = m_AnchorPosition;
                        anchor.localRotation = m_AnchorRotation;
                    }
                    //
                    if (m_IsRequestVR)
                    {
                        VRContext.main.onRecenter -= RecenterOnVRContextRecenter;
                        VRContext.main.onRecenter += RecenterOnVRContextRecenter;
                    }
                }
            }
            return(true);
        }
コード例 #6
0
        /// <summary>
        /// This function will be called by ControllerInputManager or Start().
        /// XCobra controller's position will be overwritten by this class.
        /// </summary>
        public virtual void Launch(bool checkOthers)
        {
            if (m_IsLaunched)
            {
                return;
            }
            m_IsLaunched = true;
            //
            deviceName = "XHawk-0";
            if (checkOthers)
            {
                XHawkInput other = FindAll(deviceName).Find((x) => (x != this)) as XHawkInput;
                if (other != null)
                {
                    // This will be not found by TrackingInput.Find(string).
                    gameObject.SetActive(false);
                    other.Launch(false);
                    //Log.i("XHawkInput","Use the default TrackingInput in scene.");
                    return;
                }
            }
            //
            XDevicePlugin.Init();
            if (m_Handle == -1)
            {
                m_Handle = XDevicePlugin.GetInputDeviceHandle(deviceName);
            }
            m_HmdHandle = XDevicePlugin.GetInputDeviceHandle("VRDevice");
            XDevicePlugin.SetInt(m_Handle, XDevicePlugin.kField_TrackingOrigin, (int)VRContext.trackingOrigin);
            // Set values to the plugin
            if (overridePlugin)             //&&m_Handle>0) {
            {
                if ((XDevicePlugin.GetInt(-1, XDevicePlugin.kField_CtxDeviceVersion, 0x4000) & 0xF000) == 0x4000)
                {
                    Vector3 trackerPos = PlayerPrefsEx.GetVector3("XimmerseTracker[Outside-in].position", new Vector3(0.0f, 1.675f, 1.5f));
                    Vector3 trackerRot = PlayerPrefsEx.GetVector3("XimmerseTracker[Outside-in].rotation", new Vector3(15.0f, 180.0f, 0.0f));
                    XDevicePlugin.SetTrackerPose(m_Handle, trackerPos.y, trackerPos.z, -trackerRot.x);
                }
            }
            // TODO :
            XDevicePlugin.SendMessage(m_Handle, XDevicePlugin.kMessage_RecenterSensor, 0, 0);
            //
#if XDEVICE_RELEASE
            //if((XDevicePlugin.GetInt(-1,XDevicePlugin.kField_CtxDeviceVersion,0x4000)&0xF000)!=0x4000)
#endif
            {
                int i = 0, imax = controllers.Length;
                inputs = new XCobraInput[imax];
                //
                ControllerInputManager mgr = ControllerInputManager.instance;
                ControllerInput        ci;
                if (mgr != null)
                {
                    for (; i < imax; ++i)
                    {
                        ci = mgr.GetControllerInput(controllers[i].key);
                        if (ci is XCobraInput)
                        {
                            inputs[i] = ci as XCobraInput;
                        }
                        else
                        {
                            inputs[i] = new XCobraInput(this, controllers[i].key, controllers[i].value);
                            mgr.AddControllerInput(inputs[i].name, inputs[i]);
                        }
                        //
                    }
                }
            }
            m_HmdInput = ControllerInputManager.GetInput(ControllerType.Hmd);
            // VRContext must have a CenterEyeAnchor at least.
            m_IsRequestVR = (VRContext.GetAnchor(VRNode.CenterEye) != null);
            EnsureAnchor();
            //
            if (XDevicePlugin.GetInt(-1, XDevicePlugin.kField_CtxDeviceVersion, 0) == 0x1010)
            {
                XDevicePlugin.SetInt(m_Handle, XDevicePlugin.kField_ConnectionState, (int)DeviceConnectionState.Connected);
                m_AsDaydreamEmulator = true;
                LoadHandConfigs();
            }
            //
            Log.i("XHawkInput", "Initialize successfully.");
        }