已阅读5页,还剩3页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
在VC6.0坏境下,用mfc编写的绘制3次Bezier曲线的完整代码,其功能为:单击左键绘制控制多边形和坐标点,单击右键绘制曲线。具体操作步骤如下:(1)新建mfc,工程名为Bezier。(2)编辑菜单资源并添加消息处理函数OnBezier。(3)在工程主文件中编写代码如下(红色字体为要添加代码)。/ BezierView.cpp : implementation of the CBezierView class/#include stdafx.h#include Bezier.h#include BezierDoc.h#include BezierView.h#ifdef _DEBUG#define new DEBUG_NEW#undef THIS_FILEstatic char THIS_FILE = _FILE_;#define T 20#endif/ CBezierViewIMPLEMENT_DYNCREATE(CBezierView, CView)BEGIN_MESSAGE_MAP(CBezierView, CView)/AFX_MSG_MAP(CBezierView)/ NOTE - the ClassWizard will add and remove mapping macros here./ DO NOT EDIT what you see in these blocks of generated code!ON_WM_RBUTTONDOWN()ON_WM_LBUTTONDOWN()/AFX_MSG_MAP/ Standard printing commandsON_COMMAND(ID_FILE_PRINT, CView:OnFilePrint)ON_COMMAND(ID_FILE_PRINT_DIRECT, CView:OnFilePrint)ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView:OnFilePrintPreview)END_MESSAGE_MAP()/ CBezierView construction/destructionCBezierView:CBezierView()/ TODO: add construction code hereCBezierView:CBezierView()BOOL CBezierView:PreCreateWindow(CREATESTRUCT& cs)/ TODO: Modify the Window class or styles here by modifying/ the CREATESTRUCT csreturn CView:PreCreateWindow(cs);/ CBezierView drawingvoid CBezierView:OnDraw(CDC* pDC)CBezierDoc* pDoc = GetDocument();ASSERT_VALID(pDoc);pDC-TextOut(30,20,开始绘制3次Bezier曲线,单击左键绘制控制多边形,单击右键绘制曲线);/ TODO: add draw code for native data here/ CBezierView printingBOOL CBezierView:OnPreparePrinting(CPrintInfo* pInfo)/ default preparationreturn DoPreparePrinting(pInfo);void CBezierView:OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)/ TODO: add extra initialization before printingvoid CBezierView:OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)/ TODO: add cleanup after printing/ CBezierView diagnostics#ifdef _DEBUGvoid CBezierView:AssertValid() constCView:AssertValid();void CBezierView:Dump(CDumpContext& dc) constCView:Dump(dc);CBezierDoc* CBezierView:GetDocument() / non-debug version is inlineASSERT(m_pDocument-IsKindOf(RUNTIME_CLASS(CBezierDoc);return (CBezierDoc*)m_pDocument;#endif /_DEBUG/ CBezierView message handlersint k=0;float BEN44=-1,3,-3,1, 3,-6,3,0, -3,3,0,0, 1,0,0,0; float point43 =100,100,1,200,300,1,400,300,1,300,100,1;/给定控制点void bezier(CDC*pDC,int n, int t, float p43);void matx44(float a44,float b43,float c43);void matx14(float a4,float b43, float c3);void bezier (CDC*pDC,int n,int t, float point43) /绘制Bezier曲线float cc43;float pp3;int i,xx,yy,a,b;float u4;u3=1.0; a=point00,b=point01; / 第一个控制点的横、纵坐标for(i=2;iMoveTo(a,b);pDC-LineTo(xx,yy);a=xx;b=yy;void matx44(float a44,float b43,float c43) int i,j,m;for(i=0;i4;i+)for(j=0;j3;j+) cij=0.0; /初始化中间矩阵for(m=0;m4;m+)for(i=0;i3;i+)for(j=0;j4;j+)cmi+=amj*bji;return;void matx14(float a4,float b43, float c3) int i,j;c0=c1=c2=0.0;/ 曲线点for(i=0;i3;i+)for(j=0;jTextOut(30,20,开始绘制3次Bezier曲线,单击左键绘制控制多边形,单击右键绘制曲线);float xx,yy;for(int j=0;jMoveTo(xx-3,yy-3);pDC-LineTo(xx+3,yy+3);pDC-MoveTo(xx-3,yy+3);pDC-LineTo(xx+3,yy-3);bezier(pDC,4, T, point);ReleaseDC(pDC);void CBezierView:OnRButtonDown(UINT nFlags, CPoint point)/调用绘制函数 / TODO: Add your message handler code here and/or call defaultOnBezier();/CBezierView:OnRButtonDown(nFlags, point);void CBezierView:OnLButtonDown(UINT nFlags, CPoint point1)/获得屏幕控制点坐标 / TODO: Add your message handler code here and/or call default /CBezierView:OnLButtonDown(nFlags, point);CDC *pDC=GetDC();float xx,yy;if(kMoveTo(xx-3,yy-3);pDC-LineTo(xx+3,yy+3);pDC-MoveTo(xx-3,yy+3);pDC-LineTo(xx+3,yy-3);if(k=1)pDC-MoveTo(pointk-10,pointk-11);pDC-LineTo(xx,yy);k+;/ BezierView.h : interface of the CBezierView class/#if !defined(AFX_BEZIERVIEW_H_8885C30A_7A50_4D01_860B_812CED746C52_INCLUDED_)#define AFX_BEZIERVIEW_H_8885C30A_7A50_4D01_860B_812CED746C52_INCLUDED_#if _MSC_VER 1000#pragma once#endif / _MSC_VER 1000class CBezierView : public CViewprotected: / create from serialization onlyCBezierView();DECLARE_DYNCREATE(CBezierView)/ Attributespublic:CBezierDoc* GetDocument();/ Operationspublic:/ Overrides/ ClassWizard generated virtual function overrides/AFX_VIRTUAL(CBezierView)public:virtual void OnDraw(CDC* pDC); / overridden to draw this viewvirtual BOOL PreCreateWindow(CREATESTRUCT& cs);protected:virtual BOOL OnPreparePrinting(CPrintInfo* pInfo);virtual void OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo);virtual void OnEndPrinting(CDC* pDC, CPrintInfo* pInfo);/AFX_VIRTUAL/ Implementationpublic:virtual CBezierView();#ifdef _DEBUGvirtual void AssertValid() const;virtual void Dump(CDumpContext& dc) const;#endifprotected:/ Generated message map functionsprotected:/AFX_MSG(CBezierView)/ NOTE - the ClassWizard will add and remove member functions here./ DO NOT EDIT what you see in these blocks of generated code !afx_msg void OnBezier();afx_msgvoid OnRButtonDown(UINT nFlags, CPoint point);afx_msgvoid OnLButtonDown(UINT nFlags, CPoint point);/AFX_MSGDECLARE_MESSAGE_MAP();#ifndef _DEBUG / debug version in BezierView.cppinline CBezierDoc* CBezierView:GetDocument() return (CBezierDo
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025年国机数字科技有限公司社会招聘笔试参考题库带答案详解版
- 2025年丙肝诊断试题及答案
- 2025年有关科技的试题及答案
- 2025年华为人工智能方向HCIA考试题库(含答案)
- 动物的英语演讲稿
- 乞丐版nvme协议书
- 2025年初中地理试题试卷及答案
- 史知识竞赛演讲稿
- 2025年院内感染相关试题及答案
- 2025年数学微积分测试题及答案
- 会计科目对照表
- 基于中医古籍的老年衰弱中医干预方法述要
- 检具技术协议
- 《微波传输基本理论》课件
- 安徽省合肥市第四十五中学2023-2024学年八年级上学期期中物理试题
- 四年级少先队活动课教案(完整版)
- 医院内静脉血栓栓塞症防治质量评价与管理指南(2022版)
- GB/T 12223-2023部分回转阀门驱动装置的连接
- 教育版机器人入门教程(乐聚机器人)
- 保安服务意识及礼仪
- MSL湿敏物料管控作业指导书
评论
0/150
提交评论