西工大 CC++大作业Word下载.docx

上传人:b****8 文档编号:22509738 上传时间:2023-02-04 格式:DOCX 页数:87 大小:234.08KB
下载 相关 举报
西工大 CC++大作业Word下载.docx_第1页
第1页 / 共87页
西工大 CC++大作业Word下载.docx_第2页
第2页 / 共87页
西工大 CC++大作业Word下载.docx_第3页
第3页 / 共87页
西工大 CC++大作业Word下载.docx_第4页
第4页 / 共87页
西工大 CC++大作业Word下载.docx_第5页
第5页 / 共87页
点击查看更多>>
下载资源
资源描述

西工大 CC++大作业Word下载.docx

《西工大 CC++大作业Word下载.docx》由会员分享,可在线阅读,更多相关《西工大 CC++大作业Word下载.docx(87页珍藏版)》请在冰豆网上搜索。

西工大 CC++大作业Word下载.docx

2.4开发日志19

3程序调试及运行19

3.1程序运行结果19

3.2程序使用说明22

3.3程序开发总结23

4附件(源程序)23

/*在后面的文档编写中,请你不要修改各个标题的内容,从而确保报告内容和风格一致。

完成全部内容后,你只需要在上面的目录上右键“更新域”,选择“只更新页码”就可以更新正确的目录页码。

注意:

目录的左边距为6.5厘米。

*/

1摘要

1.1设计题目

加强原有台球小游戏的功能和制作背景,加强观赏性

1.2设计内容

根据网上查找原有台球游戏代码资料,在billiards.cpp中对台球的操作按键进行了修改(括号内为原来按键):

1.将视图左旋转该为A键(向左键),右旋转改为D键(向右键),缩小改为S键(向下键);

推杆键改为T键(向上键);

增加推杆力度改为E键(<

键);

减少推杆力度改为F键(>

键)。

2.增加修饰物,增加了背景图片和背景音乐。

3.更改击规则。

1.3开发工具

codeblocks和Win32。

1.4应用平台

Windows7/Vista32位

2详细设计

2.1程序结构

本游戏程序主要由3大模块组成,1.主控制模块(说明模块),2.台球控制模块,3.背景控制模块。

各模块主要功能如2.2中说明。

2.2主要功能

1.主控制模块:

给游戏参与者一个较为友好的界面,并对游戏规则进行相关说明。

并在该模块对游戏按键进行了更改。

其代码为附录中billiards.cpp。

2.台球控制模块:

主要功能是由向量法控制台球沿推杆方向前进。

其代码为附录中mySphere.cpp。

3.背景控制模块:

主要功能是实现背景图片链接和背景音乐的链接。

其代码为附录中vector.cpp。

2.3函数实现

1.

intImageLoad(constchar*filename,Image*image){

FILE*file;

unsignedlongsize;

unsignedlongi;

unsignedshortintplanes;

unsignedshortintbpp;

chartemp,finalName[80];

strcpy(finalName,"

textures/"

);

strcat(finalName,filename);

if((file=fopen(finalName,"

rb"

))==NULL){

printf("

FileNotFound:

%s\n"

finalName);

return0;

}

fseek(file,18,SEEK_CUR);

if((i=fread(&

image->

sizeX,4,1,file))!

=1){

Errorreadingwidthfrom%s.\n"

finalName);

sizeY,4,1,file))!

Errorreadingheightfrom%s.\n"

size=image->

sizeX*image->

sizeY*3;

if((fread(&

planes,2,1,file))!

Errorreadingplanesfrom%s.\n"

if(planes!

Planesfrom%sisnot1:

%u\n"

finalName,planes);

bpp,2,1,file))!

Errorreadingbppfrom%s.\n"

if(bpp!

=24){

printf("

Bppfrom%sisnot24:

finalName,bpp);

return0;

fseek(file,24,SEEK_CUR);

image->

data=(char*)malloc(size);

if(image->

data==NULL){

Errorallocatingmemoryforcolor-correctedimagedata"

);

if((i=fread(image->

data,size,1,file))!

Errorreadingimagedatafrom%s.\n"

for(i=0;

i<

size;

i+=3){

temp=image->

data[i];

image->

data[i]=image->

data[i+2];

data[i+2]=temp;

return1;

}实现台球控制/

增加背图片

glBindTexture(GL_TEXTURE_2D,surfaceTexture);

for(GLfloatk=(width/(-2.0));

k<

(width/(2.0));

k+=(width/widthSegments)){

for(GLfloatr=(length/(-2.0));

r<

(length/(2.0));

r+=(length/lengthSegments)){

glBegin(GL_QUADS);

glNormal3f(normalX,normalY,normalZ);

glTexCoord2f(0.0,texYTile);

glVertex3f(k,elevation,r+length/lengthSegments);

glTexCoord2f(texXTile,texYTile);

glVertex3f(k+width/widthSegments,elevation,r+length/lengthSegments);

glTexCoord2f(texXTile,0.0);

glVertex3f(k+width/widthSegments,elevation,r);

glTexCoord2f(0.0,0.0);

glVertex3f(k,elevation,r);

glEnd();

}

}

glPopMatrix();

}

//呈现方式为任意4点,屏幕代表的四

voidrenderQuad(GLfloatpoint1[3],GLfloatpoint2[3],GLfloatpoint3[3],GLfloatpoint4[3],GLfloatorientation,GLfloattexXTile,GLfloattexYTile){

glBegin(GL_QUADS);

vector3theNormal=vector3(0.0,0.0,0.0);

theNormal=getNormal(point1,point3,point4);

theNormal=theNormal*orientation;

glNormal3f(theNormal.x,theNormal.y,theNormal.z);

glTexCoord2f(0.0,texYTile);

glVertex3fv(point1);

glTexCoord2f(texXTile,texYTile);

glVertex3fv(point2);

glTexCoord2f(texXTile,0.0);

glVertex3fv(point3);

glTexCoord2f(0.0,0.0);

glVertex3fv(point4);

glEnd();

//呈现曲线(任意高度和扫描部分缸)屏幕。

voidrenderCurve(GLfloatradius,GLfloatheight,GLfloatsweep,GLuintsegments,GLfloatorientation,GLuint&

aTexture){

glPushMatrix();

glBindTexture(GL_TEXTURE_2D,aTexture);

for(floatt=0.0;

t<

=sweep-(sweep/segments);

t+=sweep/segments){

GLfloatx=0.0,y=0.0,z=0.0;

GLfloatpoint1[3]={radius*cos(t),height,radius*sin(t)};

GLfloatpoint2[3]={radius*cos(t+sweep/segments),height,radius*sin(t+sweep/segments)};

GLfloatpoint3[3]={radius*cos(t+sweep/segments),0.0,radius*sin(t+sweep/segments)};

GLfloatpoint4[3]={radius*cos(t),0.0,radius*sin(t)};

renderQuad(point1,point2,point3,point4,orientation,1.0,1.0);

//渲染任何扫到屏幕的光盘(上限为圆柱体)。

voidrenderCap(GLfloatinner_radius,GLfloatouter_radius,GLfloatinner_sweep,GLfloatouter_sweep,GLuintsegments,GLuint&

myTexture){

GLfloatciX=0.0,coX=0.0,ciZ=0.0,coZ=0.0;

GLfloatangle=-1.0*outer_sweep/segments;

glBindTexture(GL_TEXTURE_2D,myTexture);

for(intk=0;

segments;

k++){

ciX=inner_radius*cos(angle+inner_sweep/segments);

ciZ=inner_radius*sin(angle+inner_sweep/segments);

coX=outer_radius*cos(angle+outer_sweep/segments);

coZ=outer_radius*sin(angle+outer_sweep/segments);

angle+=inner_sweep/segments;

glNormal3f(0.0,1.0,0.0);

glTexCoord2f(coX/(2.0*outer_radius),coZ/(2.0*outer_radius));

glVertex3f(coX,0.0,coZ);

glTexCoord2f(outer_radius*cos(angle+outer_sweep/segments)/(2.0*outer_radius),outer_radius*sin(angle+outer_sweep/segments)/(2.0*outer_radius));

glVertex3f(outer_radius*cos(angle+outer_sweep/segments),0.0,outer_radius*sin(angle+outer_sweep/segments));

glTexCoord2f(inner_radius*cos(angle+inner_sweep/segments)/(2.0*inner_radius),inner_radius*sin(angle+inner_sweep/segments)/(2.0*inner_radius));

glVertex3f(inner_radius*cos(angle+inner_sweep/segments),0.0,inner_radius*sin(angle+inner_sweep/segments));

glTexCoord2f(ciX/(2.0*inner_radius),ciZ/(2.0*inner_radius));

glVertex3f(ciX,0.0,ciZ);

//使得通用校准和预定义扫到屏幕的口袋

voidrenderPocket(GLfloatsweep){

glTranslatef(0.0,-1.55,0.0);

renderCurve(5.5,2.55,sweep,16,1,theTexture[DARK_WOOD]);

renderCurve(3.0,2.55,sweep,16,-1,theTexture[GREEN_CARPET]);

renderCap(0.0001,5.5,6.3,6.3,16,theTexture[BLACK]);

glTranslatef(0.0,1.0,0.0);

renderCap(3.0,5.5,sweep,sweep,16,theTexture[DARK_WOOD]);

glTranslatef(0.0,-1.4,0.0);

if(sweep<

M_PI+0.001)renderCap(0.0001,3.0,M_PI,M_PI,16,theTexture[BLACK]);

elserenderCap(0.0001,3.0,6.3,6.3,16,theTexture[BLACK]);

//呈现弯曲的桌腿屏幕

voidrenderTableLegs(){

glNewList(displayList[4],GL_COMPILE);

glBindTexture(GL_TEXTURE_2D,theTexture[DARK_WOOD]);

for(doublek=0;

3.0*M_PI;

k+=1.4){

for(doubleg=0;

g<

M_PI*2.0;

g+=0.5){

GLfloatpoint1[3]={3.0*sin((k+1.4)/3.0)*cos(g),k*2,3.0*sin((k+1.4)/3.0)*sin(g)};

GLfloatpoint2[3]={3.0*sin((k+1.4)/3.0)*cos(g+0.5),k*2,3.0*sin((k+1.4)/3.0)*sin(g+0.5)};

GLfloatpoint3[3]={3.0*sin(k/3.0)*cos(g+0.5),k*2-2.8,3.0*sin(k/3.0)*sin(g+0.5)};

GLfloatpoint4[3]={3.0*sin(k/3.0)*cos(g),k*2-2.8,3.0*sin(k/3.0)*sin(g)};

renderQuad(point1,point2,point3,point4,1.0,1.0,1.0);

glRotatef(90.0,1.0,0.0,0.0);

glutSolidTorus(1.0,1.8,5,8);

gluCylinder(pillarCylinder,1.0,3.0,4.0,8,2);

glEndList();

//绘制表格的一侧(通常对齐)

voiddrawSide(){

glTranslatef(0,-0.3,0);

glScalef(1.0,1.0,2.0);

glRotatef(270.0,0.0,1.0,0.0);

glRotatef(45.0,0.0,0.0,1.0);

glBindTexture(GL_TEXTURE_2D,theTexture[WOOD]);

gluCylinder(pillarCylinder,1.7,1.7,tableWidth-6,4,4);

//绿地毯的一侧

glTranslatef(-1.0*tableWidth+6,0.0,-2.35);

glRotatef(180.0,0.0,0.0,1.0);

glScalef(0.5,1.0,1.0);

glBindTexture(GL_TEXTURE_2D,theTexture[GREEN_CARPET]);

gluCylinder(pillarCylinder,1.7,1.7,tableWidth-6,3,3);

//绘制整个表屏幕

voidrenderTable(){

glNewList(displayList[1],GL_COMPILE);

glColor3f(1.0,1.0,1.0);

//表铺设地毯的区域

renderSurface(tableWidth,tableLength,10.0,15.0,-1.5,1.0,1.0,0.0,1.0,0.0,theTexture[GREEN_CARPET]);

//在铺设地毯的区域抗锯齿的游戏线

glDisable(GL_TEXTURE_2D);

glDisable(GL_LIGHTING);

glEnable(GL_BLEND);

glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);

glEnable(GL_LINE_SMOOTH);

glColor4f(0.5,0.5,0.5,0.4);

glLineWidth(2.5f);

//水平式线

glTranslatef(0.0,-1.45,0.0);

glBegin(GL_LINES);

glVertex3f(minX-pocketRadius,0.0,minZ-minZ/3);

glVertex3f(maxX+pocketRadius,0.0,minZ-minZ/3);

glEnd();

//半圈

glTranslatef(0.0,0.0,minZ-minZ/3);

glRotatef(90.0,0.0,1.0,0.0);

for(GLfloati=0.0;

i<

M_PI-(M_PI/12.0);

i+=M_PI/12.0){

glVertex3f((maxZ/6.0)*sin(i),0.0,(maxZ/6.0)*cos(i));

glVertex3f((maxZ/6.0)*sin(i+M_PI/12.0),0.0,(maxZ/6.0)*cos(i+M_PI/12.0));

glLineWidth(1.0f);

//上线的启动点

glRotatef(90.0,1.0,0.0,0.0);

gluDisk(pillarCylinder,0,0.3,9,1);

glDisable(GL_LINE_SMOOTH);

glDisable(GL_BLEND);

glEnable(GL_LIGHTING);

glEnable(GL_TEXTURE_2D);

glPo

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 解决方案 > 学习计划

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1