示例#1
0
        private void UpdateProfile()
        {
            if (NvrViewer.USE_DTR)
            {
                _NVR_GetNVRConfig(profileData);
            }

            if (profileData[13] > 0)
            {
                NvrGlobal.fovNear = profileData[13];
            }

            if (profileData[14] > 0)
            {
                NvrGlobal.fovFar = profileData[14];
            }


            if (NvrViewer.USE_DTR && !NvrGlobal.supportDtr && NvrGlobal.dftProfileParams[0] != 0)
            {
                // DFT模式加载cardboard参数
                // fov
                profileData[0] = NvrGlobal.dftProfileParams[3];  //45;
                profileData[1] = NvrGlobal.dftProfileParams[4];  //45;
                profileData[2] = NvrGlobal.dftProfileParams[5];  //51.5f;
                profileData[3] = NvrGlobal.dftProfileParams[6];  //51.5f;
                // screen size
                profileData[4] = NvrGlobal.dftProfileParams[12]; //0.110f;
                profileData[5] = NvrGlobal.dftProfileParams[13]; //0.062f;
                // ipd
                profileData[7] = NvrGlobal.dftProfileParams[0];  //0.063f;
                // screen to lens
                profileData[9] = NvrGlobal.dftProfileParams[2];  //0.035f;
                // k1 k2
                profileData[11] = NvrGlobal.dftProfileParams[7]; //0.252f;
                profileData[12] = NvrGlobal.dftProfileParams[8]; //0.019f;
            }

            NvrProfile.Viewer device = new NvrProfile.Viewer();
            NvrProfile.Screen screen = new NvrProfile.Screen();
            // left top right bottom
            device.maxFOV.outer          = profileData[0];
            device.maxFOV.upper          = profileData[2];
            device.maxFOV.inner          = profileData[1];
            device.maxFOV.lower          = profileData[3];
            screen.width                 = profileData[4];
            screen.height                = profileData[5];
            screen.border                = profileData[6];
            device.lenses.separation     = profileData[7];
            device.lenses.offset         = profileData[8];
            device.lenses.screenDistance = profileData[9];
            device.lenses.alignment      = (int)profileData[10];
            device.distortion.Coef       = new[] { profileData[11], profileData[12] };
            Profile.screen               = screen;
            Profile.viewer               = device;

            float[] rect = new float[4];
            Profile.GetLeftEyeNoLensTanAngles(rect);
            float maxRadius = NvrProfile.GetMaxRadius(rect);

            Profile.viewer.inverse = NvrProfile.ApproximateInverse(
                Profile.viewer.distortion, maxRadius);
        }
    public void UpdateStereoValues()
    {
        // Debug.Log("NvrEye->UpdateStereoValues,"+eye.ToString());
        Matrix4x4 proj = NvrViewer.Instance.Projection(eye);

        realProj = NvrViewer.Instance.Projection(eye, NvrViewer.Distortion.Undistorted);

        CopyCameraAndMakeSideBySide(controller, proj[0, 2], proj[1, 2]);

        // Fix aspect ratio and near/far clipping planes.
        float nearClipPlane = monoCamera.nearClipPlane;
        float farClipPlane  = monoCamera.farClipPlane;

        bool useDFT = NvrViewer.USE_DTR && !NvrGlobal.supportDtr;

        //DTR不需要修正
        if (Application.isEditor || useDFT)
        {
            // DFT & 编辑器模式修正投影矩阵
            NvrCameraUtils.FixProjection(cam.rect, useDFT ? NvrGlobal.fovNear : nearClipPlane, useDFT ? NvrGlobal.fovFar : farClipPlane, ref realProj);
            NvrCameraUtils.FixProjection(cam.rect, useDFT ? NvrGlobal.fovNear : nearClipPlane, useDFT ? NvrGlobal.fovFar : farClipPlane, ref proj);
        }

        // Zoom the stereo cameras if requested.
        //float monoProj11 = monoCamera.projectionMatrix[1, 1];
        //NvrCameraUtils.ZoomStereoCameras(controller.matchByZoom, controller.matchMonoFOV,
        //                                 monoProj11, ref proj);

        // Set the eye camera's projection for rendering.
        cam.projectionMatrix = proj;
        NvrViewer.Instance.UpdateEyeCameraProjection(eye);

        if (Application.isEditor)
        {
            // So you can see the approximate frustum in the Scene view when the camera is selected.
            cam.fieldOfView = 2 * Mathf.Atan(1 / proj[1, 1]) * Mathf.Rad2Deg;
        }

        // Draw to the mono camera's target, or the stereo screen.
        // Debug.Log("monoCamera.targetTexture is Null , " + (monoCamera.targetTexture == null));
        int eyeType = eye == NvrViewer.Eye.Left ? 0 : 1;

        cam.targetTexture = monoCamera.targetTexture ?? NvrViewer.Instance.GetStereoScreen(eyeType);

        // Debug.Log(eye.ToString()+" UpdateStereoValues Eye Init Texture:" + (int) cam.targetTexture.GetNativeTexturePtr()+ " .  " +Time.realtimeSinceStartup);

        if (cam.targetTexture == null)
        {
            // When drawing straight to screen, account for lens FOV limits.
            // Note: do this after all calls to FixProjection() which needs the unfixed rect.
            Rect viewport   = NvrViewer.Instance.Viewport(eye);
            bool isRightEye = eye == NvrViewer.Eye.Right;
            cam.rect = NvrCameraUtils.FixViewport(cam.rect, viewport, isRightEye);

            // The game window's aspect ratio may not match the device profile parameters.
            if (Application.isEditor)
            {
                NvrProfile.Screen profileScreen = NvrViewer.Instance.Profile.screen;
                float             profileAspect = profileScreen.width / profileScreen.height;
                float             windowAspect  = (float)Screen.width / Screen.height;
                cam.rect = NvrCameraUtils.FixEditorViewport(cam.rect, profileAspect, windowAspect);
            }
        }
    }