下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、实用文案#include stdafx.h#include #include #include #include #include using namespace std; void drawwalls(void); void drawtop(void); void drawball(void);#define IDM_APPLICATION_EXIT (101)#define IDM_APPLICATION_TEXTURE (102)#define IDM_APPLICATION_BANK (103)#define MAZE_HEIGHT (16)#define MAZE_WIDTH (16
2、)#define STARTING_POINT_X (13.5f);#define STARTING_POINT_Y (1.5f);#define STARTING_HEADING (90.0f);float player_x = STARTING_POINT_X ;float player_y = STARTING_POINT_Y ;float player_h = STARTING_HEADING ; / players headingfloat player_s = 0.0f;/ forward speed of the playerfloat player_m = 1.0f;/ spe
3、ed multiplier of the playerfloat player_t = 0.0f;/ players turning (change in heading)float player_b = 0.0f;/ viewpoint bank (roll)static float texcoordX=0.0f;intwalllist=0;intmazelist=0;intballlist=0;int status=1;bool searchroute=false;bool keystate4=false,false,false,false;char mazedataMAZE_HEIGHT
4、MAZE_WIDTH = riiii iiii iiii iiii iiii iiii iiii iiii iiii iiii iiii iiii iiii iiii iiii iiinH,H,H,H,H,H,H,H,H,H,H,H,H,H,H,H,H, , , , , , , ,H, , , , , , ,H,I I I , j j j j j j ,11, j j j j j j * * j ji i i|_ii i |_| |_| |_| |_| H, ,H, ,H,H,H, ,H, ,H, , , , ,H,i I I|_|I Ll Ll Ll Ll LinH, ,H,H, , ,H,
5、 ,H,H, ,H, ,H, ,H,H, , , , , ,H, , , , , , ,H, ,H,I I I , j j j j ,11, j j j j j ,11, j * * J jriiii i i iiii iiii iiii iiii iiii iiii iiii iiii i i iiii iiii iiii i i iiinH, ,H,H,H,H,H,H,H,H, ,H,H,H, ,H,标准文档H, , , , , , , , , , , ,H, , ,H,I I I , J J J J J J J J J J ,11, J J * * J Jriiii i i iiii i
6、iii iiii iiii iiii i i iiii iiii iiii i i iiii iiii iiii iiinH, ,H,H,H,H,H, ,H,H,H, ,H,H,H,H,i i H, ,H, , , ,H, , , ,H, , , , ,H, Ll Ll Ll Ll Ll LlH, , , ,H,H,H,H,H,H,H, , , , ,H,i i ill LinH, ,H, , , ,H, , , ,H, , ,H, ,H,riiii i i iiii iiii iiii iiii iiii i i iiii iiii iiii iiii i i iiii i i iiinH,
7、 ,H,H,H,H,H, ,H,H,H,H, ,H, ,H,H, , , , , ,H, , , , , , ,H, ,H,I i i , j j j j ,11, j j j j j ,11, j * * j jriiii iiii iiii iiii i i iiii iiii iiii iiii i i iiii iiii iiii i i iiinH, , ,H,H, ,H,H,H,H, ,H,H,H, ,H, LlH, , , ,H, ,H, , , , ,H, , , ,H,riiii iiii iiii iiii iiii iiii iiii iiii iiii iiii iii
8、i iiii iiii i i iiii iiin H,H,H,H,H,H,H,H,H,H,H,H,H, ,H,H,;void myinit()glClearColor(0.5f, 0.5f, 0.5f, 0.0f);glColor3f(1.0,1.0,1.0); glEnable(GL_DEPTH_TEST); glEnable(GL_TEXTURE_2D);walllist=glGenLists(2);mazelist=walllist+1;balllist=walllist+2; glNewList(walllist,GL_COMPILE);drawwalls();glEndList()
9、;glNewList(mazelist,GL_COMPILE);drawtop();glEndList();glNewList(balllist,GL_COMPILE);drawball();glEndList();glMatrixMode(GL_PROJECTION);glLoadIdentity();gluPerspective(60.0, 1.0 , 0.1, 60.0);glMatrixMode(GL_MODELVIEW);glHint(GL_PERSPECTIVE_CORRECTION_HINT,GL_NICEST);e 1? I 2? ?D?bool wall(int x,int
10、y) return (x=0& y=0 & xMAZE_WIDTH & yMAZE_HEIGHT &mazedatayx!= );bool onopen(int x,int y)if(wall(x,y)return(mazedatayx=H);void closeit(int x,int y) if(onopen(x,y)mazedatayx= X;bool neighbor(int x,int y,int w,int *nx,int *ny)switch(w) case 0:*nx = x-1; *ny=y;break;case 1:*nx = x;*ny=y+1; break;case 2
11、:*nx = x+1; *ny=y;break;case 3:*nx = x;*ny=y-1; break;default:break;return wall(*nx,*ny);bool diagnal(int x,int y,int w,int *nx,int *ny) switch(w) case 0:*nx = x-1; *ny=y-1; break;case 1:*nx = x-1; *ny=y+1; break; case 2:*nx = x+1; *ny=y+1; break; case 3:*nx = x+1; *ny=y-1; break; default:break;retu
12、rn wall(*nx,*ny);void dw(int x,int y,int p) int w=p;closeit(x,y);doint x2=0;int y2=0; if(neighbor(x,y,w,&x2,&y2)if(onopen(x2,y2) dw(x2,y2,(w+3)%4);else if(w+1)%4 =p)return ;else float fx;float fy;if(diagnal(x,y,w,&x2,&y2) & onopen(x2,y2) dw(x2,y2,(w+2)%4);texcoordX=(texcoordX0.5)?1.0f:0.0f;fx = (flo
13、at)x+(w=1|w=2)?1.0f:0.0f);fy = (float)y+(w=0|w=1)?1.0f:0.0f);glTexCoord2f(texcoordX,0.0f);glVertex3f(fx,fy,0.0f);glTexCoord2f(texcoordX,1.0f);glVertex3f(fx,fy,1.0f);w+;w%=4;while (w!=p);return ;void drawwalls() glEnable(GL_TEXTURE_2D); glBegin(GL_QUAD_STRIP); glColor3f(1.0,1.0,1.0); glVertex3f(0.0f,
14、 0.0f, 0.0f); glVertex3f(0.0f, 0.0f, 1.0f); dw(0,0,0);glEnd();void drawtop() int x,y;glBegin(GL_QUADS);for(y=0;yMAZE_HEIGHT;y+) for(x=0;x x+1.0f - bf) & wall(x+1,y) px = (float)(x)+1.0f-bf;h+;if(py y+1.0f-bf & wall(x,y+1)py = (float)(y)+1.0f-bf;h+;if(px x+bf & wall(x-1,y) px = (float)(x)+bf;h+;if(py
15、 y+bf & wall(x,y-1) py = (float)(y)+bf;h+;player_x=px;player_y=py;void drawball()glDisable(GL_TEXTURE_2D);glColor3f(1.0,0.0,0.0);glutSolidSphere(0.2f,15,15);void navmaze1()forward(player_x+player_s*(float)sin(player_h*3.14/180),player_y+player_s*(float)cos(player_h*3.14/180),0.2f);coutplayer_xplayer
16、_yendl;player_h+=player_t;player_b = 3*player_b/4 + player_t/4; glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity();glPushMatrix();glRotatef(-90.0f,1.0f,0.0f,0.0f);glRotatef(player_h,0.0f,0.0f,1.0f); glTranslatef(-player_x,-player_y,-0.5f);glCallList(walllist);glPopMatrix();void nav
17、maze2()forward(player_x+player_m*player_s*(float)sin(player_h*3.14/180), player_y+player_m*player_s*(float)cos(player_h*3.14/180),0.2f);coutplayer_xplayer_xendl;player_h+=player_t;player_b = 3*player_b/4 + player_t/4; glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity();glOrtho(-16.0
18、,16.0,-16.0,16.0,-2.0,20.0); glPushMatrix();glRotatef(90.0f,0.0f,0.0f,1.0f);glTranslatef(-MAZE_WIDTH /2,-MAZE_HEIGHT/2,-0.5f);glCallList(walllist);glCallList(mazelist);glPushMatrix();glTranslatef(player_x,player_y,0.5f);glCallList(balllist);glPopMatrix();glPopMatrix();void myDisplay()if(status=1)if(
19、searchroute=true)else navmaze1();if(status=3)if(searchroute=true)else navmaze2();glFlush();glutSwapBuffers();void myReshape(int w, int h)glViewport(0,0,w,h);glMatrixMode(GL_PROJECTION); glLoadIdentity(); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glutPostRedisplay();void specialKeys(int key,int x
20、,int y)switch (key)case GLUT_KEY_LEFT: keystate2 = true; player_t = -2.0f;break;case GLUT_KEY_RIGHT: keystate3 = true; player_t = 2.0f; break;case GLUT_KEY_UP: keystate0 = true; player_s = 0.01f; break;case GLUT_KEY_DOWN: keystate1 = true; player_s = -0.01f; break;default:break;void keyboard(unsigned char key,int x,int y)switch (key)case 1:status=1;break;case 3:status=3;break;default:break;glutPostRedisplay();void upSpecialKeyboard(int key,int x,int y)switch (key)case GLUT_KEY_LEFT: keystate2 = false; player_t = 0.0f;
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 农村承包合同(2篇)
- 出版物著作权合同(2篇)
- (一模)株洲市2025届高三教学质量统一检测 英语试卷
- 2024-2025学年广东省深圳市宝安区八年级(上)期末语文试卷
- 2025公司运营总监聘用合同
- 2024年度天津市公共营养师之三级营养师综合检测试卷B卷含答案
- 2024年度天津市公共营养师之二级营养师模拟题库及答案下载
- 2024年度天津市公共营养师之三级营养师模拟考试试卷B卷含答案
- 2024年度四川省公共营养师之二级营养师考前练习题及答案
- 2025标准版办公室装修合同样本
- 中国铝业股份有限公司河南分公司巩义市山川铝土矿矿山地质环境保护与土地复垦方案
- 工商企业管理毕业论文范文六篇
- 二十五项反措检查表优质资料
- 保密办主任工作总结保密办主任工作总结八篇
- 新生儿沐浴及抚触护理
- 机械原理课程设计-压床机构的设计
- 教学案例 英语教学案例 市赛一等奖
- 四川省2023职教高考英语试题
- JJG 913-2015浮标式氧气吸入器
- GB/T 12190-2006电磁屏蔽室屏蔽效能的测量方法
- 2020年贵州专升本高等数学真题及答案
评论
0/150
提交评论