Ejemplo n.º 1
0
        public override void DrawArcRing(Vec2 center, float radius, float innerRadius, float startAngle, float endAngle, Col color)
        {
            var ct = Aspect.Adjust(center);
            var r  = Aspect.Adjust(radius);
            var ri = Aspect.Adjust(innerRadius);

            if (endAngle < startAngle)
            {
                var c = startAngle;
                startAngle = endAngle;
                endAngle   = startAngle;
            }

            if (ri < float.Epsilon)
            {
                DrawArc(center, radius, startAngle, endAngle, color);
                return;
            }

            // Make sure that inner radius is smaller than the main radius
            if (ri > r)
            {
                ri = r - (ri - r);
            }

            SetPass(0);
            GLBegin(GL.TRIANGLES);
            GLColor(color);

            startAngle *= DEG2RAD;
            float angle = startAngle;

            endAngle = endAngle * DEG2RAD;

            float incr = (endAngle - angle) / (float)CircleResolution;

            while (angle < endAngle)
            {
                float s  = (float)System.Math.Sin(Utils.Clamp(angle, startAngle, endAngle));
                float c  = (float)System.Math.Cos(Utils.Clamp(angle, startAngle, endAngle));
                float si = (float)System.Math.Sin(Utils.Clamp(angle + incr, startAngle, endAngle));
                float ci = (float)System.Math.Cos(Utils.Clamp(angle + incr, startAngle, endAngle));

                Vertex3(ct.x + s * r, ct.y + c * r);
                Vertex3(ct.x + si * r, ct.y + ci * r);
                Vertex3(ct.x + s * ri, ct.y + c * ri);

                Vertex3(ct.x + s * ri, ct.y + c * ri);
                Vertex3(ct.x + si * r, ct.y + ci * r);
                Vertex3(ct.x + si * ri, ct.y + ci * ri);

                angle += incr;
            }
            GLEnd();
        }
Ejemplo n.º 2
0
        public override void DrawCircle(Vec2 center, float radius, Col color)
        {
            center = Aspect.Adjust(center);
            radius = Aspect.Adjust(radius);

            SetPass(0);
            GLBegin(GL.TRIANGLES);
            GLColor(color);
            DrawCircleCommands(center, radius, color);
            GLEnd();
        }
Ejemplo n.º 3
0
 public override void DrawTriangle(Vec2 a, Vec2 b, Vec2 c, Col color)
 {
     a = Aspect.Adjust(a);
     b = Aspect.Adjust(b);
     c = Aspect.Adjust(c);
     SetPass(0);
     // Draw lines
     GLBegin(GL.TRIANGLES);
     GLColor(color);
     Vertex3(a.x, a.y);
     Vertex3(b.x, b.y);
     Vertex3(c.x, c.y);
     GLEnd();
 }
Ejemplo n.º 4
0
        public override void DrawLine(Vec2 p0, Vec2 p1, float width, Col color, bool isRounded)
        {
            p0    = Aspect.Adjust(p0);
            p1    = Aspect.Adjust(p1);
            width = Aspect.Adjust(width);

            var dir = p1 - p0;

            dir.Normalize();
            var perpendicular = Vec2.Perpendicular(dir);

            perpendicular.Normalize();

            float halfWidth = width * 0.5f;
            var   start0    = p0 + perpendicular * halfWidth;
            var   start1    = p0 - perpendicular * halfWidth;

            var end0 = p1 + perpendicular * halfWidth;
            var end1 = p1 - perpendicular * halfWidth;

            // draw circles
            var res = CircleResolution;

            CircleResolution = 8;
            CircleResolution = res;

            SetPass(0);
            GLBegin(GL.TRIANGLES);
            GLColor(color);

            if (isRounded)
            {
                DrawCircleCommands(p0, halfWidth, color);
                DrawCircleCommands(p1, halfWidth, color);
            }

            Vertex3(start0.x, start0.y);
            Vertex3(end0.x, end0.y);
            Vertex3(end1.x, end1.y);

            Vertex3(start0.x, start0.y);
            Vertex3(end1.x, end1.y);
            Vertex3(start1.x, start1.y);

            GLEnd();
        }
Ejemplo n.º 5
0
        public override void DrawArc(Vec2 center, float radius, float startAngle, float endAngle, Col color)
        {
            if (endAngle < startAngle)
            {
                var c = startAngle;
                startAngle = endAngle;
                endAngle   = startAngle;
            }

            center = Aspect.Adjust(center);
            radius = Aspect.Adjust(radius);

            startAngle *= DEG2RAD;
            float angle = DEG2RAD;

            endAngle = endAngle * DEG2RAD;
            float incr = (endAngle - angle) / (float)CircleResolution;

            SetPass(0);
            GLBegin(GL.TRIANGLES);
            GLColor(color);

            while (angle < endAngle)
            {
                Vertex3(center.x, center.y);
                Vertex3(
                    center.x + (float)System.Math.Sin(Utils.Clamp(angle, startAngle, endAngle)) * radius,
                    center.y + (float)System.Math.Cos(Utils.Clamp(angle, startAngle, endAngle)) * radius);
                Vertex3(
                    center.x + (float)System.Math.Sin(Utils.Clamp(angle + incr, startAngle, endAngle)) * radius,
                    center.y + (float)System.Math.Cos(Utils.Clamp(angle + incr, startAngle, endAngle)) * radius);
                angle += incr;
            }

            GLEnd();
        }