Qualcomm_Snapdragon_VR_SDK SvrEye脚本简介(6)

在SvrEye中,Initialize()方法为初始化方法,具体代码如下:

public void Initialize()
{
    InitializeBuffers();
    InitializeCameras();
}

其中InitializeBuffers方法在之前的文章中已经讲到,主要的作用是根据eType值来设置左右眼Camera图像的传输类型:

  void InitializeBuffers()
    {
        for (int i = 0; i < bufferCount; ++i)
        {
            if (eyeTextures[i] != null)
                eyeTextures[i].Release();
            switch(imageType)
            {
                case eType.RenderTexture:
                    eyeTextures[i] = new RenderTexture((int)(resolution.x * resolutionScaleFactor), (int)(resolution.y * resolutionScaleFactor), depth, format);
                    eyeTextures[i].antiAliasing = antiAliasing;
                    eyeTextures[i].Create();
                    eyeTextureIds[i] = eyeTextures[i].GetNativeTexturePtr().ToInt32();
                    Debug.Log("Create Render Texture with ID: " + eyeTextureIds[i] + " Width: " + eyeTextures[i].width + " Height: " + eyeTextures[i].height + " AA: " + eyeTextures[i].antiAliasing);
                    break;

                case eType.StandardTexture:
                    if (imageTexture) eyeTextureIds[i] = imageTexture.GetNativeTexturePtr().ToInt32();
                    break;

                case eType.EglTexture:
                    eyeTextureIds[i] = 0;
                    break;
            }
        }
        dirty = false;
    }

而InitializeCameras方法主要是对左右眼的Camera属性进行一些参数的设置工作:

 void InitializeCameras()
    {
        var deviceInfo = SvrPlugin.Instance.deviceInfo;
        var deviceFov = new Vector2(deviceInfo.targetFovXRad, deviceInfo.targetFovYRad) * Mathf.Rad2Deg;
        var frustum = side == eSide.Right ? deviceInfo.targetFrustumRight : deviceInfo.targetFrustumLeft;

        foreach (var mainCamera in mainCameras)
        {
            if (frustumType == (int)SvrManager.SvrSettings.eFrustumType.Camera)
            {
                mainCamera.fieldOfView = deviceFov.y + FovMargin * deviceFov.y;
                mainCamera.aspect = deviceFov.x / deviceFov.y;
            }
            else if (frustumType == (int)SvrManager.SvrSettings.eFrustumType.Device)
            {
                mainCamera.fieldOfView = deviceFov.y;
                mainCamera.aspect = deviceFov.x / deviceFov.y;
                mainCamera.projectionMatrix = SvrManager.Perspective(frustum.left, frustum.right, frustum.bottom, frustum.top, frustum.near, mainCamera.farClipPlane);
            }
        }
    }
由于InitializeCameras方法中设计的内容比较多,因此下文中,将对该方法的具体实现进行更加详细的介绍。
阅读更多
想对作者说点什么?

博主推荐

换一批

没有更多推荐了,返回首页