Qualcomm_Snapdragon_VR_SDK SvrEye脚本简介(5)

在SvrEye中存在一个变量imageCamera表示当前eye物体上的Camera属性:

  [Tooltip("Image display transform")]
    public Camera imageCamera;

在脚本的Awake()方法中:

 void Awake()
    {
        Instances.Add(this);
        AcquireComponents();
        InitializeCoords();
    }

AcquireComponents方法的作用就是为imageCamera变量进行赋值,具体实现如下:

void AcquireComponents()
    {
        if (imageCamera == null) imageCamera = gameObject.GetComponent<Camera>();
        Debug.Assert(imageCamera != null, "ImageCamera object required");
        mainCameras = imageCamera.GetComponentsInChildren<Camera>();
    }

SvrEye脚本依赖Camera属性,因此初始化的时候需要完成imageCamera变量的赋值,具体实现是在脚本物体上获取Camera的属性值,通过该变量,用户可以方便的获取到当前的SvrEye物体上的Camera属性。

Awake中另一个方法是InitializeCoords,其具体实现如下:

 void InitializeCoords()
    {
        clipLowerLeft.Set(-1, -1, 0, 1);
        clipUpperLeft.Set(-1, 1, 0, 1);
        clipUpperRight.Set(1, 1, 0, 1);
        clipLowerRight.Set(1, -1, 0, 1);
    }

代码的逻辑比较简单,完成的只是对四个变量的赋值工作。

  [Tooltip("Image display region (camera clip space)")]
    public Vector4 clipLowerLeft = new Vector4(-1, -1, 0, 1);
    public Vector4 clipUpperLeft = new Vector4(-1, 1, 0, 1);
    public Vector4 clipUpperRight = new Vector4(1, 1, 0, 1);
    public Vector4 clipLowerRight = new Vector4(1, -1, 0, 1);

这四个变量保存的是Camera视窗的四个顶点坐标。在SvrManager中执行SubmitFrame方法时会将这四个坐标传入到底层SDK的接口中,代码逻辑如下:

 float[] lowerLeft = { eye.clipLowerLeft.x, eye.clipLowerLeft.y, eye.clipLowerLeft.z, eye.clipLowerLeft.w, eye.uvLowerLeft.x, eye.uvLowerLeft.y };
            float[] upperLeft = { eye.clipUpperLeft.x, eye.clipUpperLeft.y, eye.clipUpperLeft.z, eye.clipUpperLeft.w, eye.uvUpperLeft.x, eye.uvUpperLeft.y };
            float[] upperRight = { eye.clipUpperRight.x, eye.clipUpperRight.y, eye.clipUpperRight.z, eye.clipUpperRight.w, eye.uvUpperRight.x, eye.uvUpperRight.y };
            float[] lowerRight = { eye.clipLowerRight.x, eye.clipLowerRight.y, eye.clipLowerRight.z, eye.clipLowerRight.w, eye.uvLowerRight.x, eye.uvLowerRight.y };
            SvrSetupLayerCoords(0, eyeCount, lowerLeft, lowerRight, upperLeft, upperRight);


阅读更多
想对作者说点什么? 我来说一句

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

不良信息举报

Qualcomm_Snapdragon_VR_SDK SvrEye脚本简介(5)

最多只允许输入30个字

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭