示例#1
0
        void Start()
        {
            var ctlr = Controller;

            if (ctlr == null)
            {
                Debug.LogError("NxrEye must be child of a StereoController.");
                enabled = false;
                return;
            }
            // Save reference to the found controller and it's camera.
            controller     = ctlr;
            monoCamera     = controller.GetComponent <Camera>();
            cacheTransform = transform;
        }
示例#2
0
        /// Helper to copy camera settings from the controller's mono camera.  Used in SetupStereo() and
        /// in the custom editor for StereoController.  The parameters parx and pary, if not left at
        /// default, should come from a projection matrix returned by the SDK.  They affect the apparent
        /// depth of the camera's window.  See SetupStereo().
        public void CopyCameraAndMakeSideBySide(NxrStereoController controller,
                                                float parx = 0, float pary = 0)
        {
#if UNITY_EDITOR
            // Member variable 'cam' not always initialized when this method called in Editor.
            // So, we'll just make a local of the same name.
            var cam = GetComponent <Camera>();
#endif

            float   ipd           = NxrViewer.Instance.Profile.viewer.lenses.separation;
            Vector3 localPosition = (eye == NxrViewer.Eye.Left ? -ipd / 2 : ipd / 2) * Vector3.right;

            if (monoCamera == null)
            {
                monoCamera = controller.GetComponent <Camera>();
            }

            // Sync the camera properties.
            cam.CopyFrom(monoCamera);
#if UNITY_5_6_OR_NEWER
            cam.allowHDR  = false;
            cam.allowMSAA = false;
            // cam.allowDynamicResolution = false;
#endif
            monoCamera.useOcclusionCulling = false;

            // Not sure why we have to do this, but if we don't then switching between drawing to
            // the main screen or to the stereo rendertexture acts very strangely.
            cam.depth = eye == NxrViewer.Eye.Left ? monoCamera.depth + 1 : monoCamera.depth + 2;

            // Reset transform, which was clobbered by the CopyFrom() call.
            // Since we are a child of the mono camera, we inherit its transform already.
            transform.localPosition = localPosition;
            transform.localRotation = Quaternion.identity;
            transform.localScale    = Vector3.one;

            Rect left  = new Rect(0.0f, 0.0f, 0.5f, 1.0f);
            Rect right = new Rect(0.5f, 0.0f, 0.5f, 1.0f);
            if (eye == NxrViewer.Eye.Left)
            {
                cam.rect = left;
            }
            else
            {
                cam.rect = right;
            }

            // VR9 采用左右眼各分一半效果
            if (!NxrGlobal.isVR9Platform && NxrViewer.USE_DTR && NxrGlobal.supportDtr && Application.platform == RuntimePlatform.Android)
            {
                // DTR&DFT的Android模式左右眼视窗大小均为0~1
                cam.rect = new Rect(0, 0, 1, 1);
            }

            if (cam.farClipPlane < NxrGlobal.fovFar)
            {
                cam.farClipPlane = NxrGlobal.fovFar;
            }

            if (NxrGlobal.isVR9Platform)
            {
                // 已有绘制背景图,节省不必要的绘制操作
                cam.clearFlags        = CameraClearFlags.Nothing;
                monoCamera.clearFlags = CameraClearFlags.Nothing;
            }

#if NIBIRU_VR
            cam.aspect = 1.0f;
#endif

            Debug.Log(eye.ToString() + "," + cam.transform.localPosition.x);
        }