I was reviewing the circle algorithm (lesson 11) and I was wondering, why do we bother adding in...
Code: Select all
int x0 = 0.7071068f * rad + 0.5f;
Here's the code:
Code: Select all
void D3DGraphics::DrawCircle( int cx,int cy,int rad,int r,int g,int b )
{
float radSqr = rad * rad;
//int x0 = 0.7071068f * rad + 0.5f; //cos(45deg)=0.7071068
for( int x = 0; x <= rad; x++ )
{
int y = sqrt( radSqr - x * x ) + 0.5f;
PutPixel( cx + x,cy + y,r,g,b ); //quadrant 1
PutPixel( cx + y,cy + x,r,g,b ); //quadrant 1
PutPixel( cx - x,cy + y,r,g,b ); //quadrant 2
PutPixel( cx - y,cy + x,r,g,b ); //quadrant 2
PutPixel( cx - x,cy - y,r,g,b ); //quadrant 3
PutPixel( cx - y,cy - x,r,g,b ); //quadrant 3
PutPixel( cx + x,cy - y,r,g,b ); //quadrant 4
PutPixel( cx + y,cy - x,r,g,b ); //quadrant 4
}
}