示例#1
0
        private Vector2d LengthLock(Vector2d p1, Vector2d p2)
        {
            var diff  = _originalPos2 - _originalPos1;
            var diff2 = p2 - p1;

            if (diff.Length != diff2.Length)
            {
                var            angle  = Math.Atan2(diff2.Y, diff2.X);
                Drawing.Turtle turtle = new Drawing.Turtle(p1);
                turtle.Move(Tools.Angle.FromRadians(angle).Degrees, diff.Length);
                return(turtle.Point);
            }
            return(p2);
        }
示例#2
0
        public static void DrawTrackLine(StandardLine l, Color color, bool drawwell, bool drawcolor, bool drawknobs, bool redknobs = false)
        {
            color = Color.FromArgb(255, color);
            var   thickness = 2;
            Color color2;
            var   type = l.GetLineType();

            switch (type)
            {
            case LineType.Blue:
                color2 = Color.FromArgb(0, 0x66, 0xFF);
                break;

            case LineType.Red:
                color2 = Color.FromArgb(0xCC, 0, 0);
                break;

            default:
                throw new Exception("Rendering Invalid Line");
            }
            if (drawcolor)
            {
                var loc3 = l.Perpendicular.X > 0 ? (Math.Ceiling(l.Perpendicular.X)) : (Math.Floor(l.Perpendicular.X));
                var loc4 = l.Perpendicular.Y > 0 ? (Math.Ceiling(l.Perpendicular.Y)) : (Math.Floor(l.Perpendicular.Y));
                if (type == LineType.Red)
                {
                    var redline = l as RedLine;
                    GameDrawingMatrix.Enter();
                    GL.Color3(color2);
                    GL.Begin(PrimitiveType.Triangles);
                    var basepos = l.Position2;
                    for (int ix = 0; ix < redline.Multiplier; ix++)
                    {
                        var    angle = MathHelper.RadiansToDegrees(Math.Atan2(l.diff.Y, l.diff.X));
                        Turtle t     = new Turtle(l.Position2);
                        var    basex = 8 + (ix * 2);
                        t.Move(angle, -basex);
                        GL.Vertex2(new Vector2((float)t.X, (float)t.Y));
                        t.Move(90, l.inv ? -8 : 8);
                        GL.Vertex2(new Vector2((float)t.X, (float)t.Y));
                        t.Point = l.Position2;
                        t.Move(angle, -(ix * 2));
                        GL.Vertex2(new Vector2((float)t.X, (float)t.Y));
                    }
                    GL.End();
                    GameDrawingMatrix.Exit();
                }
                RenderRoundedLine(new Vector2d(l.Position.X + loc3, l.Position.Y + loc4),
                                  new Vector2d(l.Position2.X + loc3, l.Position2.Y + loc4), color2, thickness);
            }
            RenderRoundedLine(l.Position, l.Position2, color, thickness, drawknobs, redknobs);
            if (drawwell)
            {
                using (new GLEnableCap(EnableCap.Blend))
                {
                    GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);
                    GameDrawingMatrix.Enter();
                    GL.Begin(PrimitiveType.Quads);
                    GL.Color4(new Color4(150, 150, 150, 150));
                    var rect = StaticRenderer.GenerateThickLine((Vector2)l.Position, (Vector2)l.Position2, (float)(StandardLine.Zone * 2));

                    GL.Vertex2(l.Position);
                    GL.Vertex2(l.Position2);
                    GL.Vertex2(rect[l.inv ? 2 : 1]);
                    GL.Vertex2(rect[l.inv ? 3 : 0]);
                    GL.End();
                    GL.PopMatrix();
                }
            }
        }
示例#3
0
        private List <int> DrawTrackLine(StandardLine line, bool colors)
        {
            List <int> ret  = new List <int>((6 * 6) + 3);
            var        type = line.GetLineType();
            Color      c    = Settings.Default.NightMode ? Color.White : Color.Black;

            if (colors)
            {
                switch (type)
                {
                case LineType.Blue:
                {
                    c = Color.FromArgb(0, 0x66, 0xFF);
                    var     l    = line;
                    var     loc3 = (float)(l.Perpendicular.X > 0 ? (Math.Ceiling(l.Perpendicular.X)) : (Math.Floor(l.Perpendicular.X)));
                    var     loc4 = (float)(l.Perpendicular.Y > 0 ? (Math.Ceiling(l.Perpendicular.Y)) : (Math.Floor(l.Perpendicular.Y)));
                    Vector2 p1   = new Vector2((float)l.Position.X + loc3, (float)l.Position.Y + loc4),
                            p2   = new Vector2((float)l.Position2.X + loc3, (float)l.Position2.Y + loc4);
                    ret.AddRange(DrawBasicTrackLine(p1, p2, c));
                }
                break;

                case LineType.Red:
                {
                    c = Color.FromArgb(0xCC, 0, 0);
                    var l    = line as RedLine;
                    var loc3 = (float)(l.Perpendicular.X > 0 ? (Math.Ceiling(l.Perpendicular.X)) : (Math.Floor(l.Perpendicular.X)));
                    var loc4 = (float)(l.Perpendicular.Y > 0 ? (Math.Ceiling(l.Perpendicular.Y)) : (Math.Floor(l.Perpendicular.Y)));
                    for (int ix = 0; ix < l.Multiplier; ix++)
                    {
                        var    angle = MathHelper.RadiansToDegrees(Math.Atan2(l.diff.Y, l.diff.X));
                        Turtle t     = new Turtle(l.Position2);
                        var    basex = 8 + (ix * 2);
                        t.Move(angle, -basex);
                        var v0 = AddVertex(new Vertex((float)t.X, (float)t.Y, c));
                        t.Move(90, l.inv ? -8 : 8);
                        var v1 = AddVertex(new Vertex((float)t.X, (float)t.Y, c));
                        t.Point = l.Position2;
                        t.Move(angle, -(ix * 2));
                        var v2 = AddVertex(new Vertex((float)t.X, (float)t.Y, c));
                        ret.Add(v0);
                        ret.Add(v1);
                        ret.Add(v2);
                    }
                    Vector2 p1 = new Vector2((float)l.Position.X + loc3, (float)l.Position.Y + loc4), p2 = new Vector2((float)l.Position2.X + loc3, (float)l.Position2.Y + loc4);
                    ret.AddRange(DrawBasicTrackLine(p1, p2, c));
                }
                break;
                }
            }
            Color linecolor = Settings.Default.NightMode ? Color.White : Color.Black;
            var   linep1    = line.Position;
            var   linep2    = line.Position2;

            if (line.Trigger != null && line.Trigger.Enabled && colors)
            {
                linecolor = Color.FromArgb(0xFF, 0x95, 0x4F);
            }
#if drawextension
            if (l.Extension != StandardLine.ExtensionDirection.None)
            {
                linerider.Tools.Angle angle = Tools.Angle.FromLine(l.Position, l.Position2);
                switch (l.Extension)
                {
                case StandardLine.ExtensionDirection.Left:
                {
                    Turtle turtle = new Turtle(l.CompliantPosition);
                    turtle.Move(angle.Degrees, l.inv ? 4 : -4);
                    if (l.inv)
                    {
                        linep2 = turtle.Point;
                    }
                    else
                    {
                        linep1 = turtle.Point;
                    }
                }
                break;

                case StandardLine.ExtensionDirection.Right:
                {
                    Turtle turtle = new Turtle(l.CompliantPosition2);
                    turtle.Move(angle.Degrees, !l.inv ? 4 : -4);
                    if (l.inv)
                    {
                        linep1 = turtle.Point;
                    }
                    else
                    {
                        linep2 = turtle.Point;
                    }
                }
                break;

                case StandardLine.ExtensionDirection.Both:
                {
                    Turtle turtle = new Turtle(l.CompliantPosition);
                    turtle.Move(angle.Degrees, -2);
                    if (l.inv)
                    {
                        linep2 = turtle.Point;
                    }
                    else
                    {
                        linep1 = turtle.Point;
                    }

                    turtle = new Turtle(l.CompliantPosition2);
                    turtle.Move(angle.Degrees, !l.inv ? 4 : -4);
                    if (l.inv)
                    {
                        linep1 = turtle.Point;
                    }
                    else
                    {
                        linep2 = turtle.Point;
                    }
                }
                break;
                }
            }
#endif
            ret.AddRange(DrawBasicTrackLine((Vector2)linep1, (Vector2)linep2, linecolor));
            return(ret);
        }
示例#4
0
        public static void DrawScarf(DynamicLine[] lines, float opacity)
        {
            GLEnableCap blend = null;

            if (opacity < 1)
            {
                blend = new GLEnableCap(EnableCap.Blend);
                GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);
            }

            GameDrawingMatrix.Enter();
            VAO  scarf = new VAO(false, true);//VAO does not need disposing, it does not allocate a buffer
            bool t     = false;

            for (int i = 0; i < lines.Length; i++)
            {
                Color    c      = Color.FromArgb((byte)(255 * opacity), 209, 1, 1);
                var      alt    = Color.FromArgb((byte)(255 * opacity), 255, 100, 100);
                var      diff   = lines[i].Position2 - lines[i].Position;
                var      dangle = MathHelper.RadiansToDegrees(Math.Atan2(diff.Y, diff.X)) + 90;
                Vector2d q1;
                Vector2d q2;
                Vector2d q3;
                Vector2d q4;
                float    size = 2;
                if (i == 0)
                {
                    var    diff2   = lines[i + 1].Position2 - lines[i + 1].Position;
                    var    dangle2 = MathHelper.RadiansToDegrees(Math.Atan2(diff2.Y, diff2.X)) + 90;
                    Turtle turtle  = new Turtle(lines[i].Position);
                    turtle.Move(dangle2, -(size / 2));
                    q1 = turtle.Point;
                    turtle.Move(0, size);
                    q2           = turtle.Point;
                    turtle.Point = lines[i].Position2;
                    turtle.Move(dangle, size / 2);
                    q3 = turtle.Point;
                    turtle.Move(0, -size);
                    q4 = turtle.Point;
                }
                else
                {
                    var    diff2   = lines[i - 1].Position2 - lines[i - 1].Position;
                    var    dangle2 = MathHelper.RadiansToDegrees(Math.Atan2(diff2.Y, diff2.X)) + 90;
                    Turtle turtle  = new Turtle(lines[i].Position);
                    turtle.Move(dangle2, -(size / 2));
                    q1 = turtle.Point;
                    turtle.Move(0, size);
                    q2           = turtle.Point;
                    turtle.Point = lines[i].Position2;
                    turtle.Move(dangle, size / 2);
                    q3 = turtle.Point;
                    turtle.Move(0, -size);
                    q4 = turtle.Point;
                }
                scarf.AddVertex(new Vertex((Vector2)q1, t ? c : alt));
                scarf.AddVertex(new Vertex((Vector2)q2, t ? c : alt));
                scarf.AddVertex(new Vertex((Vector2)q3, t ? c : alt));
                scarf.AddVertex(new Vertex((Vector2)q4, t ? c : alt));
                t = !t;
            }
            scarf.Draw(PrimitiveType.Quads);
            GameDrawingMatrix.Exit();

            if (blend != null)
            {
                blend.Dispose();
            }
        }