Qualcomm_Snapdragon_VR_SDK SvrManager脚本简介(5)

在SvrManager初始化的方法中依次调用了InitializeCameras()、InitializeEyes()以及InitializeOverlays( )方法。

其中InitializeCameras的实现如下:

 private void InitializeCameras()
    {
        Vector3 eyePos; // left
        eyePos.x = -0.5f * settings.interPupilDistance;
        eyePos.y = (!settings.trackPosition ? settings.headHeight : 0);
        eyePos.z = (!settings.trackPosition ? settings.headDepth : 0);
        eyePos += head.transform.localPosition;

        Quaternion eyeRot; // left
        float convergenceAngle = 0f;
        if (settings.stereoConvergence > Mathf.Epsilon) convergenceAngle = Mathf.Rad2Deg * Mathf.Atan2(0.5f * settings.interPupilDistance, settings.stereoConvergence);
        else if (settings.stereoConvergence < -Mathf.Epsilon) convergenceAngle = -Mathf.Rad2Deg * Mathf.Atan2(0.5f * settings.interPupilDistance, -settings.stereoConvergence);
        eyeRot = Quaternion.Euler(settings.horizonElevation, -convergenceAngle, 0);

        // left
        if (leftCamera != null)
        {
            leftCamera.transform.localPosition = eyePos;
            leftCamera.transform.localRotation = eyeRot;
        }
        if (leftOverlay != null)
        {
            leftOverlay.transform.localPosition = eyePos;
            leftOverlay.transform.localRotation = eyeRot;
        }

        // right
        eyePos.x *= -1;
        eyeRot.y *= -1;
        if (rightCamera != null)
        {
            rightCamera.transform.localPosition = eyePos;
            rightCamera.transform.localRotation = eyeRot;
        }
        if (rightOverlay != null)
        {
            rightOverlay.transform.localPosition = eyePos;
            rightOverlay.transform.localRotation = eyeRot;
        }

        // mono
        eyePos.x = 0.0f;
        eyeRot = Quaternion.identity;
        if (monoCamera != null)
        {
            monoCamera.transform.localPosition = eyePos;
            monoCamera.transform.localRotation = eyeRot;
        }
        if (monoOverlay != null)
        {
            monoOverlay.transform.localPosition = eyePos;
            monoOverlay.transform.localRotation = eyeRot;
        }
    }

该方法实现逻辑比较简单,只是设置了leftCamera和rightCamera物体的初始位置。


InitializeEyes方法代码如下:

private void InitializeEyes()
	{
        eyes.Clear();
        if (monoCamera != null && monoCamera.gameObject.activeSelf)
        {
            AddEyes(monoCamera, SvrEye.eSide.Both);
        }
        if (leftCamera != null && leftCamera.gameObject.activeSelf)
        {
            AddEyes(leftCamera, SvrEye.eSide.Left);
        }
        if (rightCamera != null && rightCamera.gameObject.activeSelf)
        {
            AddEyes(rightCamera, SvrEye.eSide.Right);
        }
        for (int i = 0; i < SvrEye.Instances.Count; i++)
        {
            var eye = SvrEye.Instances[i];
            if (!eyes.Contains(eye))
            {
                eyes.Add(eye); // Add eyes found outside of svr camera hierarchy
            }
        }

        SvrPlugin.DeviceInfo info = plugin.deviceInfo;

		foreach(SvrEye eye in eyes)
		{
            if (eye == null) continue;

            eye.FovMargin               = settings.eyeFovMargin;
			eye.Format					= RenderTextureFormat.Default;
			eye.Resolution  			= new Vector2(info.targetEyeWidthPixels, info.targetEyeHeightPixels);
			eye.Depth 					= (int)settings.eyeDepth;
			eye.AntiAliasing 			= (int)settings.eyeAntiAliasing;	// hdr not supported with antialiasing
            eye.FrustumType             = (int)settings.frustumType;
            eye.OnPreRenderListener     = OnPreRenderListener;
            eye.OnPostRenderListener    = OnPostRenderListener;

            eye.Initialize();
		}
	}
该方法中在leftCamera以及rightCamera物体上添加了SvrEye脚本,并设置了SvrEye脚本中的相关属性,并执行了SvrEye中的初始化方法。


至此初始化方法的逻辑已经介绍完毕,下文将继续介绍Start方法中的其他逻辑。



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

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

不良信息举报

Qualcomm_Snapdragon_VR_SDK SvrManager脚本简介(5)

最多只允许输入30个字

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