Пример #1
0
    //画面
    void DrawPlane(int p1_index, int p2_index, int p3_index, int p4_index)
    {
        HVertex p1 = mesh[p1_index];
        HVertex p2 = mesh[p2_index];
        HVertex p3 = mesh[p3_index];
        HVertex p4 = mesh[p4_index];

        //纹理绘制到这个面上面
        p1.uv.u = 0;
        p1.uv.v = 0;

        p2.uv.u = 0;
        p2.uv.v = 1;

        p3.uv.u = 1;
        p3.uv.v = 1;

        p4.uv.u = 1;
        p4.uv.v = 0;
        HTriangle T1 = new HTriangle();

        T1.p1InObjectSpace = p1;
        T1.p2InObjectSpace = p2;
        T1.p3InObjectSpace = p3;
        DrawTriangle(T1);


        HTriangle T2 = new HTriangle();

        T2.p1InObjectSpace = p3;
        T2.p2InObjectSpace = p4;
        T2.p3InObjectSpace = p1;
        DrawTriangle(T2);
    }
Пример #2
0
    //插值屏幕坐标的顶点信息
    public HVertex InterpVertex(HVertex vertex, float t)
    {
        HVertex HVertexRet = new HVertex();

        HVertexRet.pos     = pos.InterpVec(vertex.pos, t);
        HVertexRet.uv.u    = MathHelper.Interp(uv.u, vertex.uv.u, t);
        HVertexRet.uv.v    = MathHelper.Interp(uv.v, vertex.uv.v, t);
        HVertexRet.color.r = MathHelper.Interp(color.r, vertex.color.r, t);
        HVertexRet.color.g = MathHelper.Interp(color.g, vertex.color.g, t);
        HVertexRet.color.b = MathHelper.Interp(color.b, vertex.color.b, t);
        HVertexRet.rhw     = MathHelper.Interp(rhw, vertex.rhw, t);
        return(HVertexRet);
    }
Пример #3
0
    //顶点加法
    public HVertex Add(HVertex vertex)
    {
        HVertex HVertexRet = new HVertex();

        HVertexRet.pos.x   = pos.x + vertex.pos.x;
        HVertexRet.pos.y   = pos.y + vertex.pos.y;
        HVertexRet.pos.z   = pos.z + vertex.pos.z;
        HVertexRet.pos.w   = pos.w + vertex.pos.w;
        HVertexRet.rhw     = rhw + vertex.rhw;
        HVertexRet.uv.u    = uv.u + vertex.uv.u;
        HVertexRet.uv.v    = uv.v + vertex.uv.v;
        HVertexRet.color.r = color.r + vertex.color.r;
        HVertexRet.color.g = color.g + vertex.color.g;
        HVertexRet.color.b = color.b + vertex.color.b;

        return(HVertexRet);
    }
Пример #4
0
    public HVertex Copy()
    {
        HVertex HVertexRet = new HVertex();

        HVertexRet.pos.x   = pos.x;
        HVertexRet.pos.y   = pos.y;
        HVertexRet.pos.z   = pos.z;
        HVertexRet.pos.w   = pos.w;
        HVertexRet.uv.u    = uv.u;
        HVertexRet.uv.v    = uv.v;
        HVertexRet.color.r = color.r;
        HVertexRet.color.g = color.g;
        HVertexRet.color.b = color.b;
        HVertexRet.color.a = color.a;
        HVertexRet.rhw     = rhw;

        return(HVertexRet);
    }
Пример #5
0
        public static void ChangeCaret(float left, float right, float top, float down, Color32 color)
        {
            HVertex[] hv = new HVertex[4];
            hv[0].position.x = left;
            hv[0].position.y = down;
            hv[0].color      = color;

            hv[1].position.x = right;
            hv[1].position.y = down;
            hv[1].color      = color;

            hv[2].position.x = left;
            hv[2].position.y = top;
            hv[2].color      = color;

            hv[3].position.x = right;
            hv[3].position.y = top;
            hv[3].color      = color;
            Caret.vertices   = hv;
            Caret.tris       = HGUIMesh.Rectangle;
            CaretStyle       = 1;
        }
Пример #6
0
    // Step 1/d 的步伐
    public HVertex Step(HVertex vertex, float d)
    {
        HVertex HVertexRet = new HVertex();

        if (d == 0.0f)
        {
            return(HVertexRet);
        }

        float inv = 1.0f / d;

        HVertexRet.pos.x   = (vertex.pos.x - pos.x) * inv;
        HVertexRet.pos.y   = (vertex.pos.y - pos.y) * inv;
        HVertexRet.pos.z   = (vertex.pos.z - pos.z) * inv;
        HVertexRet.pos.w   = (vertex.pos.w - pos.w) * inv;
        HVertexRet.uv.u    = (vertex.uv.u - uv.u) * inv;
        HVertexRet.uv.v    = (vertex.uv.v - uv.v) * inv;
        HVertexRet.color.r = (vertex.color.r - color.r) * inv;
        HVertexRet.color.g = (vertex.color.g - color.g) * inv;
        HVertexRet.color.b = (vertex.color.b - color.b) * inv;
        HVertexRet.rhw     = (vertex.rhw - rhw) * inv;

        return(HVertexRet);
    }
Пример #7
0
        /// <summary>
        /// 将网格线的顶点填充到ui的顶点
        /// </summary>
        /// <param name="vectors">顶点</param>
        /// <param name="vert">UI顶点</param>
        /// <param name="tris">三角形</param>
        /// <param name="color">颜色</param>
        public static void GetLineVert(Vector3[] vectors, List <HVertex> vert, List <int> tris, Color color)
        {
            int Start = vert.Count;

            for (int i = 0; i < vectors.Length; i++)
            {
                HVertex vertex = new HVertex();
                vertex.position = vectors[i];
                vertex.color    = color;
                vert.Add(vertex);
            }
            int len = vectors.Length / 4;

            for (int i = 0; i < len; i++)
            {
                int index = i * 4 + Start;
                tris.Add(index);
                tris.Add(index + 1);
                tris.Add(index + 3);
                tris.Add(index + 3);
                tris.Add(index + 1);
                tris.Add(index + 2);
            }
        }
Пример #8
0
    public int CalculateTrap(List <HTrapezoid> trapezoid)
    {
        HVertex p;
        float   k, x;

        //顶点排序
        if (p1InScreenSpace.pos.y > p2InScreenSpace.pos.y)
        {
            p = p1InScreenSpace;
            p1InScreenSpace = p2InScreenSpace;
            p2InScreenSpace = p;
        }

        if (p1InScreenSpace.pos.y > p3InScreenSpace.pos.y)
        {
            p = p1InScreenSpace;
            p1InScreenSpace = p3InScreenSpace;
            p3InScreenSpace = p;
        }

        if (p2InScreenSpace.pos.y > p3InScreenSpace.pos.y)
        {
            p = p2InScreenSpace;
            p2InScreenSpace = p3InScreenSpace;
            p3InScreenSpace = p;
        }
        if (p1InScreenSpace.pos.y == p2InScreenSpace.pos.y && p1InScreenSpace.pos.y == p3InScreenSpace.pos.y)
        {
            return(0);
        }
        if (p1InScreenSpace.pos.x == p2InScreenSpace.pos.x && p1InScreenSpace.pos.x == p3InScreenSpace.pos.x)
        {
            return(0);
        }

        if (p1InScreenSpace.pos.y == p2InScreenSpace.pos.y)             // triangle down
        {
            if (p1InScreenSpace.pos.x > p2InScreenSpace.pos.x)
            {
                p = p1InScreenSpace;
                p1InScreenSpace = p2InScreenSpace;
                p2InScreenSpace = p;
            }
            trapezoid[0].top      = p1InScreenSpace.pos.y;
            trapezoid[0].bottom   = p3InScreenSpace.pos.y;
            trapezoid[0].left.v1  = p1InScreenSpace;
            trapezoid[0].left.v2  = p3InScreenSpace;
            trapezoid[0].right.v1 = p2InScreenSpace;
            trapezoid[0].right.v2 = p3InScreenSpace;
            return((trapezoid[0].top < trapezoid[0].bottom) ? 1 : 0);
        }

        if (p2InScreenSpace.pos.y == p3InScreenSpace.pos.y)             // triangle up
        {
            if (p2InScreenSpace.pos.x > p3InScreenSpace.pos.x)
            {
                p = p2InScreenSpace;
                p2InScreenSpace = p3InScreenSpace;
                p3InScreenSpace = p;
            }
            trapezoid[0].top      = p1InScreenSpace.pos.y;
            trapezoid[0].bottom   = p3InScreenSpace.pos.y;
            trapezoid[0].left.v1  = p1InScreenSpace;
            trapezoid[0].left.v2  = p2InScreenSpace;
            trapezoid[0].right.v1 = p1InScreenSpace;
            trapezoid[0].right.v2 = p3InScreenSpace;
            return((trapezoid[0].top < trapezoid[0].bottom) ? 1 : 0);
        }

        trapezoid[0].top    = p1InScreenSpace.pos.y;
        trapezoid[0].bottom = p2InScreenSpace.pos.y;
        trapezoid[1].top    = p2InScreenSpace.pos.y;
        trapezoid[1].bottom = p3InScreenSpace.pos.y;

        k = (p3InScreenSpace.pos.y - p1InScreenSpace.pos.y) / (p2InScreenSpace.pos.y - p1InScreenSpace.pos.y);
        x = p1InScreenSpace.pos.x + (p2InScreenSpace.pos.x - p1InScreenSpace.pos.x) * k;

        if (x <= p3InScreenSpace.pos.x)                         // triangle left
        {
            trapezoid[0].left.v1  = p1InScreenSpace;
            trapezoid[0].left.v2  = p2InScreenSpace;
            trapezoid[0].right.v1 = p1InScreenSpace;
            trapezoid[0].right.v2 = p3InScreenSpace;
            trapezoid[1].left.v1  = p2InScreenSpace;
            trapezoid[1].left.v2  = p3InScreenSpace;
            trapezoid[1].right.v1 = p1InScreenSpace;
            trapezoid[1].right.v2 = p3InScreenSpace;
        }
        else                                            // triangle right
        {
            trapezoid[0].left.v1  = p1InScreenSpace;
            trapezoid[0].left.v2  = p3InScreenSpace;
            trapezoid[0].right.v1 = p1InScreenSpace;
            trapezoid[0].right.v2 = p2InScreenSpace;
            trapezoid[1].left.v1  = p1InScreenSpace;
            trapezoid[1].left.v2  = p3InScreenSpace;
            trapezoid[1].right.v1 = p2InScreenSpace;
            trapezoid[1].right.v2 = p3InScreenSpace;
        }
        return(2);
    }
Пример #9
0
        /// <summary>
        /// 获取选中区域的网格
        /// </summary>
        /// <param name="tri">三角形列表</param>
        /// <param name="vert">顶点列表</param>
        /// <param name="color">填充颜色</param>
        /// <param name="start">开始按压位置信息</param>
        /// <param name="end">结束按压位置信息</param>
        public void GetSelectArea(List <int> tri, List <HVertex> vert, ref Color32 color, ref PressInfo start, ref PressInfo end)
        {
            int sr = start.Row;
            int er = end.Row + 1;
            int st = 0;
            int c  = lines.Count;

            if (c > er)
            {
                c = er;
            }
            if (sr < 0)
            {
                sr = 0;
            }
            for (int i = sr; i < c; i++)
            {
                LineInfo info = lines[i];
                int      ls   = info.startCharIdx;
                if (ls > end.Index)
                {
                    break;
                }
                int le = lines[i].endIdx;
                if (le <= start.Index)
                {
                    continue;
                }
                int   si = start.Index;
                int   ei = end.Index;
                float left;
                if (si < ls)
                {
                    left = chars[ls].cursorPos.x;
                }
                else
                {
                    left = chars[si].cursorPos.x;
                }
                float right;
                if (ei > le)
                {
                    right = chars[le].cursorPos.x + chars[le].charWidth;
                }
                else
                {
                    right = chars[ei].cursorPos.x;
                }
                float top  = info.topY;
                float down = info.endY;

                var v = new HVertex();
                v.position.x = left;
                v.position.y = down;
                v.color      = color;
                vert.Add(v);
                v.position.x = right;
                v.position.y = down;
                v.color      = color;
                vert.Add(v);
                v.position.x = left;
                v.position.y = top;
                v.color      = color;
                vert.Add(v);
                v.position.x = right;
                v.position.y = top;
                v.color      = color;
                vert.Add(v);
                tri.Add(st);
                tri.Add(st + 2);
                tri.Add(st + 3);
                tri.Add(st);
                tri.Add(st + 3);
                tri.Add(st + 1);
                st += 4;
            }
        }
Пример #10
0
        /// <summary>
        /// 获取光标的显示网格
        /// </summary>
        /// <param name="tri">三角形列表</param>
        /// <param name="vert">顶点列表</param>
        /// <param name="color">填充颜色</param>
        /// <param name="start">按压信息</param>
        public void GetPointer(List <int> tri, List <HVertex> vert, ref Color32 color, ref PressInfo start)
        {
            if (start.Row < 0)
            {
                return;
            }
            if (start.Row >= lines.Count)
            {
                return;
            }
            int index = start.Index;

            if (index < 0)
            {
                return;
            }
            if (index >= chars.Count)
            {
                return;
            }
            int row = start.Row;

            for (int i = 0; i < lines.Count; i++)
            {
                if (index <= lines[i].endIdx)
                {
                    row = i;
                    break;
                }
            }
            float top  = lines[row].topY;
            float down = lines[row].endY;
            float p;

            if (index > lines[row].endIdx)
            {
                index--;
                if (index < 0)
                {
                    index = 0;
                }
                p = chars[index].cursorPos.x + chars[index].charWidth;
            }
            else
            {
                p = chars[index].cursorPos.x;
            }
            float left  = p - 1;
            float right = p + 1;
            var   v     = new HVertex();

            v.position.x = left;
            v.position.y = down;
            v.color      = color;
            vert.Add(v);
            v.position.x = right;
            v.position.y = down;
            v.color      = color;
            vert.Add(v);
            v.position.x = left;
            v.position.y = top;
            v.color      = color;
            vert.Add(v);
            v.position.x = right;
            v.position.y = top;
            v.color      = color;
            vert.Add(v);
            tri.Add(0);
            tri.Add(2);
            tri.Add(3);
            tri.Add(0);
            tri.Add(3);
            tri.Add(1);
        }
Пример #11
0
        protected void GetSelectArea(Color32 color, List <int> tri, List <HVertex> vert)
        {
            if (TextCom == null)
            {
                return;
            }
            tri.Clear();
            vert.Clear();
            var tl  = TextCom.uILines;
            int len = tl.Length;
            var tc  = TextCom.uIChars;

            for (int i = 0; i < ShowRow; i++)
            {
                int l = i + ShowStart;
                if (IsSelectLine(l))
                {
                    var  range = GetSelectLineRange(l);
                    bool t     = false;
                    if (range.y == lines[l].Count)
                    {
                        t = true;
                        range.y--;
                    }
                    int   s  = tl[i].startCharIdx;
                    float lx = tc[range.x + s].cursorPos.x;
                    float rx = tc[range.y + s].cursorPos.x;
                    if (t)
                    {
                        rx += tc[range.y + s].charWidth;
                    }
                    float h    = tl[i].height;
                    float top  = tl[i].topY;
                    float down = top - h;
                    int   st   = vert.Count;
                    var   v    = new HVertex();
                    v.position.x = lx;
                    v.position.y = down;
                    v.color      = color;
                    vert.Add(v);
                    v.position.x = rx;
                    v.position.y = down;
                    v.color      = color;
                    vert.Add(v);
                    v.position.x = lx;
                    v.position.y = top;
                    v.color      = color;
                    vert.Add(v);
                    v.position.x = rx;
                    v.position.y = top;
                    v.color      = color;
                    vert.Add(v);
                    tri.Add(st);
                    tri.Add(st + 2);
                    tri.Add(st + 3);
                    tri.Add(st);
                    tri.Add(st + 3);
                    tri.Add(st + 1);
                }
            }
        }