计算机图形学课程设计报告文档格式.docx
《计算机图形学课程设计报告文档格式.docx》由会员分享,可在线阅读,更多相关《计算机图形学课程设计报告文档格式.docx(12页珍藏版)》请在冰豆网上搜索。
成果验收形式:
课程设计报告(纸质)
程序运行效果图
参考文献:
时间
安排
廖宁教研室主任:
2018年12月06日
注:
本表下发学生一份,指导教师一份,栏目不够时请另附页。
课程设计任务书装订于设计计算说明书(或论文)封面之后,目录页之前。
一.设计目的……………………………………………………………
二.设计要求……………………………………………………………
1.构建基础类……………………………………………………
2.构建直线类……………………………………………………
3.构建变换类……………………………………………………
4.构建填充类……………………………………………………
5.构建光照类……………………………………………………
三.开发环境…………………………………………………………
四.详细设计
五.源程序
六.程序运行效果图
七.总结
设计目的
▪培养对图形建模、变换、投影、消隐、光照原理的理解和应用。
▪培养图形类的编程能力。
▪培养计算机图形学应用软件开发的能力。
设计要求
深入研究计算机图形学的生成原理,设计算法实现具体的类。
1.构建基础类
实现CP2类绘制二维点;
实现CP3类绘制三维点;
实现CRGB类处理RGB颜色;
实现CVector类处理矢量。
2.构建直线类
实现CLine类绘制任意斜率的直线、实现CALine类绘制任意斜率的反走样直线、实现CCLine类绘制任意斜率的颜色渐变直线、实现CACLine类绘制任意斜率的反走样颜色渐变直线。
3.构建变换类
实现CTransForm完成二维和三维图形变换。
4.构建填充类
实现CFill类使用有效边表算法填充多边形、实现CZBuffer类进行深度缓冲消隐,并使用Gouraud和Phong明暗处理填充图形面片。
5.构建光照类
实现CLight类设置点光源、实现CMaterial类设置物体材质、实现CLighting类对物体实施光照。
开发环境
ViusalC++6.0的MFC框架。
详细设计
1.利用函数Ellipse画出人物的脸,并用给脸填充颜色。
再利用Ara画出人物的嘴巴。
CRect确定人物的眼睛,给眼睛填充颜色。
利用画笔画出人物的鼻子。
2.添加ddaline()成员函数,编写自定义的成员函数ddaline()程序,编写OnDraw()函数,画出人物的脚和脚趾。
3.添加星星star()成员函数,编写自定义的成员函数star()程序,确定五角星的位置、大小和颜色。
4.添加五环circle()成员函数,并利用colorcircle()函数给五环上色。
5.添加旗子flayA()、flayB()成员函数,确定旗杆的位置,用四点坐标设置旗子的范围,将星星和五环置于旗子中。
源程序
//Yzg20166989View.cpp:
implementationoftheCYzg20166989Viewclass
//
#include"
stdafx.h"
Yzg20166989.h"
math.h"
Yzg20166989Doc.h"
Yzg20166989View.h"
#ifdef_DEBUG
#definenewDEBUG_NEW
#undefTHIS_FILE
staticcharTHIS_FILE[]=__FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
//CYzg20166989View
IMPLEMENT_DYNCREATE(CYzg20166989View,CView)
BEGIN_MESSAGE_MAP(CYzg20166989View,CView)
//{{AFX_MSG_MAP(CYzg20166989View)
//NOTE-theClassWizardwilladdandremovemappingmacroshere.
//DONOTEDITwhatyouseeintheseblocksofgeneratedcode!
//}}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()
//CYzg20166989Viewconstruction/destruction
CYzg20166989View:
CYzg20166989View()
{
//TODO:
addconstructioncodehere
}
~CYzg20166989View()
BOOLCYzg20166989View:
PreCreateWindow(CREATESTRUCT&
cs)
ModifytheWindowclassorstylesherebymodifying
//theCREATESTRUCTcs
returnCView:
PreCreateWindow(cs);
//CYzg20166989Viewdrawing
voidCYzg20166989View:
OnDraw(CDC*pDC)
CYzg20166989Doc*pDoc=GetDocument();
ASSERT_VALID(pDoc);
adddrawcodefornativedatahere
AfxGetMainWnd()->
SetWindowText("
20166989尹志刚"
);
graph(pDC,0,0);
CRectrect(200,120,430,350);
CRectrect1(250,195,275,220);
CRectrect2(355,195,380,220);
CBrushnBrush(RGB(0,255,255)),*pOldnBrush;
pOldnBrush=pDC->
SelectObject(&
nBrush);
pDC->
Ellipse(200,120,430,350);
SelectObject(pOldnBrush);
CBrushBrush(RGB(0,0,0)),*pOldBrush;
pOldBrush=pDC->
Brush);
RoundRect(rect1,CPoint(200,200));
RoundRect(rect2,CPoint(200,200));
SelectObject(pOldBrush);
CBrushmBrush(RGB(255,255,0)),*pOldmBrush;
pOldmBrush=pDC->
mBrush);
Arc(250,275,380,355,295,285,335,285);
SelectObject(pOldmBrush);
CPointp1(305,295),p2(325,295);
CPenPen,*pOldPen;
Pen.CreatePen(PS_SOLID,3,RGB(0,0,0));
pOldPen=pDC->
Pen);
MoveTo(p1);
LineTo(p2);
SelectObject(pOldPen);
SetTextColor(RGB(0,0,255));
TextOut(225,20,"
同一个世界,同一个梦想"
ddaline(pDC,225,305,225,450,RGB(255,0,0));
ddaline(pDC,405,305,405,450,RGB(255,0,0));
ddaline(pDC,225,450,225,460,RGB(0,0,0));
ddaline(pDC,225,450,215,460,RGB(0,0,0));
ddaline(pDC,225,450,235,460,RGB(0,0,0));
ddaline(pDC,405,450,405,460,RGB(0,0,0));
ddaline(pDC,405,450,395,460,RGB(0,0,0));
ddaline(pDC,405,450,415,460,RGB(0,0,0));
//CYzg20166989Viewprinting
OnPreparePrinting(CPrintInfo*pInfo)
//defaultpreparation
returnDoPreparePrinting(pInfo);
OnBeginPrinting(CDC*/*pDC*/,CPrintInfo*/*pInfo*/)
addextrainitializationbeforeprinting
OnEndPrinting(CDC*/*pDC*/,CPrintInfo*/*pInfo*/)
addcleanupafterprinting
//CYzg20166989Viewdiagnostics
AssertValid()const
CView:
AssertValid();
Dump(CDumpContext&
dc)const
Dump(dc);
CYzg20166989Doc*CYzg20166989View:
GetDocument()//non-debugversionisinline
ASSERT(m_pDocument->
IsKindOf(RUNTIME_CLASS(CYzg20166989Doc)));
return(CYzg20166989Doc*)m_pDocument;
#endif//_DEBUG
//CYzg20166989Viewmessagehandlers
ddaline(CDC*pDC,intx0,inty0,intx1,inty1,COLORREFcolor)
intlength,i;
doublex,y,dx,dy;
length=abs(x1-x0);
if(abs(y1-y0)>
length)
length=abs(y1-y0);
dx=(x1-x0)/length;
dy=(y1-y0)/length;
x=x0+0.5;
y=y0+0.5;
for(i=1;
i<
=length;
i++)
{
pDC->
SetPixel((int)x,(int)y,color);
x=x+dx;
y=y+dy;
}
flagA(CDC*pDC,intx,inty)
CBrush
redBrush(RGB(0xFF,0,0)),
yellowBransh(RGB(0xFF,0xff,0)),
woodBrash(RGB(180,180,180)),
*oldBrush;
oldBrush=pDC->
redBrush);
Rectangle(x+20,y+0,x+140,y+70);
woodBrash);
Rectangle(x+15,y+0,x+20,y+100);
yellowBransh);
SetPolyFillMode(WINDING);
star(pDC,x+40,y+20,10);
star(pDC,x+60,y+13,6);
star(pDC,x+62,y+30,6);
star(pDC,x+55,y+43,6);
star(pDC,x+40,y+48,6);
SelectObject(oldBrush);
flagB(CDC*pDC,intx,inty)
Rectangle(x+85,y+0,x+205,y+70);
Rectangle(x+205,y+0,x+210,y+100);
CPen
p1(PS_SOLID,2,RGB(0x09,0x51,0xA0)),
p2(PS_SOLID,2,RGB(0x05,0x05,0x05)),
p3(PS_SOLID,2,RGB(0xFE,0x01,0x00)),
p4(PS_SOLID,2,RGB(0xFC,0xFD,0x04)),
p5(PS_SOLID,2,RGB(0x30,0xA0,0x2D));
colorCircle(pDC,&
p1,x+60+65,y+30,10);
p2,x+82+65,y+30,10);
p3,x+104+65,y+30,10);
p4,x+70+65,y+46,10);
p5,x+92+65,y+46,10);
star(CDC*pDC,intx,inty,intr)
CPointstars[5];
constdoublePI=3.1415926;
doublealpha=PI/10;
doublebeta=2*PI/5;
for(inti=0;
5;
i++){
stars[i].x=ceil(r*cos(i*beta+alpha))+x;
stars[i].y=ceil(r*sin(i*beta+alpha))+y;
CPointstarx[5]={
stars[0],
stars[2],
stars[4],
stars[1],
stars[3],
};
Polygon(starx,5);
colorCircle(CDC*pDC,CPen*pen,intx,inty,intr)
CPen*old;
old=pDC->
SelectObject(pen);
circle(pDC,x,y,r,FALSE);
SelectObject(old);
circle(CDC*pDC,intx,inty,intr,BOOLfill)
if(fill==TRUE){
CBrushnewBrush,*oldBrush;
newBrush.CreateSolidBrush(RGB(0X33,0X33,0X33));
oldBrush=pDC->
newBrush);
Ellipse(CRect(x-r,y-r,x+r,y+r));
}else{
graph(CDC*pDC,intx,inty)
flagA(pDC,x+360,y+42);
flagB(pDC,x+40,y+44);
程序运行效果图
总结
通过课程设计项目的设计、开发、测试、总结和验收各阶段,深入理解计算机图形学课程中的理论和算法,学习计算机图形学相关类的编程技巧,初步掌握游戏开发的前期技能。