Пример #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
        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 Load()
        {
            this.LineWidth = 1;
            this.pDevice   = GLEx.device;
            this.pCamera   = GLEx.cemera;

            effect = new BasicEffect(pDevice);
            effect.VertexColorEnabled = true;

            xnaLine    = new XNALine();
            xnaRect    = new XNARectangle(pDevice);
            xnaPolygon = new XNAPolygon(pDevice);

            maxPrimitiveCount = pDevice.GraphicsProfile == GraphicsProfile.Reach ? 65535 : 1048575;

            vertsPos = new VertexPositionColor[maxPrimitiveCount];

            effect.Projection = Microsoft.Xna.Framework.Matrix.CreateOrthographicOffCenter(0f, LSystem.screenRect.width, LSystem.screenRect.height, 0f, -1.0f, 1.0f);
        }
Пример #4
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++;
        }
Пример #5
0
        public void Load()
        {
            this.LineWidth = 1;
            this.pDevice = GLEx.device;
            this.pCamera = GLEx.cemera;

            effect = new BasicEffect(pDevice);
            effect.VertexColorEnabled = true;

            xnaLine = new XNALine();
            xnaRect = new XNARectangle(pDevice);
            xnaPolygon = new XNAPolygon(pDevice);

            maxPrimitiveCount = pDevice.GraphicsProfile == GraphicsProfile.Reach ? 65535 : 1048575;

            vertsPos = new VertexPositionColor[maxPrimitiveCount];

            effect.Projection = Microsoft.Xna.Framework.Matrix.CreateOrthographicOffCenter(0f, LSystem.screenRect.width, LSystem.screenRect.height, 0f, -1.0f, 1.0f);
        }
Пример #6
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();
        }
Пример #7
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;
 }