private void Initialize() { if (m_IsInitialized) { return; } #if !UNITY_EDITOR bool result; m_TargetCamera = gameObject.GetComponent <Camera>(); var matrix_data = NRFrame.GetEyeProjectMatrix(out result, m_TargetCamera.nearClipPlane, m_TargetCamera.farClipPlane); if (result) { var eyeposFromHead = NRFrame.EyePosFromHead; switch (EyeType) { case NativeEye.LEFT: m_TargetCamera.projectionMatrix = matrix_data.LEyeMatrix; Debug.Log("[Matrix] RGB Camera Project Matrix :" + m_TargetCamera.projectionMatrix.ToString()); transform.localPosition = eyeposFromHead.LEyePose.position; transform.localRotation = eyeposFromHead.LEyePose.rotation; Debug.LogFormat("RGB Camera pos:{0} rotation:{1}", transform.localPosition.ToString(), transform.localRotation.ToString()); break; case NativeEye.RIGHT: m_TargetCamera.projectionMatrix = matrix_data.REyeMatrix; Debug.Log("[Matrix] RGB Camera Project Matrix :" + m_TargetCamera.projectionMatrix.ToString()); transform.localPosition = eyeposFromHead.REyePose.position; transform.localRotation = eyeposFromHead.REyePose.rotation; Debug.LogFormat("RGB Camera pos:{0} rotation:{1}", transform.localPosition.ToString(), transform.localRotation.ToString()); break; case NativeEye.RGB: m_TargetCamera.projectionMatrix = matrix_data.RGBEyeMatrix; Debug.Log("[Matrix] RGB Camera Project Matrix :" + m_TargetCamera.projectionMatrix.ToString()); transform.localPosition = eyeposFromHead.RGBEyePos.position; transform.localRotation = eyeposFromHead.RGBEyePos.rotation; Debug.LogFormat("RGB Camera pos:{0} rotation:{1}", transform.localPosition.ToString(), transform.localRotation.ToString()); break; default: break; } m_IsInitialized = true; } #else m_TargetCamera = gameObject.GetComponent <Camera>(); m_TargetCamera.projectionMatrix = matrix; m_IsInitialized = true; #endif }
private IEnumerator Initialize() { bool result; EyeProjectMatrixData matrix_data = NRFrame.GetEyeProjectMatrix(out result, m_TargetCamera.nearClipPlane, m_TargetCamera.farClipPlane); while (!result) { Debug.Log("Waitting to initialize camera param."); yield return(new WaitForEndOfFrame()); matrix_data = NRFrame.GetEyeProjectMatrix(out result, m_TargetCamera.nearClipPlane, m_TargetCamera.farClipPlane); } var eyeposFromHead = NRFrame.EyePosFromHead; switch (EyeType) { case NativeEye.LEFT: m_TargetCamera.projectionMatrix = matrix_data.LEyeMatrix; NRDebugger.Log("[Matrix] RGB Camera Project Matrix :" + m_TargetCamera.projectionMatrix.ToString()); transform.localPosition = eyeposFromHead.LEyePose.position; transform.localRotation = eyeposFromHead.LEyePose.rotation; NRDebugger.LogFormat("RGB Camera pos:{0} rotation:{1}", transform.localPosition.ToString(), transform.localRotation.ToString()); break; case NativeEye.RIGHT: m_TargetCamera.projectionMatrix = matrix_data.REyeMatrix; NRDebugger.Log("[Matrix] RGB Camera Project Matrix :" + m_TargetCamera.projectionMatrix.ToString()); transform.localPosition = eyeposFromHead.REyePose.position; transform.localRotation = eyeposFromHead.REyePose.rotation; NRDebugger.LogFormat("RGB Camera pos:{0} rotation:{1}", transform.localPosition.ToString(), transform.localRotation.ToString()); break; case NativeEye.RGB: m_TargetCamera.projectionMatrix = matrix_data.RGBEyeMatrix; NRDebugger.Log("[Matrix] RGB Camera Project Matrix :" + m_TargetCamera.projectionMatrix.ToString()); transform.localPosition = eyeposFromHead.RGBEyePos.position; transform.localRotation = eyeposFromHead.RGBEyePos.rotation; NRDebugger.LogFormat("RGB Camera pos:{0} rotation:{1}", transform.localPosition.ToString(), transform.localRotation.ToString()); break; default: break; } }