public MouseBasedFaceTracker()
        {
            _facePose = SRDFaceTracker.CreateDefaultFacePose();
            _focus    = Utils.SRDSettings.DeviceInfo.BodyBounds.Center;

            var dispCenterPose = new Pose(Utils.SRDSettings.DeviceInfo.BodyBounds.Center, Quaternion.Euler(-45f, 180f, 0f));

            _posTrackCoordTdispCenerCoord = SRDHelper.PoseToMatrix(dispCenterPose);
            _dispCenerCoordTposTrackCoord = SRDHelper.PoseToMatrix(SRDHelper.InvPose(dispCenterPose));
        }
        public SrdXrResult GetCurrentProjMatrices(float nearClip, float farClip, out EyeProjectionMatrices projMatrices)
        {
            projMatrices = (_prevProjMatrix != null) ? _prevProjMatrix : SRDFaceTracker.CreateDefaultProjMatrices();

            var leftMatrix  = projMatrices.LeftMatrix;
            var rightMatrix = projMatrices.RightMatrix;
            var xrResult    = SRDCorePlugin.GetProjectionMatrix(SRDSessionHandler.SessionHandle, nearClip, farClip,
                                                                out leftMatrix, out rightMatrix);

            projMatrices = new EyeProjectionMatrices(leftMatrix, rightMatrix);
            if (xrResult == SrdXrResult.ERROR_HANDLE_INVALID || xrResult == SrdXrResult.ERROR_SESSION_NOT_RUNNING)
            {
                projMatrices = SRDFaceTracker.CreateDefaultProjMatrices();
            }
            _prevProjMatrix = projMatrices;
            return(xrResult);
        }
        public SrdXrResult GetCurrentFacePose(out FacePose facePose)
        {
            facePose = (_prevFacePose != null) ? _prevFacePose : SRDFaceTracker.CreateDefaultFacePose().GetTransformedBy(_currentOrigin);

            var headPose = facePose.HeadPose;
            var eyePoseL = facePose.EyePoseL;
            var eyePoseR = facePose.EyePoseR;
            var xrResult = SRDCorePlugin.GetFacePose(SRDSessionHandler.SessionHandle,
                                                     out headPose, out eyePoseL, out eyePoseR);

            facePose = (new FacePose(headPose, eyePoseL, eyePoseR)).GetTransformedBy(_currentOrigin);
            if (xrResult == SrdXrResult.ERROR_HANDLE_INVALID || xrResult == SrdXrResult.ERROR_SESSION_NOT_RUNNING)
            {
                facePose = SRDFaceTracker.CreateDefaultFacePose().GetTransformedBy(_currentOrigin);
            }
            _prevFacePose = facePose;
            return(xrResult);
        }
        public SRDEyeViewRenderer()
        {
            _eyeTransform = new Dictionary <EyeType, Transform>();
            _eyeCamera    = new Dictionary <EyeType, Camera>();
            //_eyeCamRenderTexture = new Dictionary<EyeType, RenderTexture>();
            _eyeCamRenderTextureCache = new Dictionary <EyeType, RenderTexture>();
            _eyeCamMaterial           = new Dictionary <EyeType, Material>();

            _eyeTypes = new List <EyeType>()
            {
                EyeType.Left, EyeType.Right
            };
            _isSRPUsed = (GraphicsSettings.renderPipelineAsset != null);

            _currentFacePose     = SRDFaceTracker.CreateDefaultFacePose();
            _currentProjMatrices = SRDFaceTracker.CreateDefaultProjMatrices();

            var width  = SRDSettings.DeviceInfo.ScreenRect.Width;
            var height = SRDSettings.DeviceInfo.ScreenRect.Height;

            foreach (var type in _eyeTypes)
            {
                // RenderTarget
                //var outrt = new RenderTexture(width, height, RenderTextureDepth, RenderTextureFormat.ARGB32);
                //outrt.name = SRDHelper.SRDConstants.EyeCamRenderTexDefaultName + SRDHelper.EyeSideName[type] + "_Temp";
                //outrt.Create();
                //_eyeCamRenderTexture.Add(type, outrt);
                var camrt = new RenderTexture(width, height, RenderTextureDepth, RenderTextureFormat.ARGB32,
                                              (QualitySettings.desiredColorSpace == ColorSpace.Linear) ? RenderTextureReadWrite.Linear : RenderTextureReadWrite.Default);
                camrt.name = SRDHelper.SRDConstants.EyeCamRenderTexDefaultName + SRDHelper.EyeSideName[type];
                camrt.Create();
                _eyeCamRenderTextureCache.Add(type, camrt);

                var homographyMaterial = new Material(Shader.Find("uHomography/Homography"));
                homographyMaterial.hideFlags = HideFlags.HideAndDontSave;
                _eyeCamMaterial[type]        = homographyMaterial;
            }
        }