Jump to content
  • Advertisement
Sign in to follow this  
cyric74

2D Circle Grid

This topic is 4870 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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 ?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!