private IEnumerator Initialize() { while (NRFrame.SessionStatus != SessionState.Running) { NRDebugger.Log("[NRHMDPoseTracker] Waitting to initialize."); yield return(new WaitForEndOfFrame()); } #if !UNITY_EDITOR bool result; var matrix_data = NRFrame.GetEyeProjectMatrix(out result, leftCamera.nearClipPlane, leftCamera.farClipPlane); if (result) { leftCamera.projectionMatrix = matrix_data.LEyeMatrix; rightCamera.projectionMatrix = matrix_data.REyeMatrix; var eyeposFromHead = NRFrame.EyePosFromHead; leftCamera.transform.localPosition = eyeposFromHead.LEyePose.position; leftCamera.transform.localRotation = eyeposFromHead.LEyePose.rotation; rightCamera.transform.localPosition = eyeposFromHead.REyePose.position; rightCamera.transform.localRotation = eyeposFromHead.REyePose.rotation; centerCamera.transform.localPosition = (leftCamera.transform.localPosition + rightCamera.transform.localPosition) * 0.5f; centerCamera.transform.localRotation = Quaternion.Lerp(leftCamera.transform.localRotation, rightCamera.transform.localRotation, 0.5f); } #endif NRDebugger.Log("[NRHMDPoseTracker] Initialized success."); }
void Init() { #if !UNITY_EDITOR bool result; var matrix_data = NRFrame.GetEyeProjectMatrix(out result, leftCamera.nearClipPlane, leftCamera.farClipPlane); if (result) { leftCamera.projectionMatrix = matrix_data.LEyeMatrix; rightCamera.projectionMatrix = matrix_data.REyeMatrix; var eyeposFromHead = NRFrame.EyePosFromHead; leftCamera.transform.localPosition = eyeposFromHead.LEyePose.position; leftCamera.transform.localRotation = eyeposFromHead.LEyePose.rotation; rightCamera.transform.localPosition = eyeposFromHead.REyePose.position; rightCamera.transform.localRotation = eyeposFromHead.REyePose.rotation; centerCamera.transform.localPosition = (leftCamera.transform.localPosition + rightCamera.transform.localPosition) * 0.5f; centerCamera.transform.localRotation = Quaternion.Lerp(leftCamera.transform.localRotation, rightCamera.transform.localRotation, 0.5f); leftCamera.cullingMask = m_LeftCullingMask; rightCamera.cullingMask = m_RightCullingMask; isInited = true; } #else isInited = true; #endif }
private void Init() { bool result; var leftCamera = transform.Find("LeftCamera").GetComponent <Camera>(); var rightCamera = transform.Find("RightCamera").GetComponent <Camera>(); var matrix_data = NRFrame.GetEyeProjectMatrix(out result, leftCamera.nearClipPlane, leftCamera.farClipPlane); if (result) { if (m_PoseSource == PoseSource.CenterEye) { leftCamera.projectionMatrix = matrix_data.LEyeMatrix; rightCamera.projectionMatrix = matrix_data.REyeMatrix; var eyeposFromHead = NRFrame.EyePosFromHead; leftCamera.transform.localPosition = eyeposFromHead.LEyePose.position; leftCamera.transform.localRotation = eyeposFromHead.LEyePose.rotation; rightCamera.transform.localPosition = eyeposFromHead.REyePose.position; rightCamera.transform.localRotation = eyeposFromHead.REyePose.rotation; } else { var matrix = m_PoseSource == PoseSource.LeftEye ? matrix_data.LEyeMatrix : matrix_data.REyeMatrix; gameObject.GetComponent <Camera>().projectionMatrix = matrix; NRDebugger.Log("[HMDPoseTracker Init] apply matrix:" + matrix.ToString()); } isInited = true; } }
private IEnumerator OnUpdate() { while (!m_IsDestroyed) { NRFrame.OnUpdate(); yield return(new WaitForEndOfFrame()); } }
private void Update() { if (SessionState == SessionState.Running) { m_LostTrackingReason = NativeAPI.NativeHeadTracking.GetTrackingLostReason(); } NRFrame.OnUpdate(); }
private void UpdatePoseByTrackingType() { Pose pose = Pose.identity; var result = NRFrame.GetHeadPoseByTime(ref pose); //Debug.LogErrorFormat("get pose result: {0} Lost tracking reason:{1} pose :{2}", result, NRFrame.LostTrackingReason, pose.ToString()); if (result && NRFrame.LostTrackingReason == LostTrackingReason.NONE) { SetCameraByTrackingStatus(true); } //else //{ // SetCameraByTrackingStatus(false); //} // update pos switch (m_TrackingType) { case TrackingType.Tracking6Dof: if (UseRelative) { transform.localRotation = pose.rotation; transform.localPosition = pose.position; } else { transform.rotation = pose.rotation; transform.position = pose.position; } break; case TrackingType.Tracking3Dof: if (UseRelative) { transform.localRotation = pose.rotation; } else { transform.rotation = pose.rotation; } break; default: break; } }
private void ChangeMode(TrackingType trackingtype) { if (NRFrame.SessionStatus != SessionState.Running || trackingtype == m_TrackingType) { return; } #if !UNITY_EDITOR AsyncTaskExecuter.Instance.RunAction(() => { var result = NRSessionManager.Instance.NativeAPI.NativeTracking.SwitchTrackingMode((TrackingMode)trackingtype); if (result) { NRFrame.ClearPose(); m_TrackingType = trackingtype; } }); #endif }