opengl3D迷宫C实现源代码

上传人:re****.1 文档编号:402075519 上传时间:2022-12-03 格式:DOC 页数:9 大小:33KB
返回 下载 相关 举报
opengl3D迷宫C实现源代码_第1页
第1页 / 共9页
opengl3D迷宫C实现源代码_第2页
第2页 / 共9页
opengl3D迷宫C实现源代码_第3页
第3页 / 共9页
opengl3D迷宫C实现源代码_第4页
第4页 / 共9页
opengl3D迷宫C实现源代码_第5页
第5页 / 共9页
点击查看更多>>
资源描述

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

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)#defin

2、e 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; / speed mu

3、ltiplier 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 keystate4=false,false,false,false;char mazedataMAZE_HEIGHT

4、MAZE_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, ,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,;void myinit()glClearColor(0.5f, 0.5f, 0.5f, 0.0f);glColor3f

6、(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(balllist,GL_COMPILE);drawball();glEndList(); glMatrixMode

7、(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 onopen(int x,int y)if(wall(x,y) return(mazedatayx=H);voi

8、d 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; default:break; return wall(*nx,*ny);bool diagnal(int x,in

9、t 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; closeit(x,y); doint x2=0;int y2=0;if(neighbor(x,y,w

10、,&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)?1.0f:0.0f); glTexCoord2f(texcoordX,0.0f); glVerte

11、x3f(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

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 中学教育 > 试题/考题 > 初中试题/考题

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