Recently learned computer graphics, wrote a polygon scan conversion algorithm, posted out to share;
MFC is not too clear, mainly using the OnDraw function ...
Please advise ...
void Cpolyfillview::ondraw (cdc* pDC)
{
cpolyfilldoc* PDoc = GetDocument ();
Assert_valid (PDOC);
Todo:add Draw code for native
const int pointnum=6; Polygon points.
/define the structure body for active side table aet and new edge table net/
typedef struct XET
{
float x;
float Dx,ymax;
Xet* Next;
}aet,net;
/definition point Structure body point*/
struct POINT
{
float x;
Float y;
}polypoint[pointnum]={250,50,550,150,550,400,250,250,100,350,100,100};//Polygon Vertices
mypoint[pointnum]={100,100,200,100,200,200,100,200};//Square
/compute the y-coordinate of the highest point (scan to this end) **/
int maxy=0;
int i;
for (i=0;i<pointnum;i++)
if (Polypoint[i].y>maxy)
MAXY=POLYPOINT[I].Y;
/* Initialize AET table/
AET *paet=new AET;
paet->next=null;
/Initialization NET Table * *
NET *pnet[1024];
for (i=0;i<=maxy;i++)
{
Pnet[i]=new NET;
pnet[i]->next=null;
}
/Scan and build net table * *
for (i=0;i<=maxy;i++)
{
for (int j=0;j<pointnum;j++)
if (polypoint[j].y==i)
{
if (polypoint[(j-1+pointnum)%pointnum].y>polypoint[j].y)
{
NET *p=new net;
p->x=polypoint[j].x;
p->ymax=polypoint[(j-1+pointnum)%pointnum].y;
P->dx= (polypoint[(j-1+pointnum)%pointnum].x-polypoint[j].x)/(polypoint[(J-1+pointnum)%POINTNUM].y-polypoint [J].y);
p->next=pnet[i]->next;
pnet[i]->next=p;
}
if (polypoint[(j+1+pointnum)%pointnum].y>polypoint[j].y)
{
NET *p=new net;
p->x=polypoint[j].x;
p->ymax=polypoint[(j+1+pointnum)%pointnum].y;
P->dx= (polypoint[(j+1+pointnum)%pointnum].x-polypoint[j].x)/(polypoint[(J+1+pointnum)%POINTNUM].y-polypoint [J].y);
p->next=pnet[i]->next;
pnet[i]->next=p;
}
}
}
/Establish and update the active side table aet/
for (i=0;i<=maxy;i++)
{
Compute new intersection x, update aet/
NET *p=paet->next;
while (p)
{
P->x=p->x + p->dx;
p=p->next;
}
New AET first sorted after update