Пример #1
0
        void CheckDistortion()
        {
            if (DistortionParameters.Count == 0)
            {
                DistortionParameters = new List <float>(new float[4]);
            }

            else if (DistortionParameters.Count != 4)
            {
                throw new Exception("Length of DistortionParameters is not 4.");
            }

            if (Fisheye && !Distorted)
            {
                throw new Exception("Distorted must be true for fisheye lens.");
            }

            if (LensDistortion == null)
            {
                LensDistortion = new LensDistortion();
                LensDistortion.InitDistortion(DistortionParameters, FieldOfView, Xi, Width, Height);
            }
            else if (!LensDistortion.IsValid(DistortionParameters, FieldOfView, Xi, Width, Height))
            {
                LensDistortion.InitDistortion(DistortionParameters, FieldOfView, Xi, Width, Height);
            }
        }
Пример #2
0
        void CheckDistortion()
        {
            if (DistortionParameters.Count == 0)
            {
                DistortionParameters = new List <float>(new float[4]);
            }
            else if (DistortionParameters.Count != 4)
            {
                throw new Exception("Length of DistortionParameters is not 4.");
            }

            if (Fisheye && !Distorted)
            {
                throw new Exception("Distorted must be true for fisheye lens.");
            }

            if (LensDistortion == null || SizeChanged ||
                CurrentFieldOfView != FieldOfView || CurrentDistorted != Distorted ||
                !Enumerable.SequenceEqual(DistortionParameters, CurrentDistortionParameters) ||
                (Fisheye && CurrentXi != Xi))
            {
                // View frustum size at the focal plane.
                FrustumHeight = 2 * Mathf.Tan(FieldOfView / 2 * Mathf.Deg2Rad);
                FrustumWidth  = FrustumHeight * Width / Height;
                if (LensDistortion == null)
                {
                    LensDistortion = new LensDistortion();
                }

                LensDistortion.InitDistortion(DistortionParameters, FrustumWidth, FrustumHeight, Fisheye ? Xi : 0);
                LensDistortion.CalculateRenderTextureSize(Width, Height, out RenderTextureWidth, out RenderTextureHeight);
                if (RenderTextureWidth <= 0 || RenderTextureHeight <= 0)
                {
                    throw new Exception("Distortion parameters cause texture size invalid (<= 0).");
                }
                faceMask  = 0;
                faceMask |= 1 << (int)(CubemapFace.PositiveX); // right face
                faceMask |= 1 << (int)(CubemapFace.NegativeX); // left face
                faceMask |= 1 << (int)(CubemapFace.PositiveY); // top face
                faceMask |= 1 << (int)(CubemapFace.NegativeY); // bottom face
                faceMask |= 1 << (int)(CubemapFace.PositiveZ); // front face

                CurrentFieldOfView          = FieldOfView;
                CurrentDistorted            = Distorted;
                CurrentDistortionParameters = new List <float>(DistortionParameters);
                CurrentXi = Xi;
            }
        }