opengl 3D迷宫 C实现 源代码

上传人:pu****.1 文档编号:471727755 上传时间:2024-01-15 格式:DOC 页数:8 大小:138.50KB
返回 下载 相关 举报
opengl 3D迷宫 C实现 源代码_第1页
第1页 / 共8页
opengl 3D迷宫 C实现 源代码_第2页
第2页 / 共8页
opengl 3D迷宫 C实现 源代码_第3页
第3页 / 共8页
opengl 3D迷宫 C实现 源代码_第4页
第4页 / 共8页
opengl 3D迷宫 C实现 源代码_第5页
第5页 / 共8页
点击查看更多>>
资源描述

《opengl 3D迷宫 C实现 源代码》由会员分享,可在线阅读,更多相关《opengl 3D迷宫 C实现 源代码(8页珍藏版)》请在金锄头文库上搜索。

1、【精品文档】如有侵权,请联系网站删除,仅供学习与交流opengl 3D迷宫 C 实现 源代码.精品文档.#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)#

2、define MAZE_HEIGHT (16)#define MAZE_WIDTH (16)#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

3、speed of the playerfloat player_m = 1.0f; / speed 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;int walllist=0;int mazelist=0;int balllist=0;int status=1;bool searchroute=false;bool keysta

4、te4=false,false,false,false;char mazedataMAZE_HEIGHTMAZE_WIDTH = H,H,H,H,H,H,H,H,H,H,H,H,H,H,H,H, H, , , , , , , ,H, , , , , , ,H, H, ,H, ,H,H,H, ,H, ,H, , , , ,H, H, ,H,H, , ,H, ,H,H, ,H, ,H, ,H, H, , , , , ,H, , , , , , ,H, ,H, H, ,H,H,H,H,H,H,H,H, ,H,H,H, ,H, H, , , , , , , , , , , ,H, , ,H, H, ,

5、H,H,H,H,H, ,H,H,H, ,H,H,H,H, H, ,H, , , ,H, , , ,H, , , , ,H, H, , , ,H,H,H,H,H,H,H, , , , ,H, H, ,H, , , ,H, , , ,H, , ,H, ,H, H, ,H,H,H,H,H, ,H,H,H,H, ,H, ,H, H, , , , , ,H, , , , , , ,H, ,H, H, , ,H,H, ,H,H,H,H, ,H,H,H, ,H, H, , , ,H, ,H, , , , ,H, , , ,H, H,H,H,H,H,H,H,H,H,H,H,H,H, ,H,H,void myi

6、nit()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();glNewList(mazelist,GL_COMPILE);drawtop();glEndList();glNewList(ballli

7、st,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);/bool wall(int x,int y) return (x=0 & y=0 & xMAZE_WIDTH & yMAZE_HEIGHT & mazedatayx!= );bool onope

8、n(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: *nx = x+1; *ny=y; break; case 3: *nx = x; *ny=y-1; break; defaul

9、t: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; return wall(*nx,*ny);void dw(int x,int y,int p) int w=p;

10、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 = (float)x+(w=1|w=2)?1.0f:0.0f); fy = (float)y+(w=0|w=1

11、)?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, 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;xMAZE_WIDTH;x+) if(wall(x,y) mazedatayx= X;

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 高等教育 > 研究生课件

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号