예제 #1
0
        //4 vertex
        static void FillRadial90(VertexBuffer vb, Rect vertRect, Origin90 origin, float amount, bool clockwise)
        {
            bool flipX = origin == Origin90.TopRight || origin == Origin90.BottomRight;
            bool flipY = origin == Origin90.BottomLeft || origin == Origin90.BottomRight;

            if (flipX != flipY)
            {
                clockwise = !clockwise;
            }

            float ratio    = clockwise ? amount : (1 - amount);
            float tan      = Mathf.Tan(Mathf.PI * 0.5f * ratio);
            float thresold = vertRect.height / vertRect.width - tan;

            if (!clockwise)
            {
                thresold = -thresold;
            }
            float x  = vertRect.x + (ratio == 0 ? float.MaxValue : (vertRect.height / tan));
            float y  = vertRect.y + (ratio == 1 ? float.MaxValue : (vertRect.width * tan));
            float x2 = x;
            float y2 = y;

            if (flipX)
            {
                x2 = vertRect.width - x;
            }
            if (flipY)
            {
                y2 = vertRect.height - y;
            }
            float xMin = flipX ? (vertRect.width - vertRect.x) : vertRect.xMin;
            float yMin = flipY ? (vertRect.height - vertRect.y) : vertRect.yMin;
            float xMax = flipX ? -vertRect.xMin : vertRect.xMax;
            float yMax = flipY ? -vertRect.yMin : vertRect.yMax;

            vb.AddVert(new Vector3(xMin, yMin, 0));

            if (clockwise)
            {
                vb.AddVert(new Vector3(xMax, yMin, 0));
            }

            if (y > vertRect.yMax)
            {
                if (thresold > 0)
                {
                    vb.AddVert(new Vector3(x2, yMax, 0));
                }
                else
                {
                    vb.AddVert(new Vector3(xMax, yMax, 0));
                }
            }
            else
            {
                vb.AddVert(new Vector3(xMax, y2, 0));
            }

            if (x > vertRect.xMax)
            {
                if (thresold > 0)
                {
                    vb.AddVert(new Vector3(xMax, y2, 0));
                }
                else
                {
                    vb.AddVert(new Vector3(xMax, yMax, 0));
                }
            }
            else
            {
                vb.AddVert(new Vector3(x2, yMax, 0));
            }

            if (!clockwise)
            {
                vb.AddVert(new Vector3(xMin, yMax, 0));
            }

            if (flipX == flipY)
            {
                vb.AddTriangle(0, 1, 2);
                vb.AddTriangle(0, 2, 3);
            }
            else
            {
                vb.AddTriangle(2, 1, 0);
                vb.AddTriangle(3, 2, 0);
            }
        }
예제 #2
0
        public static void FillRadial90(Origin90 origin, float amount, bool clockwise, Rect vertRect, Rect uvRect, Vector3[] verts, Vector2[] uv)
        {
            NGraphics.FillVertsOfQuad(verts, 0, vertRect);
            NGraphics.FillUVOfQuad(uv, 0, uvRect);
            if (amount < 0.001f)
            {
                verts[0] = verts[1] = verts[2] = verts[3];
                uv[0]    = uv[1] = uv[2] = uv[3];
                return;
            }
            if (amount > 0.999f)
            {
                return;
            }

            switch (origin)
            {
            case Origin90.BottomLeft:
            {
                if (clockwise)
                {
                    float v = Mathf.Tan(Mathf.PI / 2 * (1 - amount));
                    float h = vertRect.width * v;
                    if (h > vertRect.height)
                    {
                        float ratio = (h - vertRect.height) / h;
                        verts[2].x -= vertRect.width * ratio;
                        verts[3]    = verts[2];

                        uv[2].x -= uvRect.width * ratio;
                        uv[3]    = uv[2];
                    }
                    else
                    {
                        float ratio = h / vertRect.height;
                        verts[3].y += h;
                        uv[3].y    += uvRect.height * ratio;
                    }
                }
                else
                {
                    float v = Mathf.Tan(Mathf.PI / 2 * amount);
                    float h = vertRect.width * v;
                    if (h > vertRect.height)
                    {
                        float ratio = (h - vertRect.height) / h;
                        verts[1].x += vertRect.width * (1 - ratio);
                        uv[1].x    += uvRect.width * (1 - ratio);
                    }
                    else
                    {
                        float ratio = h / vertRect.height;
                        verts[2].y -= vertRect.height * (1 - ratio);
                        verts[1]    = verts[2];

                        uv[2].y -= uvRect.height * (1 - ratio);
                        uv[1]    = uv[2];
                    }
                }
            }
            break;

            case Origin90.BottomRight:
            {
                if (clockwise)
                {
                    float v = Mathf.Tan(Mathf.PI / 2 * amount);
                    float h = vertRect.width * v;
                    if (h > vertRect.height)
                    {
                        float ratio = (h - vertRect.height) / h;
                        verts[2].x -= vertRect.width * (1 - ratio);
                        uv[2].x    -= uvRect.width * (1 - ratio);
                    }
                    else
                    {
                        float ratio = h / vertRect.height;
                        verts[1].y -= vertRect.height * (1 - ratio);
                        verts[2]    = verts[3];

                        uv[1].y -= uvRect.height * (1 - ratio);
                        uv[2]    = uv[3];
                    }
                }
                else
                {
                    float v = Mathf.Tan(Mathf.PI / 2 * (1 - amount));
                    float h = vertRect.width * v;
                    if (h > vertRect.height)
                    {
                        float ratio = (h - vertRect.height) / h;
                        verts[1].x += vertRect.width * ratio;
                        verts[0]    = verts[1];

                        uv[1].x += uvRect.width * ratio;
                        uv[0]    = uv[1];
                    }
                    else
                    {
                        float ratio = h / vertRect.height;
                        verts[0].y += h;
                        uv[0].y    += uvRect.height * ratio;
                    }
                }
            }
            break;

            case Origin90.TopLeft:
            {
                if (clockwise)
                {
                    float v = Mathf.Tan(Mathf.PI / 2 * amount);
                    float h = vertRect.width * v;
                    if (h > vertRect.height)
                    {
                        float ratio = (h - vertRect.height) / h;
                        verts[0].x += vertRect.width * (1 - ratio);
                        uv[0].x    += uvRect.width * (1 - ratio);
                    }
                    else
                    {
                        float ratio = h / vertRect.height;
                        verts[3].y += vertRect.height * (1 - ratio);
                        verts[0]    = verts[3];

                        uv[3].y += uvRect.height * (1 - ratio);
                        uv[0]    = uv[3];
                    }
                }
                else
                {
                    float v = Mathf.Tan(Mathf.PI / 2 * (1 - amount));
                    float h = vertRect.width * v;
                    if (h > vertRect.height)
                    {
                        float ratio = (h - vertRect.height) / h;
                        verts[3].x -= vertRect.width * ratio;
                        verts[2]    = verts[3];
                        uv[3].x    -= uvRect.width * ratio;
                        uv[2]       = uv[3];
                    }
                    else
                    {
                        float ratio = h / vertRect.height;
                        verts[2].y -= h;
                        uv[2].y    -= uvRect.height * ratio;
                    }
                }
            }
            break;

            case Origin90.TopRight:
            {
                if (clockwise)
                {
                    float v = Mathf.Tan(Mathf.PI / 2 * (1 - amount));
                    float h = vertRect.width * v;
                    if (h > vertRect.height)
                    {
                        float ratio = (h - vertRect.height) / h;
                        verts[0].x += vertRect.width * ratio;
                        verts[1]    = verts[2];
                        uv[0].x    += uvRect.width * ratio;
                        uv[1]       = uv[2];
                    }
                    else
                    {
                        float ratio = h / vertRect.height;
                        verts[1].y -= vertRect.height * ratio;
                        uv[1].y    -= uvRect.height * ratio;
                    }
                }
                else
                {
                    float v = Mathf.Tan(Mathf.PI / 2 * amount);
                    float h = vertRect.width * v;
                    if (h > vertRect.height)
                    {
                        float ratio = (h - vertRect.height) / h;
                        verts[3].x -= vertRect.width * (1 - ratio);
                        uv[3].x    -= uvRect.width * (1 - ratio);
                    }
                    else
                    {
                        float ratio = h / vertRect.height;
                        verts[0].y += vertRect.height * (1 - ratio);
                        verts[3]    = verts[0];
                        uv[0].y    += uvRect.height * (1 - ratio);
                        uv[3]       = uv[0];
                    }
                }
            }
            break;
            }
        }
예제 #3
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="origin"></param>
        /// <param name="amount"></param>
        /// <param name="clockwise"></param>
        /// <param name="vertRect"></param>
        /// <param name="uvRect"></param>
        /// <param name="verts"></param>
        /// <param name="uv"></param>
        public static void FillRadial90(Origin90 origin, float amount, bool clockwise, Rect vertRect, Rect uvRect, Vector3[] verts, Vector2[] uv)
        {
            NGraphics.FillVertsOfQuad(verts, 0, vertRect);
            NGraphics.FillUVOfQuad(uv, 0, uvRect);
            if (amount < 0.001f)
            {
                verts[0] = verts[1] = verts[2] = verts[3];
                uv[0] = uv[1] = uv[2] = uv[3];
                return;
            }
            if (amount > 0.999f)
                return;

            switch (origin)
            {
                case Origin90.BottomLeft:
                    {
                        if (clockwise)
                        {
                            float v = Mathf.Tan(Mathf.PI / 2 * (1 - amount));
                            float h = vertRect.width * v;
                            if (h > vertRect.height)
                            {
                                float ratio = (h - vertRect.height) / h;
                                verts[2].x -= vertRect.width * ratio;
                                verts[3] = verts[2];

                                uv[2].x -= uvRect.width * ratio;
                                uv[3] = uv[2];
                            }
                            else
                            {
                                float ratio = h / vertRect.height;
                                verts[3].y += h;
                                uv[3].y += uvRect.height * ratio;
                            }
                        }
                        else
                        {
                            float v = Mathf.Tan(Mathf.PI / 2 * amount);
                            float h = vertRect.width * v;
                            if (h > vertRect.height)
                            {
                                float ratio = (h - vertRect.height) / h;
                                verts[1].x += vertRect.width * (1 - ratio);
                                uv[1].x += uvRect.width * (1 - ratio);
                            }
                            else
                            {
                                float ratio = h / vertRect.height;
                                verts[2].y -= vertRect.height * (1 - ratio);
                                verts[1] = verts[2];

                                uv[2].y -= uvRect.height * (1 - ratio);
                                uv[1] = uv[2];
                            }
                        }
                    }
                    break;

                case Origin90.BottomRight:
                    {
                        if (clockwise)
                        {
                            float v = Mathf.Tan(Mathf.PI / 2 * amount);
                            float h = vertRect.width * v;
                            if (h > vertRect.height)
                            {
                                float ratio = (h - vertRect.height) / h;
                                verts[2].x -= vertRect.width * (1 - ratio);
                                uv[2].x -= uvRect.width * (1 - ratio);
                            }
                            else
                            {
                                float ratio = h / vertRect.height;
                                verts[1].y -= vertRect.height * (1 - ratio);
                                verts[2] = verts[3];

                                uv[1].y -= uvRect.height * (1 - ratio);
                                uv[2] = uv[3];
                            }
                        }
                        else
                        {
                            float v = Mathf.Tan(Mathf.PI / 2 * (1 - amount));
                            float h = vertRect.width * v;
                            if (h > vertRect.height)
                            {
                                float ratio = (h - vertRect.height) / h;
                                verts[1].x += vertRect.width * ratio;
                                verts[0] = verts[1];

                                uv[1].x += uvRect.width * ratio;
                                uv[0] = uv[1];
                            }
                            else
                            {
                                float ratio = h / vertRect.height;
                                verts[0].y += h;
                                uv[0].y += uvRect.height * ratio;
                            }
                        }
                    }
                    break;

                case Origin90.TopLeft:
                    {
                        if (clockwise)
                        {
                            float v = Mathf.Tan(Mathf.PI / 2 * amount);
                            float h = vertRect.width * v;
                            if (h > vertRect.height)
                            {
                                float ratio = (h - vertRect.height) / h;
                                verts[0].x += vertRect.width * (1 - ratio);
                                uv[0].x += uvRect.width * (1 - ratio);
                            }
                            else
                            {
                                float ratio = h / vertRect.height;
                                verts[3].y += vertRect.height * (1 - ratio);
                                verts[0] = verts[3];

                                uv[3].y += uvRect.height * (1 - ratio);
                                uv[0] = uv[3];
                            }
                        }
                        else
                        {
                            float v = Mathf.Tan(Mathf.PI / 2 * (1 - amount));
                            float h = vertRect.width * v;
                            if (h > vertRect.height)
                            {
                                float ratio = (h - vertRect.height) / h;
                                verts[3].x -= vertRect.width * ratio;
                                verts[2] = verts[3];
                                uv[3].x -= uvRect.width * ratio;
                                uv[2] = uv[3];
                            }
                            else
                            {
                                float ratio = h / vertRect.height;
                                verts[2].y -= h;
                                uv[2].y -= uvRect.height * ratio;
                            }
                        }
                    }
                    break;

                case Origin90.TopRight:
                    {
                        if (clockwise)
                        {
                            float v = Mathf.Tan(Mathf.PI / 2 * (1 - amount));
                            float h = vertRect.width * v;
                            if (h > vertRect.height)
                            {
                                float ratio = (h - vertRect.height) / h;
                                verts[0].x += vertRect.width * ratio;
                                verts[1] = verts[2];
                                uv[0].x += uvRect.width * ratio;
                                uv[1] = uv[2];
                            }
                            else
                            {
                                float ratio = h / vertRect.height;
                                verts[1].y -= vertRect.height * ratio;
                                uv[1].y -= uvRect.height * ratio;
                            }
                        }
                        else
                        {
                            float v = Mathf.Tan(Mathf.PI / 2 * amount);
                            float h = vertRect.width * v;
                            if (h > vertRect.height)
                            {
                                float ratio = (h - vertRect.height) / h;
                                verts[3].x -= vertRect.width * (1 - ratio);
                                uv[3].x -= uvRect.width * (1 - ratio);
                            }
                            else
                            {
                                float ratio = h / vertRect.height;
                                verts[0].y += vertRect.height * (1 - ratio);
                                verts[3] = verts[0];
                                uv[0].y += uvRect.height * (1 - ratio);
                                uv[3] = uv[0];
                            }
                        }
                    }
                    break;
            }
        }
예제 #4
0
        //4 vertex
        static void FillRadial90(VertexBuffer vb, Rectangle vertRect, Origin90 origin, float amount, bool clockwise)
        {
            bool flipX = origin == Origin90.TopRight || origin == Origin90.BottomRight;
            bool flipY = origin == Origin90.BottomLeft || origin == Origin90.BottomRight;

            if (flipX != flipY)
            {
                clockwise = !clockwise;
            }

            float ratio = clockwise ? amount : (1 - amount);
            float tan   = (float)Math.Tan(Math.PI * 0.5f * ratio);
            float x     = vertRect.X + (ratio == 0 ? float.MaxValue : (vertRect.Height / tan));
            float y     = vertRect.Y + (ratio == 1 ? float.MaxValue : (vertRect.Width * tan));
            float x2    = x;
            float y2    = y;

            if (flipX)
            {
                x2 = vertRect.Width - x;
            }
            if (flipY)
            {
                y2 = vertRect.Height - y;
            }
            float xMin = flipX ? (vertRect.Width - vertRect.X) : vertRect.X;
            float yMin = flipY ? (vertRect.Height - vertRect.Y) : vertRect.Y;
            float xMax = flipX ? -vertRect.X : vertRect.Right;
            float yMax = flipY ? -vertRect.Y : vertRect.Bottom;

            vb.AddVert(new Vector3(xMin, yMin, 0));

            if (clockwise)
            {
                vb.AddVert(new Vector3(xMax, yMin, 0));
            }

            if (y > vertRect.Bottom)
            {
                if (amount < 0.5f)
                {
                    vb.AddVert(new Vector3(x2, yMax, 0));
                }
                else
                {
                    vb.AddVert(new Vector3(xMax, yMax, 0));
                }
            }
            else
            {
                vb.AddVert(new Vector3(xMax, y2, 0));
            }

            if (x > vertRect.Right)
            {
                if (amount < 0.5f)
                {
                    vb.AddVert(new Vector3(xMax, y2, 0));
                }
                else
                {
                    vb.AddVert(new Vector3(xMax, yMax, 0));
                }
            }
            else
            {
                vb.AddVert(new Vector3(x2, yMax, 0));
            }

            if (!clockwise)
            {
                vb.AddVert(new Vector3(xMin, yMax, 0));
            }

            if (flipX == flipY)
            {
                vb.AddTriangle(0, 1, 2);
                vb.AddTriangle(0, 2, 3);
            }
            else
            {
                vb.AddTriangle(2, 1, 0);
                vb.AddTriangle(3, 2, 0);
            }
        }