计算机图形.pdf

上传人:奔*** 文档编号:89813898 上传时间:2023-05-13 格式:PDF 页数:17 大小:1.25MB
返回 下载 相关 举报
计算机图形.pdf_第1页
第1页 / 共17页
计算机图形.pdf_第2页
第2页 / 共17页
点击查看更多>>
资源描述

《计算机图形.pdf》由会员分享,可在线阅读,更多相关《计算机图形.pdf(17页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。

1、计算机图形学实验报告2014实验名称:1.实验目的:1)掌握图形变换实现原理,基本几何变换、复合变换等;2)学习使用Visual C+开发菜单、对话框等交互界面的设计;3)学习使用MFC单文档程序4)编程实现二维图形的绘制与基本几何变换、复合变换。2.实验内容:使用Visual C+建立一个单文档程序,采用实验二中定义的基本图形类。在程序中增加图形变换菜单(各基本变换对应菜单项),各图形变换的参数通过对话框提供(设计提供变换参数的对话框,如平移、旋转、比例等),实现二维图形的变换。(提示:在各图形类中增加相应成员函数实现平移;菜单选择变换弹出对应变换的参数对话框,对话框中提供参数后取出参数传递

2、给图形对象,通过调用图形变换成员函数实现图形对象的变换)。3.实验过程:void CThirdView:OnLButtonUp(UINT nFlags,CPoint point)(/TODO:Add your message handler code here and/or call defaultm_bLBDown=FALSE;m_prevPoint=point;CView:OnLButtonUp(nFlags,point);void CThirdView:OnRButtonDown(UINT nFlags,CPoint point)/TODO:Add your message handle

3、r code here and/or call defaultm_bRBDown=TRUE;m_prevPoint=point;CView:OnRButtonDown(nFlags,point);)void CThirdView:OnRButtonUp(UINT nFlags,CPoint point)(/TODO:Add your message handler code here and/or call defaultm_bRBDown=FALSE;m_prevPoint=point;CView:OnRButtonUp(nFlags,point);)void CThirdView:OnMo

4、useMove(UINT nFIags,CPoint point)(/TODO:Add your message handler code here and/or call defaultint delta;switch(m_type_transform)case TRF_TRANSLATE:if(m_bLBDown)(ClearScreen();delta=point.x-m_prevPoint.x;m_prevPoint=point;m_LT+=CPoint(delta*(int)m_xStep,0);m_LB+=CPoint(delta*(int)m_xStep,0);m_RT+=CPo

5、int(delta*(int)m_xStep,0);m_RB+=CPoint(delta*(int)m_xStep,0);DrawRect();)if(m_bRBDown)(ClearScreen();delta=point.y-m_prevPoint.y;m_prevPoint=point;m_LT+=CPoint(0,delta*(int)m_yStep);m_LB+=CPoint(0,delta*(int)m_yStep);m_RT+=CPoint(0,delta*(int)m_yStep);m_RB+=CPoint(0,delta*(int)m_yStep);DrawRect();br

6、eak;case TRF_NONE:break;)CView:OnMouseMove(nFlags,point);)void CThirdView:OnScale()(/TODO:Add your command handler code hereClearScreen();m_type_transform=TRF_SCALE;m_LT=CPoint(100,300);m_LB=CPoint(100,100);m_RT=CPoint(300,300);m_RB=CPoint(300,100);DrawRect();CClientDC dc(this);CPen*oldPen;CPen newP

7、en(PS_DASH,1 ,RGB(0,0,0);oldPen=dc.SelectObject(&newPen);dc.MoveTo(0,0);dc.LineTo(m_LT);dc.MoveTo(0,0);de.LineTo(m_RB);dc.SelectObject(oldPen);double Sx=l;double Sy=l;Dlg_Scalel dlgScale;if(dlgScale.DoModal()=IDOK)(Sx=dlgScale.m_Sx;Sy=dlgScale.m_Sy;)m_LT.x*=Sx;m_LB.x*=Sx;m_RT.x*=Sx;m_RB.x*=Sx;m_LT.y

8、*=Sy;m_LB.y*=Sy;m_RT.y*=Sy;m_RB.y*=Sy;ClearScreen();DrawRect();oldPen=dc.SelectObject(&newPen);dc.MoveTo(0,0);dc.LineTo(m_LT);dc.MoveTo(0,0);dc.LineTo(m_RB);dc.SelectObject(oIdPen);)void CThirdView:OnRptate()(/TODO:Add your command handler code hereClearScreen();m_type_transform=TRF_ROTATE;m_LT=CPoi

9、nt(100,300);m_LB=CPoint(100,100);m_RT=CPoint(300,300);m_RB=CPoint(300,100);DrawRect();CClientDC dc(this);CPen*oldPen;CPen newPen(PS_DASH,1 ,RGB(0,0,0);oldPen=dc.SelectObject(&newPen);dc.MoveTo(0,0);dc.LineTo(m_LT);dc.SelectObject(oIdPen);double angle=0;Dlg_Rotate dlgRptate;if(dlgRptate.DoModal()=IDO

10、K)angle=dlgRptate.m_RotateAngle/l 80*3.1415926;double c=cos(angle);double s=sin(angle);m_LT.x=m_LT.x*c-m_LT.y*s;m_LT.y=m_LT.x*s+m_LT.y*c;m_LB.x=m_LB.x*c-m_LB.y*s;m_LB.y=m_LB,x*s+m_LB.y*c;m_RT.x=m_RT.x*c-m_RT.y*s;m_RT.y=m_RT.x*s+m_RT.y*c;m_RB.x=m_RB.x*c-m_RB.y*s;m_RB.y=m_RB.x*s+m_RB.y*c;ClearScreen()

11、;DrawRect();oldPen=dc.SelectObject(&newPen);dc.MoveTo(0,0);dc.LineTo(m_LT);dc.SelectObject(oldPen);void CThirdView:DrawTriangle()(CClientDC dc(this);dc.MoveTo(m_LB);dc.LineTo(m_LT);dc.LineTo(m_RB);de.LineTo(m_LB);void CThirdView:OnSymmetryY()/TODO:Add your command handler code hereClearScreen();m_ty

12、pe_transform=TRF_SYMMETRY_Y;CClientDC dc(this);dc.MoveTo(0,300);dc.LineTo(800,300);dc.MoveTo(400,0);de.LineTo(400,600);m_LT=CPoint(100,150);m_LB=CPoint(100,100);m_RB=CPoint(150,100);DrawTriangle();double a=-l;double b=0;double d=0;double e=l;int x=m_LT.x;int y=m_LT.y;m_LT.x=(x-400)*a+(y-300)*b+400;m

13、_LT.y=(x-400)*d+(y-300)*e+300;x=m_LB.x;y=m_LB.y;m_LB.x=(x-400)*a+(y-300)*b+400;m_LB.y=(x-400)*d+(y-300)*e+300;x=m_RB.x;y=m_RB.y;m_RB.x=(x-400)*a+(y-300)*b+400;m_RB.y=(x-400)*d+(y-300)*e+300;DrawTriangle();)void CThirdView:OnSymmetryX()(/TODO:Add your command handler code hereClearScreen();m_type_tra

14、nsform=TRF_SYMMETRY_Y;CClientDC dc(this);dc.MoveTo(0,300);dc.LineTo(800,300);dc.MoveTo(400,0);dc.LineTo(400,600);m_LT=CPoint(100,150);m_LB=CPoint(100,100);m_RB=CPoint(150,100);DrawTriangle();double a=l;double b=0;double d=0;double e=l;int x=m_LT.x;int y=m_LT.y;m_LT.x=(x-400)*a+(y-300)*b+400;m_LT.y=(

15、x-400)*d+(y-300)*e+300;x=m_LB.x;y=m_LB.y;m_LB.x=(x-400)*a+(y-300)*b+400;m_LB.y=(x-400)*d+(y-300)*e+300;x=m_RB.x;y=m_RB.y;m_RB.x=(x-400)*a+(y-300)*b+400;m_RB.y=(x-400)*d+(y-300)*e+300;DrawTriangle();void CThirdView:OnSymmetryXy()/TODO:Add your command handler code hereClearScreen();m_type_transform=T

16、RF_SYMMETRY_Y;CClientDC dc(this);dc.MoveTo(0,300);dc.LineTo(800,300);dc.MoveTo(400,0);de.LineTo(400,600);m_LT=CPoint(100,150);m_LB=CPoint(100,100);m_RB=CPoint(150,100);DrawTriangle();double a=l;double b=0;double d=0;double e=-l;int x=m_LT.x;int y=m_LT.y;m_LT.x=(x-400)*a+(y-300)*b+400;m_LT.y=(x-400)*

17、d+(y-300)*e+300;x=m_LB.x;y=m_LB.y;m_LB.x=(x-400)*a+(y-300)*b+400;m_LB.y=(x-400)*d+(y-300)*e+300;x=m_RB.x;y=m_RB.y;m_RB.x=(x-400)*a+(y-300)*b+400;m_RB.y=(x-400)*d+(y-300)*e+300;DrawTriangle();)4.实验结果:为 OnPreparePrintingJCPrintlnOnRButtonDownfUINT nFla%OnRButtonUp(UINT nFlags.OnRptateQ|OnScaleQOnSymme

18、tryXQOnSymmetryXyQOnSymmetryYOOnTranslateQ PreCreateWindowJCREATEq m_bLBDownQ m bRBDowng m deltaQ m_LBQ m_LTq m prevPoint0 m_RBQ m_RT9 ni_typ e tra n sfo rmg m_xStep励 m_yStep 飞 Dlg ScaleE*4 Dlg Scale1出 口 Globals=i|Jjfl 无标至-third.就第B fl尢即陋一文件(F)=(E)查看(V)W(H)5.实验体会:1)掌握图形变换实现原理,基本几何变换、复合变换等;2)学习使用Visual C+开发菜单、对话框等交互界面的设计;

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 教育专区 > 教案示例

本站为文档C TO C交易模式,本站只提供存储空间、用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。本站仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知淘文阁网,我们立即给予删除!客服QQ:136780468 微信:18945177775 电话:18904686070

工信部备案号:黑ICP备15003705号© 2020-2023 www.taowenge.com 淘文阁