收藏 分销(赏)

C++(MFC)金刚石图案的绘制平移缩放.docx

上传人:xrp****65 文档编号:6395853 上传时间:2024-12-07 格式:DOCX 页数:5 大小:681.55KB
下载 相关 举报
C++(MFC)金刚石图案的绘制平移缩放.docx_第1页
第1页 / 共5页
C++(MFC)金刚石图案的绘制平移缩放.docx_第2页
第2页 / 共5页
点击查看更多>>
资源描述
实验二 实验目的: 绘制金刚石图案,并利用鼠标交互实现平移、放大和缩小 实验过程: 设置映射模式为MM_ISOTROPIC,通过在MouseDown、MouseUp及MouseMove消息处理中改变逻辑坐标的原点及范围实现图形的平移及放大和缩小 实验主要算法: CAaaaaView::CAaaaaView()//构造函数 { // TOD: add construction code here Xw=1000; Yw=1000; x0=y0=0; } void CAaaaaView::OnDraw(CDC* pDC) { CAaaaaDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); // TODO: add draw code for native data here draw(pCurrentDC); } ///////////////////////////////////////////////////////////////////////////// // CAaaaaView printing void CAaaaaView::draw(CDC *pDC) { CRect Rect;//////////////////////////////////////////////////////////////// GetClientRect(& Rect);///////////////////////////////////////////////////// pDC->SetMapMode(MM_ISOTROPIC);//////////////////////设置映射模式///////// pDC->SetWindowExt(Xw,Yw);/////////////////////////// pDC->SetWindowOrg(x0,y0); pDC->SetViewportExt(Rect.right,-Rect.bottom);///////////////////////////// pDC->SetViewportOrg(Rect.right/2,Rect.bottom/2);///////////////////////// // CBrush d(RGB(0,255,0));////////设置填充颜色 // pDC->SelectObject(d);///////////////////// pDC->Ellipse(-200,200,200,-200); int a[30][2];//////////x坐标为a[i][0];y坐标为a[i][1]; int r=200; double c=3.141592653; for(int i=0;i<=29;i++){ a[i][0]=r* cos(2*c/30*i); a[i][1]=r* sin(2*c/30*i); } //ofstream d("checkpoint.txt",ios::trunc);//写入记事本,检验是否正确创建各个点 //for(int l=0;l<30;l++){ // d<<a[l][0]<<" "<<a[l][1]<<endl; //} //d.close(); for(int j=0;j<30;j++) for(int k=0;k<30;k++){ pDC->MoveTo(a[j][0],a[j][1]); pDC->LineTo(a[k][0],a[k][1]); } } void CAaaaaView::OnLButtonDown(UINT nFlags, CPoint point) //缩放下左击放大,平移下平移 { // TODO: Add your message handler code here and/or call default if(a) { Xw=Xw/2; Yw=Yw/2; CPoint p=point; pCurrentDC->DPtoLP(&p); x0=Xw/4+p.x; y0=Yw/4+p.y; } else{ CPoint b=point; pCurrentDC->DPtoLP(&b); x0=x0-b.x; y0=y0-b.y; } Invalidate(); CView::OnLButtonDown(nFlags, point); } int CAaaaaView::OnCreate(LPCREATESTRUCT lpCreateStruct) { if (CView::OnCreate(lpCreateStruct) == -1) return -1; // TODO: Add your specialized creation code here pCurrentDC= new CClientDC(this); return 0; } void CAaaaaView::OnRButtonDown(UINT nFlags, CPoint point) //缩放下的右击缩小 { // TODO: Add your message handler code here and/or call default if(a) { Xw=Xw*2; Yw=Yw*2; CPoint p=point; pCurrentDC->DPtoLP(&p); x0=p.x+Xw/4; y0=p.y+Yw/4; Invalidate();} CView::OnRButtonDown(nFlags, point); } void CAaaaaView::On1() //缩放菜单 { // TODO: Add your command handler code here a=true; } void CAaaaaView::On2() //平移菜单 { // TODO: Add your command handler code here a=false; } 实验体会: 本次实验让我懂得如何去平移一个物体,也让我懂得如何缩放物体。
展开阅读全文

开通  VIP会员、SVIP会员  优惠大
下载10份以上建议开通VIP会员
下载20份以上建议开通SVIP会员


开通VIP      成为共赢上传
相似文档                                   自信AI助手自信AI助手

当前位置:首页 > 百科休闲 > 其他

移动网页_全站_页脚广告1

关于我们      便捷服务       自信AI       AI导航        抽奖活动

©2010-2025 宁波自信网络信息技术有限公司  版权所有

客服电话:4009-655-100  投诉/维权电话:18658249818

gongan.png浙公网安备33021202000488号   

icp.png浙ICP备2021020529号-1  |  浙B2-20240490  

关注我们 :微信公众号    抖音    微博    LOFTER 

客服