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.
Primitive Types
Page 1 of 19 Replies - 918 Views - Last Post: 10 January 2013 - 01:14 PM
Replies To: Primitive Types
#2
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?
#3
Re: Primitive Types
Posted 10 January 2013 - 08:59 AM
I use the code by this guy
, see here: http://bayinx.wordpr...tebatch-in-xna/, it works, but I can't find a formula to fill the circle

#4
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.
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.
#5
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.
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.
#6
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
, 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.

#7
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:
to be used in your game class like so:
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
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
#8
Re: Primitive Types
Posted 10 January 2013 - 12:26 PM
man, I still really young in programming, this sounds fantastic

#9
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.
#10
Re: Primitive Types
Posted 10 January 2013 - 01:14 PM
You could optimize it using the Bresenham algorithm Wikipedia link
Page 1 of 1