文章源自略懂百科-http://wswcn.cn/113025.html
数据结构:
CPoint3D: 3维点类CPolygon: 多边形类CEdge: 边类CActiveEdge: 活化边类文章源自略懂百科-http://wswcn.cn/113025.html
CScanLineZbufferProcess: 扫描线ZBuffer算法实现类,包括3ds文件加载,旋转,扫描过程,显示等。文章源自略懂百科-http://wswcn.cn/113025.html
CPoint3D
classCPoint3D{public:
CPoint3D(void);
CPoint3D(doublea,doubleb,doublec);
~CPoint3D(void);文章源自略懂百科-http://wswcn.cn/113025.html
CPoint3D(CPoint3D&rth);
CPoint3D&operator=(CPoint3D&rth);CPointGetPoint2D();public:doublex;doubley;doublez;文章源自略懂百科-http://wswcn.cn/113025.html
};文章源自略懂百科-http://wswcn.cn/113025.html
CPoint3D::CPoint3D(void)
{
x=y=z=0;
}
CPoint3D::CPoint3D(doublea,doubleb,doublec)
{
x=a;y=b;z=c;
}
CPoint3D::CPoint3D(CPoint3D&rth)
{
x=rth.x;
y=rth.y;
z=rth.z;
}文章源自略懂百科-http://wswcn.cn/113025.html
CPoint3D& CPoint3D::operator=(CPoint3D&rth)
{
x=rth.x;
y=rth.y;
z=rth.z;return*this;
}文章源自略懂百科-http://wswcn.cn/113025.html
CPoint CPoint3D::GetPoint2D()
{CPointp(x,y);returnp;
}文章源自略懂百科-http://wswcn.cn/113025.html
CPoint3D::~CPoint3D(void)
{
}文章源自略懂百科-http://wswcn.cn/113025.html
CEdge 类
classCEdge{public:CEdge(void);CEdge(CEdge&rth);~CEdge(void);public:CEdge&operator=(CEdge &rth);voidPoints2Edge(CPoint3D p1, CPoint3D p2);public:doublex;//边的上端点x的坐标doubledx;//相邻两条扫描线交点的x坐标差dx (-1/k)intdy;//边跨越的扫描线数目intid;//边所属多边形的编号intyMax;//CEdge*next;};CEdge::CEdge(void){x=0;dx=0;dy=0;id=-1;next=NULL;yMax=-100000;}CEdge::CEdge(CEdge &rth){x=rth.x;dx=rth.dx;dy=rth.dy;id=rth.id;next=rth.next;yMax=rth.yMax;}CEdge&CEdge::operator=(CEdge &rth){x=rth.x;dx=rth.dx;dy=rth.dy;id=rth.id;next=rth.next;yMax=rth.yMax;return*this;}CEdge::~CEdge(void){if(next)deletenext;}voidCEdge::Points2Edge(CPoint3D p1, CPoint3D p2){/*CPoint3DtopPoint = p1;yMax=p1.y;dy=abs(p1.y-p2.y);*/dy=abs(p1.y-p2.y);if(p1.y>p2.y){//p1是TOPpointyMax=p1.y;x=p1.x;if(dy!=0){dx=(p2.x-p1.x)/(p1.y-p2.y);}}else{//p2是TOPpointyMax=p2.y;x=p2.x;if(dy!=0){dx=(p1.x-p2.x)/(p2.y-p1.y);}}dy+=1;}文章源自略懂百科-http://wswcn.cn/113025.html
CEdgeList
classCEdgeList{public:
CEdgeList(void);
~CEdgeList(void);public:intymax;
CEdge *head;
};
CEdgeList::CEdgeList(void)
{
ymax =-1;
head=NULL;
}文章源自略懂百科-http://wswcn.cn/113025.html
CEdgeList::~CEdgeList(void)
{
}文章源自略懂百科-http://wswcn.cn/113025.html
CActiveEdge
classCActiveEdge{
public:CActiveEdge(void);
~CActiveEdge(void);
public:doublexl;//左交点的x坐标doubledxl;//(左交点边上)两相邻扫描线交点的x坐标之差intdyl;//以和左交点所在边相交的扫描线数为初值,doublexr;//右交点的x坐标doubledxr;//(右交点边上)两相邻扫描线交点的x坐标之差intdyr;//以和右交点所在边相交的扫描线数为初值,doublezl;//左交点处多边形所在平面的深度值;doubledzx;//沿扫描线向右走过一个像素时,多边形所在平面的深度增量。对于平面方程,dzx=-a/c(c≠0);doubledzy;//沿y方向向下移过一根扫描线时,多边形所在平面的深度增量。对于平面方程,dzy=b/c(c≠0);intid;//交点对所在的多边形的编号;CActiveEdge*next;文章源自略懂百科-http://wswcn.cn/113025.html
};CActiveEdge::CActiveEdge(void)
{
dxl =0;
dxr=0;
dyl=0;
dyr=0;
dzx=0;
dzy=0;
xl=0;
xr=0;
zl=0;文章源自略懂百科-http://wswcn.cn/113025.html
next =NULL;id=-1;
}CActiveEdge::~CActiveEdge(void)
{
}文章源自略懂百科-http://wswcn.cn/113025.html
CPolygon
//这里的多边形都是三角形,方便计算classCPolygon{public:
CPolygon(void);
CPolygon(CPolygon &rth);voidPoint2Face(CPoint3D p1, CPoint3D p2, CPoint3D p3);voidPoint2Face(CPoint3D *p,intnpoints);voidget_dy();CEdge*getEdgeList();//获取边表voidClearHorizontalEdge();//清除水平边.平行X的边~CPolygon(void);public:
CPolygon&operator=(CPolygon &rth);public:doublea,b,c,d;//多边形所在平面的方程系数ax+by+cz+d=0intid;//多边形的编号intdy;//多边形跨越的扫描线数目COLORREF color;//多边形的颜色intyMax;intnPoints;//点数CPolygon *next;文章源自略懂百科-http://wswcn.cn/113025.html
CPoint3D *point;//按顺序的点,要求前三个不能是共线的点};include"StdAfx.h"include"Polygon.h"CPolygon::CPolygon(void)
{
a =0;
b =0;
c =0;
d =0;文章源自略懂百科-http://wswcn.cn/113025.html
id =-1;
dy =0;文章源自略懂百科-http://wswcn.cn/113025.html
color = RGB(255,255,255);//默认底色为白next =NULL;文章源自略懂百科-http://wswcn.cn/113025.html
nPoints =0;
yMax =-100000;
}
CPolygon::CPolygon(CPolygon &rth)
{
a = rth.a;
b = rth.b;
c = rth.c;
d = rth.d;文章源自略懂百科-http://wswcn.cn/113025.html
id = rth.id;
dy = rth.dy;
color = rth.color;文章源自略懂百科-http://wswcn.cn/113025.html
next = rth.next;文章源自略懂百科-http://wswcn.cn/113025.html
}
CPolygon& CPolygon::operator=(CPolygon &rth)
{
a =rth.a;
b =rth.b;
c =rth.c;
d = rth.d;文章源自略懂百科-http://wswcn.cn/113025.html
id = rth.id;
dy = rth.dy;
color = rth.color;文章源自略懂百科-http://wswcn.cn/113025.html
point = rth.point;
nPoints = rth.nPoints;文章源自略懂百科-http://wswcn.cn/113025.html
next = rth.next;return*this;
}//三点不共线下求平面方程参数voidCPolygon::Point2Face(CPoint3D p1, CPoint3D p2, CPoint3D p3)
{doublex1 = p1.x, y1 = p1.y, z1 = p1.z;doublex2 = p2.x, y2 = p2.y, z2 = p2.z;doublex3 = p3.x, y3 = p3.y, z3 = p3.z;文章源自略懂百科-http://wswcn.cn/113025.html
a = (y2-y1)*(z3-z1)-(y3-y1)*(z2-z1);
b = (x3-x1)*(z2-z1)-(x2-x1)*(z3-z1);
c = (x2-x1)*(y3-y1)-(x3-x1)*(y2-y1);文章源自略懂百科-http://wswcn.cn/113025.html
d = -(a*x1+b*y1+c*z1);文章源自略懂百科-http://wswcn.cn/113025.html
}//voidCPolygon::Point2Face(CPoint3D *p,intnpoints)
{
point = p;
nPoints = npoints;文章源自略懂百科-http://wswcn.cn/113025.html
Point2Face(p[0],p[1],p[2]); }文章源自略懂百科-http://wswcn.cn/113025.html
dy = yMax - yMin +1; pOld = pt; }returnpHead;文章源自略懂百科-http://wswcn.cn/113025.html
}voidCPolygon::ClearHorizontalEdge() CPolygon::~CPolygon(void) CPolygonList文章源自略懂百科-http://wswcn.cn/113025.html
pragmaonceinclude" polygon.h"classcpolygonlist{public:="" cpolygonlist(void);="" ~cpolygonlist(void);public:intymax;="" 多边形的最大y坐标cpolygon="" *head;="" };="" cpolygonlist::cpolygonlist(void)="" ymax="-1;" head="NULL;" }="" cpolygonlist::~cpolygonlist(void)="" } bInit =false;文章源自略懂百科-http://wswcn.cn/113025.html
m_bYZ =false;//false:Y轴在上,Z轴为深度 true:Z轴在上,Y轴为深度angle_x =0.0; m_EdgeShow =false;文章源自略懂百科-http://wswcn.cn/113025.html
}文章源自略懂百科-http://wswcn.cn/113025.html
CScanLineZbufferProcess::~CScanLineZbufferProcess(void) PolygonList[y+nHeight/2].head =NULL;文章源自略懂百科-http://wswcn.cn/113025.html
CEdge* tpEdge = EdgeList[y+nHeight/2].head;//删除边表if(tpEdge) EdgeList[y+nHeight/2].head =NULL;文章源自略懂百科-http://wswcn.cn/113025.html
}catch(...) face->id = ++faceid; face->get_dy();if(face->c!=0) }//将边按照yMax存入相应的边表void CScanLineZbufferProcess::SortEdge(CEdge* pEdge) tpEdge = tOldpEdge;文章源自略懂百科-http://wswcn.cn/113025.html
}while(tpEdge); tPolygon = tPolygon->next; CPolygon *oldPolygon = PolygonList[y+nHeight/2].head;//y是当前的扫描线y值while(oldPolygon) *tnewPolygon = *oldPolygon;if(ActivePolygonList->head==NULL) tPolygon = tnewPolygon; oldPolygon = oldPolygon->next; CPolygon *tOldPolygon = tPolygon;while(tPolygon) tPolygon->dy -=1;//每一个多边形的dy:dy = dy-1if(tPolygon->dy<=0) //当dy <=0时,该多边形要从多边形活化表中删除{if(ActivePolygonList->head==tPolygon) tPolygon = tPolygon->next; CPolygon* tPolygon = PolygonList[y+nHeight/2].head;while(tPolygon) CEdge* tpEdge = EdgeList[y+nHeight/2].head;//这里的多边形都是三角形,方便计算CActiveEdge* tActiveEdge =newCActiveEdge();while(tpEdge) tActiveEdge->dxl = tpEdge->dx; tActiveEdge->dzx = -(tPolygon->a / tPolygon->c); i++;文章源自略懂百科-http://wswcn.cn/113025.html
}else{if((tActiveEdge->xl + tActiveEdge->dxl) > (tpEdge->x+tpEdge->dx)) tActiveEdge->dxl = tpEdge->dx; tpEdge = tpEdge->next; tPolygon = tPolygon->next;文章源自略懂百科-http://wswcn.cn/113025.html
}returntrue; CActiveEdge *tOldActiveEdgeList = tActiveEdgeList;while(tActiveEdgeList&&tActiveEdgeList->id!=-1) tActiveEdgeList->xl +=tActiveEdgeList->dxl; tActiveEdgeList->xr +=tActiveEdgeList->dxr;//边和下一条扫描线交点的x值tActiveEdgeList->zl += tActiveEdgeList->dzx * tActiveEdgeList->dxl + tActiveEdgeList->dzy;//若dyl或dyr小于0,相应的边就要从一个边对if(tActiveEdgeList->dyl<=0||tActiveEdgeList->dyr<=0) {if(IsInActivePolygonList(tActiveEdgeList->id)) }else{//更新右边tActiveEdgeList->dxr = tpEdge->dx; }文章源自略懂百科-http://wswcn.cn/113025.html
tpEdge = tpEdge->next; }else{//删除该边对if(tActiveEdgeList == ActiveEdgeList) tOldActiveEdgeList = ActiveEdgeList;文章源自略懂百科-http://wswcn.cn/113025.html
}else{ } tActiveEdgeList = tActiveEdgeList->next;//下一个边对}文章源自略懂百科-http://wswcn.cn/113025.html
}//获取多边形颜色值COLORREF CScanLineZbufferProcess::GetPolygonColor(int id) }//step2 增量式的深度更新void CScanLineZbufferProcess::UpdateZBufferColor(int y) int index = (nHeight/2-y)*nWidth + nWidth/2+x;if(Zx > ZBuffer[index]) FrameBuffer[index] = GetPolygonColor(tActiveEdgeList->id);//更新颜色}文章源自略懂百科-http://wswcn.cn/113025.html
}文章源自略懂百科-http://wswcn.cn/113025.html
Zx += tActiveEdgeList->dzx;文章源自略懂百科-http://wswcn.cn/113025.html
}文章源自略懂百科-http://wswcn.cn/113025.html
tActiveEdgeList = tActiveEdgeList->next;//下一个边对} 0人点赞文章源自略懂百科-http://wswcn.cn/113025.html
图形学文章源自略懂百科-http://wswcn.cn/113025.html
文章源自略懂百科-http://wswcn.cn/113025.html
}//求出dyvoidCPolygon::get_dy()
{
CPoint3D *p = point;intyMin =100000;for(inti=0;i
yMax = tp->y;if(yMin>tp->y)
yMin = tp->y;文章源自略懂百科-http://wswcn.cn/113025.html
}//获取边表CEdge* CPolygon::getEdgeList()
{
CEdge* pHead =NULL;// = new CEdge();/*pHead->Points2Edge(point[0], point[1]);
pHead->id = id;*/CEdge* pOld =NULL;// = pHead;for(inti=0;i
pt->id = id;
pt->next =NULL;if(pHead==NULL)
{
pHead = pt;文章源自略懂百科-http://wswcn.cn/113025.html
}else{
pOld->next = pt;
pOld = pt;
}文章源自略懂百科-http://wswcn.cn/113025.html
{
}文章源自略懂百科-http://wswcn.cn/113025.html
{if(next)deletenext;
}文章源自略懂百科-http://wswcn.cn/113025.html
CScanLineZbufferProcessclassCScanLineZbufferProcess{public:
CScanLineZbufferProcess(void);
~CScanLineZbufferProcess(void);public:intnWidth,nHeight;//显示屏幕的尺寸CPaintDC *pDC;
CPolygonList *PolygonList;//分类的多边形表CEdgeList *EdgeList;//分类边表CPolygonList *ActivePolygonList;//活化分类的多边形表CActiveEdge *ActiveEdgeList;//活化分类边表COLORREF *FrameBuffer;//帧缓冲器double*ZBuffer;//z缓冲器COLORREF BackGroundColor;//背景色doubleminZ;//最小z值public:voidInitBuffer(intwidth,intheight,CPaintDC *pdc);//void InitPolygonListEdgeList();voidSortEdge(CEdge* pEdge);boolAddActivePolygonList(inty);//添加新多边形进活化多边形表voidUpdateActivePolygonList();//更新多边形进活化多边形表boolAddActiveEdgeList(inty);//添加新边堆到活化边表voidUpdateActiveEdgeList(inty);//更新新边对中的一边,由于一边结束,而多边形还在扫描区域,删除一条边,加入新边boolIsInActivePolygonList(intid);//指定的多边形是否在活化多边形表中COLORREFGetPolygonColor(intid);//获取多边形的颜色voidUpdateZBufferColor(inty);voidScan();voidShow();voidOnX(doubleangle, CPoint3D *p);voidOnY(doubleangle, CPoint3D *p);voidAddFace(CPoint3D *pFacePoint,intnpoints, COLORREF faceColor);//增加面intfaceid;public:
Lib3dsFile *model;boolLoad3ds(char*argv);//加载3ds文件voidrender_node(Lib3dsNode *node);boolbInit;floatm_Scale;//缩放比例floatm_Max;voidgetScalFor3dsFile(char*argv);voidget_nodeMax(Lib3dsNode *node);voidClear();//清除所有数据boolm_bYZ;boolm_EdgeShow;doubleangle_x;//绕x轴旋转角度doubleangle_y;//绕y轴旋转角度include "StdAfx.h"include "ScanLineZbufferProcess.h"include CScanLineZbufferProcess::CScanLineZbufferProcess(void)
{
faceid =-1;
BackGroundColor = RGB(255,255,255);//背景为白色minZ =-100000;文章源自略懂百科-http://wswcn.cn/113025.html
angle_y =0.0;文章源自略懂百科-http://wswcn.cn/113025.html
{
Clear();
}//清除所有数据void CScanLineZbufferProcess::Clear()
{for(int y = nHeight/2; y>-nHeight/2;y--)//从上往下扫描{try{//删除多边形表CPolygon *oldPolygon = PolygonList[y+nHeight/2].head;//y是当前的扫描线y值if(oldPolygon)
delete oldPolygon;文章源自略懂百科-http://wswcn.cn/113025.html
delete tpEdge;文章源自略懂百科-http://wswcn.cn/113025.html
{
}
}//清除FrameBuffer、ZBufferint nCount = nWidth*nHeight;for(int i=0;i
face->color = faceColor;文章源自略懂百科-http://wswcn.cn/113025.html
{//与xoy面没有投影的面去掉face->next = PolygonList[face->yMax+nHeight/2].head;
PolygonList[face->yMax+nHeight/2].head = face;//多边形表CEdge *pEdge = face->getEdgeList();//边表SortEdge(pEdge);
}文章源自略懂百科-http://wswcn.cn/113025.html
{
CEdge* tpEdge = pEdge;do{
CEdge* tOldpEdge = tpEdge->next;if(tpEdge->yMax+nHeight/2<=nHeight) //去除Ymax超过边界的值{ tpEdge->next = EdgeList[tpEdge->yMax+nHeight/2].head;
EdgeList[tpEdge->yMax+nHeight/2].head = tpEdge;//坐标原点在画板中心EdgeList[tpEdge->yMax+nHeight/2].ymax = tpEdge->yMax;
}文章源自略懂百科-http://wswcn.cn/113025.html
}//step1 添加活化多边形表bool CScanLineZbufferProcess::AddActivePolygonList(int y)
{if(PolygonList[y+nHeight/2].head!=NULL)
{
CPolygon *tPolygon = ActivePolygonList->head;while(tPolygon && tPolygon->next)
{文章源自略懂百科-http://wswcn.cn/113025.html
}文章源自略懂百科-http://wswcn.cn/113025.html
{if(oldPolygon->c!=0)
{
CPolygon *tnewPolygon =newCPolygon();文章源自略懂百科-http://wswcn.cn/113025.html
{
ActivePolygonList->head = tnewPolygon;
}else{
tPolygon->next = tnewPolygon;
}文章源自略懂百科-http://wswcn.cn/113025.html
}文章源自略懂百科-http://wswcn.cn/113025.html
}returntrue;//有新多边形加入}returnfalse;
}//更新活化多边形表,删除不再扫描区域的多边形void CScanLineZbufferProcess::UpdateActivePolygonList()
{//活化多边形表中的元素修改CPolygon *tPolygon = ActivePolygonList->head;文章源自略懂百科-http://wswcn.cn/113025.html
{文章源自略懂百科-http://wswcn.cn/113025.html
ActivePolygonList->head = tPolygon->next;//删除第一个节点else{
tOldPolygon->next = tPolygon->next;
}
}else{//不删除,才需更新上一个指针tOldPolygon = tPolygon;
}文章源自略懂百科-http://wswcn.cn/113025.html
}
}//有新多边形加入时添加新边对到活化边表bool CScanLineZbufferProcess::AddActiveEdgeList(int y)
{文章源自略懂百科-http://wswcn.cn/113025.html
{
int i=0;文章源自略懂百科-http://wswcn.cn/113025.html
{if(tpEdge->id==tPolygon->id)
{if(tpEdge->dy<=1) //是水平线{ tpEdge=tpEdge->next;continue;
}if(i==0)
{
tActiveEdge->id = tPolygon->id;文章源自略懂百科-http://wswcn.cn/113025.html
tActiveEdge->dyl = tpEdge->dy;
tActiveEdge->xl = tpEdge->x;文章源自略懂百科-http://wswcn.cn/113025.html
tActiveEdge->dzy = tPolygon->b / tPolygon->c;
tActiveEdge->zl = -( tPolygon->a * tpEdge->x + tPolygon->b*y +tPolygon->d )/tPolygon->c;文章源自略懂百科-http://wswcn.cn/113025.html
{//左右两边交换tActiveEdge->dxr = tActiveEdge->dxl;
tActiveEdge->dyr = tActiveEdge->dyl;
tActiveEdge->xr = tActiveEdge->xl;文章源自略懂百科-http://wswcn.cn/113025.html
tActiveEdge->dyl = tpEdge->dy;
tActiveEdge->xl = tpEdge->x;
}else{
tActiveEdge->dxr = tpEdge->dx;
tActiveEdge->dyr = tpEdge->dy;
tActiveEdge->xr = tpEdge->x;
}/******************加入活化表*****************************/if(ActiveEdgeList==NULL||ActiveEdgeList->id==-1)
ActiveEdgeList = tActiveEdge;else{
tActiveEdge->next = ActiveEdgeList;//插入表头ActiveEdgeList = tActiveEdge;
}/*******************end 加入活化表**************************/i =0;break;//寻找下一个多边形}
}文章源自略懂百科-http://wswcn.cn/113025.html
}文章源自略懂百科-http://wswcn.cn/113025.html
}//更新活化边表void CScanLineZbufferProcess::UpdateActiveEdgeList(int y)
{
CActiveEdge *tActiveEdgeList = ActiveEdgeList;文章源自略懂百科-http://wswcn.cn/113025.html
{
tActiveEdgeList->dyl -=1; tActiveEdgeList->dyr -=1;文章源自略懂百科-http://wswcn.cn/113025.html
{
tOldActiveEdgeList = tActiveEdgeList;//保存为前向节点//还在活化多边形表中,选择修改边对,删除原来的,加入新边CEdge *tpEdge = EdgeList[y+nHeight/2].head;while(tpEdge)
{if(tpEdge->id==tActiveEdgeList->id)
{if(tActiveEdgeList->dyl<=0) {//更新左边tActiveEdgeList->dxl = tpEdge->dx;
tActiveEdgeList->dyl = tpEdge->dy;
tActiveEdgeList->xl = tpEdge->x;文章源自略懂百科-http://wswcn.cn/113025.html
tActiveEdgeList->dyr = tpEdge->dy;
tActiveEdgeList->xr = tpEdge->x;
}break;文章源自略懂百科-http://wswcn.cn/113025.html
}文章源自略懂百科-http://wswcn.cn/113025.html
{//表头ActiveEdgeList = tActiveEdgeList->next;文章源自略懂百科-http://wswcn.cn/113025.html
tOldActiveEdgeList->next = tActiveEdgeList->next;文章源自略懂百科-http://wswcn.cn/113025.html
}
}else{
tOldActiveEdgeList = tActiveEdgeList;//保存为前向节点}文章源自略懂百科-http://wswcn.cn/113025.html
{
CPolygon *tPolygon = ActivePolygonList->head;while(tPolygon)
{if(tPolygon->id == id)
{returntPolygon->color;
}
tPolygon = tPolygon->next;
}returnthis->BackGroundColor;//没找到返回背景色}//指定的多边形是否在活化多边形表中bool CScanLineZbufferProcess::IsInActivePolygonList(int id)
{
CPolygon *tPolygon = ActivePolygonList->head;while(tPolygon)
{if(tPolygon->id == id)
{returntrue;
}
tPolygon = tPolygon->next;
}returnfalse;文章源自略懂百科-http://wswcn.cn/113025.html
{
CActiveEdge *tActiveEdgeList = ActiveEdgeList;while(tActiveEdgeList && tActiveEdgeList->id!=-1)
{
double Zx = tActiveEdgeList->zl;for(int x = tActiveEdgeList->xl;x<=tActiveEdgeList->xr;x++)
{if(abs(x)>nWidth/2)
{
Zx += tActiveEdgeList->dzx;continue;
}文章源自略懂百科-http://wswcn.cn/113025.html
{
ZBuffer[index] = Zx;//更新深度值if(m_EdgeShow)
{if( x == (int)tActiveEdgeList->xl || x==(int)tActiveEdgeList->xr)
FrameBuffer[index] = RGB(255,255,255);//边界线都是白色else{
FrameBuffer[index] = GetPolygonColor(tActiveEdgeList->id);//更新颜色}
}else{文章源自略懂百科-http://wswcn.cn/113025.html
}//扫描void CScanLineZbufferProcess::Scan()
{
ActivePolygonList =newCPolygonList();//活化多边形表ActiveEdgeList =newCActiveEdge();//活化边表for(int y = nHeight/2; y>-nHeight/2;y--)//从上往下扫描{try{//step1 添加新的多边形进活化多边形表,有新多变形加入时添加边对进活化边表AddActivePolygonList(y);
AddActiveEdgeList(y);//step2 增量式的深度更新UpdateZBufferColor(y);//活化多边形表中的元素修改UpdateActivePolygonList();//step3 活化边表中的元素修改:修改后的活化边表是下一条扫描线的活化边表UpdateActiveEdgeList(y);
}catch(...)
{
AfxMessageBox(_T(" 出错!"));="" 显示framebuffer图形void="" cscanlinezbufferprocess::show()="" dc="" 的原点在(nwidth="" 2,nheight="" 2)]for(int="" y="nHeight/2;" y>-nheight="" 2;="" y--)="" {for(int="" x="-nWidth/2;" x
评论