Skip to main content
GameDev.net gamedev.net
🔒 Locked

Circle to 2D-array

Started by Doggolainen Dec 19, 2011 at 9:03 PM 1 replies 2.1k views
Original Post
Doggolainen
Doggolainen
I want to remove the overlap between a 2D-array containing a circle and another 2D-array containing alpha values of a pictures. (Think an explosion in liero or worms)


But my problem is creating the circle 2D-array from a given radius. I've been looking into the midpoint circle algorithm a little bit, but I cant find any good hits on filled circles.

int[,] CreateCircle(float radius)
{
//return a int matrix where 1 is a pixel part of the circle and 0 is outside the circle
}
luca-deltodesco
luca-deltodesco
Why can you not use the midpoint circle algorithm?

http://en.wikipedia....ircle_algorithm

taking the first source example, you get in each iteration:


setPixel(x0 + x, y0 + y);
setPixel(x0 - x, y0 + y);
setPixel(x0 + x, y0 - y);
setPixel(x0 - x, y0 - y);
setPixel(x0 + y, y0 + x);
setPixel(x0 - y, y0 + x);
setPixel(x0 + y, y0 - x);
setPixel(x0 - y, y0 - x);


just replace with:


for(ix = x0-x; ix<=x0+x; ix++) {
setPixel(ix, y0 + y);
setPixel(ix, y0 - y);
}
for(ix = x0-y; ix<=x0+y; ix++) {
setPixel(ix, y0 + x);
setPixel(ix, y0 - x);
}


and you can do the same with the improved version
LorenzoGatti
LorenzoGatti
Shouldn't you use a sprite (possibly the alpha channel of the explosion image: opaque=destroyed, transparent=untouched, partly transparent=use a threshold to decide) instead of calculating circles over and over again at runtime? Sprites allow you to use any explosion shape, not only discs, and build complex explosions by compositing multiple particles.
Omae Wa Mou Shindeiru

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.