Exemplo n.º 1
0
Arquivo: GLUI.cs Projeto: wjk17/WSA
        public static void _DrawLineOrtho(Vector2 p1, Vector2 p2, Color color1, Color color2, bool clip = true)
        {
            SetLineMaterial();
            //clip
            if (clip)
            {
                var RT = UI.owner as RectTransform;
                if (RT != null)
                {
                    var rect = RT.Rect();
                    if (LineClip.ClipCohSuth(rect[0], rect[1], ref p1, ref p2) == LineClip.Result.discard)
                    {
                        return;
                    }
                }
            }
            //normalize & flip y
            p1 = p1.ToNDC();
            p2 = p2.ToNDC();

            GL.Begin(GL.LINES);
            GL.Color(color1);
            GL.Vertex(p1);
            GL.Color(color2);
            GL.Vertex(p2);
            GL.End();
        }
Exemplo n.º 2
0
Arquivo: GLUI.cs Projeto: wjk17/WSA
        // 控制粗细的线条实际是画四边形,不一定与坐标轴垂直。
        public static void _DrawLineWidth(Vector2 p1, Vector2 p2, float width, Color color, bool clip = true)
        {
            SetLineMaterial();
            //clip
            if (clip)
            {
                var RT = UI.owner as RectTransform;
                if (RT != null)
                {
                    var rect = RT.Rect();
                    if (LineClip.ClipCohSuth(rect[0], rect[1], ref p1, ref p2) == LineClip.Result.discard)
                    {
                        return;
                    }
                }
            }
            var v  = p2 - p1;
            var v2 = p1 - p2;

            width *= 0.5f;
            var p1a = p1 + new Vector2(-v.y, v.x).normalized *width;
            var p1b = p1 + new Vector2(v.y, -v.x).normalized *width;
            var p2a = p2 + new Vector2(-v2.y, v2.x).normalized *width;
            var p2b = p2 + new Vector2(v2.y, -v2.x).normalized *width;

            //四边形可能切成更多边形,暂时没做画多边形功能因此暂不裁剪宽度,只裁剪长度
            _DrawQuad(color, p1a, p1b, p2a, p2b);
        }