2D Circle Grid

Started by
3 comments, last by Fahrenheit451 18 years, 10 months ago
In my current project, an online 2D space sim, players are able to initiate a battle radius around their ship. Anything in this circle enters a turn-based movement and attack mode--all of this has already been implemented. My problem is something more aesthetic, but still important to the combat function of the game; I want the combat area (currently just a lightly alpha-blended circle of variable radius depending on size of initiatiing ship) to have an inner grid whos cell dimensions remain constant no matter what size the whole of the circle is. How would I go about finding the edges of the circle and filling in the grid to match? Thanks, cyric
Advertisement
A way I could think of would be to use a grid texture which you draw multiple times on a quad/sprite with the size of (the circles radius*2)*(the circles radius*2) so you've got the right sized grid and use an lightmap with an circle in it which fits to the borders. This light map is mapped on the quad/sprite not repeated but stretched so you've got an circle area visible and the corners are dark.

I don't know how you're rendering your stuff, but if you are working with texture quads this should be possible, I think actually.

Should just be an idea.


Hope it helps.

cheers,
Marcel
2 ways to get the circle edge.
The first one is to use Bresenham circle alogorithm, that is a quick algo to draw circles. Width that, you can get get all edges with only integers.
The second way use floating operations :

for an angle, x = CenterX+cos(angle) ; y = CenterY+sin(angle)
Maybe it should help you to find edges, and clip your grid in :)

Maybe you want, for a given y, have the x limit ?
Limits are, of course, -x and x.
(of course, add center position to match the correct coordinate)

from the given y, let Y = y/radius.
you know that tan(angle) = Y/radius
then angle = arctan(Y/radius)
after, x = cos(angle)

may it help you ?
Thanks for the suggestions. I will try your second suggestion, Fvirtman, as it seems to make the most sense to me. Will post the results when done.
Gamedev has it's very own article on the Bresenham Circle Algo.

This topic is closed to new replies.

Advertisement