图形程序 大作业报告.doc_第1页
图形程序 大作业报告.doc_第2页
图形程序 大作业报告.doc_第3页
图形程序 大作业报告.doc_第4页
图形程序 大作业报告.doc_第5页
已阅读5页,还剩4页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

大连民族学院计算机科学与工程学院大作业报告实验题目: 3D乒乓球 课程名称: 图形程序设计 实验类型:演示性 验证性 操作性 设计性 综合性专业:计算机科学与技术 班级:082班学生姓名:杨丽鹏 学号:2008081228实验日期:2011年 6月23日 实验地点:多媒体实验室 实验学时:16学时 实验成绩:指导教师签字: 年 月 日一、游戏介绍本游戏是我们平常玩的乒乓球,这是一个在三维场景下进行比较真实的游戏,击回去的乒乓球威力可以增大以不同的角度反击对方打过来的 球,成功反击得一分。具体玩法如下:1. 运行程序,进入游戏;2. 键盘控制键功能如下:1) 程序运行之后出现一个选择界面进行相应选择;2) “W”“S”“A”“D”:控制运动员向前、后、左、右移动;3) “Q”“E”“Z”“C”:控制运动员向左、右、上、下旋转;3. 每次由游戏本人发球,使用鼠标右键发球,鼠标左键为回击,之后机器会对发的球进行回击,玩家需要像真实的乒乒乓球运动一样做出各种动作将球还击,最后打败对手位置否则失败 二、游戏设计构想通过分析知道本游戏主要解决的问题如下:1 环境设定:预定将整个游戏设定在一个场馆中,场馆中央有比赛球桌,两边为观众坐席 。2 玩法设计:玩家通过键盘上的控制键控制运动员在场景中的移动和旋转, 将乒乓球回击给对方。3 乒乓球设计: D3DX库提供了一些用于生成简单3D几何体的网格数据方法,被回击击打物体可以通过这些方法创建。4 对打处理:当玩家回击对方打来的球时,分情况进行处理:1)如果玩家将球回击出去了,则说明球拍打到球打到球了,不做任何处理。2)如果没接到球或是球经玩家手弹出桌面外,则判机器玩家分数加一分。三、过程1环境设定场景整体设置:以一个体育场馆为场景,模拟真实的比赛场地,周围有符合比赛的主题壁画,地上有运动装用的地板以及两边的观众席,而作为中心的球桌是激烈球赛的主场地。相关主要代码实现: glmDraw(GLMmodel* model, GLuint mode) static GLuint i; static GLMgroup* group; static GLMtriangle* triangle; static GLMmaterial* material; assert(model); assert(model-vertices); /* do a bit of warning */ if (mode & GLM_FLAT & !model-facetnorms) printf(glmDraw() warning: flat render mode requested with no facet normals defined.n); mode &= GLM_FLAT; if (mode & GLM_SMOOTH & !model-normals) printf(glmDraw() warning: smooth render mode requested with no normals defined.n); mode &= GLM_SMOOTH; if (mode & GLM_TEXTURE & !model-texcoords) printf(glmDraw() warning: texture render mode requested with no texture coordinates defined.n); mode &= GLM_TEXTURE; if (mode & GLM_FLAT & mode & GLM_SMOOTH) printf(glmDraw() warning: flat render mode requested and smooth render mode requested (using smooth).n); mode &= GLM_FLAT; if (mode & GLM_COLOR & !model-materials) printf(glmDraw() warning: color render mode requested with no materials defined.n); mode &= GLM_COLOR; if (mode & GLM_MATERIAL & !model-materials) printf(glmDraw() warning: material render mode requested with no materials defined.n); mode &= GLM_MATERIAL; if (mode & GLM_COLOR & mode & GLM_MATERIAL) printf(glmDraw() warning: color and material render mode requested using only material mode.n); mode &= GLM_COLOR; if (mode & GLM_COLOR) glEnable(GL_COLOR_MATERIAL); else if (mode & GLM_MATERIAL) glDisable(GL_COLOR_MATERIAL);2玩法设计 移动包括:平移(前后左右)和旋转(俯仰、偏航和滚动),本程序中“W”“S”“A”“D”控制摄像机的平移,“Q”“E”“Z”“C”控制摄像机的旋转,方向键控制摄像机的旋转。主代码:GLvoidglmDimensions(GLMmodel* model, GLfloat* dimensions) GLuint i; GLfloat maxx, minx, maxy, miny, maxz, minz; assert(model); assert(model-vertices); assert(dimensions); /* get the max/mins */ maxx = minx = model-vertices3 + 0; maxy = miny = model-vertices3 + 1; maxz = minz = model-vertices3 + 2; for (i = 1; i numvertices; i+) if (maxx vertices3 * i + 0) maxx = model-vertices3 * i + 0; if (minx model-vertices3 * i + 0) minx = model-vertices3 * i + 0; if (maxy vertices3 * i + 1) maxy = model-vertices3 * i + 1; if (miny model-vertices3 * i + 1) miny = model-vertices3 * i + 1; if (maxz vertices3 * i + 2) maxz = model-vertices3 * i + 2; if (minz model-vertices3 * i + 2) minz = model-vertices3 * i + 2; 这样便可以通过控制键盘上相应按键控制运动员的移动,以配合球赛的正常开打了。3乒乓球的实现D3DX库提供了一些用于生成简单3D几何体的网格数据方法,乒乓球体可以通过这些方法创建。主代码: GLvoidglmSpheremapTexture(GLMmodel* model) GLMgroup* group; GLfloat theta, phi, rho, x, y, z, r; GLuint i; assert(model); assert(model-normals); if (model-texcoords) free(model-texcoords); model-numtexcoords = model-numnormals; model-texcoords=(GLfloat*)malloc(sizeof(GLfloat)*2*(model-numtexcoords+1); for (i = 1; i numnormals; i+) z = model-normals3 * i + 0; /* re-arrange for pole distortion */ y = model-normals3 * i + 1; x = model-normals3 * i + 2; r = sqrt(x * x) + (y * y); rho = sqrt(r * r) + (z * z); if(r = 0.0) theta = 0.0; phi = 0.0; else if(z = 0.0) phi = 3.14159265 / 2.0; else phi = acos(z / rho); if(y = 0.0) theta = 3.141592365 / 2.0; else theta = asin(y / r) + (3.14159265 / 2.0); model-texcoords2 * i + 0 = theta / 3.14159265; model-texcoords2 * i + 1 = phi / 3.14159265; /* go through and put texcoord indices in all the triangles */ group = model-groups; while(group) for (i = 0; i numtriangles; i+) T(group-trianglesi).tindices0 = T(group-trianglesi).nindices0; T(group-trianglesi).tindices1 = T(group-trianglesi).nindices1; T(group-trianglesi).tindices2 = T(group-trianglesi).nindices2; group = group-next; 四、游戏界面1游戏初始界面2游戏进行画面3游戏大体场馆五遇到的问题及解决方法 游戏运行后发现有个bug,当我们控制的运动员进行乒乓球赛时,不

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论