图形学实验报告2分解Word文档下载推荐.docx
《图形学实验报告2分解Word文档下载推荐.docx》由会员分享,可在线阅读,更多相关《图形学实验报告2分解Word文档下载推荐.docx(24页珍藏版)》请在冰点文库上搜索。
TransformView.h"
#include<
math.h>
#ifdef_DEBUG
#definenewDEBUG_NEW
#undefTHIS_FILE
staticcharTHIS_FILE[]=__FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
//CTransformView
IMPLEMENT_DYNCREATE(CTransformView,CView)
BEGIN_MESSAGE_MAP(CTransformView,CView)
//{{AFX_MSG_MAP(CTransformView)
ON_COMMAND(ID_MENU_TRANSFORM_TRANSLATE,OnMenuTransformTranslate)
ON_COMMAND(ID_MENU_TRANSFORM_SCALE,OnMenuTransformScale)
ON_COMMAND(ID_MENU_TRANSFORM_ROTATE,OnMenuTransformRotate)
ON_WM_KEYDOWN()
//}}AFX_MSG_MAP
//Standardprintingcommands
ON_COMMAND(ID_FILE_PRINT,CView:
:
OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT,CView:
ON_COMMAND(ID_FILE_PRINT_PREVIEW,CView:
OnFilePrintPreview)
END_MESSAGE_MAP()
//CTransformViewconstruction/destruction
CTransformView:
CTransformView()
{
//TODO:
addconstructioncodehere
Pt[0].x=200;
Pt[0].y=220;
Pt[1].x=260;
Pt[1].y=300;
Pt[2].x=360;
Pt[2].y=180;
dAngle=0.0;
}
~CTransformView()
BOOLCTransformView:
PreCreateWindow(CREATESTRUCT&
cs)
ModifytheWindowclassorstylesherebymodifying
//theCREATESTRUCTcs
returnCView:
PreCreateWindow(cs);
//CTransformViewdrawing
voidCTransformView:
OnDraw(CDC*pDC)
CTransformDoc*pDoc=GetDocument();
ASSERT_VALID(pDoc);
adddrawcodefornativedatahere
DrawTriangle(pDC);
//CTransformViewprinting
OnPreparePrinting(CPrintInfo*pInfo)
//defaultpreparation
returnDoPreparePrinting(pInfo);
OnBeginPrinting(CDC*/*pDC*/,CPrintInfo*/*pInfo*/)
addextrainitializationbeforeprinting
OnEndPrinting(CDC*/*pDC*/,CPrintInfo*/*pInfo*/)
addcleanupafterprinting
//CTransformViewdiagnostics
AssertValid()const
CView:
AssertValid();
Dump(CDumpContext&
dc)const
Dump(dc);
CTransformDoc*CTransformView:
GetDocument()//non-debugversionisinline
ASSERT(m_pDocument->
IsKindOf(RUNTIME_CLASS(CTransformDoc)));
return(CTransformDoc*)m_pDocument;
#endif//_DEBUG
//CTransformViewmessagehandlers
DrawTriangle(CDC*pDC)
pDC->
MoveTo(Pt[0]);
LineTo(Pt[1]);
LineTo(Pt[2]);
LineTo(Pt[0]);
OnMenuTransformTranslate()
Addyourcommandhandlercodehere
intnX=50;
intnY=80;
//平移的X坐标和Y坐标
for(inti=0;
i<
3;
i++)
{
Pt[i].x+=nX;
Pt[i].y+=nY;
}
RedrawWindow();
OnMenuTransformScale()
floatdScaleX=2.0;
floatdScaleY=0.5;
Pt[i].x*=dScaleX;
Pt[i].y*=dScaleY;
#definePI3.1415926
OnMenuTransformRotate()
floatdRadiusAngle=30.0*PI/180.0;
Pt[i].x=Pt[i].x*cos(dRadiusAngle)-Pt[i].y*sin(dRadiusAngle);
Pt[i].y=Pt[i].x*sin(dRadiusAngle)+Pt[i].y*cos(dRadiusAngle);
OnKeyDown(UINTnChar,UINTnRepCnt,UINTnFlags)
Addyourmessagehandlercodehereand/orcalldefault
inti=0;
CPointTmpPt=Pt[0];
switch(nChar){
caseVK_UP:
//上
for(i=0;
{
Pt[i].y-=5;
}
break;
caseVK_DOWN:
//下
Pt[i].y+=5;
caseVK_LEFT:
//左
Pt[i].x-=5;
caseVK_RIGHT:
//右
Pt[i].x+=5;
case0X5A:
//Z的ASCII码
Pt[1]=Pt[1]-Pt[0];
Pt[2]=Pt[2]-Pt[0];
Pt[0].x=Pt[0].y=0;
for(i=1;
Pt[i].x*=0.5;
Pt[i].y*=0.5;
Pt[0]=TmpPt;
Pt[1]=Pt[1]+Pt[0];
Pt[2]=Pt[2]+Pt[0];
case0X58:
//X的ASCII码
Pt[i].x*=2.0;
Pt[i].y*=2.0;
case0X52:
//R的ASCII码
dAngle=-1.0;
floatdRadiusAngle=dAngle*PI/180.0;
for(inti=1;
i++)//由于CPoint的x和y坐标值都为正值,所以如果计算出是负值来时,就直接赋0
Pt[i].x=(float)Pt[i].x*cos(dRadiusAngle)-(float)Pt[i].y*sin(dRadiusAngle);
Pt[i].y=(float)Pt[i].x*sin(dRadiusAngle)+(float)Pt[i].y*cos(dRadiusAngle);
OnKeyDown(nChar,nRepCnt,nFlags);
2、中心投影
中心投影.h"
中心投影Doc.h"
中心投影View.h"
math.h"
dlg.h"
dlgangl.h"
point.h"
#include<
time.h>
//时间处理函数原型及数据结构
pointp[10],tp[10];
intxx;
//CMyView
IMPLEMENT_DYNCREATE(CMyView,CView)
BEGIN_MESSAGE_MAP(CMyView,CView)
//{{AFX_MSG_MAP(CMyView)
ON_COMMAND(IDC_dai,Ondai)
ON_COMMAND(IDD_anypoint,Onanypoint)
ON_COMMAND(IDD_any2,Onany2)
ON_COMMAND(IDD_anyPmap,OnanyPmap)
//CMyViewconstruction/destruction
CMyView:
CMyView()
~CMyView()
BOOLCMyView:
//CMyViewdrawing
voidCMyView:
CMyDoc*pDoc=GetDocument();
/*edgeEd[12];
facefc[6];
inta=200;
volumv;
v.num=12;
v.en[0]=0;
v.en[1]=1;
v.en[2]=2;
v.en[3]=3;
v.en[4]=4;
v.en[5]=5;
v.en[6]=6;
v.en[7]=7;
v.en[8]=8;
v.en[9]=9;
v.en[10]=10;
v.en[11]=11;
//pDC->
LineTo(100,100);
p[0].x=a;
p[0].y=a;
p[0].z=a;
p[1].x=100+a;
p[1].y=a;
p[1].z=a;
p[2].x=100+a;
p[2].y=100+a;
p[2].z=a;
p[3].x=a;
p[3].y=100+a;
p[3].z=a;
p[4].x=a;
p[4].y=a;
p[4].z=100+a;
p[5].x=100+a;
p[5].y=a;
p[5].z=100+a;
p[6].x=100+a;
p[6].y=100+a;
p[6].z=100+a;
p[7].x=a;
p[7].y=100+a;
p[7].z=100+a;
//pDC->
LineTo(p[6].x+100,p[6].y);
Ed[0].sn=0;
Ed[0].en=1;
Ed[1].sn=1;
Ed[1].en=2;
Ed[2].sn=2;
Ed[2].en=3;
Ed[3].sn=3;
Ed[3].en=0;
Ed[4].sn=4;
Ed[4].en=5;
Ed[5].sn=5;
Ed[5].en=6;
Ed[6].sn=6;
Ed[6].en=7;
Ed[7].sn=7;
Ed[7].en=4;
Ed[8].sn=0;
Ed[8].en=4;
Ed[9].sn=1;
Ed[9].en=5;
Ed[10].sn=2;
Ed[10].en=6;
Ed[11].sn=3;
Ed[11].en=7;
doubleseta=-3.14/6,fai=-3.14/8;
doublesseta,cseta,sfai,cfai;
CStrings;
sseta=sin(seta);
cseta=cos(seta);
sfai=sin(fai);
cfai=cos(fai);
s.Format("
%.2f%.2f%.2f%.2f"
sseta,cseta,sfai,cfai);
pDC->
TextOut(100,100,s);
floatxe,ye,ze,x,y,z;
inti,j,k,D=600,d=200;
longtx,ty;
for(i=0;
i<
8;
i++)
{xe=p[i].x*cseta-p[i].y*sseta;
ye=p[i].x*sseta*cfai+p[i].y*cseta*cfai-p[i].z*sfai;
ze=D-(p[i].x*sseta*sfai+p[i].y*cseta*sfai+p[i].z*cfai);
tp[i].x=d*xe/ze;
//p[i].x;
tp[i].y=d*ye/ze;
//p[i].y;
}
intesn,een,ent;
12;
i++)//v.num;
{
esn=Ed[v.en[i]].sn;
een=Ed[v.en[i]].en;
tx=tp[esn].x;
ty=tp[esn].y;
**%d%d%d%d"
esn,een,tx,ty);
TextOut(200+j*30,200+j*20,s);
MoveTo(tx,ty);
//要求int
tx=tp[een].x;
ty=tp[een].y;
LineTo(tx,ty);
*/
//CMyViewdiagnostics
CMyDoc*CMyView:
IsKindOf(RUNTIME_CLASS(CMyDoc)));
return(CMyDoc*)m_pDocument;
//CMyViewmessagehandlers
//操作步骤:
1.改变d的大小:
可见z轴向外,
//2。
改变y的大小,确定y或x方向
//3。
旋转seita=30,确定绕z轴转
//4。
旋转fai=90,确定绕x轴转
//5.一起转,看结果
MatrixM(array3Ao,array3A1,array3A2)
{inti,j;
//Ao[1][1]=A1[1][1]*A2[1][1]+A1[1]