Exemplo n.º 1
0
            public ReflectorOptics(Vector3 pupilPosition,
                                   EllipsoidTransform ellipse,
                                   Transform Screen,
                                   Vector4 projectionParameters,
                                   Pose?headsetOrigin = null,
                                   Quaternion?optionalPupilRotation = null,
                                   bool updateEllipsoid             = true)
            {
                eyePosition = pupilPosition;

                bool didEllipsoidActuallyUpdate = false;

                if (updateEllipsoid)
                {
                    didEllipsoidActuallyUpdate = ellipse.UpdateEllipsoid();
                }
                sphereToWorldSpace = ellipse.sphereToWorldSpace;

                ellipseMajorAxis = ellipse.MajorAxis;
                ellipseMinorAxis = ellipse.MinorAxis;

                screenForward      = Screen.forward;
                screenPosition     = Screen.position;
                worldToScreenSpace = Screen.worldToLocalMatrix;
                cameraProjection   = projectionParameters;

                eyeRotation = Quaternion.identity;
                if (optionalPupilRotation.HasValue)
                {
                    var pupilRotation = optionalPupilRotation.Value;
                    if (optionalPupilRotation == default(Quaternion))
                    {
                        optionalPupilRotation = Quaternion.identity;
                    }
                    eyeRotation = pupilRotation;
                }

                if (headsetOrigin.HasValue)
                {
                    // If debugging this, helps to draw matrices with:
                    // var drawer = HyperMegaStuff.HyperMegaLines.drawer;
                    // (new Geometry.Sphere(radius)).DrawLines(
                    //   drawer.DrawLine,
                    //   overrideMatrix: aLocalToWorldMatrix);
                    var headsetWorldToLocal = headsetOrigin.Value.inverse.matrix;
                    eyePosition = headsetWorldToLocal.MultiplyPoint3x4(eyePosition);
                    eyeRotation = OpticalCalibrationManager.LossyMatrixMultQuaternion(
                        headsetWorldToLocal, eyeRotation
                        );
                    screenForward = headsetWorldToLocal.MultiplyVector(Screen.forward)
                                    .normalized;
                    screenPosition     = headsetWorldToLocal.MultiplyPoint3x4(Screen.position);
                    worldToScreenSpace = (headsetWorldToLocal * Screen.localToWorldMatrix)
                                         .inverse;
                    if (didEllipsoidActuallyUpdate)
                    {
                        sphereToWorldSpace = headsetWorldToLocal * sphereToWorldSpace;
                    }
                }
            }
Exemplo n.º 2
0
        public void CreateDistortionMesh(RuntimeGizmoDrawer drawer = null)
        {
            if (eyePerspective == null)
            {
                eyePerspective = GetComponent <Camera>();
            }                                                                 /// 1.12f; }
            eyePerspective.aspect = aspectRatio;

            ellipse.UpdateEllipsoid();

            meshVertices.Clear();
            meshUVs.Clear();
            meshTriangles.Clear();

            //Full range = 0f - 1f
            for (float i = 0; i <= meshResolution.x; i++)
            {
                for (float j = 0; j <= meshResolution.y; j++)
                {
                    Vector2 RenderUV = new Vector2(i / meshResolution.x, j / meshResolution.y);
                    meshUVs.Add(RenderUV);
                    meshVertices.Add(RenderUVToDisplayUV(RenderUV, (i % 5 == 0 && j % 5 == 0), drawer) - (Vector2.one * 0.5f));

                    //drawer.DrawSphere(filter.transform.TransformPoint(meshVertices[meshVertices.Count - 1]), 0.005f);
                }
            }

            for (int x = 1; x <= meshResolution.x; x++)
            {
                for (int y = 1; y <= meshResolution.y; y++)
                {
                    //Adds the index of the three vertices in order to make up each of the two tris
                    meshTriangles.Add((int)meshResolution.x * x + y);           //Top right
                    meshTriangles.Add((int)meshResolution.x * x + y - 1);       //Bottom right
                    meshTriangles.Add((int)meshResolution.x * (x - 1) + y - 1); //Bottom left - First triangle
                    meshTriangles.Add((int)meshResolution.x * (x - 1) + y - 1); //Bottom left
                    meshTriangles.Add((int)meshResolution.x * (x - 1) + y);     //Top left
                    meshTriangles.Add((int)meshResolution.x * x + y);           //Top right - Second triangle
                }
            }

            _distortionMesh.SetVertices(meshVertices);
            _distortionMesh.SetUVs(0, meshUVs);
            _distortionMesh.SetTriangles(meshTriangles, 0);
            _distortionMesh.RecalculateNormals();

            if (filter != null)
            {
                filter.sharedMesh = _distortionMesh;
            }

            if (deformer != null)
            {
                deformer.InitializeMeshDeformations();
            }
        }
Exemplo n.º 3
0
            public OpticalSystem(Camera eyePerspective,
                                 EllipsoidTransform ellipse,
                                 Transform Screen,
                                 Pose?headsetOrigin = null)
            {
                eyePosition = eyePerspective.transform.position;

                bool didEllipsoidActuallyUpdate = ellipse.UpdateEllipsoid(); // Sigh.

                sphereToWorldSpace = ellipse.sphereToWorldSpace;
                worldToSphereSpace = ellipse.worldToSphereSpace;

                ellipseMajorAxis   = ellipse.MajorAxis;
                ellipseMinorAxis   = ellipse.MinorAxis;
                screenForward      = Screen.forward;
                screenPosition     = Screen.position;
                worldToScreenSpace = Screen.worldToLocalMatrix;
                clipToWorld        = eyePerspective.cameraToWorldMatrix *
                                     eyePerspective.projectionMatrix.inverse;

                Debug.Log(eyePerspective.projectionMatrix);

                if (headsetOrigin.HasValue)
                {
                    // If debugging this, helps to draw matrices with:
                    // var drawer = HyperMegaStuff.HyperMegaLines.drawer;
                    // (new Geometry.Sphere(radius)).DrawLines(
                    //   drawer.DrawLine,
                    //   overrideMatrix: aLocalToWorldMatrix);
                    var headsetWorldToLocal = headsetOrigin.Value.inverse.matrix;
                    eyePosition = headsetWorldToLocal.MultiplyPoint3x4(eyePosition);

                    screenForward = headsetWorldToLocal.MultiplyVector(Screen.forward)
                                    .normalized;
                    screenPosition     = headsetWorldToLocal.MultiplyPoint3x4(Screen.position);
                    worldToScreenSpace = (headsetWorldToLocal * Screen.localToWorldMatrix)
                                         .inverse;
                    clipToWorld = headsetWorldToLocal * clipToWorld;

                    if (didEllipsoidActuallyUpdate)
                    {
                        sphereToWorldSpace = headsetWorldToLocal * sphereToWorldSpace;
                        worldToSphereSpace = sphereToWorldSpace.inverse;
                    }
                }
            }