public override bool InitInternal() { if ((XDevicePlugin.GetInt(XDevicePlugin.ID_CONTEXT, XDevicePlugin.kField_CtxDeviceVersionInt, 0) & 0xF000) != 0x3000) { return(false); } // TODO : Read offsets from the plugin. #if !true m_AnchorPosition = Vector3.zero; m_AnchorRotation = Quaternion.identity; #else VRDevice vrDevice = VRContext.currentDevice; if (vrDevice != null) { m_AnchorPosition = vrDevice.inOutsideMarkPose.position; m_AnchorRotation = vrDevice.inOutsideMarkPose.rotation; } else { m_AnchorPosition = Vector3.zero; m_AnchorRotation = Quaternion.identity; } #endif // return(base.InitInternal()); }
/// <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); }
public static string ToString(TrackerInput input, int[] nodes) { System.Text.StringBuilder sb = new System.Text.StringBuilder(string.Format( "TrackingInput@{0} Timestamp:{1}\n", input.m_Handle, input.m_State.frameCount)); if (XDevicePlugin.GetInt(input.m_Handle, XDevicePlugin.kField_ConnectionStateInt, 0) != (int)DeviceConnectionState.Connected) { // sb.Append("Connection State=\"" + ((DeviceConnectionState)XDevicePlugin.GetInt(input.m_Handle, XDevicePlugin.kField_ConnectionStateInt, 0))); sb.Append("\"\nError Code=\"" + XDevicePlugin.GetInt(input.m_Handle, XDevicePlugin.kField_ErrorCodeInt, 0) + "\""); } else { Vector3 pos = new Vector3(); int node; for (int i = 0, imax = nodes.Length; i < imax; ++i) { node = nodes[i]; if (input.Exists(node)) { pos = input.GetLocalPosition(node); sb.AppendLine(string.Format("Node@{0} is {1}", node, pos.ToString("F3"))); } else { sb.AppendLine(string.Format("Node@{0} is not existed.", node)); } } } return(sb.ToString()); }
public override bool InitInternal() { if ((XDevicePlugin.GetInt(XDevicePlugin.ID_CONTEXT, XDevicePlugin.kField_CtxDeviceVersionInt, 0x4000) & 0xF000) != 0x4000) { return(false); } // if (true) { Vector3 position = PlayerPrefsEx.GetVector3("XimmerseTracker[Outside-in].position"); Vector3 rotation = PlayerPrefsEx.GetVector3("XimmerseTracker[Outside-in].rotation"); XDevicePlugin.SetTrackerPose(m_Handle, position.y, position.z, rotation.x); // XDevicePlugin.GetTrackerPose(m_Handle, out position.y, out position.z, out rotation.x); // int i = m_Controllers.Length; while (i-- > 0) { XDevicePlugin.SetBool(XDevicePlugin.GetInputDeviceHandle(m_Controllers[i].key), XDevicePlugin.kField_IsAbsRotationBool, true); } // //PlayerPrefsEx.SetBool("VRDevice.forceFadeOnBadTracking",true); XDevicePlugin.NativeMethods.XDeviceSetDecoderFeature(XDevicePlugin.FEATURE_BLOB_AUTO); } return(base.InitInternal()); }
/// <summary> /// Initializes the device module. /// </summary> public static void InitializeDeviceModule(bool isFirst = true) { if (isInitialized) { return; } if (Application.platform == RuntimePlatform.Android) { Ximmerse.InputSystem.XDevicePlugin.Init(); //Apply logs: XDevicePlugin.SetLogger((int level, string _tag, string log) => { Debug.LogFormat("level:{0} ,tag:{1}, log:{2}", level, _tag, log); }); if (isFirst) { XDevicePlugin.CopyAssetsToPath(kConfigFileDirectory); } DevicerHandle.SlideInContext = XDevicePlugin.NewContext(XDevicePlugin.XContextTypes.kXContextTypeSlideIn);/// 创建SlideIn设备上下文 DevicerHandle.HmdHandle = XDevicePlugin.GetDeviceHandle(DevicerHandle.SlideInContext, "XHawk-0"); if (isFirst) { TagTrackingUtil.ApplyDefaultConfig(); } DeviceConnectionState vpuConn = (DeviceConnectionState)XDevicePlugin.GetInt(DevicerHandle.HmdHandle, XDevicePlugin.XVpuAttributes.kXVpuAttr_Int_ConnectionState, 0); isVPUConnected = vpuConn == DeviceConnectionState.Connected; XDevicePlugin.RegisterObserver(DevicerHandle.HmdHandle, XDevicePlugin.XVpuAttributes.kXVpuAttr_Int_ConnectionState, new XDevicePlugin.XDeviceConnectStateChangeDelegate(OnVPUConnectionStateChanged), DevicerHandle.HmdHandle); isInitialized = true; Debug.LogFormat("Slide in HLAPI initialized successfully. HLAPI version : {0}, Algorithm version: {1}", HLAPIVersion.Version, HLAPIVersion.AlgVersion); Debug.LogFormat("VPU device state {0} ", vpuConn); } else if (Application.platform == RuntimePlatform.WindowsEditor || Application.platform == RuntimePlatform.WindowsPlayer) { Ximmerse.InputSystem.XDevicePlugin.Init(); XDevicePlugin.SetLogger((int level, string _tag, string log) => { Debug.LogFormat("level:{0} ,tag:{1}, log:{2}", level, _tag, log); }); DevicerHandle.SlideInContext = XDevicePlugin.NewContext(XDevicePlugin.XContextTypes.kXContextTypeSlideIn);/// 创建SlideIn设备上下文 DevicerHandle.HmdHandle = XDevicePlugin.GetDeviceHandle(DevicerHandle.SlideInContext, "XHawk-0"); Debug.LogFormat("VPU Context: {0}, Hmd handle:{1}", DevicerHandle.SlideInContext.mNativeHandle.ToInt32(), DevicerHandle.HmdHandle.mNativeHandle.ToInt32()); TagTrackingUtil.ApplyDefaultConfig(); var vpuConn = (DeviceConnectionState)XDevicePlugin.GetInt(DevicerHandle.HmdHandle, XDevicePlugin.XVpuAttributes.kXVpuAttr_Int_ConnectionState, 0); isVPUConnected = vpuConn == DeviceConnectionState.Connected; XDevicePlugin.RegisterObserver(DevicerHandle.HmdHandle, XDevicePlugin.XVpuAttributes.kXVpuAttr_Int_ConnectionState, new XDevicePlugin.XDeviceConnectStateChangeDelegate(OnVPUConnectionStateChanged), DevicerHandle.HmdHandle); isInitialized = true; Debug.LogFormat("Slide in HLAPI initialized successfully. HLAPI version : {0}, Algorithm version: {1}", HLAPIVersion.Version, HLAPIVersion.AlgVersion); Debug.LogFormat("VPU device state {0} ", vpuConn); } else { Debug.LogWarningFormat("Tracking Library not available for current platform : {0}. Currently we supports Android/Windows platform.", Application.platform); } }
public virtual bool Exists(int node) { if (Controller != null && pointer != null) { return(XDevicePlugin.GetInt(Controller.handle, XDevicePlugin.kField_ConnectionStateInt, 0) == (int)DeviceConnectionState.Connected && pointer.localPosition.sqrMagnitude > 0.0f); } return(false); }
public virtual bool Exists(int node) { if (Controller != null) { return(XDevicePlugin.GetInt(Controller.handle, XDevicePlugin.kField_ConnectionStateInt, 0) == (int)DeviceConnectionState.Connected); //return Controller.connectionState==DeviceConnectionState.Connected; } return(false); }
public override bool InitInternal() { if ((XDevicePlugin.GetInt(XDevicePlugin.ID_CONTEXT, XDevicePlugin.kField_CtxDeviceVersionInt, 0x4000) & 0xF000) != 0x4000) { return(false); } // return(base.InitInternal()); }
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()); } } } }
public virtual int InitInput() { if ((XDevicePlugin.GetInt(XDevicePlugin.ID_CONTEXT, XDevicePlugin.kField_CtxDeviceVersionInt, 0) & 0xF000) != 0x1000) { return(-1); } // Override ControllerInput in ControllerInputManager. if (true) { // ControllerInputManager mgr = ControllerInputManager.instance; ControllerInput ci; if (mgr != null) { for (int i = 0, imax = m_Controllers.Length; i < imax; ++i) { if (m_Controllers[i].handedness != ControllerType.None) { ci = mgr.GetControllerInput(m_Controllers[i].name); if (ci is TrackedControllerInput) { m_Controllers[i].Controller = ci as TrackedControllerInput; m_Controllers[i].Controller.inputTracking = m_Controllers[i]; m_Controllers[i].Controller.node = -1; } else { m_Controllers[i].Controller = new TrackedControllerInput(m_Controllers[i].name, m_Controllers[i], -1); if (m_Controllers[i].Controller.handle != -1) { mgr.AddControllerInput(m_Controllers[i].name, m_Controllers[i].Controller); } else { m_Controllers[i].Controller = null; } } // m_Controllers[i].Start(); } } } else { return(-1); } } // return(0); }
public override void Recenter() { switch ((XDevicePlugin.GetInt(-1, XDevicePlugin.kField_CtxDeviceVersion, 0x4000) & 0xF000)) { case 0x3000: break; case 0x4000: Recenter_DK4(); break; } // if (onRecenter != null) { onRecenter.Invoke(); } }
/// <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); }
/// <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."); }