Ejemplo n.º 1
0
    // Builds a tessellated grid of quads across the provided bounds with three sets of UVs used to account for
    // lens distortion and chromatic aberration.
    public static Mesh CreateDistortMesh(SteamVR.IHmd hmd, SteamVR.Hmd_Eye eye, int resU, int resV, Rect bounds)
    {
        int numVerts = resU * resV;
        var vertices = new Vector3[numVerts];
        var redUVs   = new Vector3[numVerts];
        var greenUVs = new Vector2[numVerts];
        var blueUVs  = new Vector2[numVerts];

        int iTri      = 0;
        int resUm1    = resU - 1;
        int resVm1    = resV - 1;
        var triangles = new int[2 * 3 * resUm1 * resVm1];

        for (int iV = 0; iV < resV; iV++)
        {
            float v = (float)iV / resVm1;
            float y = SteamVR_Utils.Lerp(bounds.yMax, bounds.yMin, v);             // ComputeDistortion expects 0,0 in upper left
            for (int iU = 0; iU < resU; iU++)
            {
                float u      = (float)iU / resUm1;
                float x      = SteamVR_Utils.Lerp(bounds.xMin, bounds.xMax, u);
                var   coords = hmd.ComputeDistortion(eye, u, v);

                int idx = iV * resU + iU;
                vertices[idx] = new Vector3(x, y, 0.1f);

                redUVs[idx]   = new Vector3(coords.rfRed[0], 1.0f - coords.rfRed[1], 0);
                greenUVs[idx] = new Vector2(coords.rfGreen[0], 1.0f - coords.rfGreen[1]);
                blueUVs[idx]  = new Vector2(coords.rfBlue[0], 1.0f - coords.rfBlue[1]);

                if (iV > 0 && iU > 0)
                {
                    int a = (iV - 1) * resU + (iU - 1);
                    int b = (iV - 1) * resU + iU;
                    int c = iV * resU + (iU - 1);
                    int d = iV * resU + iU;

                    triangles[iTri++] = a;
                    triangles[iTri++] = b;
                    triangles[iTri++] = d;

                    triangles[iTri++] = a;
                    triangles[iTri++] = d;
                    triangles[iTri++] = c;
                }
            }
        }

        var mesh = new Mesh();

        mesh.vertices  = vertices;
        mesh.normals   = redUVs;       // stuff data in normals since only two uv sets exposed
        mesh.uv        = greenUVs;
        mesh.uv2       = blueUVs;
        mesh.triangles = triangles;
        return(mesh);
    }
Ejemplo n.º 2
0
    // Sends the figurine down to the destination position over time.  Once down, actually spawns the entity
    // and destroys the figurine.
    // Assumes the figurine is no longer grabbed.
    private IEnumerator dropFigurineToSpawn(Vector3 startPos, Vector3 destination, Hand hand)
    {
        _elapsedSpawnSeconds = 0f;
        float totalMeters   = Vector3.Distance(startPos, destination);
        float _totalSeconds = totalMeters / _spawnMetersPerSecond;

        while (_elapsedSpawnSeconds < _totalSeconds)
        {
            hand.controller.TriggerHapticPulse(HapticSpawnDrop);

            var currentPos = SteamVR_Utils.Lerp(startPos, destination, _elapsedSpawnSeconds / _totalSeconds);
            transform.position = currentPos;

            _elapsedSpawnSeconds += Time.deltaTime;
            yield return(new WaitForEndOfFrame());
        }

        FigurinePlacedEvent.Invoke(destination);
    }
Ejemplo n.º 3
0
 public void Interpolate(RigidTransform to, float t)
 {
     pos = SteamVR_Utils.Lerp(pos, to.pos, t);
     rot = SteamVR_Utils.Slerp(rot, to.rot, t);
 }
Ejemplo n.º 4
0
        public static Mesh CreateHiddenAreaMesh(HiddenAreaMesh_t src, VRTextureBounds_t bounds)
        {
            if (src.unTriangleCount == 0u)
            {
                return(null);
            }
            float[] array = new float[src.unTriangleCount * 3u * 2u];
            Marshal.Copy(src.pVertexData, array, 0, array.Length);
            Vector3[] array2 = new Vector3[src.unTriangleCount * 3u + 12u];
            int[]     array3 = new int[src.unTriangleCount * 3u + 24u];
            float     num    = 2f * bounds.uMin - 1f;
            float     num2   = 2f * bounds.uMax - 1f;
            float     num3   = 2f * bounds.vMin - 1f;
            float     num4   = 2f * bounds.vMax - 1f;
            int       num5   = 0;
            int       num6   = 0;

            while ((long)num5 < (long)((ulong)(src.unTriangleCount * 3u)))
            {
                float x = SteamVR_Utils.Lerp(num, num2, array[num6++]);
                float y = SteamVR_Utils.Lerp(num3, num4, array[num6++]);
                array2[num5] = new Vector3(x, y, 0f);
                array3[num5] = num5;
                num5++;
            }
            int num7 = (int)(src.unTriangleCount * 3u);
            int num8 = num7;

            array2[num8++] = new Vector3(-1f, -1f, 0f);
            array2[num8++] = new Vector3(num, -1f, 0f);
            array2[num8++] = new Vector3(-1f, 1f, 0f);
            array2[num8++] = new Vector3(num, 1f, 0f);
            array2[num8++] = new Vector3(num2, -1f, 0f);
            array2[num8++] = new Vector3(1f, -1f, 0f);
            array2[num8++] = new Vector3(num2, 1f, 0f);
            array2[num8++] = new Vector3(1f, 1f, 0f);
            array2[num8++] = new Vector3(num, num3, 0f);
            array2[num8++] = new Vector3(num2, num3, 0f);
            array2[num8++] = new Vector3(num, num4, 0f);
            array2[num8++] = new Vector3(num2, num4, 0f);
            int num9 = num7;

            array3[num9++] = num7;
            array3[num9++] = num7 + 1;
            array3[num9++] = num7 + 2;
            array3[num9++] = num7 + 2;
            array3[num9++] = num7 + 1;
            array3[num9++] = num7 + 3;
            array3[num9++] = num7 + 4;
            array3[num9++] = num7 + 5;
            array3[num9++] = num7 + 6;
            array3[num9++] = num7 + 6;
            array3[num9++] = num7 + 5;
            array3[num9++] = num7 + 7;
            array3[num9++] = num7 + 1;
            array3[num9++] = num7 + 4;
            array3[num9++] = num7 + 8;
            array3[num9++] = num7 + 8;
            array3[num9++] = num7 + 4;
            array3[num9++] = num7 + 9;
            array3[num9++] = num7 + 10;
            array3[num9++] = num7 + 11;
            array3[num9++] = num7 + 3;
            array3[num9++] = num7 + 3;
            array3[num9++] = num7 + 11;
            array3[num9++] = num7 + 6;
            return(new Mesh
            {
                vertices = array2,
                triangles = array3,
                bounds = new Bounds(Vector3.zero, new Vector3(float.MaxValue, float.MaxValue, float.MaxValue))
            });
        }
Ejemplo n.º 5
0
 public void Interpolate(SteamVR_Utils.RigidTransform to, float t)
 {
     this.pos = SteamVR_Utils.Lerp(this.pos, to.pos, t);
     this.rot = SteamVR_Utils.Slerp(this.rot, to.rot, t);
 }
Ejemplo n.º 6
0
 public static Vector3 Lerp(Vector3 A, Vector3 B, float t)
 {
     return(new Vector3(SteamVR_Utils.Lerp(A.x, B.x, t), SteamVR_Utils.Lerp(A.y, B.y, t), SteamVR_Utils.Lerp(A.z, B.z, t)));
 }