bresenham circle algorithm help?

Started by
3 comments, last by cozman 21 years, 11 months ago
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<    </pre> 

"this one time at computer camp..."    
Advertisement
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 .

hey, that worked real well, who is the author of that book? I think i should look for it, thanks for all your help.
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.

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;		}	}}  

This topic is closed to new replies.

Advertisement