예제 #1
0
        public void DrawOval(float x1, float y1, float width, float height,
                             int segments, float start, float end, Color c)
        {
            while (end < start)
            {
                end += 360;
            }
            float cx   = x1 + (width / 2.0f);
            float cy   = y1 + (height / 2.0f);
            int   step = 360 / segments;

            int hashCode = 1;

            hashCode = LSystem.Unite(hashCode, x1);
            hashCode = LSystem.Unite(hashCode, y1);
            hashCode = LSystem.Unite(hashCode, width);
            hashCode = LSystem.Unite(hashCode, height);
            hashCode = LSystem.Unite(hashCode, segments);
            hashCode = LSystem.Unite(hashCode, start);
            hashCode = LSystem.Unite(hashCode, end);
            hashCode = LSystem.Unite(hashCode, c.PackedValue);
            XNAPolygon poly = (XNAPolygon)CollectionUtils.Get(polyLazy, hashCode);

            if (poly == null)
            {
                poly             = new XNAPolygon(GLEx.device);
                poly.Stroke      = c;
                poly.StrokeWidth = 1;
                for (float a = start; a < (end + step); a += step)
                {
                    float ang = a;
                    if (ang > end)
                    {
                        ang = end;
                    }
                    float x = (cx + (MathUtils.Cos(MathUtils.ToRadians(ang)) * width / 2.0f));
                    float y = (cy + (MathUtils.Sin(MathUtils.ToRadians(ang)) * height / 2.0f));
                    poly.AddPoint(new Vector2(x, y));
                }
                CollectionUtils.Put(polyLazy, hashCode, poly);
            }
            if (batch == null)
            {
                batch = new SpriteBatch(GLEx.device);
            }
            batch.Begin(SpriteSortMode.Deferred, c.A == 255 ? BlendState.AlphaBlend : BlendState.Additive, null, null, GLEx.Device.RasterizerState, null, GLEx.cemera.viewMatrix);
            poly.Draw(batch);
            batch.End();
        }
예제 #2
0
파일: XNA_Shape.cs 프로젝트: vb0067/LGame
        public XNAPolygon ToPolygon()
        {
            XNAPolygon polygon = new XNAPolygon(pdevice)
            {
                StrokeWidth = StrokeWidth,
                Stroke      = Stroke
            };

            foreach (var line in lines)
            {
                foreach (var point in line.Points)
                {
                    polygon.AddPoint(point);
                }
            }
            return(polygon);
        }
예제 #3
0
        public void DrawArc(float x1, float y1, float width, float height,
             int segments, float start, float end)
        {
            while (end < start)
            {
                end += 360;
            }
            float cx = x1 + (width / 2.0f);
            float cy = y1 + (height / 2.0f);
            int step = 360 / segments;

            int hashCode = 1;

            hashCode = LSystem.Unite(hashCode, x1);
            hashCode = LSystem.Unite(hashCode, y1);
            hashCode = LSystem.Unite(hashCode, width);
            hashCode = LSystem.Unite(hashCode, height);
            hashCode = LSystem.Unite(hashCode, segments);
            hashCode = LSystem.Unite(hashCode, start);
            hashCode = LSystem.Unite(hashCode, end);
            hashCode = LSystem.Unite(hashCode, color.PackedValue);
            SubmitDraw();
            XNAPolygon poly = (XNAPolygon)CollectionUtils.Get(polyLazy, hashCode);
            if (poly == null)
            {
                poly = new XNAPolygon(GLEx.device);
                poly.Stroke = color;
                poly.StrokeWidth = 1;
                for (float a = start; a < (end + step); a += step)
                {
                    float ang = a;
                    if (ang > end)
                    {
                        ang = end;
                    }
                    float x = (cx + (MathUtils.Cos(MathUtils.ToRadians(ang)) * width / 2.0f));
                    float y = (cy + (MathUtils.Sin(MathUtils.ToRadians(ang)) * height / 2.0f));
                    poly.AddPoint(new Vector2(x, y));
                }
                CollectionUtils.Put(polyLazy, hashCode, poly);
            }
            poly.Draw(batch);
            idx++;
        }
예제 #4
0
        public void DrawOval(float x1, float y1, float width, float height,
             int segments, float start, float end, Color c)
        {
            while (end < start)
            {
                end += 360;
            }
            float cx = x1 + (width / 2.0f);
            float cy = y1 + (height / 2.0f);
            int step = 360 / segments;

            int hashCode = 1;

            hashCode = LSystem.Unite(hashCode, x1);
            hashCode = LSystem.Unite(hashCode, y1);
            hashCode = LSystem.Unite(hashCode, width);
            hashCode = LSystem.Unite(hashCode, height);
            hashCode = LSystem.Unite(hashCode, segments);
            hashCode = LSystem.Unite(hashCode, start);
            hashCode = LSystem.Unite(hashCode, end);
            hashCode = LSystem.Unite(hashCode, c.PackedValue);
            XNAPolygon poly = (XNAPolygon)CollectionUtils.Get(polyLazy, hashCode);
            if (poly == null)
            {
                poly = new XNAPolygon(GLEx.device);
                poly.Stroke = c;
                poly.StrokeWidth = 1;
                for (float a = start; a < (end + step); a += step)
                {
                    float ang = a;
                    if (ang > end)
                    {
                        ang = end;
                    }
                    float x = (cx + (MathUtils.Cos(MathUtils.ToRadians(ang)) * width / 2.0f));
                    float y = (cy + (MathUtils.Sin(MathUtils.ToRadians(ang)) * height / 2.0f));
                    poly.AddPoint(new Vector2(x, y));
                }
                CollectionUtils.Put(polyLazy, hashCode, poly);
            }
            if (batch == null)
            {
                batch = new SpriteBatch(GLEx.device);
            }
            batch.Begin(SpriteSortMode.Deferred, c.A == 255 ? BlendState.AlphaBlend : BlendState.Additive, null, null, GLEx.Device.RasterizerState, null, GLEx.cemera.viewMatrix);
            poly.Draw(batch);
            batch.End();
        }
예제 #5
0
 public XNAPolygon ToPolygon()
 {
     XNAPolygon polygon = new XNAPolygon(pdevice)
     {
         StrokeWidth = StrokeWidth,
         Stroke = Stroke
     };
     foreach (var line in lines)
     {
         foreach (var point in line.Points)
         {
             polygon.AddPoint(point);
         }
     }
     return polygon;
 }
예제 #6
0
        public void Draw(Shape shape, Color c)
        {
            if (shape == null)
            {
                return;
            }
            if (glType == GL.GL_LINE_STRIP || shape is Path)
            {
                xnaPolygon.ClearPoints();
                float[] points = shape.GetPoints();
                if (points == null)
                {
                    return;
                }
                if (points.Length == 0)
                {
                    return;
                }
                float x = points[0];
                float y = points[1];
                if (batch == null)
                {
                    batch = new SpriteBatch(GLEx.Device);
                }
                batch.Begin(SpriteSortMode.Deferred, c.A == 255 ? BlendState.AlphaBlend : BlendState.Additive, null, null, GLEx.Device.RasterizerState, null, GLEx.cemera.viewMatrix);
                for (int i = 0; i < points.Length; i += 2)
                {
                    DrawLine(batch, new Vector2(x, y), new Vector2(points[i], points[i + 1]), GLEx.WhitePixel, c);
                    x = points[i];
                    y = points[i + 1];
                }
                batch.End();
            }
            else
            {
                if (LineWidth == 0)
                {
                    float[] points = shape.GetPoints();
                    if (points.Length == 0)
                    {
                        return;
                    }
                    GLBegin(GL_LINES);
                    for (int i = 0; i < points.Length; i += 2)
                    {
                        GLVertex2f(points[i], points[i + 1]);
                    }
                    if (shape.Closed())
                    {
                        GLVertex2f(points[0], points[1]);
                    }
                    GLEnd(c);
                }
                else
                {
                    xnaPolygon.ClearPoints();
                    float[] points = shape.GetPoints();
                    if (points == null)
                    {
                        return;
                    }
                    if (points.Length == 0)
                    {
                        return;
                    }

                    for (int i = 0; i < points.Length; i += 2)
                    {
                        xnaPolygon.AddPoint(new Vector2(points[i], points[i + 1]));
                    }
                    if (shape.Closed())
                    {
                        xnaPolygon.AddPoint(new Vector2(points[0], points[1]));
                    }
                    xnaPolygon.Stroke      = c;
                    xnaPolygon.StrokeWidth = LineWidth;
                    if (batch == null)
                    {
                        batch = new SpriteBatch(GLEx.Device);
                    }
                    batch.Begin(SpriteSortMode.Deferred, c.A == 255 ? BlendState.AlphaBlend : BlendState.Additive, null, null, GLEx.Device.RasterizerState, null, GLEx.cemera.viewMatrix);
                    xnaPolygon.Draw(batch);
                    batch.End();
                }
            }
        }