Ejemplo n.º 1
0
        public override void UpdateScreenData()
        {
            // configData is 0.062000,0.037250,0.039000,40.000000,40.000000,43.299999,43.299999,0.127560,0.084400,2560.000000,1440.000000,0.003000,0.120960,0.068040
            string deviceConfigInfo = "ar device config parameter : ";

            if (deviceConfigData != null)
            {
                for (int i = 0; i < deviceConfigData.Length; i++)
                {
                    deviceConfigInfo += deviceConfigData[i];
                    if (i < deviceConfigData.Length - 1)
                    {
                        deviceConfigInfo += ",";
                    }
                }
                Debug.Log(deviceConfigInfo);
            }

            Profile = NxrProfile.GetKnownProfile(NxrViewer.Instance.ScreenSize, NxrViewer.Instance.ViewerType);
            if (loadConfigData && deviceConfigData != null)
            {
                Profile.screen.width  = deviceConfigData[12];
                Profile.screen.height = deviceConfigData[13];
                Profile.viewer        = new NxrProfile.Viewer
                {
                    lenses =
                    {
                        separation     = deviceConfigData[0],
                        offset         = deviceConfigData[1],
                        screenDistance = deviceConfigData[2],
                        alignment      = NxrProfile.Lenses.AlignBottom,
                    },
                    maxFOV =
                    {
                        outer = deviceConfigData[3],
                        inner = deviceConfigData[4],
                        upper = deviceConfigData[5],
                        lower = deviceConfigData[6]
                    },
                    distortion =
                    {
                        Coef = new [] { deviceConfigData[7], deviceConfigData[8] },
                    },
                    inverse = NxrProfile.ApproximateInverse(new[] { deviceConfigData[7], deviceConfigData[8] })
                };
            }

            if (userIpd > 0)
            {
                Profile.viewer.lenses.separation = userIpd;
            }

            ComputeEyesFromProfile(1, 2000);
            profileChanged = true;
            Debug.Log("UpdateScreenData=" + Profile.viewer.lenses.separation);
        }
Ejemplo n.º 2
0
        private void UpdateProfile()
        {
            if (NxrViewer.USE_DTR)
            {
                _NVR_GetNVRConfig(profileData);
            }

            if (profileData[13] > 0)
            {
                NxrGlobal.fovNear = profileData[13];
            }

            if (profileData[14] > 0)
            {
                NxrGlobal.fovFar = profileData[14] > NxrGlobal.fovFar ? profileData[14] : NxrGlobal.fovFar;
            }


            if (NxrViewer.USE_DTR && !NxrGlobal.supportDtr && NxrGlobal.dftProfileParams[0] != 0)
            {
                // DFT模式加载cardboard参数 0.062_0.03725_0.06_40.0_40.0_43.3_43.3_0.11825_0.39027_1920.0_1080.0_0.003_0.126_0.0625_-1
                // fov
                profileData[0] = NxrGlobal.dftProfileParams[3];  //45;
                profileData[1] = NxrGlobal.dftProfileParams[4];  //45;
                profileData[2] = NxrGlobal.dftProfileParams[5];  //51.5f;
                profileData[3] = NxrGlobal.dftProfileParams[6];  //51.5f;
                // screen size
                profileData[4] = NxrGlobal.dftProfileParams[12]; //0.110f;
                profileData[5] = NxrGlobal.dftProfileParams[13]; //0.062f;
                // ipd
                profileData[7] = NxrGlobal.dftProfileParams[0];  //0.063f;
                // screen to lens
                profileData[9] = NxrGlobal.dftProfileParams[2];  //0.035f;
                // k1 k2
                profileData[11] = NxrGlobal.dftProfileParams[7]; //0.252f;
                profileData[12] = NxrGlobal.dftProfileParams[8]; //0.019f;
                if (NxrGlobal.offaxisDistortionEnabled)
                {
                    // profileData[7] = 0.058f;
                }
            }

            NxrProfile.Viewer device = new NxrProfile.Viewer();
            NxrProfile.Screen screen = new NxrProfile.Screen();
            // left top right bottom
            device.maxFOV.outer          = profileData[0];
            device.maxFOV.upper          = profileData[2];
            device.maxFOV.inner          = profileData[1];
            device.maxFOV.lower          = profileData[3];
            screen.width                 = profileData[4];
            screen.height                = profileData[5];
            screen.border                = profileData[6];
            device.lenses.separation     = profileData[7];
            device.lenses.offset         = profileData[8];
            device.lenses.screenDistance = profileData[9];
            device.lenses.alignment      = (int)profileData[10];
            device.distortion.Coef       = new[] { profileData[11], profileData[12] };
            Profile.screen               = screen;
            Profile.viewer               = device;

            float[] rect = new float[4];
            Profile.GetLeftEyeNoLensTanAngles(rect);
            float maxRadius = NxrProfile.GetMaxRadius(rect);

            Profile.viewer.inverse = NxrProfile.ApproximateInverse(
                Profile.viewer.distortion, maxRadius);
        }
Ejemplo n.º 3
0
        private static void ComputeMeshPoints(int width, int height, bool distortVertices,
                                              out Vector3[] vertices, out Vector2[] tex)
        {
            float[]    lensFrustum   = new float[4];
            float[]    noLensFrustum = new float[4];
            Rect       viewport;
            NxrProfile profile = NxrViewer.Instance.Profile;

            profile.GetLeftEyeVisibleTanAngles(lensFrustum);
            profile.GetLeftEyeNoLensTanAngles(noLensFrustum);
            viewport = profile.GetLeftEyeVisibleScreenRect(noLensFrustum);
            vertices = new Vector3[2 * width * height];
            tex      = new Vector2[2 * width * height];
            for (int e = 0, vidx = 0; e < 2; e++)
            {
                for (int j = 0; j < height; j++)
                {
                    for (int i = 0; i < width; i++, vidx++)
                    {
                        float u = (float)i / (width - 1);
                        float v = (float)j / (height - 1);
                        float s, t;  // The texture coordinates in StereoScreen to read from.
                        if (distortVertices)
                        {
                            // Grid points regularly spaced in StreoScreen, and barrel distorted in the mesh.
                            s = u;
                            t = v;
                            float x = Mathf.Lerp(lensFrustum[0], lensFrustum[2], u);
                            float y = Mathf.Lerp(lensFrustum[3], lensFrustum[1], v);
                            float d = Mathf.Sqrt(x * x + y * y);
                            float r = profile.viewer.distortion.distortInv(d);
                            float p = x * r / d;
                            float q = y * r / d;
                            u = (p - noLensFrustum[0]) / (noLensFrustum[2] - noLensFrustum[0]);
                            v = (q - noLensFrustum[3]) / (noLensFrustum[1] - noLensFrustum[3]);
                        }
                        else
                        {
                            // Grid points regularly spaced in the mesh, and pincushion distorted in
                            // StereoScreen.
                            float p = Mathf.Lerp(noLensFrustum[0], noLensFrustum[2], u);
                            float q = Mathf.Lerp(noLensFrustum[3], noLensFrustum[1], v);
                            float r = Mathf.Sqrt(p * p + q * q);
                            float d = profile.viewer.distortion.distort(r);
                            float x = p * d / r;
                            float y = q * d / r;
                            s = Mathf.Clamp01((x - lensFrustum[0]) / (lensFrustum[2] - lensFrustum[0]));
                            t = Mathf.Clamp01((y - lensFrustum[3]) / (lensFrustum[1] - lensFrustum[3]));
                        }
                        // Convert u,v to mesh screen coordinates.
                        float aspect = profile.screen.width / profile.screen.height;
                        u = (viewport.x + u * viewport.width - 0.5f) * aspect;
                        v = viewport.y + v * viewport.height - 0.5f;
                        vertices[vidx] = new Vector3(u, v, 1);
                        // Adjust s to account for left/right split in StereoScreen.
                        s         = (s + e) / 2;
                        tex[vidx] = new Vector2(s, t);
                    }
                }
                float w = lensFrustum[2] - lensFrustum[0];
                lensFrustum[0] = -(w + lensFrustum[0]);
                lensFrustum[2] = w - lensFrustum[2];
                w = noLensFrustum[2] - noLensFrustum[0];
                noLensFrustum[0] = -(w + noLensFrustum[0]);
                noLensFrustum[2] = w - noLensFrustum[2];
                viewport.x       = 1 - (viewport.x + viewport.width);
            }
        }