private void BuildMesh()
    {
        var rect = new HmdQuad_t();
        GetBounds(ref rect);
        var corners = new HmdVector3_t[] { rect.vCorners0, rect.vCorners1, rect.vCorners2, rect.vCorners3 };

        vertices = new Vector3[corners.Length * 2];
        for (int i = 0; i < corners.Length; i++)
        {
            var c = corners[i];
            vertices[i] = new Vector3(c.v0, 0.01f, c.v2);
        }

        for (int i = 0; i < corners.Length; i++)
        {
            vertices[corners.Length + i] = vertices[i];
        }
    }
예제 #2
0
    public void BuildMesh()
    {
        var rect = new HmdQuad_t();
        if ( !GetBounds( size, ref rect ) )
            return;

        var corners = new HmdVector3_t[] { rect.vCorners0, rect.vCorners1, rect.vCorners2, rect.vCorners3 };

        vertices = new Vector3[corners.Length * 2];
        for (int i = 0; i < corners.Length; i++)
        {
            var c = corners[i];
            vertices[i] = new Vector3(c.v0, 0.01f, c.v2);
        }

        if (borderThickness == 0.0f)
        {
            GetComponent<MeshFilter>().mesh = null;
            return;
        }

        for (int i = 0; i < corners.Length; i++)
        {
            int next = (i + 1) % corners.Length;
            int prev = (i + corners.Length - 1) % corners.Length;

            var nextSegment = (vertices[next] - vertices[i]).normalized;
            var prevSegment = (vertices[prev] - vertices[i]).normalized;

            var vert = vertices[i];
            vert += Vector3.Cross(nextSegment, Vector3.up) * borderThickness;
            vert += Vector3.Cross(prevSegment, Vector3.down) * borderThickness;

            vertices[corners.Length + i] = vert;
        }

        var triangles = new int[]
        {
            0, 1, 4,
            1, 5, 4,
            1, 2, 5,
            2, 6, 5,
            2, 3, 6,
            3, 7, 6,
            3, 0, 7,
            0, 4, 7
        };

        var uv = new Vector2[]
        {
            new Vector2(0.0f, 0.0f),
            new Vector2(1.0f, 0.0f),
            new Vector2(0.0f, 0.0f),
            new Vector2(1.0f, 0.0f),
            new Vector2(0.0f, 1.0f),
            new Vector2(1.0f, 1.0f),
            new Vector2(0.0f, 1.0f),
            new Vector2(1.0f, 1.0f)
        };

        var colors = new Color[]
        {
            color,
            color,
            color,
            color,
            new Color(color.r, color.g, color.b, 0.0f),
            new Color(color.r, color.g, color.b, 0.0f),
            new Color(color.r, color.g, color.b, 0.0f),
            new Color(color.r, color.g, color.b, 0.0f)
        };

        var mesh = new Mesh();
        GetComponent<MeshFilter>().mesh = mesh;
        mesh.vertices = vertices;
        mesh.uv = uv;
        mesh.colors = colors;
        mesh.triangles = triangles;

        var renderer = GetComponent<MeshRenderer>();
        #if UNITY_EDITOR
        renderer.material = UnityEditor.AssetDatabase.GetBuiltinExtraResource<Material>("Sprites-Default.mat");
        #else
        renderer.material = Resources.GetBuiltinResource<Material>("Sprites-Default.mat");
        #endif
        renderer.reflectionProbeUsage = UnityEngine.Rendering.ReflectionProbeUsage.Off;
        renderer.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off;
        renderer.receiveShadows = false;
        renderer.lightProbeUsage = LightProbeUsage.Off;
    }
        public void BuildMesh()
        {
            var rect = new HmdQuad_t();

            if (!GetBounds(size, ref rect))
            {
                return;
            }

            var corners = new HmdVector3_t[] { rect.vCorners0, rect.vCorners1, rect.vCorners2, rect.vCorners3 };

            vertices = new Vector3[corners.Length * 2];
            for (int i = 0; i < corners.Length; i++)
            {
                var c = corners[i];
                vertices[i] = new Vector3(c.v0, 0.01f, c.v2);
            }

            if (borderThickness == 0.0f)
            {
                GetComponent <MeshFilter>().mesh = null;
                return;
            }

            for (int i = 0; i < corners.Length; i++)
            {
                int next = (i + 1) % corners.Length;
                int prev = (i + corners.Length - 1) % corners.Length;

                var nextSegment = (vertices[next] - vertices[i]).normalized;
                var prevSegment = (vertices[prev] - vertices[i]).normalized;

                var vert = vertices[i];
                vert += Vector3.Cross(nextSegment, Vector3.up) * borderThickness;
                vert += Vector3.Cross(prevSegment, Vector3.down) * borderThickness;

                vertices[corners.Length + i] = vert;
            }

            var triangles = new int[]
            {
                0, 4, 1,
                1, 4, 5,
                1, 5, 2,
                2, 5, 6,
                2, 6, 3,
                3, 6, 7,
                3, 7, 0,
                0, 7, 4
            };

            var uv = new Vector2[]
            {
                new Vector2(0.0f, 0.0f),
                new Vector2(1.0f, 0.0f),
                new Vector2(0.0f, 0.0f),
                new Vector2(1.0f, 0.0f),
                new Vector2(0.0f, 1.0f),
                new Vector2(1.0f, 1.0f),
                new Vector2(0.0f, 1.0f),
                new Vector2(1.0f, 1.0f)
            };

            var colors = new Color[]
            {
                color,
                color,
                color,
                color,
                new Color(color.r, color.g, color.b, 0.0f),
                new Color(color.r, color.g, color.b, 0.0f),
                new Color(color.r, color.g, color.b, 0.0f),
                new Color(color.r, color.g, color.b, 0.0f)
            };

            var mesh = new Mesh();

            GetComponent <MeshFilter>().mesh = mesh;
            mesh.vertices  = vertices;
            mesh.uv        = uv;
            mesh.colors    = colors;
            mesh.triangles = triangles;

            var renderer = GetComponent <MeshRenderer>();

            renderer.material             = new Material(Shader.Find("Sprites/Default"));
            renderer.reflectionProbeUsage = UnityEngine.Rendering.ReflectionProbeUsage.Off;
            renderer.shadowCastingMode    = UnityEngine.Rendering.ShadowCastingMode.Off;
            renderer.receiveShadows       = false;
            renderer.lightProbeUsage      = LightProbeUsage.Off;
        }
예제 #4
0
    void Awake()
    {
        resetDimensions();

        // Remember the dimensions of the base:
        initialBaseWidth = rectBase.GetComponent <Renderer>().bounds.size.x;
        initialBaseDepth = rectBase.GetComponent <Renderer>().bounds.size.z;

        if (viveRig.activeInHierarchy)
        {
            // Default values:
            float width = 3f;
            float depth = 2f;
            // Try to get the room size from the mesh:
            SteamVR_PlayArea playArea = viveRig.GetComponent <SteamVR_PlayArea>();
            if (playArea != null)
            {
                Valve.VR.HmdQuad_t rect = new Valve.VR.HmdQuad_t();
                if (SteamVR_PlayArea.GetBounds(playArea.size, ref rect))
                {
                    var corners = new Valve.VR.HmdVector3_t[] { rect.vCorners0, rect.vCorners1, rect.vCorners2, rect.vCorners3 };

                    Vector2 min = new Vector2(float.MaxValue, float.MaxValue);
                    Vector2 max = new Vector2(float.MinValue, float.MinValue);
                    for (int i = 0; i < corners.Length; i++)
                    {
                        if (corners [i].v0 < min.x)
                        {
                            min.x = corners [i].v0;
                        }
                        if (corners [i].v2 < min.y)
                        {
                            min.y = corners [i].v2;
                        }

                        if (corners [i].v0 > max.x)
                        {
                            max.x = corners [i].v0;
                        }
                        if (corners [i].v2 > max.y)
                        {
                            max.y = corners [i].v2;
                        }
                    }

                    Vector2 size = max - min;
                    width = size.x;
                    depth = size.y;
                }
            }

            /*Mesh roomMesh = viveRig.GetComponent<MeshFilter>().mesh;
             * if (roomMesh != null) {
             *      width = roomMesh.bounds.size.x;
             *      depth = roomMesh.bounds.size.z;
             *      SteamVR_PlayArea playArea.
             *      Debug.Log ("Room mesh found. Setting room size to " + width + "x" + depth + "m.");
             * }*/
            setRectangular(width, depth);
        }
        else
        {
            setRounded();
        }
    }
 protected Vector3 GetUnityCoordinateAngularVelocity(HmdVector3_t vector)
 {
     return(GetUnityCoordinateAngularVelocity(vector.v0, vector.v1, vector.v2));
 }
예제 #6
0
 public void BuildMesh()
 {
     HmdQuad_t hmdQuad_t = default(HmdQuad_t);
     if (!SteamVR_PlayArea.GetBounds(this.size, ref hmdQuad_t))
     {
         return;
     }
     HmdVector3_t[] array = new HmdVector3_t[]
     {
         hmdQuad_t.vCorners0,
         hmdQuad_t.vCorners1,
         hmdQuad_t.vCorners2,
         hmdQuad_t.vCorners3
     };
     this.vertices = new Vector3[array.Length * 2];
     for (int i = 0; i < array.Length; i++)
     {
         HmdVector3_t hmdVector3_t = array[i];
         this.vertices[i] = new Vector3(hmdVector3_t.v0, 0.01f, hmdVector3_t.v2);
     }
     if (this.borderThickness == 0f)
     {
         base.GetComponent<MeshFilter>().mesh = null;
         return;
     }
     for (int j = 0; j < array.Length; j++)
     {
         int num = (j + 1) % array.Length;
         int num2 = (j + array.Length - 1) % array.Length;
         Vector3 normalized = (this.vertices[num] - this.vertices[j]).normalized;
         Vector3 normalized2 = (this.vertices[num2] - this.vertices[j]).normalized;
         Vector3 vector = this.vertices[j];
         vector += Vector3.Cross(normalized, Vector3.up) * this.borderThickness;
         vector += Vector3.Cross(normalized2, Vector3.down) * this.borderThickness;
         this.vertices[array.Length + j] = vector;
     }
     int[] triangles = new int[]
     {
         0,
         1,
         4,
         1,
         5,
         4,
         1,
         2,
         5,
         2,
         6,
         5,
         2,
         3,
         6,
         3,
         7,
         6,
         3,
         0,
         7,
         0,
         4,
         7
     };
     Vector2[] uv = new Vector2[]
     {
         new Vector2(0f, 0f),
         new Vector2(1f, 0f),
         new Vector2(0f, 0f),
         new Vector2(1f, 0f),
         new Vector2(0f, 1f),
         new Vector2(1f, 1f),
         new Vector2(0f, 1f),
         new Vector2(1f, 1f)
     };
     Color[] colors = new Color[]
     {
         this.color,
         this.color,
         this.color,
         this.color,
         new Color(this.color.r, this.color.g, this.color.b, 0f),
         new Color(this.color.r, this.color.g, this.color.b, 0f),
         new Color(this.color.r, this.color.g, this.color.b, 0f),
         new Color(this.color.r, this.color.g, this.color.b, 0f)
     };
     Mesh mesh = new Mesh();
     base.GetComponent<MeshFilter>().mesh = mesh;
     mesh.vertices = this.vertices;
     mesh.uv = uv;
     mesh.colors = colors;
     mesh.triangles = triangles;
     MeshRenderer component = base.GetComponent<MeshRenderer>();
     component.material = Resources.GetBuiltinResource<Material>("Sprites-Default.mat");
     component.reflectionProbeUsage = ReflectionProbeUsage.Off;
     component.shadowCastingMode = ShadowCastingMode.Off;
     component.receiveShadows = false;
     component.useLightProbes = false;
 }
예제 #7
0
 internal static extern bool VR_IVRCompositor_ComputeOverlayIntersection(IntPtr instancePtr, ref Compositor_OverlaySettings pSettings, float fAspectRatio, TrackingUniverseOrigin eOrigin, HmdVector3_t vSource, HmdVector3_t vDirection, ref HmdVector2_t pvecIntersectionUV, ref HmdVector3_t pvecIntersectionTrackingSpace);
예제 #8
0
파일: World.cs 프로젝트: hsuanhauliu/RuGo
    public void ShowShelf(bool show)
    {
        if (!show)
        {
            BurstBubble();
            StartCoroutine(DelayHideShelf());
        }
        else
        {
            mGadgetShelf.SetActive(show);
            mGadgetShelf.GetComponent <AudioSource>().Play();

            Transform myCamera           = GameManager.Instance.MainCamera.transform;
            Vector3   pureCameraRotation = myCamera.rotation.eulerAngles;

            // Get play area size
            Valve.VR.HmdQuad_t roomSize = new Valve.VR.HmdQuad_t();
            Vector3            offset   = Vector3.zero;

            if (SteamVR_PlayArea.GetBounds(SteamVR_PlayArea.Size.Calibrated, ref roomSize))
            {
                Valve.VR.HmdVector3_t[] roomCorners = new Valve.VR.HmdVector3_t[] { roomSize.vCorners0, roomSize.vCorners1, roomSize.vCorners2, roomSize.vCorners3 };
                Vector3[] cornerPositions           = new Vector3[roomCorners.Length];
                for (int i = 0; i < roomCorners.Length; i++)
                {
                    cornerPositions[i] = new Vector3(roomCorners[i].v0, roomCorners[i].v1, roomCorners[i].v2);
                }

                // Get two corners
                float minX = 0.0f;
                float minZ = 0.0f;
                float maxX = 0.0f;
                float maxZ = 0.0f;
                for (int i = 0; i < cornerPositions.Length; i++)
                {
                    minX = Math.Min(minX, cornerPositions[i].x);
                    maxX = Math.Max(maxX, cornerPositions[i].x);
                    minZ = Math.Min(minZ, cornerPositions[i].z);
                    maxZ = Math.Max(maxZ, cornerPositions[i].z);
                }

                // Calculate the shelf's position
                Vector3 shelfPosition = myCamera.position + myCamera.forward * shelfRadius;

                if (shelfPosition.x < 0 && shelfPosition.x < minX)
                {
                    offset += new Vector3(minX - shelfPosition.x, 0, 0);
                }
                else if (shelfPosition.x > 0 && shelfPosition.x > maxX)
                {
                    offset -= new Vector3(shelfPosition.x - maxX, 0, 0);
                }

                if (shelfPosition.z < 0 && shelfPosition.z < minZ)
                {
                    offset += new Vector3(0, 0, minZ - shelfPosition.z);
                }
                else if (shelfPosition.z > 0 && shelfPosition.z > maxZ)
                {
                    offset -= new Vector3(0, 0, shelfPosition.z - maxZ);
                }
            }

            mGadgetShelf.transform.position = myCamera.position + offset;
            mGadgetShelf.transform.rotation = Quaternion.Euler(0.0f, myCamera.rotation.eulerAngles.y - 90.0f, 0.0f);

            for (int i = 0; i < shelfGadgetContainersPositions.Length; i++)
            {
                StartCoroutine(ShiftContainer(i, shelfGadgetContainersPositions[i]));
                StartCoroutine(RotateGadget(i));
            }

            for (int i = 0; i < NUM_SAVE_SLOTS; i++)
            {
                StartCoroutine(ShiftContainer(shelfGadgetContainersPositions.Length + i, shelfFileContainersPositions[i]));
                StartCoroutine(RotateGadget(shelfGadgetContainersPositions.Length + i));
            }
        }
    }