Archived

This topic is now archived and is closed to further replies.

bresenham circle algorithm help?

Recommended Posts

can anyone point me in the right direction here (i''m trying to write a primitives library, i based this code on the code found in this article http://www.gamedev.net/reference/articles/article767.asp but for some reason i draw a + rather than any sort of circle.. does anyone know what i did wrong?
	int d,mx,my;

d = 3 - (2<
"this one time at computer camp..."


Share on other sites
This is the algorithm my ''graphics algorithm book'' has for circles (editted somewhat so that I can type it quicker). It isn''t exactly like yours, but it has the same basic idea, so you can probably compare them.

  void circlePlotPoints(int xC, int yC, int x, iny y) {  setPixel(xC + x, yC + y);  setPixel(xC - x, yC + y);  setPixel(xC + x, yC - y);  setPixel(xC - x, yC - y);  setPixel(xC + y, yC + x);  setPixel(xC - y, yC + x);   setPixel(xC + y, yC - x);  setPixel(xC - y, yC - x);}void circleMidPoint(int xC, int yC, int Rad) {  int x = 0;  int y = Rad;  int p = 1 - Rad;  circlePlotPoints(xC,yC,x,y);  while(x < y) {    ++x;    if(p < 0)      p += 2 * x + 1;    else {      --y;      p += 2 * (x-y) + 1;    }    circlePlotPoints(xC,xY,x,y);  }}

Let''s hope I didn''t typo .

Share on other sites
hey, that worked real well, who is the author of that book? I think i should look for it, thanks for all your help.

Share on other sites
quote:
Original post by cozman
hey, that worked real well, who is the author of that book? I think i should look for it, thanks for all your help.

It''s Computer Graphics: C Version by Donald Hearn and M. Pauline Baker. I don''t know if there are non-hardback versions of it, so it''s somewhat expensive (\$60 US). It''s basically an equation reference with occasional code for simple things (mostly 2D). It''s lacking a lot of modern 3D stuff, unless you want to make a software renderer.

Share on other sites
here is my algorithm now

  void DrawCircle(SDL_Surface *surface, Uint32 x, Uint32 y, Uint32 radius, Uint32 color){	int p,mx,my;	p = 1 - radius;	mx = 0;	my = radius;	while(mx <= my)	{		DrawPixel(surface,x+mx,y+my,color);		DrawPixel(surface,x+mx,y-my,color);		DrawPixel(surface,x-mx,y+my,color);		DrawPixel(surface,x-mx,y-my,color);		DrawPixel(surface,x+my,y+mx,color);		DrawPixel(surface,x+my,y-mx,color);		DrawPixel(surface,x-my,y+mx,color);		DrawPixel(surface,x-my,y-mx,color);		mx++;		if(p < 0)			p += 2*mx +1;		else 		{			my--;			p += 2*(mx-my) +1;		}	}}

• Forum Statistics

• Total Topics
628394
• Total Posts
2982428

• 10
• 9
• 19
• 24
• 9