Hello,
This code gives a circle that is nor perfect
It’s sort of squarish. Has anyone got a clue why?
The transition between 1st and 2nd, 3rd and 4th, 5th and 6th, 7th and 8th is disturbed, so the circle’s not smooth…
long Regards
//draws a Circle according to Midpoint Circle Algorithm
void midCircle(float nxc, float nyc , int r)
{
int h = glutGet(GLUT_WINDOW_HEIGHT);
int w = glutGet(GLUT_WINDOW_WIDTH);
int xc = (int)w*nxc ;
int yc = (int)h*nyc ;
int x = 0;
int y = r;
int yr = y ;
int decP = 1 - r ;
/* Plot first set of points */
plotPoints(xc, yc, x, yr) ;
glBegin(GL_POINTS) ;
glColor3f(0, 0, 0) ;
while (x < yr)
{
x++;
if (decP < 0)
decP += 2*x + 1;
else {
y++;
yr-- ;
decP += 2 * (x-y) + 1;
}
plotPoints(xc, yc, x, yr) ;
}
glEnd();
glFlush();
}//midCircle
void plotPoints(int xCenter, int yCenter, int x, int y)
{
glBegin(GL_POINTS) ;
glColor3f(0, 0, 0) ;
glVertex2i(xCenter + x, yCenter + y) ;
glVertex2i(xCenter - x, yCenter + y) ;
glVertex2i(xCenter + x, yCenter - y) ;
glVertex2i(xCenter - x, yCenter - y) ;
glVertex2i(xCenter + y, yCenter + x) ;
glVertex2i(xCenter - y, yCenter + x) ;
glVertex2i(xCenter + y, yCenter - x) ;
glVertex2i(xCenter - y, yCenter - x) ;
glEnd();
glFlush();
}