洛阳理工学院实验报告系别计算机与信息工程系班级B120531学号B12053113姓名课程名称计算机图形学实验日期2013-11-7实验名称多边形填充算法编程成绩实验目的:熟悉多边形填充算法,掌握MFC图形编程的基本方法和调试技巧。实验条件:计算机;VS2008;OpenGL实验内容:,参考界面效果如下://#include""#include""#include""#include<>#defineRound(d)int(floor(d+))//四舍五入宏定义#ifdef_DEBUG#definenewDEBUG_NEW#endif//hildView::CChildView(){}CChildView::~CChildView(){}hildView,CWnd)ON_WM_PAINT()ON_WM_CREATE()MAND(ID_DRAW_PIC,&CChildView::OnDrawPic)END_MESSAGE_MAP()//hildView::PreCreateWindow(CREATESTRUCT&cs){if(!CWnd::PreCreateWindow(cs))returnFALSE;|=WS_EX_CLIENTEDGE;&=~WS_BORDER;=AfxRegisterWndClass(CS_HREDRAW|CS_VREDRAW|CS_DBLCLKS,::LoadCursor(NULL,IDC_ARROW),reinterpret_cast<HBRUSH>(COLOR_WINDOW+1),NULL);returnTRUE;}hildView::OnPaint(){CPaintDCdc(this);//用于绘制的设备上下文//TODO:在此处添加消息处理程序代码DrawGraph();//不要为绘制消息而调用CWnd::OnPaint()}hildView::ReadPoint(){P[0].x=50;P[0].y=100;P[1].x=-150;P[1].y=300;P[2].x=-250;P[2].y=50;P[3].x=-150;P[3].y=-250;P[4].x=0;P[4].y=-50;P[5].x=100;P[5].y=-250;P[6].x=300;P[6].y=150;}hildView::DrawPolygon(CDC*pDC){CLine*line=newCLine;//点表//绘制多边形边界CP2t;for(inti=0;i<7;i++){if(i==0){line->MoveTo(pDC,P[i]);t=P[i];}else{line->o(pDC,P[i]);}}line->o(pDC,t);deleteline;//绘制多边形//闭合多边形}hildView::DrawGraph(){CRectrect;GetClientRect(&rect);CDC*pDC=GetDC();pDC->SetMapMode(MM_ANISOTROPIC);pDC->SetWindowExt((),());pDC->SetViewportExt((),-());垂直向上//绘制图形//定义客户区//获得客户区的大小//定义设备上下文指针//自定义坐标系//设置窗口比例//设置视区比例,且x轴水平向右,y轴pDC->(()/2,()/2);(-()/2,-()/2);if(!bFill)//设置客户区中心为坐标系原点//矩形与客户区重合DrawPolygon(pDC);elseFillPolygon(pDC);ReleaseDC(pDC);//绘制多边形//填充多边形//释放DC}hildView::FillPolygon(CDC*pDC){for(inti=0;i<7;i++){//填充多边形//转储顶点坐标,y坐标取为整数P1[i].x=P[i].x;P1[i].y=Round(P[i].y);P1[i].c=CRGB(bRed/,bGreen/,bBlue/);}CFill*fill=newCFill;fill->SetPoint(P1,7);fill->CreateBucket();//动态分配内存//初始化Fill对象//建立桶表fill
实验三计算机图形学多边形填充算法汇总 来自淘豆网m.daumloan.com转载请标明出处.