三维图形几何变换与投影变换Word格式文档下载.doc
《三维图形几何变换与投影变换Word格式文档下载.doc》由会员分享,可在线阅读,更多相关《三维图形几何变换与投影变换Word格式文档下载.doc(7页珍藏版)》请在冰点文库上搜索。
BuildPointEdge()
{
doubled=400;
P[0].x=d/2;
P[0].y=d/2;
P[0].z=d/2;
P[1].x=d/2;
P[1].y=-d/2;
P[1].z=-d/2;
P[2].x=-d/2;
P[2].y=-d/2;
P[2].z=d/2;
P[3].x=-d/2;
P[3].y=d/2;
P[3].z=-d/2;
E[0].SetPointsIndex(0,1);
E[1].SetPointsIndex(0,2);
E[2].SetPointsIndex(0,3);
E[3].SetPointsIndex(1,2);
E[4].SetPointsIndex(1,3);
E[5].SetPointsIndex(2,3);
}
OnDraw(CDC*pDC)
CTrans3DDoc*pDoc=GetDocument();
ASSERT_VALID(pDoc);
if(!
pDoc)
return;
//TODO:
在此处为本机数据添加绘制代码
CRectrect;
GetClientRect(&
rect);
pDC->
SetMapMode(MM_ANISOTROPIC);
SetWindowExt(rect.Width(),rect.Height());
SetViewportExt(rect.Width(),-rect.Height());
SetViewportOrg(rect.Width()/2,rect.Height()/2);
//双缓冲机制
CDCMemDC;
CBitmapNewBitmap,*pOldBitmap;
MemDC.CreateCompatibleDC(pDC);
NewBitmap.CreateCompatibleBitmap(pDC,rect.Width(),rect.Height());
//兼容位图
pOldBitmap=MemDC.SelectObject(&
NewBitmap);
//将兼容位图选入MemDc
MemDC.FillSolidRect(rect,pDC->
GetBkColor());
MemDC.SetMapMode(MM_ANISOTROPIC);
MemDC.SetWindowExt(rect.Width(),rect.Height());
MemDC.SetViewportExt(rect.Width(),-rect.Height());
MemDC.SetViewportOrg(rect.Width()/2,rect.Height()/2);
Line*line=newLine;
//动态创建直线绘制类对象
//绘制坐标轴
line->
SetLineColor(RGB(0,0,0));
MoveTo(CP2(-rect.Width()/2,0));
//X轴
LineTo(CP2(rect.Width()/2,0),&
MemDC);
MoveTo(CP2(0,-rect.Height()/2));
//Y轴
LineTo(CP2(0,rect.Height()/2),&
//旋转、缩放、正交投影变换
CTrans3tans;
tans.SetPoints(P,4);
//在0.5~2.0之间缩放
staticdoubles=1.0;
staticdoublestep=0.01;
if(s>
=2.0||s<
=0.5)
step=-step;
s+=step;
tans.Scale(s,s,s);
//绕Y轴匀速逆时针旋转
staticfloattheta=0.0;
theta+=1.0;
if(theta>
360)
theta=0.0;
tans.RotateY(theta);
//二维正交投影
tans.ProjXOY();
//绘制动态旋转和缩放的四面体
for(inti=0;
i<
6;
i++)
{
line->
SetLineColor(RGB(0,255,0));
MoveTo(tans.m_p2Screen[E[i].Start]);
LineTo(tans.m_p2Screen[E[i].End],&
}
deleteline;
//将内存位图拷贝到屏幕
BitBlt(-rect.Width()/2,-rect.Height()/2,rect.Width(),rect.Height(),&
MemDC,-rect.Width()/2,-rect.Height()/2,SRCCOPY);
MemDC.SelectObject(pOldBitmap);
NewBitmap.DeleteObject();
Invalidate(FALSE);
3.2程序设计实现及流程图
平移变换矩阵
绕x,y,z旋转变换矩阵
比例变换矩阵
流程图:
4典型测试结果
5实验问题总结
通过这次试验让我知道了要实现三维图形几何变换主要还是依靠二位图形几何变换的变换矩阵,包括平移变换矩阵,绕X、Y、Z旋转变换矩阵,比例变换矩阵,正交投影变换矩阵。
通过这几个变换矩阵相乘即可可到三维图形最终的变换矩阵,将其与原来的矩阵做一次相乘即可得到最终矩阵。
透视投影变换的过程分为两步:
从世界坐标系到观察坐标系的观察变换;
从观察坐标系到屏幕坐标系的透视变换。
观察变换和透视变换也分别通过一个变换矩阵实现。