9 Replies - 737 Views - Last Post: 10 January 2013 - 01:14 PM

#1 FelipeBormann  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 19-September 12

Primitive Types

Posted 09 January 2013 - 07:35 PM

Guys , I researched a lot, but I didn't find a good way and most important: that I could understand about how to draw a filled 2d circle, I found a code,and after study a bit I could understand, but they just draw the outRadius of the circle, do you have any article or a place where I could start study about it? I'm really pleasured guys, If I did this in the wrong place, please, advice me, I still learning how the forum works.
Is This A Good Question/Topic? 0
  • +

Replies To: Primitive Types

#2 MrShoes  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 312
  • View blog
  • Posts: 486
  • Joined: 13-June 12

Re: Primitive Types

Posted 10 January 2013 - 01:54 AM

Really you should be rendering images using the SpriteBatch in XNA. What code were you looking at?
Was This Post Helpful? 0
  • +
  • -

#3 FelipeBormann  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 19-September 12

Re: Primitive Types

Posted 10 January 2013 - 08:59 AM

I use the code by this guy :D , see here: http://bayinx.wordpr...tebatch-in-xna/, it works, but I can't find a formula to fill the circle
Was This Post Helpful? 0
  • +
  • -

#4 lordofduct  Icon User is offline

  • I'm a cheeseburger
  • member icon


Reputation: 2506
  • View blog
  • Posts: 4,615
  • Joined: 24-September 10

Re: Primitive Types

Posted 10 January 2013 - 09:12 AM

You're not going to find a formula to fill those circles as those circles are just a bunch of small draws laid out to look like a circle.

Is there a reason you're trying to draw filled shapes? And is there a reason why textures won't do for your task? Because if you look at that code really it's just drawing a small texture to create a pixel and draw lines with that... I think a simple 1 texture drawn once, to the size you need, will be far more efficient.
Was This Post Helpful? 0
  • +
  • -

#5 KidFunkyFried  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 32
  • Joined: 18-July 12

Re: Primitive Types

Posted 10 January 2013 - 09:29 AM

You could draw a filled circle by creating a bitmap, draw the circle into it and use the spritebatch to render it to the game-window. Circles aren't all that tricky to draw, since they're symmetric and can be generated by a simple formula. Or you could use the .Net framework bitmap, create a graphics object onto it and use the built-in functionality - then create a memory-stream or similar and texture it onto whatever or use a spritebatch to draw it. The XNA spritebatch may even be able to draw .Net framework bitmaps - haven't checked.
Or you could draw primitives from triangles; colored or textured.

But I wouldn't recommend using spritebatches to draw single pixels as in the example - it must be terribly inefficient.
Was This Post Helpful? 0
  • +
  • -

#6 FelipeBormann  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 19-September 12

Re: Primitive Types

Posted 10 January 2013 - 09:46 AM

i'm creating a tower defense, I need this to reproduce the radio of my towers and show this to the gamer's, thank you guys :D, KidFunky, I need create a resizable radius, a class that I could modify the way that is drawed, thank you for the help. Do you know the formula KidFunky? I still don't understand it at all.
Was This Post Helpful? 0
  • +
  • -

#7 KidFunkyFried  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 32
  • Joined: 18-July 12

Re: Primitive Types

Posted 10 January 2013 - 11:52 AM

Well it's not exactly rocket science. You can try something along the lines of:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace CircleDraw
{
    class FilledCircle : DrawableGameComponent
    {
        SpriteBatch _sbatch;
        RenderTarget2D _rtarget;

        Vector2 _location;
        int _radius;

        public FilledCircle(Game project, Vector2 location, int radius) : base(project)
        {
            _location = location;
            _radius = radius;
        }

        protected override void LoadContent()
        {
            int dim = _radius * 2 - 1;
            int x_rad, y_rad, _rad_sq, _index;
            Color[] _pixels = new Color[dim * dim];

            _index = 0;
            _rad_sq = _radius * _radius;

            for (int i = 0; i < dim; i++)
            {
                x_rad = (i - _radius) * (i - _radius);

                for (int j = 0; j < dim; j++)
                {
                    y_rad = (j - _radius) * (j - _radius);

                    _pixels[_index++] = (x_rad + y_rad <= _rad_sq) ? Color.Red : Color.Transparent;
                }
            }

            _rtarget = new RenderTarget2D(GraphicsDevice, dim, dim);
            _rtarget.SetData<Color>(_pixels);

            _sbatch = new SpriteBatch(GraphicsDevice);

            base.LoadContent();
        }

        protected override void UnloadContent()
        {
            _rtarget.Dispose();

            base.UnloadContent();
        }

        public override void Draw(GameTime gameTime)
        {
            _sbatch.Begin();
            _sbatch.Draw(_rtarget, _location, Color.White);
            _sbatch.End();

            base.Draw(gameTime);
        }
    }
}


to be used in your game class like so:

        protected override void Initialize()
        {
            FilledCircle mycircle = new FilledCircle(this, new Vector2(100, 100), 100);
            Components.Add(mycircle);

            base.Initialize();
        }


This is mainly for illustration purposes, since for any real application, you'd most likely want to tune the calculations to make for faster generation.

Tom
Was This Post Helpful? 0
  • +
  • -

#8 FelipeBormann  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 19-September 12

Re: Primitive Types

Posted 10 January 2013 - 12:26 PM

man, I still really young in programming, this sounds fantastic :o
Was This Post Helpful? 0
  • +
  • -

#9 FelipeBormann  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 19-September 12

Re: Primitive Types

Posted 10 January 2013 - 12:36 PM

I don't know how to edit my post, sorry, anyways Kid, can you help me find an article where they teach the algorithm? like, step by step, I found one, is great, but freaks me out because they just jump a lot of steps while explaining, and I can't figure out all this together, thank you.
Was This Post Helpful? 0
  • +
  • -

#10 KidFunkyFried  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 32
  • Joined: 18-July 12

Re: Primitive Types

Posted 10 January 2013 - 01:14 PM

You could optimize it using the Bresenham algorithm Wikipedia link
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1