欢迎来到天天文库
浏览记录
ID:1325382
大小:173.00 KB
页数:17页
时间:2017-11-10
《实验三计算机图形学多边形填充算法》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、洛阳理工学院实验报告系别计算机与信息工程系班级B120531学号B12053113姓名课程名称计算机图形学实验日期2013-11-7实验名称多边形填充算法编程成绩实验目的:熟悉多边形填充算法,掌握MFC图形编程的基本方法和调试技巧。实验条件:计算机;VS2008;OpenGL实验内容:1.使用MFC技术实现多边形有效边表填充算法,参考界面效果如下://ChildView.cpp:CChildView类的实现#include"stdafx.h"#include"demo.h"#include"ChildView.h"#include2、h>#defineRound(d)int(floor(d+0.5))//四舍五入宏定义#ifdef_DEBUG#definenewDEBUG_NEW#endif//CChildViewCChildView::CChildView(){}CChildView::~CChildView(){}BEGIN_MESSAGE_MAP(CChildView,CWnd)ON_WM_PAINT()ON_WM_CREATE()ON_COMMAND(ID_DRAW_PIC,&CChildView::OnDrawPic)END_MESSAGE_MAP()//CCh3、ildView消息处理程序BOOLCChildView::PreCreateWindow(CREATESTRUCT&cs){if(!CWnd::PreCreateWindow(cs))returnFALSE;cs.dwExStyle4、=WS_EX_CLIENTEDGE;cs.style&=~WS_BORDER;cs.lpszClass=AfxRegisterWndClass(CS_HREDRAW5、CS_VREDRAW6、CS_DBLCLKS,::LoadCursor(NULL,IDC_ARROW),reinterpret_cast7、>(COLOR_WINDOW+1),NULL);returnTRUE;}voidCChildView::OnPaint(){CPaintDCdc(this);//用于绘制的设备上下文//TODO:在此处添加消息处理程序代码DrawGraph();//不要为绘制消息而调用CWnd::OnPaint()}voidCChildView::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;P8、[4].x=0;P[4].y=-50;P[5].x=100;P[5].y=-250;P[6].x=300;P[6].y=150;}voidCChildView::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->LineTo(pDC,P[i]);}}line->LineTo(pDC,t);//闭合多边形deleteline;}vo9、idCChildView::DrawGraph()//绘制图形{CRectrect;//定义客户区GetClientRect(&rect);//获得客户区的大小CDC*pDC=GetDC();//定义设备上下文指针pDC->SetMapMode(MM_ANISOTROPIC);//自定义坐标系pDC->SetWindowExt(rect.Width(),rect.Height());//设置窗口比例pDC->SetViewportExt(rect.Width(),-rect.Height());//设置视区比例,且x轴水平向右,y轴垂直向上p10、DC->SetViewportOrg(rect.Width()/2,rect.Height()/2);//设置客户区中心为坐标系原点rect.OffsetRect(-rect.Width()/2,-rect.Height()/2);//矩形与客户区重合if(!bFill)DrawPolygon(pDC);//绘制多边形elseFillPolygon(pDC);//填充多边形ReleaseDC(pDC);//释放DC}voidCChildView::FillPolygon(CDC*pDC)//填充多边形{for(inti=0;i<7;i++)/11、/转储顶点坐标,y坐标取为整数{P1[i].x=P[i].x;P1[i].y=Round(P[i].y);P1[i].c=CRGB(bRed/255.0,bGree
2、h>#defineRound(d)int(floor(d+0.5))//四舍五入宏定义#ifdef_DEBUG#definenewDEBUG_NEW#endif//CChildViewCChildView::CChildView(){}CChildView::~CChildView(){}BEGIN_MESSAGE_MAP(CChildView,CWnd)ON_WM_PAINT()ON_WM_CREATE()ON_COMMAND(ID_DRAW_PIC,&CChildView::OnDrawPic)END_MESSAGE_MAP()//CCh
3、ildView消息处理程序BOOLCChildView::PreCreateWindow(CREATESTRUCT&cs){if(!CWnd::PreCreateWindow(cs))returnFALSE;cs.dwExStyle
4、=WS_EX_CLIENTEDGE;cs.style&=~WS_BORDER;cs.lpszClass=AfxRegisterWndClass(CS_HREDRAW
5、CS_VREDRAW
6、CS_DBLCLKS,::LoadCursor(NULL,IDC_ARROW),reinterpret_cast7、>(COLOR_WINDOW+1),NULL);returnTRUE;}voidCChildView::OnPaint(){CPaintDCdc(this);//用于绘制的设备上下文//TODO:在此处添加消息处理程序代码DrawGraph();//不要为绘制消息而调用CWnd::OnPaint()}voidCChildView::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;P8、[4].x=0;P[4].y=-50;P[5].x=100;P[5].y=-250;P[6].x=300;P[6].y=150;}voidCChildView::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->LineTo(pDC,P[i]);}}line->LineTo(pDC,t);//闭合多边形deleteline;}vo9、idCChildView::DrawGraph()//绘制图形{CRectrect;//定义客户区GetClientRect(&rect);//获得客户区的大小CDC*pDC=GetDC();//定义设备上下文指针pDC->SetMapMode(MM_ANISOTROPIC);//自定义坐标系pDC->SetWindowExt(rect.Width(),rect.Height());//设置窗口比例pDC->SetViewportExt(rect.Width(),-rect.Height());//设置视区比例,且x轴水平向右,y轴垂直向上p10、DC->SetViewportOrg(rect.Width()/2,rect.Height()/2);//设置客户区中心为坐标系原点rect.OffsetRect(-rect.Width()/2,-rect.Height()/2);//矩形与客户区重合if(!bFill)DrawPolygon(pDC);//绘制多边形elseFillPolygon(pDC);//填充多边形ReleaseDC(pDC);//释放DC}voidCChildView::FillPolygon(CDC*pDC)//填充多边形{for(inti=0;i<7;i++)/11、/转储顶点坐标,y坐标取为整数{P1[i].x=P[i].x;P1[i].y=Round(P[i].y);P1[i].c=CRGB(bRed/255.0,bGree
7、>(COLOR_WINDOW+1),NULL);returnTRUE;}voidCChildView::OnPaint(){CPaintDCdc(this);//用于绘制的设备上下文//TODO:在此处添加消息处理程序代码DrawGraph();//不要为绘制消息而调用CWnd::OnPaint()}voidCChildView::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
8、[4].x=0;P[4].y=-50;P[5].x=100;P[5].y=-250;P[6].x=300;P[6].y=150;}voidCChildView::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->LineTo(pDC,P[i]);}}line->LineTo(pDC,t);//闭合多边形deleteline;}vo
9、idCChildView::DrawGraph()//绘制图形{CRectrect;//定义客户区GetClientRect(&rect);//获得客户区的大小CDC*pDC=GetDC();//定义设备上下文指针pDC->SetMapMode(MM_ANISOTROPIC);//自定义坐标系pDC->SetWindowExt(rect.Width(),rect.Height());//设置窗口比例pDC->SetViewportExt(rect.Width(),-rect.Height());//设置视区比例,且x轴水平向右,y轴垂直向上p
10、DC->SetViewportOrg(rect.Width()/2,rect.Height()/2);//设置客户区中心为坐标系原点rect.OffsetRect(-rect.Width()/2,-rect.Height()/2);//矩形与客户区重合if(!bFill)DrawPolygon(pDC);//绘制多边形elseFillPolygon(pDC);//填充多边形ReleaseDC(pDC);//释放DC}voidCChildView::FillPolygon(CDC*pDC)//填充多边形{for(inti=0;i<7;i++)/
11、/转储顶点坐标,y坐标取为整数{P1[i].x=P[i].x;P1[i].y=Round(P[i].y);P1[i].c=CRGB(bRed/255.0,bGree
此文档下载收益归作者所有